Example #1
0
        public void Initialize()
        {
            string asmDir = PathEx.GetDirectoryName(typeof(GitTests).Assembly.Location);

            this.rootDir = PathEx.Combine(asmDir, "test-root");
            DirectoryEx.Create(this.rootDir);
            DirectoryEx.Clear(this.rootDir);

            if (FileEx.Exists(credentialsFilePath))
            {
                var lines = File.ReadAllLines(credentialsFilePath);
                this.userName = lines[0];
                this.password = SecureStringExtensions.ToSecureString(lines[1]);
            }

            var fileOps = new TestFileOperationsExecuter(Path.Combine(this.rootDir, "agent"));

            //var fileOps = new SimulatedFileOperationsExecuter(fileOps);
            //fileOps.MessageLogged += (s, e) => TestLogger.Instance.Log(e.Level, e.Message);

            this.fileOps = fileOps;

            this.processExecuter = new TestRemoteProcessExecuter();
            this.jobExecuter     = new TestRemoteJobExecuter();
        }
 public RemoteLibGitSharpClient(IRemoteJobExecuter jobExecuter, string workingDirectory, bool simulation, CancellationToken cancellationToken, GitRepositoryInfo repository, ILogSink log)
     : base(repository, log)
 {
     this.jobExecuter       = jobExecuter ?? throw new NotSupportedException("A hosted agent must be used with the built-in LibGitSharp git client.");
     this.workingDirectory  = workingDirectory;
     this.simulation        = simulation;
     this.cancellationToken = cancellationToken;
 }
Example #3
0
        public RemoteLibGitSharpClient(IRemoteJobExecuter jobExecuter, string workingDirectory, bool simulation, CancellationToken cancellationToken, GitRepositoryInfo repository, ILogger log)
            : base(repository, log)
        {
            if (jobExecuter == null)
            {
                throw new NotSupportedException("A hosted agent must be used with the built-in LibGitSharp git client.");
            }
            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(WorkspacePath));
            }

            this.jobExecuter       = jobExecuter;
            this.workingDirectory  = workingDirectory;
            this.simulation        = simulation;
            this.cancellationToken = cancellationToken;
        }
Example #4
0
        private static async Task <Dictionary <string, RuntimeValueType> > GetPropertyTypesAsync(IOperationExecutionContext context, IRemoteJobExecuter jobRunner, string resourceName, string moduleName, ILogSink log)
        {
            var job = new ExecutePowerShellJob
            {
                CollectOutput = true,
                ScriptText    = @"$h = @{}
foreach($p in (Get-DscResource -Name $Name -Module $ModuleName).Properties) {
    $h[$p.Name] = $p.PropertyType
}
Write-Output $h",
                Variables     = new Dictionary <string, RuntimeValue>(StringComparer.OrdinalIgnoreCase)
                {
                    ["Name"]       = resourceName,
                    ["ModuleName"] = AH.CoalesceString(moduleName, "PSDesiredStateConfiguration")
                }
            };

            job.MessageLogged += (s, e) => log.Log(e.Level, e.Message);

            var result = (ExecutePowerShellJob.Result) await jobRunner.ExecuteJobAsync(job, context.CancellationToken);

            var properties = result.Output.FirstOrDefault().AsDictionary();

            var types = new Dictionary <string, RuntimeValueType>(StringComparer.OrdinalIgnoreCase);

            if (properties != null)
            {
                foreach (var p in properties)
                {
                    var value = p.Value.AsString();
                    types[p.Key] = (!string.IsNullOrWhiteSpace(value) && IsArrayPropertyRegex.IsMatch(value)) ? RuntimeValueType.Vector : RuntimeValueType.Scalar;
                }
            }

            return(types);
        }