示例#1
0
        private string GetXmlOutputPath(IFileOperationsExecuter fileOps)
        {
            if (string.IsNullOrWhiteSpace(this.CustomXmlOutputPath))
            {
                return(fileOps.CombinePath(this.Context.TempDirectory, Guid.NewGuid().ToString() + ".xml"));
            }

            return(fileOps.CombinePath(this.Context.SourceDirectory, this.CustomXmlOutputPath));
        }
示例#2
0
        private string GetAbsPath(IFileOperationsExecuter agt, string path)
        {
            // TODO This duplicates pathing logic in AgentHelper::GetWorkingDirectory
            //   The reason we have to do this here is because the RemoteActionExecutor
            //   will split the working directory into source and target. Until there is
            //   a way to override or block the splitting, then this logic is required.

            if (path == null)
            {
                return(this.Context.SourceDirectory);
            }
            else if (Path.IsPathRooted(path))
            {
                return(path);
            }
            else if (path.StartsWith("~"))
            {
                return(agt.GetLegacyWorkingDirectory((IGenericBuildMasterContext)this.Context, path));
            }
            else
            {
                return(agt.CombinePath(
                           this.Context.SourceDirectory,
                           path
                           ));
            }
        }
        private async Task UnlockRegistryAsync(IFileOperationsExecuter fileOps)
        {
            if (this.LockToken == null)
            {
                return;
            }

            var fileName = fileOps.CombinePath(this.RegistryRoot, ".lock");

            if (!await fileOps.FileExistsAsync(fileName).ConfigureAwait(false))
            {
                return;
            }

            string token;

            using (var lockStream = await fileOps.OpenFileAsync(fileName, FileMode.Open, FileAccess.Read).ConfigureAwait(false))
                using (var reader = new StreamReader(lockStream, InedoLib.UTF8Encoding))
                {
                    reader.ReadLine();
                    token = reader.ReadLine();
                }

            if (token == this.LockToken)
            {
                await fileOps.DeleteFileAsync(fileName).ConfigureAwait(false);
            }

            this.LockToken = null;
        }
示例#4
0
        private string GetNUnitExePath(IFileOperationsExecuter fileOps)
        {
            if (!string.IsNullOrWhiteSpace(this.ExePath))
            {
                return(fileOps.CombinePath(this.Context.SourceDirectory, this.ExePath));
            }

            var configurer = (NUnitConfigurer)this.GetExtensionConfigurer();

            if (string.IsNullOrWhiteSpace(configurer.NUnitConsoleExePath))
            {
                throw new InvalidOperationException("The path to NUnit was not specified in either the action or the selected NUnit extension's configuration.");
            }

            return(fileOps.CombinePath(this.Context.SourceDirectory, configurer.NUnitConsoleExePath));
        }
            public RemoteTemporaryFile(IFileOperationsExecuter fileOps, ILogSink log)
            {
                this.fileOps = fileOps;
                this.log     = log;

                string workingDirectory = fileOps.GetBaseWorkingDirectory();
                string fileName         = Guid.NewGuid().ToString("n");

                this.Path = fileOps.CombinePath(workingDirectory, fileName);
            }
        private static async Task WriteInstalledPackagesAsync(IFileOperationsExecuter fileOps, string registryRoot, IEnumerable <RegisteredPackage> packages)
        {
            var fileName = fileOps.CombinePath(registryRoot, "installedPackages.json");

            using (var configStream = await fileOps.OpenFileAsync(fileName, FileMode.Create, FileAccess.Write).ConfigureAwait(false))
                using (var streamWriter = new StreamWriter(configStream, InedoLib.UTF8Encoding))
                    using (var jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        new JsonSerializer {
                            Formatting = Formatting.Indented
                        }.Serialize(jsonWriter, packages.ToArray());
                    }
        }
        private static string GetBuildMasterExecutionBaseWorkingDirectory(IFileOperationsExecuter agent, IOperationExecutionContext context)
        {
            if (agent == null)
            {
                throw new ArgumentNullException(nameof(agent));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var relativePath = "_E" + context.ExecutionId;

            return(agent.CombinePath(agent.GetBaseWorkingDirectory(), relativePath));
        }
        private static async Task <List <RegisteredPackage> > GetInstalledPackagesAsync(IFileOperationsExecuter fileOps, string registryRoot)
        {
            var fileName = fileOps.CombinePath(registryRoot, "installedPackages.json");

            if (!await fileOps.FileExistsAsync(fileName).ConfigureAwait(false))
            {
                return(new List <RegisteredPackage>());
            }

            using (var configStream = await fileOps.OpenFileAsync(fileName, FileMode.Open, FileAccess.Read).ConfigureAwait(false))
                using (var streamReader = new StreamReader(configStream, InedoLib.UTF8Encoding))
                    using (var jsonReader = new JsonTextReader(streamReader))
                    {
                        return((new JsonSerializer().Deserialize <RegisteredPackage[]>(jsonReader) ?? new RegisteredPackage[0]).ToList());
                    }
        }
示例#9
0
 public static string GetFullRepositoryPath(this IGitRepository repo, IFileOperationsExecuter agent)
 {
     return(agent.CombinePath(agent.GetBaseWorkingDirectory(), "GitRepositories", repo.RepositoryPath));
 }
        private async Task LockRegistryAsync(IFileOperationsExecuter fileOps, CancellationToken cancellationToken)
        {
            var fileName = fileOps.CombinePath(this.RegistryRoot, ".lock");

            var lockDescription = "Locked by " + SDK.ProductName;
            var lockToken       = Guid.NewGuid().ToString();

TryAgain:
            var fileInfo = await getFileInfoAsync().ConfigureAwait(false);

            string lastToken = null;

            while (fileInfo.Item1 != null && DateTime.UtcNow - fileInfo.Item1.LastWriteTimeUtc <= new TimeSpan(0, 0, 10))
            {
                if ((lastToken == null || !string.Equals(lastToken, fileInfo.Item3)) && fileInfo.Item3 != null)
                {
                    this.logger?.LogDebug("Package registry is locked: " + fileInfo.Item2);
                    lastToken = fileInfo.Item3;
                }
                await Task.Delay(500, cancellationToken).ConfigureAwait(false);

                fileInfo = await getFileInfoAsync().ConfigureAwait(false);
            }

            // ensure registry root exists
            await fileOps.CreateDirectoryAsync(this.RegistryRoot).ConfigureAwait(false);

            try
            {
                // write out the lock info
                using (var lockStream = await fileOps.OpenFileAsync(fileName, FileMode.Create, FileAccess.Write).ConfigureAwait(false))
                    using (var writer = new StreamWriter(lockStream, InedoLib.UTF8Encoding))
                    {
                        writer.WriteLine(lockDescription);
                        writer.WriteLine(lockToken);
                    }

                // verify that we acquired the lock
                using (var lockStream = await fileOps.OpenFileAsync(fileName, FileMode.Open, FileAccess.Read).ConfigureAwait(false))
                    using (var reader = new StreamReader(lockStream, InedoLib.UTF8Encoding))
                    {
                        if (reader.ReadLine() != lockDescription)
                        {
                            goto TryAgain;
                        }

                        if (reader.ReadLine() != lockToken)
                        {
                            goto TryAgain;
                        }
                    }
            }
            catch (IOException ex)
            {
                this.logger?.LogDebug("Locking package registry failed: " + ex.Message);

                // file may be in use by other process
                goto TryAgain;
            }

            // at this point, lock is acquired provided everyone is following the rules
            this.LockToken = lockToken;

            async Task <(SlimFileInfo, string, string)> getFileInfoAsync()
            {
                try
                {
                    var info = await fileOps.GetFileInfoAsync(fileName).ConfigureAwait(false);

                    string description = null, token = null;
                    try
                    {
                        using (var lockStream = await fileOps.OpenFileAsync(fileName, FileMode.Open, FileAccess.Read).ConfigureAwait(false))
                            using (var reader = new StreamReader(lockStream, InedoLib.UTF8Encoding))
                            {
                                description = await reader.ReadLineAsync().ConfigureAwait(false);

                                token = await reader.ReadLineAsync().ConfigureAwait(false);
                            }
                    }
                    catch (IOException)
                    {
                    }

                    return(info, description, token);
                }
                catch (FileNotFoundException)
                {
                    return(null, null, null);
                }
                catch (DirectoryNotFoundException)
                {
                    return(null, null, null);
                }
            }
        }
        private string GetXmlOutputPath(IFileOperationsExecuter fileOps)
        {
            if (string.IsNullOrWhiteSpace(this.CustomXmlOutputPath))
                return fileOps.CombinePath(this.Context.TempDirectory, Guid.NewGuid().ToString() + ".xml");

            return fileOps.CombinePath(this.Context.SourceDirectory, this.CustomXmlOutputPath);
        }
示例#12
0
 public static string GetFullRepositoryPath(this IGitRepository repo, IFileOperationsExecuter agent)
 {
     return agent.CombinePath(agent.GetBaseWorkingDirectory(), "GitRepositories", repo.RepositoryPath);
 }