Exemplo n.º 1
0
 void StartDownloadReleaseNotes()
 {
     VersionState = UpdateVersionState.DownloadingReleaseNotes;
     _webClient.DownloadDataAsync( new Uri( GetReleaseNoteUrl( HostInformation.SubAppName, NewVersion ) ) );
 }
Exemplo n.º 2
0
        void OnDownloadDataCompleted( object sender, DownloadDataCompletedEventArgs e )
        {
            if( e.Cancelled )
            {
                VersionState = (UpdateVersionState)e.UserState;
            }
            else
            {
                Debug.Assert( _versionState == UpdateVersionState.CheckingForNewVersion || _versionState == UpdateVersionState.DownloadingReleaseNotes );

                try
                {
                    if( _versionState == UpdateVersionState.CheckingForNewVersion )
                    {
                        if( e.Error != null )
                        {
                            _log.Error( "Error while checking version", e.Error );
                            VersionState = UpdateVersionState.ErrorWhileCheckingVersion;
                            return;
                        }

                        string version = Encoding.UTF8.GetString( e.Result ).Replace( "\"", string.Empty );
                        NewVersion = SemanticVersion20.Parse( version );
                        if( NewVersion > SemanticVersion20.Parse( HostInformation.AppVersion.ToString() ) )//If the version retrieved from the server is greater than the currently installed one
                        {
                            // If the version retrived from the server is greater than the one that has been downloaded last
                            string retrievedVersionString = Configuration.System.GetOrSet<string>( "LastDownloadedVersion", "0.0.0" );
                            SemanticVersion20 retrievedVersion;
                            if( SemanticVersion20.TryParse( retrievedVersionString, out retrievedVersion ) && retrievedVersion < NewVersion )
                            {
                                // if a new version is available, try to download release notes before we show the update to the user.
                                StartDownloadReleaseNotes();
                            }
                        }
                        else
                            VersionState = UpdateVersionState.NoNewerVersion;
                    }
                    else if( _versionState == UpdateVersionState.DownloadingReleaseNotes )
                    {
                        VersionState = UpdateVersionState.NewerVersionAvailable;
                        string rn = null;
                        if( e.Error == null )
                        {
                            rn = Encoding.UTF7.GetString( e.Result );
                        }
                        // Ask the user to download it.
                        Application.Current.Dispatcher.BeginInvoke( (Action)(() =>
                        {
                            OnNewerVersionAvailable( rn );
                        }) );
                    }
                }
                catch( Exception ex )
                {
                    _log.Error( "Error while checking version", ex );
                    VersionState = UpdateVersionState.ErrorWhileCheckingVersion;
                }
            }
        }
Exemplo n.º 3
0
 public bool Setup( IPluginSetupInfo info )
 {
     _versionState = UpdateVersionState.Unknown;
     _downloadState = DownloadState.None;
     _webClient = new WebClient();
     // Used to read the available version.
     _webClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler( OnDownloadDataCompleted );
     // Used to download the new version.
     _webClient.DownloadFileCompleted += new AsyncCompletedEventHandler( OnDownloadFileCompleted );
     return true;
 }
Exemplo n.º 4
0
        public void CheckForUpdate()
        {
            CheckNotBusy();

            UpdateVersionState savedState = _versionState;
            VersionState = UpdateVersionState.CheckingForNewVersion;
            string httpRequest = GetCheckUpdateUrl( HostInformation.SubAppName );

            _webClient.DownloadDataAsync( new Uri( httpRequest ), savedState );
        }
Exemplo n.º 5
0
        void _webClient_DownloadDataCompleted( object sender, DownloadDataCompletedEventArgs e )
        {
            if( e.Cancelled )
            {
                VersionState = (UpdateVersionState)e.UserState;
            }
            else if( e.Error != null )
            {
                _log.Error( "Error while checking version", e.Error );
                VersionState = UpdateVersionState.ErrorWhileCheckingVersion;
            }
            else
            {
                Debug.Assert( _versionState == UpdateVersionState.CheckingForNewVersion );
                try
                {
                    string version = Encoding.UTF8.GetString( e.Result );
                    NewVersion = new Version( version );
                    if( NewVersion > HostInformation.AppVersion )//If the version retrieved from the server is greater than the currently installed one
                    {
                        //If the version retrived from the server is greater than the one that has been downloaded last
                        string retrievedVersionString = Configuration.System.GetOrSet<string>( "LastDownloadedVersion", "0.0.0" );
                        Version retrievedVersion;
                        if( Version.TryParse( retrievedVersionString, out retrievedVersion ) && retrievedVersion < NewVersion )
                        {
                            VersionState = UpdateVersionState.NewerVersionAvailable;
                            // Ask the user to download it.
                            OnNewerVersionAvailable();
                        }
                    }

                    VersionState = UpdateVersionState.NoNewerVersion;
                }
                catch( Exception ex )
                {
                    _log.Error( "Error while checking version", ex );
                    VersionState = UpdateVersionState.ErrorWhileCheckingVersion;
                }
            }
        }
Exemplo n.º 6
0
        public void CheckForUpdate()
        {
            CheckNotBusy();
            _distributionName = HostInformation.SubAppName;

            UpdateVersionState savedState = _versionState;
            VersionState = UpdateVersionState.CheckingForNewVersion;
            string httpRequest = GetServerUrl() + "version/updated/currentversion/" + HostInformation.AppName + @"-" + _distributionName + "/" + HostInformation.AppVersion.ToString();
            Task.Factory.StartNew( () =>
            {
                // This task exist to bypass the long proxy lookup (10s on my Comp) that freez the OS during bootstrap of the update checker
                _webClient.DownloadDataAsync( new Uri( httpRequest ), savedState );//gets the new version from its package repository
            } );
        }