示例#1
0
        /// <summary>
        /// Checks the specified state.
        /// </summary>
        /// <param name="state">The state.</param>
        private void Check(object state)
        {
            try
            {
                Log.Write("{0} started.", MethodInfoHelper.GetCurrentMethodName());

                if (_updating)
                {
                    Log.Write("Updater is already updating.");
                }

                var fetch     = new Fetch(2, 5000, 500);
                var remoteUri = new Uri(_localConfig.RemoteConfigUri);
                fetch.Load(remoteUri.AbsoluteUri);

                if (!fetch.Success)
                {
                    Log.Write("Fetch error: {0}", fetch.Response.StatusDescription);
                    _remoteConfig = null;
                    return;
                }

                string data = Encoding.UTF8.GetString(fetch.ResponseData);
                _remoteConfig = new Manifest(data);

                if (_remoteConfig == null)
                {
                    return;
                }

                if (_localConfig.SecurityToken != _remoteConfig.SecurityToken)
                {
                    Log.Write("Security token mismatch.");
                    return;
                }

                Log.Write("Remote config is valid. Local version is {0}. Remote version is {1}.",
                          _localConfig.Version, _remoteConfig.Version);

                if (_remoteConfig.Version == _localConfig.Version)
                {
                    Log.Write("Versions are the same.");
                    return;
                }

                if (_remoteConfig.Version < _localConfig.Version)
                {
                    Log.Write("Remote version is older.");
                    return;
                }

                if (OnEvent(string.Format("Current version is {0}. Do you want to ugrade to version {1}?",
                                          _localConfig.Version, _remoteConfig.Version)))
                {
                    _updating = true;
                    Update();
                    _updating = false;
                }
            }
            catch (Exception ex)
            {
                Log.Write("{0} failed. {1}", MethodInfoHelper.GetCurrentMethodName(), ex.Message);
            }
            finally
            {
                Log.Write("{0} ended.", MethodInfoHelper.GetCurrentMethodName());
                _updating = false;
            }
        }