Ejemplo n.º 1
0
        public static IObservable<VisualStudioNotification> Check()
        {
            return Observable.Create<VisualStudioNotification>(obs =>
            {
                var exePath = Assembly.GetExecutingAssembly().Location;

                var currentIntegrationStatus = GetCurrentIntegrationStatus();
                Log.InfoFormat("Current integrations = {0}", string.Join(", ", currentIntegrationStatus.Select(x => "({0}, {1})".FormatInvariant(x.Key, x.Value))));
                var possibleIntegrations = GetPossibleIntegrationStatus(exePath);
                Log.InfoFormat("Possible integrations = {0}", string.Join(", ", possibleIntegrations.Select(x => "({0}, {1})".FormatInvariant(x.Version, x.IntegrationStatus))));

                // remember versions the user has already declined to integrate with
                foreach (var model in possibleIntegrations)
                {
                    VisualStudioIntegrationStatus currentStatus;
                    if (model.IntegrationStatus == VisualStudioIntegrationStatus.Available &&
                        currentIntegrationStatus.TryGetValue(model.Version, out currentStatus) &&
                        currentStatus == VisualStudioIntegrationStatus.NotInstalled)
                    {
                        model.IntegrationStatus = VisualStudioIntegrationStatus.NotInstalled;
                    }

                    if (model.IntegrationStatus != VisualStudioIntegrationStatus.NotInstalled)
                    {
                        Log.InfoFormat("Setting IsChecked ({0}) true by default", model.Version);
                        model.IsChecked = true;
                    }
                }

                // show notification if there are any available versions to integrate with
                if (possibleIntegrations.Any(x => x.IntegrationStatus == VisualStudioIntegrationStatus.Available))
                {
                    Log.InfoFormat("Notifying integrations = {0}", string.Join(", ", possibleIntegrations.Select(x => "({0}, {1}, {2})".FormatInvariant(x.Version, x.IntegrationStatus, x.IsChecked))));
                    var visualStudioNotification = new VisualStudioNotification(possibleIntegrations);
                    visualStudioNotification.IntegrateCommand.Subscribe(x => IntegrateWithVisualStudio(obs, exePath, visualStudioNotification, true));
                    visualStudioNotification.DoNotIntegrateCommand.Subscribe(x => IntegrateWithVisualStudio(obs, null, visualStudioNotification, false));
                    obs.OnNext(visualStudioNotification);
                }
                else
                {
                    Log.Info("No integrations available");
                    obs.OnCompleted();
                }

                return Disposable.Empty;
            }).SubscribeOn(TaskPoolScheduler.Default);
        }
Ejemplo n.º 2
0
        public static IObservable <VisualStudioNotification> Check()
        {
            return(Observable.Create <VisualStudioNotification>(obs =>
            {
                var exePath = Assembly.GetExecutingAssembly().Location;

                var currentIntegrationStatus = GetCurrentIntegrationStatus();
                Log.InfoFormat("Current integrations = {0}", string.Join(", ", currentIntegrationStatus.Select(x => "({0}, {1})".FormatInvariant(x.Key, x.Value))));
                var possibleIntegrations = GetPossibleIntegrationStatus(exePath);
                Log.InfoFormat("Possible integrations = {0}", string.Join(", ", possibleIntegrations.Select(x => "({0}, {1})".FormatInvariant(x.Version, x.IntegrationStatus))));

                // remember versions the user has already declined to integrate with
                foreach (var model in possibleIntegrations)
                {
                    VisualStudioIntegrationStatus currentStatus;
                    if (model.IntegrationStatus == VisualStudioIntegrationStatus.Available &&
                        currentIntegrationStatus.TryGetValue(model.Version, out currentStatus) &&
                        currentStatus == VisualStudioIntegrationStatus.NotInstalled)
                    {
                        model.IntegrationStatus = VisualStudioIntegrationStatus.NotInstalled;
                    }

                    if (model.IntegrationStatus != VisualStudioIntegrationStatus.NotInstalled)
                    {
                        Log.InfoFormat("Setting IsChecked ({0}) true by default", model.Version);
                        model.IsChecked = true;
                    }
                }

                // show notification if there are any available versions to integrate with
                if (possibleIntegrations.Any(x => x.IntegrationStatus == VisualStudioIntegrationStatus.Available))
                {
                    Log.InfoFormat("Notifying integrations = {0}", string.Join(", ", possibleIntegrations.Select(x => "({0}, {1}, {2})".FormatInvariant(x.Version, x.IntegrationStatus, x.IsChecked))));
                    var visualStudioNotification = new VisualStudioNotification(possibleIntegrations);
                    visualStudioNotification.IntegrateCommand.Subscribe(x => IntegrateWithVisualStudio(obs, exePath, visualStudioNotification, true));
                    visualStudioNotification.DoNotIntegrateCommand.Subscribe(x => IntegrateWithVisualStudio(obs, null, visualStudioNotification, false));
                    obs.OnNext(visualStudioNotification);
                }
                else
                {
                    Log.Info("No integrations available");
                    obs.OnCompleted();
                }

                return Disposable.Empty;
            }).SubscribeOn(TaskPoolScheduler.Default));
        }
Ejemplo n.º 3
0
        private static void IntegrateWithVisualStudio(IObserver <VisualStudioNotification> observer, string commandPath, VisualStudioNotification model, bool integrate)
        {
            string preference = string.Join(";", model.Versions.Select(x => GetEffectivePreference(integrate, x)));

            AppModel.SetRegistrySetting("VisualStudioIntegration", preference);

            if (integrate)
            {
                Log.InfoFormat("Integrating with {0}", string.Join(", ", model.Versions.Select(x => "({0}, {1}, {2})".FormatInvariant(x.Version, x.IntegrationStatus, x.IsChecked))));
                // TODO: Delete tools where !x.IsChecked && x.IntegrationStatus == VisualStudioIntegrationStatus.Installed
                IntegrateWithVisualStudio(commandPath, model.Versions.Where(x => x.IsChecked && x.IntegrationStatus == VisualStudioIntegrationStatus.Available));
            }

            Log.Info("Completing observer");
            observer.OnNext(null);
            observer.OnCompleted();
        }
Ejemplo n.º 4
0
        private static void IntegrateWithVisualStudio(IObserver<VisualStudioNotification> observer, string commandPath, VisualStudioNotification model, bool integrate)
        {
            string preference = string.Join(";", model.Versions.Select(x => GetEffectivePreference(integrate, x)));
            AppModel.SetRegistrySetting("VisualStudioIntegration", preference);

            if (integrate)
            {
                Log.InfoFormat("Integrating with {0}", string.Join(", ", model.Versions.Select(x => "({0}, {1}, {2})".FormatInvariant(x.Version, x.IntegrationStatus, x.IsChecked))));
                // TODO: Delete tools where !x.IsChecked && x.IntegrationStatus == VisualStudioIntegrationStatus.Installed
                IntegrateWithVisualStudio(commandPath, model.Versions.Where(x => x.IsChecked && x.IntegrationStatus == VisualStudioIntegrationStatus.Available));
            }

            Log.Info("Completing observer");
            observer.OnNext(null);
            observer.OnCompleted();
        }