CheckForNewerVersion

Nov 30, 2012 at 2:26 PM

For my app I wanted to let the user know if they had the latest version and if not let them update. So I changed the check for new version to be an Action<bool> instead of just action so that when it returned I could decide what to show them.

public static void CheckForNewVersion(string uri, Action action)
{
    CheckForNewVersion(uri, (n) => { if (n == true) action.Invoke(); });
}

public static void CheckForNewVersion(string uri, Action<bool> action)
{
   ....
}

private static void DoWebRequest(string uri, Version appVersion, Action<bool> action)
{
  ....
    try
    {
        Version currentVersion;

        if (Version.TryParse(response, out currentVersion))
        {
            if (action != null)
            {
                logger.Write("NOTE: version check of application. v{0} vs. v{1}.", appVersion, currentVersion);

                try
                {
                    action(appVersion < currentVersion);
                }
                catch (Exception ex)
                {
                    logger.Write("Failed to run action! {0}.", ex.Message);
                }
            }
        }
    }
    catch
    {
    }
  ....
}

Might be worth adding to the source here.

 

 

Coordinator
Nov 30, 2012 at 3:41 PM
Edited Nov 30, 2012 at 4:38 PM

Great idea. I will make the change this weekend.

Coordinator
Nov 30, 2012 at 4:38 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Dec 1, 2012 at 3:19 AM
Edited Dec 1, 2012 at 3:20 AM

I might have misunderstand your request. Why would you want an Action<bool> ? You determine what will be executed when there is a new version. So you can notify the user that way.

As displayed in the example

 

            /* Example of Version Checking */
            NorthernLights.VersionManagement.CheckForNewVersion("http://www.yourwebsite.com/appversion.txt", () =>
            {
                // new version available. open the marketplace.
            });

EDIT: oh wait, you also want to be notified when the user has the latest version...

Coordinator
Dec 1, 2012 at 3:27 AM

Updated code is checked in.

Dec 1, 2012 at 1:25 PM

Great! Thanks!