Example #1
0
        /// <summary>
        /// The callback method for the <see cref="IMasterServerReader.BeginReadVersionFileList"/>.
        /// </summary>
        /// <param name="sender">The <see cref="IMasterServerReader"/> this event came from.</param>
        /// <param name="info">The information from the master server(s).</param>
        /// <param name="userState">An optional state object passed by the caller to supply information to the callback method
        /// from the method call.</param>
        void MasterServerReader_Callback_VersionFileList(IMasterServerReader sender, IMasterServerReadInfo info, object userState)
        {
            State = UpdateClientState.ReadingLiveVersionFileListDone;

            // Check for a valid VersionFileList
            if (string.IsNullOrEmpty(info.VersionFileListText))
            {
                const string errmsg =
                    "Could not get a valid VersionFileList file from the master servers for version `{0}` - download failed.";

                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, info.Version);

                if (MasterServerReaderError != null)
                    MasterServerReaderError(this, string.Format(errmsg, info.Version));

                HasErrors = true;
                return;
            }

            try
            {
                _versionFileList = VersionFileList.CreateFromString(info.VersionFileListText);
            }
            catch (Exception ex)
            {
                const string errmsg =
                    "Could not get a valid VersionFileList file from the master servers for version `{0}`. Exception: {1}";

                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, info.Version, ex);

                if (MasterServerReaderError != null)
                    MasterServerReaderError(this, string.Format(errmsg, info.Version, ex));

                HasErrors = true;
                return;
            }

            // Find the files to update
            var toUpdate = FindFilesToUpdate(_versionFileList);

            // If all file hashes match, then we are good to go
            if (toUpdate.Count() == 0)
            {
                CheckIfDownloadManagerComplete();
                return;
            }

            // There was one or more files to update, so start the updating...

            // Create the DownloadManager
            _dm = new DownloadManager(Settings.TargetPath, Settings.TempPath, info.Version);
            _dm.DownloadFinished += DownloadManager_DownloadFinished;
            _dm.FileMoveFailed += DownloadManager_FileMoveFailed;
            _dm.DownloadFailed += DownloadManager_DownloadFailed;
            _dm.Finished += DownloadManager_Finished;

            State = UpdateClientState.UpdatingFiles;

            // Add the sources to the DownloadManager
            var sources = info.DownloadSources.Select(x => x.Instantiate());
            _dm.AddSources(sources);

            // Enqueue the files that need to be downloaded
            _dm.Enqueue(toUpdate);
        }
Example #2
0
        /// <summary>
        /// The callback method for the <see cref="IMasterServerReader.BeginReadVersionFileList"/>.
        /// </summary>
        /// <param name="sender">The <see cref="IMasterServerReader"/> this event came from.</param>
        /// <param name="info">The information from the master server(s).</param>
        /// <param name="userState">An optional state object passed by the caller to supply information to the callback method
        /// from the method call.</param>
        void MasterServerReader_Callback_VersionFileList(IMasterServerReader sender, IMasterServerReadInfo info, object userState)
        {
            State = UpdateClientState.ReadingLiveVersionFileListDone;

            // Check for a valid VersionFileList
            if (string.IsNullOrEmpty(info.VersionFileListText))
            {
                const string errmsg =
                    "Could not get a valid VersionFileList file from the master servers for version `{0}` - download failed.";

                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, info.Version);
                }

                if (MasterServerReaderError != null)
                {
                    MasterServerReaderError(this, string.Format(errmsg, info.Version));
                }

                HasErrors = true;
                return;
            }

            try
            {
                _versionFileList = VersionFileList.CreateFromString(info.VersionFileListText);
            }
            catch (Exception ex)
            {
                const string errmsg =
                    "Could not get a valid VersionFileList file from the master servers for version `{0}`. Exception: {1}";

                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, info.Version, ex);
                }

                if (MasterServerReaderError != null)
                {
                    MasterServerReaderError(this, string.Format(errmsg, info.Version, ex));
                }

                HasErrors = true;
                return;
            }

            // Find the files to update
            var toUpdate = FindFilesToUpdate(_versionFileList);

            // If all file hashes match, then we are good to go
            if (toUpdate.Count() == 0)
            {
                CheckIfDownloadManagerComplete();
                return;
            }

            // There was one or more files to update, so start the updating...

            // Create the DownloadManager
            _dm = new DownloadManager(Settings.TargetPath, Settings.TempPath, info.Version);
            _dm.DownloadFinished += DownloadManager_DownloadFinished;
            _dm.FileMoveFailed   += DownloadManager_FileMoveFailed;
            _dm.DownloadFailed   += DownloadManager_DownloadFailed;
            _dm.Finished         += DownloadManager_Finished;

            State = UpdateClientState.UpdatingFiles;

            // Add the sources to the DownloadManager
            var sources = info.DownloadSources.Select(x => x.Instantiate());

            _dm.AddSources(sources);

            // Enqueue the files that need to be downloaded
            _dm.Enqueue(toUpdate);
        }
Example #3
0
        /// <summary>
        /// The callback method for the <see cref="IMasterServerReader.BeginReadVersion"/>.
        /// </summary>
        /// <param name="sender">The <see cref="IMasterServerReader"/> this event came from.</param>
        /// <param name="info">The information from the master server(s).</param>
        /// <param name="userState">An optional state object passed by the caller to supply information to the callback method
        /// from the method call.</param>
        void MasterServerReader_Callback(IMasterServerReader sender, IMasterServerReadInfo info, object userState)
        {
            State = UpdateClientState.ReadingLiveVersionDone;

            // Check for errors
            if (info.Error != null)
            {
                HasErrors = true;

                // Raise error event
                try
                {
                    if (MasterServerReaderError != null)
                        MasterServerReaderError(this, info.Error);
                }
                catch (NullReferenceException ex)
                {
                    Debug.Fail(ex.ToString());
                }

                // Change the state
                State = UpdateClientState.Completed;

                // Set to not running
                lock (_isRunningSync)
                {
                    Debug.Assert(_isRunning);

                    _isRunning = false;

                    try
                    {
                        if (IsRunningChanged != null)
                            IsRunningChanged(this);
                    }
                    catch (NullReferenceException ex)
                    {
                        Debug.Fail(ex.ToString());
                    }
                }

                return;
            }

            // Set the found live version
            LiveVersion = info.Version;

            // Check if the live version equals our version and, if so, there is no need to continue with the update process
            var currentVersion = Settings.GetCurrentVersion();
            if (currentVersion.HasValue && currentVersion.Value == LiveVersion.Value)
            {
                // Change the state
                State = UpdateClientState.Completed;

                // Set to not running
                lock (_isRunningSync)
                {
                    Debug.Assert(_isRunning);

                    _isRunning = false;

                    try
                    {
                        if (IsRunningChanged != null)
                            IsRunningChanged(this);
                    }
                    catch (NullReferenceException ex)
                    {
                        Debug.Fail(ex.ToString());
                    }
                }

                return;
            }

            // Grab the VersionFileList
            State = UpdateClientState.ReadingLiveVersionFileList;

            _msr.BeginReadVersionFileList(MasterServerReader_Callback_VersionFileList, info.Version, this);
        }
Example #4
0
        /// <summary>
        /// The callback method for the <see cref="IMasterServerReader.BeginReadVersion"/>.
        /// </summary>
        /// <param name="sender">The <see cref="IMasterServerReader"/> this event came from.</param>
        /// <param name="info">The information from the master server(s).</param>
        /// <param name="userState">An optional state object passed by the caller to supply information to the callback method
        /// from the method call.</param>
        void MasterServerReader_Callback(IMasterServerReader sender, IMasterServerReadInfo info, object userState)
        {
            State = UpdateClientState.ReadingLiveVersionDone;

            // Check for errors
            if (info.Error != null)
            {
                HasErrors = true;

                // Raise error event
                try
                {
                    if (MasterServerReaderError != null)
                    {
                        MasterServerReaderError(this, info.Error);
                    }
                }
                catch (NullReferenceException ex)
                {
                    Debug.Fail(ex.ToString());
                }

                // Change the state
                State = UpdateClientState.Completed;

                // Set to not running
                lock (_isRunningSync)
                {
                    Debug.Assert(_isRunning);

                    _isRunning = false;

                    try
                    {
                        if (IsRunningChanged != null)
                        {
                            IsRunningChanged(this);
                        }
                    }
                    catch (NullReferenceException ex)
                    {
                        Debug.Fail(ex.ToString());
                    }
                }

                return;
            }

            // Set the found live version
            LiveVersion = info.Version;

            // Check if the live version equals our version and, if so, there is no need to continue with the update process
            var currentVersion = Settings.GetCurrentVersion();

            if (currentVersion.HasValue && currentVersion.Value == LiveVersion.Value)
            {
                // Change the state
                State = UpdateClientState.Completed;

                // Set to not running
                lock (_isRunningSync)
                {
                    Debug.Assert(_isRunning);

                    _isRunning = false;

                    try
                    {
                        if (IsRunningChanged != null)
                        {
                            IsRunningChanged(this);
                        }
                    }
                    catch (NullReferenceException ex)
                    {
                        Debug.Fail(ex.ToString());
                    }
                }

                return;
            }

            // Grab the VersionFileList
            State = UpdateClientState.ReadingLiveVersionFileList;

            _msr.BeginReadVersionFileList(MasterServerReader_Callback_VersionFileList, info.Version, this);
        }