public LoggingConfiguration(IProgram program, IOperatingSystem os, IVSServices vsservice)
        {
            NLog.Config.LoggingConfiguration conf;
            string assemblyFolder = program.ExecutingAssemblyDirectory;

            try
            {
                conf = new XmlLoggingConfiguration(Path.Combine(assemblyFolder, "NLog.config"), true);
            }
            catch (Exception ex)
            {
                vsservice.ActivityLogError(string.Format(CultureInfo.InvariantCulture, "Error loading nlog.config. {0}", ex));
                conf = new NLog.Config.LoggingConfiguration();
            }

            var fileTarget = conf.FindTargetByName("file") as FileTarget;

            if (fileTarget == null)
            {
                fileTarget = new FileTarget();
                conf.AddTarget(Path.GetRandomFileName(), fileTarget);
                conf.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, fileTarget));
            }
            fileTarget.FileName = Path.Combine(os.Environment.GetLocalGitHubApplicationDataPath(), "extension.log");
            fileTarget.Layout   = layout;

            try
            {
                LogManager.Configuration = conf;
            }
            catch (Exception ex)
            {
                vsservice.ActivityLogError(string.Format(CultureInfo.InvariantCulture, "Error configuring the log. {0}", ex));
            }
        }
Example #2
0
 public GitHubContextService(IGitHubServiceProvider serviceProvider, IGitService gitService, IVSServices vsServices)
 {
     this.serviceProvider = serviceProvider;
     this.gitService      = gitService;
     this.vsServices      = vsServices;
     textManager          = new Lazy <IVsTextManager2>(() => serviceProvider.GetService <SVsTextManager, IVsTextManager2>());
 }
        public GitHubConnectSection(IGitHubServiceProvider serviceProvider,
                                    ISimpleApiClientFactory apiFactory,
                                    ITeamExplorerServiceHolder holder,
                                    IConnectionManager manager,
                                    IPackageSettings packageSettings,
                                    IVSServices vsServices,
                                    ILocalRepositories localRepositories,
                                    int index)
            : base(serviceProvider, apiFactory, holder, manager)
        {
            Guard.ArgumentNotNull(apiFactory, nameof(apiFactory));
            Guard.ArgumentNotNull(holder, nameof(holder));
            Guard.ArgumentNotNull(manager, nameof(manager));
            Guard.ArgumentNotNull(packageSettings, nameof(packageSettings));
            Guard.ArgumentNotNull(vsServices, nameof(vsServices));
            Guard.ArgumentNotNull(localRepositories, nameof(localRepositories));

            Title        = "GitHub";
            IsEnabled    = true;
            IsVisible    = false;
            LoggedIn     = false;
            sectionIndex = index;

            this.packageSettings   = packageSettings;
            this.vsServices        = vsServices;
            this.localRepositories = localRepositories;

            Clone = CreateAsyncCommandHack(DoClone);

            connectionManager.Connections.CollectionChanged += RefreshConnections;
            PropertyChanged += OnPropertyChange;
            UpdateConnection();
        }
        public RepositoryCloneService(IOperatingSystem operatingSystem, IVSServices vsservices)
        {
            this.operatingSystem = operatingSystem;
            this.vsservices      = vsservices;

            defaultClonePath = GetLocalClonePathFromGitProvider(operatingSystem.Environment.GetUserDocumentsPathForApplication());
        }
Example #5
0
        public GitHubConnectSection(IGitHubServiceProvider serviceProvider,
                                    ISimpleApiClientFactory apiFactory,
                                    ITeamExplorerServiceHolder holder,
                                    IConnectionManager manager,
                                    IPackageSettings packageSettings,
                                    IVSServices vsServices,
                                    IRepositoryCloneService cloneService,
                                    IDialogService dialogService,
                                    int index)
            : base(serviceProvider, apiFactory, holder, manager)
        {
            Title        = "GitHub";
            IsEnabled    = true;
            IsVisible    = false;
            LoggedIn     = false;
            sectionIndex = index;

            this.packageSettings = packageSettings;
            this.vsServices      = vsServices;
            this.cloneService    = cloneService;
            this.dialogService   = dialogService;

            Clone = CreateAsyncCommandHack(DoClone);

            connectionManager.Connections.CollectionChanged += RefreshConnections;
            PropertyChanged += OnPropertyChange;
            UpdateConnection();
        }
        public RepositoryCloneService(IOperatingSystem operatingSystem, IVSServices vsservices)
        {
            this.operatingSystem = operatingSystem;
            this.vsservices = vsservices;

            defaultClonePath = GetLocalClonePathFromGitProvider(operatingSystem.Environment.GetUserRepositoriesPath());
        }
 RepositoryCloneViewModel(
     IConnectionRepositoryHostMap connectionRepositoryHostMap,
     IRepositoryCloneService repositoryCloneService,
     IOperatingSystem operatingSystem,
     IVSServices vsServices)
     : this(connectionRepositoryHostMap.CurrentRepositoryHost, repositoryCloneService, operatingSystem, vsServices)
 { }
        public LoggingConfiguration(IProgram program, IOperatingSystem os, IVSServices vsservice)
        {
            NLog.Config.LoggingConfiguration conf;
            string assemblyFolder = program.ExecutingAssemblyDirectory;
            try
            {
                conf = new XmlLoggingConfiguration(Path.Combine(assemblyFolder, "NLog.config"), true);
            }
            catch (Exception ex)
            {
                vsservice.ActivityLogError(string.Format(CultureInfo.InvariantCulture, "Error loading nlog.config. {0}", ex));
                conf = new NLog.Config.LoggingConfiguration();
            }

            var fileTarget = conf.FindTargetByName("file") as FileTarget;
            if (fileTarget == null)
            {
                fileTarget = new FileTarget();
                conf.AddTarget(Path.GetRandomFileName(), fileTarget);
                conf.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, fileTarget));
            }
            fileTarget.FileName = Path.Combine(os.Environment.GetLocalGitHubApplicationDataPath(), "extension.log");
            fileTarget.Layout = layout;

            try
            {
                LogManager.Configuration = conf;
            }
            catch (Exception ex)
            {
                vsservice.ActivityLogError(string.Format(CultureInfo.InvariantCulture, "Error configuring the log. {0}", ex));
            }
        }
 RepositoryCloneViewModel(
     IConnectionRepositoryHostMap connectionRepositoryHostMap,
     IRepositoryCloneService repositoryCloneService,
     IOperatingSystem operatingSystem,
     IVSServices vsServices)
     : this(connectionRepositoryHostMap.CurrentRepositoryHost, repositoryCloneService, operatingSystem, vsServices)
 {
 }
Example #10
0
 public EnsureLoggedInSection(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
                              IConnectionManager cm, IRepositoryHosts hosts, IVSServices vsServices)
     : base(apiFactory, holder, cm)
 {
     IsVisible       = false;
     this.hosts      = hosts;
     this.vsServices = vsServices;
 }
 public EnsureLoggedInSection(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
     IConnectionManager cm, IRepositoryHosts hosts, IVSServices vsServices)
     : base(apiFactory, holder, cm)
 {
     IsVisible = false;
     this.hosts = hosts;
     this.vsServices = vsServices;
 }
Example #12
0
 public GitHubConnectSection0(IGitHubServiceProvider serviceProvider,
                              ISimpleApiClientFactory apiFactory,
                              ITeamExplorerServiceHolder holder,
                              IConnectionManager manager,
                              IPackageSettings settings,
                              IVSServices vsServices)
     : base(serviceProvider, apiFactory, holder, manager, settings, vsServices, 0)
 {
 }
 static OpenFromClipboardCommand CreateOpenFromClipboardCommand(
     IGitHubContextService gitHubContextService = null,
     ITeamExplorerContext teamExplorerContext   = null,
     IVSServices vsServices             = null,
     GitHubContext contextFromClipboard = null,
     string repositoryDir   = null,
     string repositoryName  = null,
     string repositoryOwner = null,
     string currentBranch   = null,
     (string, string, string)?resolveBlobResult = null,
 public GitHubConnectSection0(IGitHubServiceProvider serviceProvider,
                              ISimpleApiClientFactory apiFactory,
                              ITeamExplorerServiceHolder holder,
                              IConnectionManager manager,
                              IPackageSettings settings,
                              IVSServices vsServices,
                              ILocalRepositories localRepositories,
                              IUsageTracker usageTracker)
     : base(serviceProvider, apiFactory, holder, manager, settings, vsServices, localRepositories, usageTracker, 0)
 {
 }
Example #15
0
 public GitHubConnectSection1(IGitHubServiceProvider serviceProvider,
                              ISimpleApiClientFactory apiFactory,
                              ITeamExplorerServiceHolder holder,
                              IConnectionManager manager,
                              IPackageSettings settings,
                              IVSServices vsServices,
                              IRepositoryCloneService cloneService,
                              IDialogService dialogService)
     : base(serviceProvider, apiFactory, holder, manager, settings, vsServices, cloneService, dialogService, 1)
 {
 }
 public static IRepositoryPublishViewModel GetViewModel(
     IRepositoryHosts hosts = null,
     IRepositoryPublishService service = null,
     IVSServices vsServices = null,
     IConnectionManager connectionManager = null)
 {
     hosts = hosts ?? Substitutes.RepositoryHosts;
     service = service ?? Substitute.For<IRepositoryPublishService>();
     vsServices = vsServices ?? Substitute.For<IVSServices>();
     connectionManager = connectionManager ?? Substitutes.ConnectionManager;
     return new RepositoryPublishViewModel(hosts, service, vsServices, connectionManager);
 }
Example #17
0
 public static IRepositoryPublishViewModel GetViewModel(
     IRepositoryHosts hosts               = null,
     IRepositoryPublishService service    = null,
     IVSServices vsServices               = null,
     IConnectionManager connectionManager = null)
 {
     hosts             = hosts ?? Substitutes.RepositoryHosts;
     service           = service ?? Substitute.For <IRepositoryPublishService>();
     vsServices        = vsServices ?? Substitute.For <IVSServices>();
     connectionManager = connectionManager ?? Substitutes.ConnectionManager;
     return(new RepositoryPublishViewModel(hosts, service, vsServices, connectionManager));
 }
Example #18
0
        public UsageTracker(
            IProgram program,
            IConnectionManager connectionManager,
            IPackageSettings userSettings,
            IVSServices vsservices,
            [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
        {
            fileExists  = (path) => System.IO.File.Exists(path);
            readAllText = (path, encoding) =>
            {
                try
                {
                    return(System.IO.File.ReadAllText(path, encoding));
                }
                catch
                {
                    return(null);
                }
            };
            writeAllText = (path, content, encoding) =>
            {
                try
                {
                    System.IO.File.WriteAllText(path, content, encoding);
                }
                catch {}
            };
            dirCreate = (path) => System.IO.Directory.CreateDirectory(path);

            this.connectionManager = connectionManager;
            this.userSettings      = userSettings;
            this.vsservices        = vsservices;
            this.client            = serviceProvider.GetExportedValue <IMetricsService>();
            this.timer             = new DispatcherTimer(
                TimeSpan.FromMinutes(1),
                DispatcherPriority.Background,
                TimerTick,
                Dispatcher.CurrentDispatcher);
            this.storePath = System.IO.Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                program.ApplicationName,
                StoreFileName);

            userSettings.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(userSettings.CollectMetrics))
                {
                    UpdateTimer(false);
                }
            };

            UpdateTimer(true);
        }
Example #19
0
        async Task Initialize()
        {
            // The services needed by the usage tracker are loaded when they are first needed to
            // improve the startup time of the extension.
            if (!initialized)
            {
                await ThreadingHelper.SwitchToMainThreadAsync();

                client            = gitHubServiceProvider.TryGetService <IMetricsService>();
                connectionManager = gitHubServiceProvider.GetService <IConnectionManager>();
                vsservices        = gitHubServiceProvider.GetService <IVSServices>();
                initialized       = true;
            }
        }
        public RepositoryCloneViewModel(
            IRepositoryHost repositoryHost,
            IRepositoryCloneService cloneService,
            IOperatingSystem operatingSystem,
            IVSServices vsServices)
        {
            this.repositoryHost  = repositoryHost;
            this.cloneService    = cloneService;
            this.operatingSystem = operatingSystem;
            this.vsServices      = vsServices;

            Title                   = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, repositoryHost.Title);
            Repositories            = new ReactiveList <IRepositoryModel>();
            loadRepositoriesCommand = ReactiveCommand.CreateAsyncObservable(OnLoadRepositories);
            isLoading               = this.WhenAny(x => x.LoadingFailed, x => x.Value)
                                      .CombineLatest(loadRepositoriesCommand.IsExecuting, (failed, loading) => !failed && loading)
                                      .ToProperty(this, x => x.IsLoading);
            loadRepositoriesCommand.Subscribe(Repositories.AddRange);
            filterTextIsEnabled = this.WhenAny(x => x.Repositories.Count, x => x.Value > 0)
                                  .ToProperty(this, x => x.FilterTextIsEnabled);
            noRepositoriesFound = this.WhenAny(x => x.FilterTextIsEnabled, x => x.IsLoading, x => x.LoadingFailed
                                               , (any, loading, failed) => !any.Value && !loading.Value && !failed.Value)
                                  .ToProperty(this, x => x.NoRepositoriesFound);

            var filterResetSignal = this.WhenAny(x => x.FilterText, x => x.Value)
                                    .DistinctUntilChanged(StringComparer.OrdinalIgnoreCase)
                                    .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler);

            FilteredRepositories = Repositories.CreateDerivedCollection(
                x => x,
                filter: FilterRepository,
                signalReset: filterResetSignal
                );

            BaseRepositoryPathValidator = this.CreateBaseRepositoryPathValidator();

            var canCloneObservable = this.WhenAny(
                x => x.SelectedRepository,
                x => x.BaseRepositoryPathValidator.ValidationResult.IsValid,
                (x, y) => x.Value != null && y.Value);

            canClone     = canCloneObservable.ToProperty(this, x => x.CanClone);
            CloneCommand = ReactiveCommand.CreateAsyncObservable(canCloneObservable, OnCloneRepository);

            browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog());
            this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value)
            .Subscribe();
            BaseRepositoryPath = cloneService.DefaultClonePath;
        }
        public RepositoryCloneViewModel(
            IRepositoryHost repositoryHost,
            IRepositoryCloneService cloneService,
            IOperatingSystem operatingSystem,
            IVSServices vsServices)
        {
            this.repositoryHost = repositoryHost;
            this.cloneService = cloneService;
            this.operatingSystem = operatingSystem;
            this.vsServices = vsServices;

            Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, repositoryHost.Title);
            Repositories = new ReactiveList<IRepositoryModel>();
            loadRepositoriesCommand = ReactiveCommand.CreateAsyncObservable(OnLoadRepositories);
            isLoading = this.WhenAny(x => x.LoadingFailed, x => x.Value)
                .CombineLatest(loadRepositoriesCommand.IsExecuting, (failed, loading) => !failed && loading)
                .ToProperty(this, x => x.IsLoading);
            loadRepositoriesCommand.Subscribe(Repositories.AddRange);
            filterTextIsEnabled = this.WhenAny(x => x.Repositories.Count, x => x.Value > 0)
                .ToProperty(this, x => x.FilterTextIsEnabled);
            noRepositoriesFound = this.WhenAny(x => x.FilterTextIsEnabled, x => x.IsLoading, x => x.LoadingFailed
                , (any, loading, failed) => !any.Value && !loading.Value && !failed.Value)
                .ToProperty(this, x => x.NoRepositoriesFound);

            var filterResetSignal = this.WhenAny(x => x.FilterText, x => x.Value)
                .DistinctUntilChanged(StringComparer.OrdinalIgnoreCase)
                .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler);

            FilteredRepositories = Repositories.CreateDerivedCollection(
                x => x,
                filter: FilterRepository,
                signalReset: filterResetSignal
            );

            BaseRepositoryPathValidator = this.CreateBaseRepositoryPathValidator();

            var canCloneObservable = this.WhenAny(
                x => x.SelectedRepository,
                x => x.BaseRepositoryPathValidator.ValidationResult.IsValid,
                (x, y) => x.Value != null && y.Value);
            canClone = canCloneObservable.ToProperty(this, x => x.CanClone);
            CloneCommand = ReactiveCommand.CreateAsyncObservable(canCloneObservable, OnCloneRepository);

            browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog());
            this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value)
                .Subscribe();
            BaseRepositoryPath = cloneService.DefaultClonePath;
        }
Example #22
0
        async Task Initialize()
        {
            if (initialized)
            {
                return;
            }

            // The services needed by the usage tracker are loaded when they are first needed to
            // improve the startup time of the extension.
            await JoinableTaskContext.Factory.SwitchToMainThreadAsync();

            client            = gitHubServiceProvider.TryGetService <IMetricsService>();
            connectionManager = gitHubServiceProvider.GetService <IConnectionManager>();
            vsservices        = gitHubServiceProvider.GetService <IVSServices>();
            initialized       = true;
        }
 public static IRepositoryPublishViewModel SetupConnectionsAndViewModel(
     IRepositoryHosts hosts = null,
     IRepositoryPublishService service = null,
     IVSServices vs = null,
     IConnectionManager cm = null,
     string uri = GitHubUrls.GitHub)
 {
     cm = cm ?? Substitutes.ConnectionManager;
     hosts = hosts ?? Substitute.For<IRepositoryHosts>();
     var adds = new List<HostAddress>();
     var hsts = new List<IRepositoryHost>();
     var conns = new List<IConnection>();
     SetupConnections(hosts, cm, adds, conns, hsts, uri);
     hsts[0].ModelService.GetAccounts().Returns(Observable.Return(new ReactiveList<IAccount>()));
     cm.Connections.Returns(new ObservableCollection<IConnection>(conns));
     return GetViewModel(hosts, service, vs, cm);
 }
Example #24
0
        public static IRepositoryPublishViewModel SetupConnectionsAndViewModel(
            IRepositoryHosts hosts            = null,
            IRepositoryPublishService service = null,
            IVSServices vs        = null,
            IConnectionManager cm = null,
            string uri            = GitHubUrls.GitHub)
        {
            cm    = cm ?? Substitutes.ConnectionManager;
            hosts = hosts ?? Substitute.For <IRepositoryHosts>();
            var adds  = new List <HostAddress>();
            var hsts  = new List <IRepositoryHost>();
            var conns = new List <IConnection>();

            SetupConnections(hosts, cm, adds, conns, hsts, uri);
            hsts[0].ModelService.GetAccounts().Returns(Observable.Return(new ReactiveList <IAccount>()));
            cm.Connections.Returns(new ObservableCollection <IConnection>(conns));
            return(GetViewModel(hosts, service, vs, cm));
        }
Example #25
0
        async Task Initialize()
        {
            // The services needed by the usage tracker are loaded when they are first needed to
            // improve the startup time of the extension.
            if (userSettings == null)
            {
                await ThreadingHelper.SwitchToMainThreadAsync();

                client            = gitHubServiceProvider.GetService <IMetricsService>();
                connectionManager = gitHubServiceProvider.GetService <IConnectionManager>();
                userSettings      = gitHubServiceProvider.GetService <IPackageSettings>();
                vsservices        = gitHubServiceProvider.GetService <IVSServices>();

                var program = gitHubServiceProvider.GetService <IProgram>();
                storePath = System.IO.Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                    program.ApplicationName,
                    StoreFileName);
            }
        }
        public ConnectionManager(IProgram program, Rothko.IOperatingSystem os, IVSServices services)
        {
            vsServices = services;
            fileExists = (path) => os.File.Exists(path);
            readAllText = (path, encoding) => os.File.ReadAllText(path, encoding);
            writeAllText = (path, content) => os.File.WriteAllText(path, content);
            fileDelete = (path) => os.File.Delete(path);
            dirExists = (path) => os.Directory.Exists(path);
            dirCreate = (path) => os.Directory.CreateDirectory(path);

            Connections = new ObservableCollection<IConnection>();
            cachePath = System.IO.Path.Combine(
                os.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                program.ApplicationName,
                cacheFile);

            LoadConnectionsFromCache();

            Connections.CollectionChanged += RefreshConnections;
        }
Example #27
0
        public ConnectionManager(IProgram program, Rothko.IOperatingSystem os, IVSServices services)
        {
            vsServices   = services;
            fileExists   = (path) => os.File.Exists(path);
            readAllText  = (path, encoding) => os.File.ReadAllText(path, encoding);
            writeAllText = (path, content) => os.File.WriteAllText(path, content);
            fileDelete   = (path) => os.File.Delete(path);
            dirExists    = (path) => os.Directory.Exists(path);
            dirCreate    = (path) => os.Directory.CreateDirectory(path);

            Connections = new ObservableCollection <IConnection>();
            cachePath   = System.IO.Path.Combine(
                os.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                program.ApplicationName,
                cacheFile);

            LoadConnectionsFromCache();

            Connections.CollectionChanged += RefreshConnections;
        }
        public GitHubConnectSection(IGitHubServiceProvider serviceProvider,
                                    ISimpleApiClientFactory apiFactory,
                                    ITeamExplorerServiceHolder holder,
                                    IConnectionManager manager,
                                    IPackageSettings packageSettings,
                                    IVSServices vsServices,
                                    int index)
            : base(serviceProvider, apiFactory, holder, manager)
        {
            Title        = "GitHub";
            IsEnabled    = true;
            IsVisible    = false;
            LoggedIn     = false;
            sectionIndex = index;

            this.packageSettings = packageSettings;
            this.vsServices      = vsServices;

            connectionManager.Connections.CollectionChanged += RefreshConnections;
            PropertyChanged += OnPropertyChange;
            UpdateConnection();
        }
Example #29
0
        async Task Initialize()
        {
            if (initialized)
            {
                return;
            }

            // The services needed by the usage tracker are loaded when they are first needed to
            // improve the startup time of the extension.
            await JoinableTaskContext.Factory.SwitchToMainThreadAsync();

            client            = gitHubServiceProvider.TryGetService <IMetricsService>();
            connectionManager = gitHubServiceProvider.GetService <IConnectionManager>();
            vsservices        = gitHubServiceProvider.GetService <IVSServices>();

            if (vsTelemetry)
            {
                log.Verbose("Creating VisualStudioUsageTracker");
                visualStudioUsageTracker = new VisualStudioUsageTracker(connectionManager);
            }

            initialized = true;
        }
Example #30
0
 public RepositoryPublishService(IGitClient gitClient, IVSServices services)
 {
     this.gitClient        = gitClient;
     this.activeRepository = services.GetActiveRepo();
 }
        public RepositoryPublishViewModel(
            IRepositoryHosts hosts,
            IRepositoryPublishService repositoryPublishService,
            IVSServices vsServices,
            IConnectionManager connectionManager)
        {
            this.vsServices = vsServices;
            this.hosts = hosts;

            title = this.WhenAny(
                x => x.SelectedHost,
                x => x.Value != null ?
                    string.Format(CultureInfo.CurrentCulture, "Publish repository to {0}", x.Value.Title) :
                    "Publish repository"
            )
            .ToProperty(this, x => x.Title);

            Connections = new ReactiveList<IConnection>(connectionManager.Connections);
            this.repositoryPublishService = repositoryPublishService;

            if (Connections.Any())
            {
                SelectedConnection = Connections.FirstOrDefault(x => x.HostAddress.IsGitHubDotCom()) ?? Connections[0];
            }

            accounts = this.WhenAny(x => x.SelectedConnection, x => x.Value != null ? hosts.LookupHost(x.Value.HostAddress) : RepositoryHosts.DisconnectedRepositoryHost)
                .Where(x => !(x is DisconnectedRepositoryHost))
                .SelectMany(host => host.ModelService.GetAccounts())
                .ObserveOn(RxApp.MainThreadScheduler)
                .ToProperty(this, x => x.Accounts, initialValue: new ReadOnlyCollection<IAccount>(new IAccount[] {}));

            this.WhenAny(x => x.Accounts, x => x.Value)
                .WhereNotNull()
                .Where(accts => accts.Any())
                .Subscribe(accts => {
                    var selectedAccount = accts.FirstOrDefault();
                    if (selectedAccount != null)
                    {
                        SelectedAccount = accts.FirstOrDefault();
                    }
                });

            isHostComboBoxVisible = this.WhenAny(x => x.Connections, x => x.Value)
                .WhereNotNull()
                .Select(h => h.Count > 1)
                .ToProperty(this, x => x.IsHostComboBoxVisible);

            InitializeValidation();

            PublishRepository = InitializePublishRepositoryCommand();

            canKeepPrivate = CanKeepPrivateObservable.CombineLatest(PublishRepository.IsExecuting,
                (canKeep, publishing) => canKeep && !publishing)
                .ToProperty(this, x => x.CanKeepPrivate);

            isPublishing = PublishRepository.IsExecuting
                .ToProperty(this, x => x.IsPublishing);

            var defaultRepositoryName = repositoryPublishService.LocalRepositoryName;
            if (!string.IsNullOrEmpty(defaultRepositoryName))
            {
                DefaultRepositoryName    = defaultRepositoryName;
            }

            this.WhenAny(x => x.SelectedConnection, x => x.SelectedAccount,
                (a,b) => true)
                .Where(x => RepositoryNameValidator.ValidationResult != null && SafeRepositoryNameWarningValidator.ValidationResult != null)
                .Subscribe(async _ =>
                {
                    var name = RepositoryName;
                    RepositoryName = null;
                    await RepositoryNameValidator.ResetAsync();
                    await SafeRepositoryNameWarningValidator.ResetAsync();
                    RepositoryName = name;
                });
        }
 public EnsureLoggedInSectionSync(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
     IConnectionManager cm, IRepositoryHosts hosts, IVSServices vsServices)
     : base(apiFactory, holder, cm, hosts, vsServices)
 {}
 public RepositoryPublishService(IGitClient gitClient, IVSServices services)
 {
     this.gitClient = gitClient;
     this.activeRepository = services.GetActiveRepo();
 }
        public RepositoryPublishViewModel(
            IRepositoryHosts hosts,
            IRepositoryPublishService repositoryPublishService,
            IVSServices vsServices,
            IConnectionManager connectionManager)
        {
            this.vsServices = vsServices;
            this.hosts      = hosts;

            title = this.WhenAny(
                x => x.SelectedHost,
                x => x.Value != null ?
                string.Format(CultureInfo.CurrentCulture, "Publish repository to {0}", x.Value.Title) :
                "Publish repository"
                )
                    .ToProperty(this, x => x.Title);

            Connections = new ReactiveList <IConnection>(connectionManager.Connections);
            this.repositoryPublishService = repositoryPublishService;

            if (Connections.Any())
            {
                SelectedConnection = Connections.FirstOrDefault(x => x.HostAddress.IsGitHubDotCom()) ?? Connections[0];
            }

            accounts = this.WhenAny(x => x.SelectedConnection, x => x.Value != null ? hosts.LookupHost(x.Value.HostAddress) : RepositoryHosts.DisconnectedRepositoryHost)
                       .Where(x => !(x is DisconnectedRepositoryHost))
                       .SelectMany(host => host.ModelService.GetAccounts())
                       .ObserveOn(RxApp.MainThreadScheduler)
                       .ToProperty(this, x => x.Accounts, initialValue: new ReadOnlyCollection <IAccount>(new IAccount[] {}));

            this.WhenAny(x => x.Accounts, x => x.Value)
            .WhereNotNull()
            .Where(accts => accts.Any())
            .Subscribe(accts => {
                var selectedAccount = accts.FirstOrDefault();
                if (selectedAccount != null)
                {
                    SelectedAccount = accts.FirstOrDefault();
                }
            });

            isHostComboBoxVisible = this.WhenAny(x => x.Connections, x => x.Value)
                                    .WhereNotNull()
                                    .Select(h => h.Count > 1)
                                    .ToProperty(this, x => x.IsHostComboBoxVisible);

            InitializeValidation();

            PublishRepository = InitializePublishRepositoryCommand();

            canKeepPrivate = CanKeepPrivateObservable.CombineLatest(PublishRepository.IsExecuting,
                                                                    (canKeep, publishing) => canKeep && !publishing)
                             .ToProperty(this, x => x.CanKeepPrivate);

            isPublishing = PublishRepository.IsExecuting
                           .ToProperty(this, x => x.IsPublishing);

            var defaultRepositoryName = repositoryPublishService.LocalRepositoryName;

            if (!string.IsNullOrEmpty(defaultRepositoryName))
            {
                DefaultRepositoryName = defaultRepositoryName;
            }

            this.WhenAny(x => x.SelectedConnection, x => x.SelectedAccount,
                         (a, b) => true)
            .Where(x => RepositoryNameValidator.ValidationResult != null && SafeRepositoryNameWarningValidator.ValidationResult != null)
            .Subscribe(async _ =>
            {
                var name       = RepositoryName;
                RepositoryName = null;
                await RepositoryNameValidator.ResetAsync();
                await SafeRepositoryNameWarningValidator.ResetAsync();
                RepositoryName = name;
            });
        }
Example #35
0
        async Task Initialize()
        {
            // The services needed by the usage tracker are loaded when they are first needed to
            // improve the startup time of the extension.
            if (userSettings == null)
            {
                await ThreadingHelper.SwitchToMainThreadAsync();

                client = uiProvider.GetService<IMetricsService>();
                connectionManager = uiProvider.GetService<IConnectionManager>();
                userSettings = uiProvider.GetService<IPackageSettings>();
                vsservices = uiProvider.GetService<IVSServices>();

                var program = uiProvider.GetService<IProgram>();
                storePath = System.IO.Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                    program.ApplicationName,
                    StoreFileName);
            }
        }
Example #36
0
 public EnsureLoggedInSectionSync(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
                                  IConnectionManager cm, IRepositoryHosts hosts, IVSServices vsServices)
     : base(apiFactory, holder, cm, hosts, vsServices)
 {
 }