titanium alloy global functions - mobile

i have a question, are the global functions set in alloy.js runs every time the app is started or every time a new window is open?
because i actually would like to create a unique user id for the user and assign it a global variable so it can be used through the app but i ain't sure if it will re-create and re-assign the generated user id whenever the app tries to open another window or will it use same user_id that the app generated after instantiating the mobile app.
hope someone could answer me. >.<

The functions in alloy.js will run every time the app is loaded, and they will load near the beginning of the execution of the app. So the answer is NO, your unique ID will NOT be re-created every time a new window opens.
From the Titanium DOC:
The initializer file app/alloy.js can be used to execute some code near the beginning of the application's lifecycle. The contents of this file will be executed right before the initial index.js controller is loaded, allowing you to execute code before any UI components are loaded and to override builtin Alloy functions before they are executed.
Also, here's an example of how to run a function and store the result in a global variable (your unique_id function would work the same way):
Alloy.Globals.myId = function(){
var id = (CODE TO GENERATE ID)
return id;
}

Related

Move specific application to a specific screen

I have read over here how to move an application to a specific screen.
In my case I have a variation of this. In this case I want to open for example Todoist on a specific screen. This code below opens Todoist but on my wrong screen.
How can I solve this?
local screens = hs.screen.allScreens()
hs.application.open("Todoist")
local win = hs.application:findWindow("Todoist")
win.moveToScreen(screens[1])
findWindow() is an instance method, so it cannot be called directly as hs.application:findWindow(). To properly call this method, you must create an instance of the hs.application class and then call findWindow() on that instance.
The following snippet should work, although you may need to adjust the wait time (and the screens index). It is generally recommended to use hs.application.watcher to watch for when an app has been launched, rather than using a timer.
local notes = hs.application.open("Notes")
hs.timer.doAfter(1, function()
-- `notes:mainWindow()` will return `nil` if called immediately after opening the app,
-- so we wait for a second to allow the window to be launched.
local notesMainWindow = notes:mainWindow()
local screens = hs.screen.allScreens()
notesMainWindow:moveToScreen(screens[1])
end)

Runnig N times the simulation in anylogic

In my anylogic Project, I want to terminate my execution and run the simulation for N times. in each of the simulation I store my output in an excel file which depends on the run count.
Instead of stopping and running by my click, I want to do it automatically. How can I do that?
I try to use an event and write by while loop (myparm<=N) and in loop I wrote getEngine().run, but it didn't work!
if it is possible please help me.
Thanks
Below is an overview of a methodology of how you can do it using the existing simulation framework used by AnyLogic
You need to make use of the simulation setup in order to run multiple runs of the model and save the output. My suggested setup will be the following:
Have a button on your Simulation Experiment page (The first page you see when running the model) that you will use to start off the multiple model runs. In here you set the engine to not run in real time mode by using
getEngine().setRealTimeMode(false);
you might also want to set the initial seed and some other model parameters that you might also want to change and perhaps save after model execution. When you have setup the model the way you want use run() to start running the model.
Now under the Simulation Experiment setup page under the 'Java actions' section you need to specify what the model must do after it finished running the model. In the 'After simulation run' section write some code to save the data from the model into your Excel files. To access variables and objects from the model use root, e.g.
saveSomeData(root.myDataset);
where saveSomeData is a function on the Simulation page to save my data set found on the model, called myDataset, to an Excel file. It would be great to also save the seed and the specific parameters, if you changed any, to the Excel file for future reference.
Once you have saved the data output from the model you can specify a new seed and perhaps change parameters again and then call the run() again to run the model for another iteration. When the model has finished running it will again call the 'After simulation run' code here, so do put a stop condition otherwise it will just continue running one iteration after the other. You can access the number of model runs by using
getEngine().getRunCount()
Also, your model needs to have some stop condition, otherwise once it starts running it will never stop. You can specify this in the Simulation Experiment page under the 'Model time' section or programatically in your model using
finishSimulation();
In order to run the model cyclically, please use the following code in the Action field of a timeout triggered event or On destroy field of the top-level agent:
new Thread(){
public void run(){
// stops the model
getExperiment().stop();
try {
// delay
this.sleep(1000);
} catch(Exception e) {};
// runs it again
((Simulation) getExperiment()).button.action();
}
}.start();
The model results should be written to the Excel file before executing this code.
As Jaco-Ben suggested, you can specify getEngine().getRunCount() as condition of restarting the Simulation experiment.

SugarCRM - Prevent record for a customized module

I would like to be able to create a module as an interaction between sugarCRM and an other database. For that I built a module thanks to the module builder tool, and I would like to connect it to a new table which is a join between sugar data and my second app data (to prevent data duplication).
As my new table for the module is a view between two others, sugar views the content without any problem, but throws an exception whenever I try to insert anything. So I would like to use a logic hook who will directly store the data within the two "original" tables.
Here is my problem : even if the data are correctly stored, I would like to prevent sugar to try to store anything. Is there something I can do within my hook to stop sugar action, once my hook finished its job ?
Sorry for my terrible english and thanks for reading.
What I recommend is overriding the Save method in your custom module's controller.
Once you build and deploy the module, there will be a new directory: custom/modules/yourcustommodule. In that directory, create a file named controller.php.
That file should include the following (untested) code:
require_once('include/MVC/Controller/SugarController.php');
class yourcustommoduleController extends SugarController {
function action_save() {
return;
}
}
You could even move your before/after hooks into this custom action function. As long as you don't call the default save method (parent::action_save(); I think), SugarCRM's default save action(s) won't happen.
Important: after deploying a custom module, SugarCRM's best practice is to never redeploy it, but to make all subsequent changes in Studio. This is important because once you make these file-level changes to a custom module, those changes would be lost if you redeploy the module.

Calling .Net function on UI test instance in TestComplete

I have a simple wpf app which has a button that increments a value on clicking. I also have a function that returns the latest value. The default value is 5. I also have a UI test in testcomplete that clicks the button 3 times (so 8). I need to call the .Net function to get this value and assert it. Below is my test code.
After some search I figured out the CLRbridge details and implemented it. However, As you can see below, the UI test instance and the instance on which I am claling the function are different. So, the function returns 5.
My question is, how do I invoke the function from the same instance loaded by testcomplete. Or am I going completely the wrong way for this? I tried both script and UI test with if..then, nothing worked. I have tried both direct instance and calling on the appdomain, both doesnt seem to work.
NOTE: I do understand that I can display the value in a UI control and validate the control. However, i am specifically trying this out for a more complex testing functionality we need in a project.
function Test2()
{
var Increment;
Increment = 0;
//Runs the "TCompTest" tested application.
TestedApps.TCompTest.Run();
//Clicks the 'button1' button.
Aliases.TCompTest.HwndSource_MainWindow.MainWindow.Grid.button1.ClickButton();
//Clicks the 'button1' button.
Aliases.TCompTest.HwndSource_MainWindow.MainWindow.Grid.button1.ClickButton();
//Clicks the 'button1' button.
Aliases.TCompTest.HwndSource_MainWindow.MainWindow.Grid.button1.ClickButton();
//Increment = dotNET.Incrementer.Incr1.zctor().IntValue(true);
Increment = dotNET.Incrementer.Incr1.zctor().IntValue(true);
**OR**
Increment = Sys.Process("TCompTest").AppDomain("TCompTest.exe").dotNET.Incrementer.Incr1.zctor().IntValue(true)
// if(Increment == 8)
// {//Posts an information message to the test log.
Log.Message(Increment);
// }
//Closes the 'HwndSource_MainWindow' window.
Aliases.TCompTest.HwndSource_MainWindow.Close();
}
It should be possible to do what you need from TestComplete. But first of all, to avoid misunderstanding, let me explain the problems with the approaches you tried:
Addressing a class through the "dotNET" object.
When you do this, TestComplete initializes .NET in its service process, loads the specified assembly into it, and works with the classes of this assembly loaded to TestComplete's AppDomain (though living in a separate process). This means that this instance of your assembly has nothing to do with your tested application. So, you can't access your application's data through the dotNET object.
Addressing the Incrementer assembly through the tested application's AppDomain.
OK, in this case you are closer to a solution - you work with the AppDomain of the tested application, so you can access the application's data. However, in your code, you create a new instance of the Incr1 class (via calling zctor). This means that the new class instance will initialize its counter in the constructor, and it will be 5. And this is the value you are getting in your code.
So, the right approach:
Unless the counter field of the Incr1 class containing the current counter value is a static field, you need to address an existing object of the Incr1 class to get the current value of the property, not to create a new class instance. The actual implementation will depend on where you are storing the Incr1 class instance reference in your application. Let's suppose, you store the reference in the Counter property of the MainWindow object:
// Creating an instance of the class somewhere in your code
MainWindow.Counter = new Incr1();
// ...
// And this line of code is in the button click handler
MainWindow.Counter.Increment();
In the described case, you will be able to get the current counter value in your TestComplete script as follows:
var MainWnd = Aliases.TCompTest.HwndSource_MainWindow.MainWindow;
Log.Message(MainWnd.Counter.IntValue(true));
If your setup is different, please describe it - I will try to help accordingly.

Google App Engine + Objectify: Register object once?

I recently got objectify working with app engine, but I'm having trouble with registering a class for objectify multiple times. While developing in Eclipse, which recompiles and runs again every time the localhost is refreshed, the script that registers the student is run multiple times, and crashes the program after just one refresh.
<%
//In my main.jsp file, which is the main interactive html page
ObjectifyService.register(Object.class);
%>
How can I ensure that this script is only run once? Is there a way to check if a class is registered with objectify? I followed a suggestion on another stackoverflow thread to do the following:
public class Object {
...
static {
ObjectifyService.register(Object.class);
}
...
}
This gave me a different error. How can I solve this?
Put it on your ServletContextListener, specifically, on the contextInitialized() hook. This will ensure that the Objectify register code is only executed once when the server is warming up.
by looking on a reliable example like this:
Objectify in JSP
you can find similar attempt to register the class, BUT... Read the comments from the example:
// BE CAREFUL with this line! This a example, but in a real world project, you should look a better
// place for register an entity, at the very beginning of your application is recommended.
So... You probably have a java class in which you implemented several methods like: get/put/delete etc... and in that java class you should place the code to register the class
static {
ObjectifyService.register(Object.class);
}
OR, look for some other place that is being called once upon the application starts

Resources