コード例 #1
0
ファイル: Updater.cs プロジェクト: injeetender/SQLSure
        private void bwFetchManifest_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                var remoteUri = new Uri(this._localConfig.RemoteConfigUri);

                Log.Write("Fetching '{0}'.", remoteUri.AbsoluteUri);

                var http = new Fetch {
                    Retries = 5, RetrySleep = 30000, Timeout = 30000
                };

                http.Load(remoteUri.AbsoluteUri);

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

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

                if (this._remoteConfig == null)
                {
                    return;
                }

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

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

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

                if (this._remoteConfig.Version < this._localConfig.Version)
                {
                    Log.Write("Remote version is older. That's weird.");
                    Log.Write("Check ending.");
                    return;
                }

                Log.Write("Remote version is newer. Updating.");

                ManifestSuccess = true;
            }

            catch
            {
                ManifestSuccess = false;
            }
        }
コード例 #2
0
ファイル: Updater.cs プロジェクト: injeetender/SQLSure
        private void bwFetchPayload_DoWork(object sender, DoWorkEventArgs e)
        {
            _updating = true;

            Log.Write("Updating '{0}' files.", this._remoteConfig.Payloads.Length);

            // Clean up failed attempts.

            if (Directory.Exists(WorkPath))
            {
                Log.Write("WARNING: Work directory already exists.");

                try
                {
                    Directory.Delete(WorkPath, true);
                }

                catch (IOException)
                {
                    Log.Write("Cannot delete open directory '{0}'.", WorkPath);
                    return;
                }
            }

            Directory.CreateDirectory(WorkPath);

            // Download files in manifest.

            try
            {
                foreach (string update in this._remoteConfig.Payloads)
                {
                    Log.Write("Fetching '{0}'.", update);

                    var url  = this._remoteConfig.BaseUri + update;
                    var file = Fetch.Get(url);

                    if (file == null)
                    {
                        Log.Write("Fetch failed.");
                    }
                    else
                    {
                        var info = new FileInfo(Path.Combine(WorkPath, update));

                        Directory.CreateDirectory(info.DirectoryName);
                        File.WriteAllBytes(Path.Combine(WorkPath, update), file);
                    }
                }
            }

            catch (Exception ex)
            {
                Log.Write("Fetch failed " + ex.Message);
                return;
            }

            PayloadSuccess = true;

            _updating = false;

            Log.Write("Check ending.");
        }