Esempio n. 1
0
        /// <inheritdoc />
        protected override void Process()
        {
            this.WriteVerbose("Obtaining relying party document.");

            DocumentsResponse response = ConfigurationManager.GetRelyingPartyDocumentAsync(this.AccountId, this.Filename).Result;
            ConfigFileStream  document = response.Documents.First();

            using (Stream stream = document.Stream)
            {
                if (string.IsNullOrEmpty(this.Destination))
                {
                    using (StreamReader sr = new StreamReader(stream))
                    {
                        this.WriteObject(sr.ReadToEnd());
                    }
                }
                else
                {
                    this.EnsureDirectory(this.Destination);
                    string path = Path.Combine(this.Destination, document.Name);
                    using (StreamWriter sw = File.CreateText(path))
                    {
                        stream.CopyTo(sw.BaseStream);
                    }

                    this.WriteVerbose($"Document saved as {path}");
                }
            }
        }
        private static async Task <int> GetRelyingPartyDocumentAsync(GetRelyingPartyDocumentOptions options)
        {
            Console.WriteLine("Obtaining relying party document.");
            Console.WriteLine();

            DocumentsResponse response = await ConfigurationManager.GetRelyingPartyDocumentAsync(options.AccountId, options.Filename);

            ConfigFileStream document = response.Documents.First();

            using (Stream stream = document.Stream)
            {
                if (string.IsNullOrEmpty(options.Destination))
                {
                    using (StreamReader sr = new StreamReader(stream))
                    {
                        Console.WriteLine(sr.ReadToEnd());
                    }
                }
                else
                {
                    EnsureDirectory(options.Destination);
                    string path = Path.Combine(options.Destination, document.Name);
                    using (StreamWriter sw = File.CreateText(path))
                    {
                        await stream.CopyToAsync(sw.BaseStream);
                    }

                    Console.WriteLine($"Document saved as {path}");
                }
            }

            return(0);
        }