How to wait the p2 profile gets completed - eclipse

We are using p2 to update our RCP application, and this worked so far quite well until today I realized in some case the P2 IProfile was emty (not null but empty) and always of course return emty result queries.
This happend when launching the application only, meaning that if I request the same profile later in time, I get a complete profile.
The Javadoc of IProfile mention the fact that profile is a snapshot of a particular state.
So it seems I am querying the ProfileRegistry to early and the profile is not yet complete.
I could not find any way on the javadoc to wait for a profile to be filled properly.
I would be grateful to anyone that would help me solve this problem nicely, because using a sleep (which works) is not an acceptable solution.
Thanks.

here is the ugly solution I am implemented, basically testing the time stam to be sure the profile has been loaded
// there seems to be a bug because if the agent is created too quickly then the profile is empty.
// so we loop until we get a proper profile
do {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
interrupted = true;
}
if (agent != null) {
agent.stop();
}
agent = agentProvider.createAgent(getP2AgentUri());
IProfileRegistry profRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
profile = profRegistry.getProfile(getP2ProfileId());
} while (profile != null && profile.getTimestamp() == 0 && !interrupted && !progress.isCanceled());
The profile I use is SELF but I use a method to get the ProfileId because I have JUnit tests that are base on another external p2 profile.

Related

Flutter: Calling a function once in a lifetime of the flutter app

I want to call a function when app runs for the first time, which will ask the user to enter firstName , lastName and add a profile picture.
Once the above process is done the function will never again be called during the lifetime of the app.
For something like this you need to check if the user has already entered that data or not. If not then show him the page where he can enter information otherwise take him to HomePage. For this When the user enters the information you need to save it to some persistent storage and check it whenever the app runs. In this way, your function will be called only once until the user deletes the app or clear its memory. You could use the following libraries to store the data.
Hive,
Shared Preference
These libraries save the data in key-value pair and read data faster especially hive.
Use SharePreference
see below code snippet with little advancement in code you can achieve your result.
Future<bool> isFirstTime() async {
var firstTime = SharedPref.pref.getBool('first_time');
if (firstTime != null && !firstTime) {
SharedPref.pref.setBool('first_time', false);
return false;
} else {
SharedPref.pref.setBool('first_time', false);
return true;
}
}

How to detect failure of task execution from a vscode extension?

My Visual Studio code extension allows users to deploy and debug applications on remote devices.
To do this I need to have the application "installed" in a local folder that will then be synchronized to the target using rsync.
Some languages/tools provide a simple and standardized way to do this (ex: dotnet publish, for .NET core apps), others don't.
To be flexible and let users choose the method they prefer, my extension relies on a task with a specific name to perform the operation.
I have a resolveDebugConfiguration function that executes the task and then fills out the information inside debug connection to let user debug his app.
As long as this is a single task, this is not an issue. I can start it using vscode.tasks.executeTask and wait for its completion using OnEndTaskProcess. The task should be shell/process and a non-zero exit code means failure. I also check OnEndTask, to be sure that I don't miss other kinds of completition (ex: an invalid path in the cmd field or the user defined a custom task etc.).
Some users may want to have a more complex structure for this. For example having their deployment tasks depend on a build task, to ensure that the latest version is deployed, or perform additional operations in between, so I no longer have a single task, but a chain of tasks connected via dependson.
This is ok and still works...until it fails.
Or, better, until one of the dependency tasks fail.
In this case, I have no notification from OnEndTaskProcess or even OnEndTask and the tasks after the failed one remain inside vscode.tasks.taskExecutions list forever, it seems.
So my resolveDebugConfiguration function never returns and vscode remains in the "starting debugger" state forever...
My code looks like this:
// retrieve task given its name
const tasks = await vscode.tasks.fetchTasks();
var deploy: vscode.Task | undefined = undefined;
for (var task of tasks) {
switch (task.name) {
case "deploy":
deploy = task;
break;
}
}
if (deploy === undefined) {
// error message telling user that he has to define a task named "deploy"
return null;
}
var emitter = new EventEmitter();
// the process event arrives before the generic terminate one (checked inside vscode sources)
vscode.tasks.onDidEndTaskProcess(e => {
if (e.execution.task.name === "deploy") {
emitter.emit("terminated", e.exitCode);
}
});
vscode.tasks.onDidEndTask(e => {
// check if task is still running, otherwise report an error
var taskexecutions = vscode.tasks.taskExecutions;
for (var taskexecution of taskexecutions) {
if (taskexecution.task.name === "deploy") {
return;
}
}
emitter.emit("terminated", -1);
});
try {
var execution = await vscode.tasks.executeTask(deploy);
}
catch (e) {
// catch execution exceptions and show a message to the user
return null;
}
var code = await new Promise<Number>((resolve, reject) => {
emitter.on("terminated", code => resolve(code));
});
if (code !== 0) {
// deploy task failed
return null;
}
// local deployment succeeded, move on...
Some of the tasks may take a long time, so using a timeout may be a solution worse than the problem.
It would be nice to have OnEndTask called even when a dependency fails, preventing the actual task from running, but this does not seem to happen.
I plan to open an issue on vscode github repo, but maybe someone has a solution that doesn't involves changes to the ide itself.

Symbol Barcode Reader on_read issue

I have a Moto Mc9096 device, EDMK SDK, VS2008 etc all of the prereq's
I'm having an issue where once I've scanned a barcode it constantly repeats the event. normally when this happens its a flag or status needs changing but there are no obvious settings to stop it reading again.
code below
private void Barcode_Read(object sender, ReaderData readerdata)
{
if (readerdata.Text != null)
{
if (readerdata.Text == "abc")
{
MessageBox.Show(readerdata.text);
}
}
}
Notes
I've tried
bar.Dispose();
bar.Reader.Actions.Flush();
bar.ReaderData.Dispose() ;
with no success. the EnabledScanner is set on form load and off during form close.
My expectation was when the user scans a barcode it fires the read event once.
but it constantly fires after the users first scan.
You might want to check the aimType property, by default it should be AIM_TYPE_TRIGGER but other settings allow a single trigger pull to perform multiple scans (AIM_TYPE_CONTINUOUS_READ) so perhaps that has been changed.
You should have some samples installed by the SDK at file:///C:/Users/Public/Motorola%20EMDK%20for%20.NET/v2.9/SampLauncher2008.htm (by default) that show best practice.

xamarin.forms read app version from app store / google store

I need to know when i start running my app if a new version exists in Google Play Store / ios app store.
I want to do it by comparing my running app version to the one in the store.
How do i read the app version from the store in run time ?
string url = "http://itunes.apple.com/lookup?bundleId=YourBundelID";
using (var webClient = new System.Net.WebClient())
{
string jsonString = webClient.DownloadString(string.Format(url));
var lookup = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);
if (lookup != null
&& lookup.Count >= 1
&& lookup["resultCount"] != null
&& Convert.ToInt32(lookup["resultCount"].ToString()) > 0)
{
var results = JsonConvert.DeserializeObject<List<object>>(lookup[#"results"].ToString());
if (results != null && results.Count > 0)
{
var values = JsonConvert.DeserializeObject<Dictionary<string, object>>(results[0].ToString());
appStoreAppVersion = values.ContainsKey("version") ? values["version"].ToString() : string.Empty;
}
}
}
return appStoreAppVersion;
If there's no easy way to achieve this, build your own easy way ;-)
For example: with every upload to the app store you upload the current version info to an online resource you can access from your app. All you need is a webserver where you can either run your own API or just upload a file containing the version info.
Maybe not a solution you awaited, but it's definitely going to work.
There is no (easy) way to do that. The best way to do it would be to access the app details through some API but I don't think they make that (publicly) available. So the other way would probably to scrape the according sites, but I'm pretty sure they will be unhappy with that method and maybe their license even forbids it.
Also, mostly that kind of solutions is due to poor design. The user has to be able to use the old version for the length of days, although you should strive for fast adoption of your new version.
But just keep in mind while designing your backend etc. that you have to be backwards compatible.
Lastly, as a user I really hate those kind of messages. Depending on what kind of app it is I just want to use it then, not be forced to update, so go out, update, and try to do the thing I opened it for in the first place.

Get Mode in XMPP/Smack

My chat application has a procedure to set the presence/ mode status of the user i.e - Online, Offline, Invisible, Away etc. I am doing this using the following code :-
presence = new Presence(Presence.Type.available);
if (USER_STATE.equalsIgnoreCase("Online")) {
presence.setMode(Presence.Mode.available);
setUserPresence(0);
}else if (USER_STATE.equalsIgnoreCase("Invisible")) {
presence.setMode(Presence.Mode.xa);
setUserPresence(1);
} else if (USER_STATE.equalsIgnoreCase("Away")) {
presence.setMode(Presence.Mode.away);
setUserPresence(2);
} else if (USER_STATE.equalsIgnoreCase("Busy")) {
presence.setMode(Presence.Mode.dnd);
setUserPresence(3);
}
Here when I set the User Presence to Away or Invisible etc. and log out the user. Now when the user is logged in again I want to get the mode of the User that he had set earlier since his last logout. I am getting it as :-
System.out.println("Loggeddd innn");
// Set presence to online!
Presence userPresence = new Presence(Presence.Type.available);
userPresence.setStatus("Hello CCM!");
userPresence.setPriority(24);
userPresence.setMode(userPresence.getMode());
connection.sendPacket(userPresence);
Here I always get NULL in user.getMode() and also I always get Status as Available (shown in openfire portal)
Anybody please help ?
userPresence.setMode(userPresence.getMode()) seems like a no-op to me.
You should store the previous mode on the device itself (eg in SharedPreferences)