I'm trying to use forge.prefs to store variables but nothing seems to be saving.
I am using the following:
var all = forge.prefs.keys(function(keysArray){ return keysArray},
function(content){return content});
forge.logging.log(all);
But this always returns undefined
I am also having the same issue with setting, nothing seems to be working.
var set = forge.prefs.set(key,value,function(){},function(content){return content;});
forge.logging.log(set);
Again returns undefined and no error or anything.
Am I doing something wrong?
Using the docs found here
UPDATE
I won't to do something like the following:
var get = forge.prefs.get(key,
function(value){return value;},
function(error){forge.logging.log(error);
});
if(get){
// do something here
}else{
// do something here
}
Those methods are asynchronous which means that subsequent code might be executed before the callback success and error functions are returned. All subsequent code that relies on the outcome of this should run within the callback:
forge.prefs.keys(function(keysArray){ // success
forge.logging.log(keysArray);
// subsequent code relying on a positive outcome here ...
},
function(error){ // error
forge.logging.log('Something bad happened: ' + error);
});
forge.prefs.set(key, value, function(){ // success
forge.logging.log(key + ' was properly set);
// subsequent code relying on a positive outcome here ...
},
function(error){ // error
forge.logging.log('Something bad happened: ' + error);
});
UPDATE: use this to achieve the updated part of your question:
var get;
forge.prefs.get(key, function(value){ // success
get = value;
forge.logging.log('Found value: ' + get);
// subsequent code here ...
},
function(error){ // error
forge.logging.log('Something bad happened: ' + error);
});
It appears you're not returning anything in the forge.pref.set success function. Your return content; is in the error function so if it's not throwing an error you won't return anything.
Try this:
var set = forge.prefs.set(key,value,function(){ return value; },function(content){return content;});
forge.logging.log(set);
Related
I have a block of code that I found online and it seems to be working and not working at the same time. I think its probably my lack of understanding but I cant seem to get it to work the way I want it.
selectPicture() {
let context = imagepicker.create({
mode: "single" // use "multiple" for multiple selection
});
var imageBase64
context
.authorize()
.then(function() {
return context.present();
})
.then(function(selection) {
selection.forEach(function(selected) {
imageSourceModule.fromAsset(selected).then((imageSource) => {
imageBase64 = imageSource.toBase64String("jpg",60);
console.log("Image saved successfully!")
console.log(imageBase64)
console.log("test test") //runs fine
this.image = "~/assets/images/account/camera.png" //cant seem to run
console.log("test test 2")
}).catch(function (e) {
// process error
console.log("got error 1")
});
})
}).catch(function (e) {
// process error
console.log("got error 2")
});
},
Within the imageSourceModule.fromAsset(selected).then((imageSource), I was trying to save the base64 info in another variable but cant seem to do anything within other than console log a string. When I run this.image = "~/assets/images/account/camera.png" (just a placeholder, even calling a method does not work too) for example it catches an error.
What could the problem be? thank you!
UPDATE
I changed console.log("got error 1") to log the actual update and what i got was:
undefined is not an object (evaluating 'this.image = "~/assets/images/account/camera.png"')*
I now think that theres a problem with my understanding calling variable outside. My variable 'image' is within the script at
data() {
return {
image : ""
}
}
first of all check what this variable is, because you do not use es6 arrow functions, so this is probably not the vue instance.
the second thing: when you change vue-variables asynchronously use the $set method, like: this.$set(this, 'image', '~/assets/images/account/camera.png')
I'm able to sucessfully hook into an Android method using Frida, but I am trying to find out who is calling that method. I can find that out if I can rewrite the method with Frida to print the stacktrace when the method gets called. I've tried a few things, but all of them have had some sort of error. This is the latest thing I have tried.
setImmediate(function() {
console.log("[*] Starting script");
Java.perform(function () {
var Activity = Java.use("com.package.MyClass");
Activity.getUpdates.overload('boolean', 'java.lang.String', 'java.lang.String').implementation = function (v1, v2, v3) {
console.log("v1: " + v1);
console.log("v2: " + v2);
console.log("v3: " + v3);
Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new())
};
});
})
This is resulting in the following error
Error: Not allowed outside Java.perform() callback
at d (frida/node_modules/frida-java/index.js:86)
at frida/node_modules/frida-java/index.js:366
at [anon] (repl1.js:11)
at input:1
Any idea how I can achieve this?
I fixed it by using this:
Java.perform(function() {
console.log(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new()))
});
It is necessary to add an additional Java.perform call
I´v got a "detail" view and a controller that initilizes data with an id.
My view:
<div ng-app="AFApp" ng-controller="AgentCtrl" ng-init="init('#Model.Id')">
My controller:
$scope.id;
$scope.agent = {};
$scope.init = function (id) {
$scope.id = id;
getAgent();
getAgentStatus();
getSystemInfo();
getActions();
};
The problem is that the method "getAgentStatus();" gets executed before "getAgent();". The "getAgentStatus" needs the $scope.agent data that "getAgent" provides. The function getAgentStatus has an attached timer, and it gets the value as the timer elepses but not in the init function. Can someone please help me out with the method execution sequence in angular controllers and how the id parameter is provided the best possible way.
See methods below:
function getAgent() {
agentDataFactory.getAgent($scope.id)
.success(function (data) {
$scope.agent = data;
})
.error(function (error) {
console.log('Unable to load data: ' + error.message);
});
};
function getAgentStatus() {
if (typeof ($scope.agent.ServiceUrl) == 'undefined' || $scope.agent.ServiceUrl == null) {
console.log('getAgentStatus: ServiceUrl is undefined ' + JSON.stringify($scope.agent));
}
agentDataFactory.getAgentStatus($scope.agent.ServiceUrl)
.success(function (data) {
$scope.agent.CurrentStatus = data.Status;
$scope.agent.CurrentInterval = data.Interval;
})
.error(function (error) {
console.log('Unable to load data: ' + error);
});
$timeout(getAgentStatus, 3000);
};
You can pass getAgentStatus() as a callback parameter to getAgent() and have it executed in the success callback (at which point agent will be defined):
function getAgent(callback) {
agentDataFactory.getAgent($scope.id)
.success(function (data) {
$scope.agent = data;
callback && callback();
})
.error(function (error) {
console.log('Unable to load data: ' + error.message);
});
};
$scope.init = function (id) {
$scope.id = id;
getAgent(getAgentStatus);
getSystemInfo();
getActions();
};
Short explanation:
Some highlights first:
agentDataFactory.getAgent($scope.id).success(...).error(...);:
Creates a promise (which will be resolved) asynchronously and registers two callbacks, one if the promise is successfully resolved and one for the case of an error.
.success(function (data) { $scope.agent = data; }):
Registers a callbackfor when the promise is successfully resolved. When (and if) that happens, $scope.agent will be set.
function getAgentStatus() { if (typeof ($scope.agent.ServiceUrl...:
Tries to access some properties of $scope.agent and thus requires the object to be defined.
So, what happens with your code:
getAgent() is gets called.
[$scope.agent is undefined]
A promise is created that when resolved will set $scope.agent.
[$scope.agent is undefined]
getAgent() returns and getAgentStatus() is called.
[$scope.agent is undefined]
getAgentStatus() tries to access $scope.agent's properties and fails.
[$scope.agent is undefined]
The promise created in step 2 is resolved and its success callback get executed.
[$scope.agent is finally defined]
My version of the code ensures that getAgentStatus() is not executed before the promise is resolved and thus $scope.agent is defined:
getAgent() is gets called.
[$scope.agent is undefined]
A promise is created that when resolved will set $scope.agent.
[$scope.agent is undefined]
getAgent() returns and other functions get called (e.g. getSystemInfo(), getActions(), etc.).
[$scope.agent is undefined]
The promise created in step 2 is resolved and its success callback get executed.
[$scope.agent is finally defined]
Only now does getAgentStatus() get called and it works as expected since...
[$scope.agent is defined]
Take a look at the $q service for more info on Angular promises.
during Save changes, there are instance when validation is failing, but how do i get back and display the actual Error Message. The saveFailed function is executed, but i want more details information, about what validations failed and those individual error emssages
function saveChanges() {
if (manager.hasChanges()) {
manager.saveChanges()
.then(saveSucceeded)
.fail(saveFailed);
} else {
alert("Nothing to save");
};
};
function saveSucceeded() {
alert("changes saved successfully");
};
function saveFailed(error) {
alert("Error while saving changes" + error.message);
};
Have a look at the TODO sample that is provided with the breeze download.
The dataservice.js clearly shows you how to catch and display validation errors.
The 'error' object returned by the fail handler, should contain additional details, depending on the error. The following properties should always be there
error.message - the error message
error.status - http error code - usually a 400 or 500 code
error.detail - any details relevant to the error
error.XHR - the raw XML HttpResponse object
error.responseText
For validation errors, right now they appear in the error.message, but we are looking at breaking them out in a cleaner fashion, possibly into another property. But for now they will appear in the error.message.
var display_message="";
$('input:checked').each(function(index) {
var profile_id=$(this).val();
$.ajax({
type: 'post',
url: 'myUrl',
data: data,
success: function(data) {
if(data=="ok")
display_message = display_message + data +", ";
}
});
});
alert(display_message);
alert(display_message);
if($.trim(display_message)!=""){
jAlert("Your birthdate already exits in "+display_message.substring(0, display_message.length - 2)+".", "Bdate");
return false;
}
in this code, i use two alert-box for display display_message variable value.
when i run successfully this code, in 1st alert-box i get blank value and second alert-box i get value which i needed, then it will go in if condition.
if i doesn't use alert box then it will always take null value in display_message variable and never enters into the if condition. so what i need to change to run this code without alert box?
You are making an asynchronous call via AJAX, but your code is executing synchronously. So it is returning before the AJAX call completes. The first alert box just gives the function time to catch up. You need to handle all this code in your success callback.
var display_message="";
$('input:checked').each(function(index) {
var profile_id=$(this).val();
$.ajax({
type: 'post',
url: 'myUrl',
data: data,
success: function(data) {
if(data=="ok")
display_message = display_message + data +", ";
if($.trim(display_message)!=""){
jAlert("Your birthdate already exits in "+display_message.substring(0, display_message.length - 2)+".", "Bdate");
return false;
}
});
});
You want all your ajax queries to finish and return results, right?
Then this is a synchronization problem.
I would suggest this approach (code is simplified for clarity).
var inputs_processed = -1;
var inputs_to_process = -1;
function queryData() {
inputs_to_process = $('input:checked').length;
$('input:checked').each(function() {
$.ajax({success: function(data) {
inputs_processed += 1;
// build up that message
}});
});
}
function displayResult() {
if (inputs_processed == inputs_to_process) {
// display result
} else {
// not all queries finished yet. Wait.
setTimeout(displayResult, 500);
}
}
queryData();
displayResult();
Basically, you know how many requests should be made and you don't display result until that number of requests returns.
Why your data is "data"? I cant see any variable called data is declared here. You should pass in the value you want to use as the parameter into the data options.
Edit: This is why u getting the null value. data is not initialize into anything. Only after the success function, your "data" will have the value since you declare the return value with the same name