protected override void Process()

in Powershell/XblConfig/GetDocuments.cs [64:125]


        protected override void Process()
        {
            if (!Enum.TryParse<DocumentType>(this.DocumentType, out DocumentType documentType))
            {
                throw new ArgumentException("Invalid DocumentType. Must be either 'Sandbox' or 'Account'.", nameof(this.DocumentType));
            }

            if (!Enum.TryParse(this.View, out View view))
            {
                throw new ArgumentException("Invalid View. Must be either 'Working' or 'Published'.", nameof(this.View));
            }

            if (documentType == Microsoft.Xbox.Services.DevTools.XblConfig.DocumentType.Sandbox && string.IsNullOrEmpty(this.Sandbox))
            {
                throw new ArgumentException("Sandbox must be specified when obtaining sandbox documents.");
            }

            if (documentType == Microsoft.Xbox.Services.DevTools.XblConfig.DocumentType.Sandbox && this.Scid == Guid.Empty)
            {
                throw new ArgumentException("SCID must be specified when obtaining sandbox documents.");
            }

            if (documentType == Microsoft.Xbox.Services.DevTools.XblConfig.DocumentType.Account)
            {
                this.Sandbox = null;
            }

            this.EnsureDirectory(this.Destination);

            Task<DocumentsResponse> documentsTask;
            if (documentType == Microsoft.Xbox.Services.DevTools.XblConfig.DocumentType.Sandbox)
            {
                this.WriteVerbose("Obtaining sandbox documents.");
                documentsTask = ConfigurationManager.GetSandboxDocumentsAsync(this.Scid, this.Sandbox);
            }
            else
            {
                this.WriteVerbose("Obtaining account documents.");
                documentsTask = ConfigurationManager.GetAccountDocumentsAsync(this.AccountId);
            }

            using (DocumentsResponse documents = documentsTask.Result)
            {
                this.WriteVerbose($"ETag: {documents.ETag}");
                this.WriteVerbose($"Version: {documents.Version}");
                this.WriteVerbose("Files: ");

                foreach (ConfigFileStream file in documents.Documents)
                {
                    string path = Path.Combine(this.Destination, file.Name);
                    using (FileStream fileStream = File.Create(path))
                    {
                        file.Stream.CopyTo(fileStream);
                    }

                    this.WriteVerbose($" - {file.Name}");
                }

                this.SaveETag(documents.ETag, this.Destination, this.Sandbox);
                this.WriteVerbose($"Saved {documents.Documents.Count()} files to {this.Destination}.");
            }
        }