Exemplo n.º 1
0
        public static void Copy(SPath fromPath, SPath toPath)
        {
            Logger.Trace("Copying from {0} to {1}", fromPath, toPath);

            try
            {
                CopyFolder(fromPath, toPath);
            }
            catch (Exception ex1)
            {
                Logger.Warning(ex1, "Error copying.");

                try
                {
                    CopyFolderContents(fromPath, toPath);
                }
                catch (Exception ex2)
                {
                    Logger.Error(ex2, "Error copying contents.");
                    throw;
                }
            }
            finally
            {
                fromPath.DeleteIfExists();
            }
        }
Exemplo n.º 2
0
        public IntegrationTestEnvironment(ICacheContainer cacheContainer,
                                          NPath repoPath,
                                          NPath solutionDirectory,
                                          NPath?environmentPath     = null,
                                          bool enableTrace          = false,
                                          bool initializeRepository = true)
        {
            defaultEnvironment = new DefaultEnvironment(cacheContainer);

            defaultEnvironment.FileSystem.SetCurrentDirectory(repoPath);
            environmentPath = environmentPath ??
                              defaultEnvironment.UserCachePath.EnsureDirectoryExists("IntegrationTests");

            UserCachePath   = environmentPath.Value.Combine("User");
            SystemCachePath = environmentPath.Value.Combine("System");

            var installPath = solutionDirectory.Parent.Parent.Combine("src", "GitHub.Api");

            Initialize(UnityVersion, installPath, solutionDirectory, NPath.Default, repoPath.Combine("Assets"));

            InitializeRepository(initializeRepository ? (NPath?)repoPath : null);

            this.enableTrace = enableTrace;

            if (enableTrace)
            {
                logger.Trace("EnvironmentPath: \"{0}\" SolutionDirectory: \"{1}\" ExtensionInstallPath: \"{2}\"",
                             environmentPath, solutionDirectory, ExtensionInstallPath);
            }
        }
Exemplo n.º 3
0
        public IntegrationTestEnvironment(ICacheContainer cacheContainer,
                                          NPath repoPath,
                                          NPath solutionDirectory,
                                          CreateEnvironmentOptions options = null,
                                          bool enableTrace          = false,
                                          bool initializeRepository = true)
        {
            this.enableTrace = enableTrace;

            options = options ?? new CreateEnvironmentOptions(NPath.SystemTemp.Combine(ApplicationInfo.ApplicationName, "IntegrationTests"));

            defaultEnvironment = new DefaultEnvironment(cacheContainer);
            defaultEnvironment.FileSystem.SetCurrentDirectory(repoPath);

            var environmentPath = options.UserProfilePath;

            LocalAppData    = environmentPath.Combine("User");
            UserCachePath   = LocalAppData.Combine("Cache");
            CommonAppData   = environmentPath.Combine("System");
            SystemCachePath = CommonAppData.Combine("Cache");

            var installPath = solutionDirectory.Parent.Parent.Parent.Combine("src", "com.unity.git.api", "Api");

            Initialize(UnityVersion, installPath, solutionDirectory, NPath.Default, repoPath.Combine("Assets"));

            InitializeRepository(initializeRepository ? (NPath?)repoPath : null);

            GitDefaultInstallation = new GitInstaller.GitInstallDetails(UserCachePath, this);

            if (enableTrace)
            {
                logger.Trace("EnvironmentPath: \"{0}\" SolutionDirectory: \"{1}\" ExtensionInstallPath: \"{2}\"",
                             environmentPath, solutionDirectory, ExtensionInstallPath);
            }
        }
Exemplo n.º 4
0
        public static void CopyFolder(NPath fromPath, NPath toPath)
        {
            Logger.Trace("CopyFolder fromPath: {0} toPath:{1}", fromPath.ToString(), toPath.ToString());

            toPath.EnsureParentDirectoryExists();
            fromPath.Move(toPath);
        }
Exemplo n.º 5
0
        public IntegrationTestEnvironment(ICacheContainer cacheContainer,
                                          NPath repoPath,
                                          NPath solutionDirectory,
                                          NPath environmentPath     = null,
                                          bool enableTrace          = false,
                                          bool initializeRepository = true)
        {
            defaultEnvironment = new DefaultEnvironment(cacheContainer);
            defaultEnvironment.FileSystem.SetCurrentDirectory(repoPath);
            environmentPath = environmentPath ??
                              defaultEnvironment.GetSpecialFolder(Environment.SpecialFolder.LocalApplicationData)
                              .ToNPath()
                              .EnsureDirectoryExists(ApplicationInfo.ApplicationName + "-IntegrationTests");

            integrationTestEnvironmentPath = environmentPath;
            UserCachePath   = integrationTestEnvironmentPath.Combine("User");
            SystemCachePath = integrationTestEnvironmentPath.Combine("System");

            var installPath = solutionDirectory.Parent.Parent.Combine("src", "GitHub.Api");

            Initialize(UnityVersion, installPath, solutionDirectory, repoPath.Combine("Assets"));

            if (initializeRepository)
            {
                InitializeRepository();
            }

            this.enableTrace = enableTrace;

            if (enableTrace)
            {
                logger.Trace("EnvironmentPath: \"{0}\" SolutionDirectory: \"{1}\" ExtensionInstallPath: \"{2}\"",
                             environmentPath, solutionDirectory, ExtensionInstallPath);
            }
        }
Exemplo n.º 6
0
 private void OnCacheUpdated(CacheType cacheType, DateTimeOffset datetime)
 {
     Logger.Trace("OnCacheUpdated cacheType:{0} datetime:{1}", cacheType, datetime);
     if (CacheUpdated != null)
     {
         CacheUpdated.Invoke(cacheType, datetime);
     }
 }
Exemplo n.º 7
0
        private async Task <GitHubRepository> CreateRepositoryInternal(string repositoryName, string organization, string description, bool isPrivate)
        {
            try
            {
                logger.Trace("Creating repository");

                var user = await GetCurrentUser();

                var keychainAdapter = keychain.Connect(OriginalUrl);

                var command = new StringBuilder("publish -r \"");
                command.Append(repositoryName);
                command.Append("\"");

                if (!string.IsNullOrEmpty(description))
                {
                    command.Append(" -d \"");
                    command.Append(description);
                    command.Append("\"");
                }

                if (!string.IsNullOrEmpty(organization))
                {
                    command.Append(" -o \"");
                    command.Append(organization);
                    command.Append("\"");
                }

                if (isPrivate)
                {
                    command.Append(" -p");
                }

                var octorunTask = new OctorunTask(taskManager.Token, nodeJsExecutablePath, octorunScriptPath, command.ToString(),
                                                  user: user.Login, userToken: keychainAdapter.Credential.Token)
                                  .Configure(processManager);

                var ret = await octorunTask.StartAwait();

                if (ret.IsSuccess && ret.Output.Length == 2)
                {
                    return(new GitHubRepository
                    {
                        Name = ret.Output[0],
                        CloneUrl = ret.Output[1]
                    });
                }

                throw new ApiClientException(ret.GetApiErrorMessage() ?? "Publish failed");
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error Creating Repository");
                throw;
            }
        }
Exemplo n.º 8
0
        public void Run(bool firstRun)
        {
            Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);

            var initEnvironmentTask = new ActionTask <NPath>(CancellationToken,
                                                             (_, path) => InitializeEnvironment(path))
            {
                Affinity = TaskAffinity.UI
            };

            isBusy = true;

            var octorunInstaller = new OctorunInstaller(Environment, TaskManager);
            var setupTask        = octorunInstaller
                                   .SetupOctorunIfNeeded()
                                   .Then((s, octorunPath) =>
            {
                Environment.OctorunScriptPath = octorunPath;
            });

            var initializeGitTask = new FuncTask <NPath>(CancellationToken, () =>
            {
                var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
                if (gitExecutablePath.HasValue && gitExecutablePath.Value.FileExists())     // we have a git path
                {
                    Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
                    return(gitExecutablePath.Value);
                }
                return(NPath.Default);
            });

            initializeGitTask.OnEnd += (t, path, _, __) =>
            {
                if (path.IsInitialized)
                {
                    return;
                }

                Logger.Trace("Using portable git");

                var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager);

                var task = gitInstaller.SetupGitIfNeeded();
                task.Progress(progressReporter.UpdateProgress);
                task.OnEnd += (thisTask, result, success, exception) =>
                {
                    thisTask.GetEndOfChain().Then(initEnvironmentTask, taskIsTopOfChain: true);
                };

                // append installer task to top chain
                t.Then(task, taskIsTopOfChain: true);
            };

            setupTask.Then(initializeGitTask).Start();
        }
Exemplo n.º 9
0
        private async Task SetupGit()
        {
            Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);

            if (Environment.GitExecutablePath == null)
            {
                Environment.GitExecutablePath = await DetermineGitExecutablePath();

                Logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", Environment.GitExecutablePath, Environment.GitExecutablePath.FileExists());

                if (Environment.IsWindows)
                {
                    var credentialHelper = await GitClient.GetConfig("credential.helper", GitConfigSource.Global).StartAwait();

                    if (!string.IsNullOrEmpty(credentialHelper))
                    {
                        Logger.Trace("Windows CredentialHelper: {0}", credentialHelper);
                    }
                    else
                    {
                        Logger.Warning("No Windows CredentialHeloper found: Setting to wincred");

                        await GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global).StartAwait();
                    }
                }
            }
        }
Exemplo n.º 10
0
        public UsageTracker(ISettings userSettings, NPath storePath, string guid, string unityVersion)
        {
            this.userSettings = userSettings;
            this.guid         = guid;
            this.storePath    = storePath;
            this.unityVersion = unityVersion;

            Logger.Trace("guid:{0}", guid);
            if (Enabled)
            {
                RunTimer(3 * 60);
            }
        }
Exemplo n.º 11
0
        public async void Execute(string data)
        {
            log.Trace(">>>>>>>>> REMOVE EXERCISE");

            await scenes.UnloadAll();

            bundles.Remove(runnerSettings.ExerciseInfo.Bundles);

            log.Trace(">>>>>>>>> ON COMPLETE EXERCISE " + data);

            platform.CaptureInput = false;

            sender.OnCompleteExercise(data);
        }
Exemplo n.º 12
0
        public virtual async Task Run(bool firstRun)
        {
            Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);

            if (Environment.GitExecutablePath == null)
            {
                GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
                Environment.GitExecutablePath = await DetermineGitExecutablePath();

                Logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", Environment.GitExecutablePath, Environment.GitExecutablePath.FileExists());

                if (Environment.IsWindows)
                {
                    var credentialHelper = await GitClient.GetConfig("credential.helper", GitConfigSource.Global).StartAwait();

                    if (string.IsNullOrEmpty(credentialHelper))
                    {
                        await GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global).StartAwait();
                    }
                }
            }

            RestartRepository();
            InitializeUI();
        }
Exemplo n.º 13
0
 private T ScheduleUI <T>(T task, bool setupFaultHandler)
     where T : ITask
 {
     if (setupFaultHandler)
     {
         task.Task.ContinueWith(tt =>
         {
             logger.Trace(tt.Exception.InnerException, String.Format("Exception on ui thread: {0} {1}", tt.Id, task.Name));
         },
                                cts.Token,
                                TaskContinuationOptions.OnlyOnFaulted, ConcurrentScheduler
                                );
     }
     return((T)task.Start(UIScheduler));
 }
Exemplo n.º 14
0
 protected void StartTrackTime(Stopwatch watch, ILogging logger = null, string message = "")
 {
     if (!String.IsNullOrEmpty(message))
         logger.Trace(message);
     watch.Reset();
     watch.Start();
 }
Exemplo n.º 15
0
        public TestData(string testName, ILogging logger, string serverDirectory)
        {
            TestName    = testName;
            Logger      = logger;
            Watch       = new Stopwatch();
            TestPath    = SPath.CreateTempDirectory(testName);
            TaskManager = new TaskManager();

            try
            {
                TaskManager.Initialize();
            }
            catch
            {
                // we're on the nunit sync context, which can't be used to create a task scheduler
                // so use a different context as the main thread. The test won't run on the main nunit thread
                ourContext = new MainThreadSynchronizationContext(TaskManager.Token);
                TaskManager.Initialize(ourContext);
            }

            Environment = new UnityEnvironment(testName);
            InitializeEnvironment();
            ProcessManager = new ProcessManager(Environment);
            Configuration  = new ServerConfiguration(serverDirectory);

            Logger.Trace($"START {testName}");
            Watch.Start();
        }
Exemplo n.º 16
0
 public void Dispose()
 {
     Watch.Stop();
     ProcessManager.Dispose();
     TaskManager.Dispose();
     ourContext?.Dispose();
     Logger.Trace($"STOP {TestName} :{Watch.ElapsedMilliseconds}ms");
 }
Exemplo n.º 17
0
        public async void Execute(string text)
        {
            log.Trace(">>>>>>>>> LOAD EXERCISE");
            var info = parser.Deserialize <ExerciseInfo>(text);

            settings.ExerciseId   = info.Id;
            settings.ExerciseInfo = info;

            localization.Add(info.Localization);

            await loadBundle.Execute(info.Bundles);

            await InitContexts(info.Contexts, context);

            log.Trace(">>>>>>>>> ON EXERCISE READY");
            sender.OnExerciseReady();
        }
Exemplo n.º 18
0
        public TestData(string testName, ILogging logger, string testRepoName = null, bool withHttpServer = false,
                        ICacheContainer cacheContainer = null,
                        IFileSystem fileSystem         = null)
        {
            TestName         = testName;
            Logger           = logger;
            Watch            = new Stopwatch();
            SourceDirectory  = TestContext.CurrentContext.TestDirectory.ToSPath();
            TestPath         = SPath.CreateTempDirectory(testName);
            SPath.FileSystem = fileSystem ?? new FileSystem(TestPath);

            if (cacheContainer == null)
            {
                var container = new CacheContainer();
                container.SetCacheInitializer(CacheType.Branches, () => BranchesCache.Instance);
                container.SetCacheInitializer(CacheType.GitAheadBehind, () => GitAheadBehindCache.Instance);
                container.SetCacheInitializer(CacheType.GitLocks, () => GitLocksCache.Instance);
                container.SetCacheInitializer(CacheType.GitLog, () => GitLogCache.Instance);
                container.SetCacheInitializer(CacheType.GitStatus, () => GitStatusCache.Instance);
                container.SetCacheInitializer(CacheType.GitUser, () => GitUserCache.Instance);
                container.SetCacheInitializer(CacheType.RepositoryInfo, () => RepositoryInfoCache.Instance);
                cacheContainer = container;
            }


            Environment = new IntegrationTestEnvironment(cacheContainer, TestPath, TestPath.Parent, testName);
            InitializeEnvironment(testRepoName);

            ApplicationManager = new ApplicationManagerBase(new MainThreadSynchronizationContext(), Environment);

            if (testRepoName != null)
            {
                var testZipFilePath = SourceDirectory.Combine("IOTestsRepo.zip");
                ZipHelper.Instance.Extract(testZipFilePath, TestPath, (_, __) => { }, (value, total, name) => true, token: TaskManager.Token);
                TestRepo = new TestRepoData(this, testRepoName);

                InstallTestGit();
                InitializeRepository();
            }

#if NUNIT
            if (withHttpServer)
            {
                var filesToServePath = SourceDirectory.Combine("files");
                HttpServer = new HttpServer(filesToServePath, 0);
                var started = new ManualResetEventSlim();
                var task    = TaskManager.With(HttpServer.Start, TaskAffinity.None);
                task.OnStart += _ => started.Set();
                task.Start();
                started.Wait();
            }
#endif
            ((ApplicationManagerBase)ApplicationManager).Initialize();

            Logger.Trace($"START {testName}");
            Watch.Start();
        }
Exemplo n.º 19
0
 internal void StartTrackTime(Stopwatch watch, ILogging logger, string message = "")
 {
     if (!string.IsNullOrEmpty(message))
     {
         logger.Trace(message);
     }
     watch.Reset();
     watch.Start();
 }
Exemplo n.º 20
0
        public UsageTracker(IMetricsService metricsService, ISettings userSettings,
                            IUsageLoader usageLoader,
                            string userId, string unityVersion, string instanceId)
        {
            this.userSettings   = userSettings;
            this.usageLoader    = usageLoader;
            this.metricsService = metricsService;
            this.userId         = userId;
            this.appVersion     = ApplicationInfo.Version;
            this.unityVersion   = unityVersion;
            this.instanceId     = instanceId;

            Logger.Trace("userId:{0} instanceId:{1}", userId, instanceId);
            if (Enabled)
            {
                RunTimer(3 * 60);
            }
        }
Exemplo n.º 21
0
        public void Start()
        {
            if (!IsRunning)
            {
                lock (_lock)
                {
                    if (!IsRunning)
                    {
                        logger.Trace("Starting");

                        httpListener = new HttpListener();
                        httpListener.Prefixes.Add(CallbackUrl.AbsoluteUri + "/");
                        httpListener.Start();
                        Task.Factory.StartNew(Listen, cancelSource.Token);
                        IsRunning = true;
                    }
                }
            }
        }
        public virtual async Task Run(bool firstRun)
        {
            Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);

            if (Environment.GitExecutablePath != null)
            {
                GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
            }
            else
            {
                var progress = new ProgressReport();

                var gitClient    = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
                var gitSetup     = new GitInstaller(Environment, CancellationToken);
                var expectedPath = gitSetup.GitInstallationPath;
                var setupDone    = await gitSetup.SetupIfNeeded(progress.Percentage, progress.Remaining);

                if (setupDone)
                {
                    Environment.GitExecutablePath = gitSetup.GitExecutablePath;
                }
                else
                {
                    Environment.GitExecutablePath = await LookForGitInstallationPath(gitClient, SystemSettings).SafeAwait();
                }

                GitClient = gitClient;

                Logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", gitSetup.GitExecutablePath, gitSetup.GitExecutablePath.FileExists());

                if (Environment.IsWindows)
                {
                    var credentialHelper = await GitClient.GetConfig("credential.helper", GitConfigSource.Global).StartAwait();

                    if (string.IsNullOrEmpty(credentialHelper))
                    {
                        await GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global).StartAwait();
                    }
                }
            }

            RestartRepository();
            InitializeUI();

            new ActionTask(CancellationToken, SetupMetrics).Start();
            new ActionTask(new Task(() => LoadKeychain().Start())).Start();
            new ActionTask(CancellationToken, RunRepositoryManager).Start();
        }
Exemplo n.º 23
0
        public async Task <IKeychainAdapter> Load(UriString host)
        {
            var keychainAdapter = FindOrCreateAdapter(host);

            logger.Trace("Load KeychainAdapter Host:\"{0}\"", host);
            var keychainItem = await credentialManager.Load(host);

            if (keychainItem == null)
            {
                logger.Warning("Cannot load host from credential manager; removing from cache");
                await Clear(host, false);
            }
            else
            {
                logger.Trace("Loading KeychainItem:{0}", keychainItem.ToString());
                keychainAdapter.Set(keychainItem);
            }

            return(keychainAdapter);
        }
Exemplo n.º 24
0
        public IProcess Reconnect(IProcess processTask, int pid)
        {
            logger.Trace("Reconnecting process " + pid);
            var p = Process.GetProcessById(pid);

            p.StartInfo.RedirectStandardInput  = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError  = true;
            processTask.Configure(p);
            return(processTask);
        }
Exemplo n.º 25
0
 private static void MoveFrom(string path)
 {
     try
     {
         logger.Trace("Installer move from '{0}'", path);
         // TODO: Create the necessary structure and perform the actual move of files into it from the given install path
     }
     catch (Exception e)
     {
         Failure(e.ToString());
     }
 }
Exemplo n.º 26
0
        public void Run(bool firstRun)
        {
            Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);

            var octorunScriptPath = Environment.UserCachePath.Combine("octorun", "src", "bin", "app.js");

            Logger.Trace("Using octorunScriptPath: {0}", octorunScriptPath);

            var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();

            if (gitExecutablePath.HasValue && gitExecutablePath.Value.FileExists()) // we have a git path
            {
                Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
                InitializeEnvironment(gitExecutablePath.Value, octorunScriptPath);
            }
            else // we need to go find git
            {
                Logger.Trace("No git path found in settings");

                var initEnvironmentTask = new ActionTask <NPath>(CancellationToken, (_, path) => InitializeEnvironment(path, octorunScriptPath))
                {
                    Affinity = TaskAffinity.UI
                };
                var findExecTask = new FindExecTask("git", CancellationToken)
                                   .FinallyInUI((b, ex, path) => {
                    if (b && path.IsInitialized)
                    {
                        Logger.Trace("FindExecTask Success: {0}", path);
                        InitializeEnvironment(path, octorunScriptPath);
                    }
                    else
                    {
                        Logger.Warning("FindExecTask Failure");
                        Logger.Error("Git not found");
                    }
                });

                var installDetails = new GitInstallDetails(Environment.UserCachePath, true);
                var gitInstaller   = new GitInstaller(Environment, CancellationToken, installDetails);

                // if successful, continue with environment initialization, otherwise try to find an existing git installation
                gitInstaller.SetupGitIfNeeded(initEnvironmentTask, findExecTask);
            }
        }
Exemplo n.º 27
0
        public async void Execute(string text)
        {
            var info = parser.Deserialize <AppInfo>(text);

            if (info.EnableLogging == 0)
            {
//                log.Level = LoggingLevel.OFF;
            }
            log.Trace(">>>>>>>>> INIT APP");
            localization.Add(info.Localization);

            var parameters = UriExtentsions.GetParams(platform.URL);

            if (platform.IsEditor)
            {
                settings.ExerciseId = info.DefaultExercise;
                settings.Mode       = settings.Mode ?? info.DefaultMode;
            }
            else if (!parameters.ContainsKey(RunnerConsts.IS_LOCAL))
            {
                settings.BasePath = info.BasePath;
            }

            platform.AntiAliasing  = GetAA(parameters, info.AntiAliasing);
            platform.EnableLogging = info.EnableLogging;

            var startedAt = info.StartedAt;
            var startTime = DateTimeOffset.FromUnixTimeSeconds(startedAt);

            var span = DateTime.UtcNow - startTime;

            log.Info("+++++++++++++++++++++++++++++++++++++++++ Time to start the unity app: " + span);

            var bundles = info.Bundles;
            await loadBundle.Execute(bundles);

            log.Trace(">>>>>>>>> ON ENGINE READY");
            sender.OnEngineReady();
        }
Exemplo n.º 28
0
        private void CacheHasBeenInvalidated(CacheType cacheType)
        {
            if (repositoryManager == null)
            {
                if (!cacheInvalidationRequests.Contains(cacheType))
                {
                    cacheInvalidationRequests.Add(cacheType);
                }
                return;
            }

            Logger.Trace($"CacheInvalidated {cacheType.ToString()}");
            switch (cacheType)
            {
            case CacheType.Branches:
                repositoryManager?.UpdateBranches();
                break;

            case CacheType.GitLog:
                repositoryManager?.UpdateGitLog();
                break;

            case CacheType.GitAheadBehind:
                repositoryManager?.UpdateGitAheadBehindStatus();
                break;

            case CacheType.GitLocks:
                if (CurrentRemote != null)
                {
                    repositoryManager?.UpdateLocks();
                }
                break;

            case CacheType.GitUser:
                // user handles its own invalidation event
                break;

            case CacheType.RepositoryInfo:
                repositoryManager?.UpdateRepositoryInfo();
                break;

            case CacheType.GitStatus:
                repositoryManager?.UpdateGitStatus();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(cacheType), cacheType, null);
            }
        }
Exemplo n.º 29
0
        public async Task <LoginResultData> ContinueLogin(LoginResultData loginResultData, string twofacode)
        {
            var client  = loginResultData.Client;
            var newAuth = loginResultData.NewAuth;
            var host    = loginResultData.Host;

            try
            {
                logger.Trace("2FA Continue");

                var auth = await CreateAndDeleteExistingApplicationAuthorization(
                    client,
                    newAuth,
                    twofacode);

                EnsureNonNullAuthorization(auth);

                keychain.SetToken(host, auth.Token);
                await keychain.Save(host);

                return(new LoginResultData(LoginResultCodes.Success, "", host));
            }
            catch (TwoFactorAuthorizationException e)
            {
                logger.Debug(e, "2FA TwoFactorAuthorizationException: {0} {1}", LoginResultCodes.CodeFailed, e.Message);

                return(new LoginResultData(LoginResultCodes.CodeFailed, Localization.Wrong2faCode, client, host, newAuth));
            }
            catch (ApiValidationException e)
            {
                logger.Debug(e, "2FA ApiValidationException: {0}", e.Message);

                var message = e.ApiError.FirstErrorMessageSafe();
                await keychain.Clear(host, false);

                return(new LoginResultData(LoginResultCodes.Failed, message, host));
            }
            catch (Exception e)
            {
                logger.Debug(e, "Exception: {0}", e.Message);

                await keychain.Clear(host, false);

                return(new LoginResultData(LoginResultCodes.Failed, e.Message, host));
            }
        }
Exemplo n.º 30
0
        public UsageTracker(IMetricsService metricsService, ISettings userSettings, NPath storePath, string userId, string unityVersion, string instanceId)
        {
            this.userSettings   = userSettings;
            this.metricsService = metricsService;
            this.userId         = userId;
            this.storePath      = storePath;
            this.unityVersion   = unityVersion;
            this.instanceId     = instanceId;

            Logger.Trace("userId:{0} instanceId:{1}", userId, instanceId);
            if (Enabled)
            {
                RunTimer(3 * 60);
            }
        }