protected override void Process()

in Powershell/XblConfig/GetSchemas.cs [56:119]


        protected override void Process()
        {
            dynamic obj = new DynamicDictionary(this.RuntimeParameters);

            if (string.IsNullOrEmpty(obj.Type))
            {
                // Get the schema types.
                this.WriteVerbose("Obtaining document schema types.");
                this.WriteObject(this.GetSchemaTypes());

                if (!string.IsNullOrEmpty(obj.Destination))
                {
                    foreach (string schemaType in this.GetSchemaTypes())
                    {
                        this.EnsureDirectory(obj.Destination);
                        ConfigResponse<IEnumerable<SchemaVersion>> versions = ConfigurationManager.GetSchemaVersionsAsync(schemaType).Result;
                        foreach (SchemaVersion version in versions.Result)
                        {
                            ConfigResponse<Stream> schema = ConfigurationManager.GetSchemaAsync(schemaType, version.Version).Result;
                            string path = Path.Combine(obj.Destination, $"{schemaType.ToLowerInvariant()}_{version.Version}.xsd");
                            using (FileStream fileStream = File.Create(path))
                            {
                                schema.Result.CopyTo(fileStream);
                            }
                        }
                    }
                }
            }
            else if (obj.Version <= 0)
            {
                // Get the schema versions.
                this.WriteVerbose($"Obtaining document schema versions for type {obj.Type}.");

                ConfigResponse<IEnumerable<SchemaVersion>> schemaVersions = ConfigurationManager.GetSchemaVersionsAsync(obj.Type).Result;
                this.WriteObject(schemaVersions.Result);
            }
            else
            {
                this.WriteVerbose($"Obtaining document schema {this.GetParameter<string>("Type")} for version {obj.Version}.");

                ConfigResponse<Stream> schema = ConfigurationManager.GetSchemaAsync(obj.Type, obj.Version).Result;

                if (string.IsNullOrEmpty(obj.Destination))
                {
                    // The destination wasn't specified. Output the schema to stdout.
                    using (StreamReader sr = new StreamReader(schema.Result))
                    {
                        this.WriteObject(sr.ReadToEnd());
                    }
                }
                else
                {
                    // The destination exists. Save the file to the directory.
                    this.EnsureDirectory(obj.Destination);
                    string path = Path.Combine(obj.Destination, $"{obj.Type.ToLowerInvariant()}_{obj.Version}.xsd");
                    using (FileStream fileStream = File.Create(path))
                    {
                        schema.Result.CopyTo(fileStream);
                    }

                    this.WriteVerbose($"Schema saved as {path}");
                }
            }
        }