示例#1
0
        private static void PerformCheck(Object stateInfo)
        {
            try
            {
                ShrewProperties properties = ShrewConfiguration.LoadProperties();

                Version localVersion = Assembly.GetExecutingAssembly().GetName().Version;

                //userID used to track active user count.
                WebRequest   request  = HttpWebRequest.Create(string.Format(VERSION_URL, properties.userId, localVersion.ToString(), getArch()));
                WebResponse  response = request.GetResponse();
                StreamReader rdr      = new StreamReader(response.GetResponseStream());
                char[]       buffer   = new char[response.ContentLength];
                rdr.Read(buffer, 0, (Int32)response.ContentLength);
                Version latestVersion       = new Version(new String(buffer));
                bool    newVersionAvailable = latestVersion.CompareTo(localVersion) > 0;
                if (newVersionAvailable && UpdateAvailable != null)
                {
                    UpdateAvailable(null, new UpdateAvailableArgs(latestVersion));
                }
                properties.lastUpdateCheck = DateTime.UtcNow;
                ShrewConfiguration.SaveProperties(properties);
            }
            catch (Exception)
            {
                //Eat all errors
            }
        }
示例#2
0
        public static void CheckForUpdate()
        {
            ShrewProperties properties = ShrewConfiguration.LoadProperties();

            if (properties == null)
            {
                properties        = new ShrewProperties();
                properties.userId = Guid.NewGuid();
                ShrewConfiguration.SaveProperties(properties);
            }
            long initalDelay = 0;

            if (properties.lastUpdateCheck != null)
            {
                initalDelay = (long)properties.lastUpdateCheck.AddMilliseconds(UPDATE_CHECK_INTERVAL_MILLIS)
                              .Subtract(DateTime.UtcNow).TotalMilliseconds;
                if (initalDelay < 0)
                {
                    initalDelay = 0;
                }
            }

            updateCheckTimer = new Timer(UpdateChecker.PerformCheck, null, initalDelay, UPDATE_CHECK_INTERVAL_MILLIS);
        }