Пример #1
0
        private IObservable <UpdateAvailableNotification> CheckForUpdates()
        {
            return(Observable.Create <UpdateAvailableNotification>(async obs =>
            {
                string updateUrl = AppModel.GetRegistrySetting("UpdateUrl");
                Log.DebugFormat("UpdateUrl = {0}", updateUrl);
                using (var updateManager = new UpdateManager(updateUrl ?? @"http://bradleygrainger.com/GitBlame/download", "GitBlame", FrameworkVersion.Net45))
                {
                    try
                    {
                        UpdateInfo updateInfo = await updateManager.CheckForUpdate();
                        var releases = updateInfo == null ? new List <ReleaseEntry>() : updateInfo.ReleasesToApply.ToList();
                        if (updateInfo == null)
                        {
                            Log.Info("CheckForUpdate returned (null)");
                        }
                        else
                        {
                            Log.InfoFormat("CheckForUpdate: Current=({0}), Future=({1}), {2} ReleasesToApply", ToLog(updateInfo.CurrentlyInstalledVersion), ToLog(updateInfo.FutureReleaseEntry), releases.Count);
                        }

                        if (releases.Count != 0)
                        {
                            await updateManager.DownloadReleases(releases);
                            Log.Info("Downloaded releases");
                            var newDirectory = await updateManager.ApplyReleases(updateInfo);
                            Log.InfoFormat("ApplyReleases: {0}", newDirectory);

                            if (!string.IsNullOrEmpty(newDirectory))
                            {
                                var newPath = Path.Combine(newDirectory, "GitBlame.exe");
                                VisualStudioIntegration.ReintegrateWithVisualStudio(newPath);
                                obs.OnNext(new UpdateAvailableNotification(newPath));
                            }
                        }
                    }
                    catch (TimeoutException ex)
                    {
                        // Failed to check for updates; try again the next time the app is run
                        Log.ErrorFormat("CheckForUpdates timed out: {0}", ex, ex.Message);
                    }
                    catch (Exception ex)
                    {
                        // Squirrel throws a new Exception in many failure scenarios
                        Log.ErrorFormat("CheckForUpdates failed: {0}", ex, ex.Message);
                        if (ex.InnerException != null)
                        {
                            Log.ErrorFormat("CheckForUpdates inner exception: {0}", ex.InnerException, ex.InnerException.Message);
                        }
                    }
                }
                obs.OnCompleted();
            }));
        }
Пример #2
0
        public MainWindowModel()
        {
            m_positionHistory = new Stack <BlamePositionModel>();
            m_positionFuture  = new Stack <BlamePositionModel>();

            m_windowTitle = this.WhenAny(x => x.Position, x => x.Value).Select(x => (x == null ? "" : Path.GetFileName(x.FileName) + " - ") + "GitBlame").ToProperty(this, x => x.WindowTitle);

            var openFileNotifications = this.WhenAny(x => x.Position, x => x.Value)
                                        .Select(x => x == null ? new OpenFileNotification() : x.RepoPath == null ? new OpenFileNotification(x.FilePath) : null);
            var notifications = openFileNotifications.Cast <NotificationBase>().StartWith(default(NotificationBase)).CombineLatest(
                CheckForUpdates().Cast <NotificationBase>().StartWith(default(NotificationBase)),
                VisualStudioIntegration.Check().Cast <NotificationBase>().StartWith(default(NotificationBase)),
                (of, ua, vs) => of ?? ua ?? vs)
                                .DistinctUntilChanged();

            m_notification = notifications.ToProperty(this, x => x.Notification);

            CheckForUpdates();
        }