Пример #1
0
        public async Task Create_EndToEnd()
        {
            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            // act

            dynamic create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);
            await ContentClient.PublishContent("aut", schemaName, create1id);

            await ContentClient.PublishContent("aut", schemaName, create2id);

            // note : eventual consistency and all that sometimes we don't get away with validating right away.

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.AssertContentMustExists("aut", schemaName, create1id, delay : TimeSpan.FromSeconds(0.5));

            await ContentClient.AssertContentMustExists("aut", schemaName, create2id, delay : TimeSpan.FromSeconds(0.5));

            // todo : verify export content

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
Пример #2
0
        public async Task ContentDelete_Execute_EndToEnd()
        {
            var name1 = GetRandomSchemaName;
            await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(name1));

            await SchemaClient.PublishSchema("aut", name1);

            dynamic create1response = await ContentClient.CreateContent("aut", name1, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", name1, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);
            await ContentClient.PublishContent("aut", name1, create1id);

            await ContentClient.PublishContent("aut", name1, create2id);

            // act

            await ContentStories.DeleteContent(ContentDeleteSystemUnderTest, "aut", name1, create1id);

            // todo : verify export content

            await ContentClient.AssertContentMustNotExists("aut", name1, create1id, delay : TimeSpan.FromSeconds(0.5));

            await ContentClient.AssertContentMustExists("aut", name1, create2id, delay : TimeSpan.FromSeconds(0.5));

            // clean up

            await SchemaClient.DeleteSchema("aut", name1);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
Пример #3
0
        public async Task Get_EndToEnd()
        {
            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            dynamic create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);
            await ContentClient.PublishContent("aut", schemaName, create1id);

            await ContentClient.PublishContent("aut", schemaName, create2id);

            // act

            var get1response = await ContentClient.GetContent("aut", schemaName, create1id);

            var get2response = await ContentClient.GetContent("aut", schemaName, create2id);

            // todo : verify export content

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
Пример #4
0
        public async Task ContentPost_Execute_EndToEnd()
        {
            var name1 = GetRandomSchemaName;
            await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(name1));

            await SchemaClient.PublishSchema("aut", name1);

            var expectedFirst  = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[0];
            var expectedSecond = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[1];

            // act

            await ContentStories.PostContent(ContentPostSystemUnderTest, "aut", name1, AssetLoader.AsPath(AssetLoader.Schema1Data1PostName), publish : true);

            await ContentStories.PostContent(ContentPostSystemUnderTest, "aut", name1, AssetLoader.AsPath(AssetLoader.Schema1Data2PostName), publish : true);

            var content = await ContentClient.QueryContent("aut", name1, new QueryRequest()
            {
                Skip = 0,
                Top  = 100
            });

            int contentTotal = Convert.ToInt32(content.Total);

            contentTotal.Should().Be(2);
            var actualFirst  = content.Items[0];
            var actualSecond = content.Items[1];

            // todo : verify export content

            await SchemaClient.DeleteSchema("aut", name1);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
Пример #5
0
        public async Task ContentImport_Execute_EndToEnd()
        {
            var name1 = GetRandomSchemaName;
            await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(name1));

            await SchemaClient.PublishSchema("aut", name1);

            var expected1 = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[0];
            var expected2 = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[1];

            await ContentStories.ImportContent(ContentImportSystemUnderTest, "aut", name1, AssetLoader.AsPath(AssetLoader.Schema1DataImportName), publish : true);

            var actuals = await ContentClient.QueryContent("aut", name1, new QueryRequest()
            {
                Skip = 0,
                Top  = 100
            });

            var actualsTotal = actuals.Total;

            actualsTotal.Should().Be(2);

            var actual1 = actuals.Items[0];
            var actual2 = actuals.Items[1];

            // todo : verify

            await SchemaClient.DeleteSchema("aut", name1);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
Пример #6
0
 protected override void BeginProcessing()
 {
     if (!DefaultTimeToLive.HasValue) DefaultTimeToLive = TimeSpan.FromDays(999);
     if (DefaultTimeToLive <= TimeSpan.Zero) throw new PSArgumentException("DefaultTimeToLive must be a positive value. Try using [TimeSpan]::FromMinutes(123) or similar.");
     if (string.IsNullOrEmpty(SchemaName)) throw new PSArgumentException("SchemaName is required.");
     base.BeginProcessing();
     schemaClient = new SchemaClient(ConnectionString, SchemaName);
 }
Пример #7
0
        public async Task Restore_EndToEnd()
        {
            // Query only 'sees' published records so that is a quick way to determine publish state
            // - insert some records
            // - publish them
            // - archive them
            // - assert there are none (because we archived them)

            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            var create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            var create2response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.PublishContent("aut", schemaName, create1response.Id);

            await ContentClient.PublishContent("aut", schemaName, create2response.Id);

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.ArchiveContent("aut", schemaName, create1response.Id);

            await ContentClient.ArchiveContent("aut", schemaName, create2response.Id);

            // act

            // note : eventual consistency and all that sometimes we don't get away with validating right away.

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.RestoreContent("aut", schemaName, create1response.Id);

            await ContentClient.RestoreContent("aut", schemaName, create2response.Id);

            await Task.Delay(TimeSpan.FromSeconds(1));

            //var content = await ContentClient.Query<dynamic>("aut", schemaName, new QueryRequest()
            //{
            //  Skip = 0,
            //  Top = 100
            //});
            var content = await ContentClient.QueryContent("aut", schemaName, top : 100, skip : 0);

            // ma
            content.Total.Should().Be(2);

            // clean up

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
        public async Task DeleteSchema_EndToEnd()
        {
            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createresult = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var deleteresult = await SchemaClient.DeleteSchema("aut", schemaName);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
        public async Task SchemaImport_Execute_EndToEnd()
        {
            var name1 = GetRandomSchemaName;

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            await SchemaStories.ImportSchema(SchemaImportSystemUnderTest, "aut", name1, AssetLoader.AsPath(AssetLoader.Schema1Name));

            await SchemaClient.AssertSchemaMustExist("aut", name1, delay : TimeSpan.FromSeconds(0.5));

            await SchemaClient.DeleteSchema("aut", name1);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
        public async Task SchemaDelete_Execute_EndToEnd()
        {
            var name1 = GetRandomSchemaName;

            await SchemaClient.AssertNoSchemasExist("aut");

            await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(name1));

            await SchemaClient.PublishSchema("aut", name1);

            await SchemaStories.DeleteSchema(SchemaDeleteSystemUnderTest, "aut", name1);

            await SchemaClient.AssertSchemaMustNotExist("aut", name1, delay : TimeSpan.FromSeconds(5));

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
        public async Task PublishSchema_EndToEnd()
        {
            var schema1name = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var create1result = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schema1name));

            var result = await SchemaClient.PublishSchema("aut", schema1name);

            //int count = Convert.ToInt32(that.Count);
            //count.Should().Be(2);

            var delete1result = await SchemaClient.DeleteSchema("aut", schema1name);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
        private async Task PurgeSchema()
        {
            var data = await SchemaClient.GetAllSchemas("aut");

            var count = Convert.ToInt32(data.Count);

            if (count == 0)
            {
                return;
            }

            var allnames = ((IEnumerable <dynamic>)data).Select(d => Convert.ToString(d.name));

            foreach (var name in allnames)
            {
                await SchemaClient.DeleteSchema("aut", name);
            }
        }
Пример #13
0
        public async Task Patch_EndToEnd()
        {
            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            dynamic create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            string  create1id      = Convert.ToString(create1response.id);
            dynamic patch1response = await ContentClient.PatchContent("aut", schemaName, create1id, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            // clean up

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
Пример #14
0
        protected void Initialize(string baseAddress, TimeSpan commandTimeout, string username = "", string password = "")
        {
            Client             = new HttpClient();
            Client.BaseAddress = new Uri(baseAddress);
            Client.Timeout     = commandTimeout;

            Token = null;

            Security    = new SecurityClient(this);
            Schema      = new SchemaClient(this);
            Transaction = new TransactionClient(this);
            Document    = new DocumentClient(this);
            Query       = new QueryClient(this);

            if (string.IsNullOrWhiteSpace(username) == false)
            {
                Security.Login(username, password);
            }
        }
Пример #15
0
        public async Task Publish_EndToEnd()
        {
            // Query only 'sees' published records so that is a quick way to determine publish state
            // - insert some records
            // - assert that there are none (because we havent published them)
            // - publish them
            // - assert there are two (because we published two)

            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            dynamic create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);


            // act

            // note : eventual consistency and all that sometimes we don't get away with validating right away.

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.PublishContent("aut", schemaName, create1id);

            await ContentClient.PublishContent("aut", schemaName, create2id);

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.AssertContentMustExists("aut", schemaName, create1id, delay : TimeSpan.FromSeconds(0.5));

            await ContentClient.AssertContentMustExists("aut", schemaName, create2id, delay : TimeSpan.FromSeconds(0.5));

            // clean up

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
Пример #16
0
        public async Task Query_EndToEnd()
        {
            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            dynamic create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);
            await ContentClient.PublishContent("aut", schemaName, create1id);

            await ContentClient.PublishContent("aut", schemaName, create2id);

            // act

            // note : eventual consistency and all that sometimes we don't get away with validating right away.

            await Task.Delay(TimeSpan.FromSeconds(1));

            //var content = await ContentClient.Query<dynamic>("aut", schemaName, new QueryRequest()
            //{
            //  Skip = 0,
            //  Top = 100
            //});
            var content = await ContentClient.QueryContent("aut", schemaName, top : 100, skip : 0);

            int contenttotal = Convert.ToInt32(content.total);

            contenttotal.Should().Be(2);
            var actualFirst  = content.items[0];
            var actualSecond = content.items[1];

            // todo : verify export content

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
Пример #17
0
        public async Task SchemaExists_EndToEnd()
        {
            var schemaName = GetRandomName;

            var nothingExists = await SchemaClient.SchemaExists("aut");

            nothingExists.Should().BeFalse();

            var somethingDoesNotExist = await SchemaClient.SchemaExists("aut", schemaName);

            somethingDoesNotExist.Should().BeFalse();

            var createresult = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var somethingDefinatelyExist = await SchemaClient.SchemaExists("aut", schemaName);

            somethingDefinatelyExist.Should().BeTrue();

            var deleteresult = await SchemaClient.DeleteSchema("aut", schemaName);
        }
        public async Task GetAllSchemas_EndToEnd()
        {
            var schema1name = GetRandomName;
            var schema2name = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var create1result = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schema1name));

            var create2result = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schema2name));

            var all = await SchemaClient.GetAllSchemas("aut");

            int count = Convert.ToInt32(all.Count);

            count.Should().Be(2);

            var delete1result = await SchemaClient.DeleteSchema("aut", schema1name);

            var delete2result = await SchemaClient.DeleteSchema("aut", schema2name);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
        public async Task SchemaExport_Execute_EndToEnd()
        {
            var name1       = GetRandomSchemaName;
            var exportPath1 = Path.Combine(AssetLoader.ExportPath, $"{nameof(SchemaHandlersIntegrationTest)} {nameof(SchemaExport_Execute_EndToEnd)}-out.json");

            await SchemaClient.AssertNoSchemasExist("aut");

            await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(name1));

            await SchemaClient.PublishSchema("aut", name1);

            await SchemaStories.ExportSchema(SchemaExportSystemUnderTest, "aut", name1, exportPath1);

            var exportedFileExists = File.Exists(exportPath1);

            exportedFileExists.Should().BeTrue($"{nameof(SchemaExportRequest)} failed to export file");

            // todo validate export file

            await SchemaClient.DeleteSchema("aut", name1);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
Пример #20
0
        public async Task ContentExport_Execute_EndToEnd()
        {
            var name1  = GetRandomSchemaName;
            var export = Path.Combine(AssetLoader.ExportPath, $"{nameof(ContentHandlersIntegrationTest)} {nameof(ContentExport_Execute_EndToEnd)}-out.json");

            await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(name1));

            await SchemaClient.PublishSchema("aut", name1);

            dynamic create1response = await ContentClient.CreateContent("aut", name1, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", name1, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);
            await ContentClient.PublishContent("aut", name1, create1id);

            await ContentClient.PublishContent("aut", name1, create2id);

            var expected1 = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[0];
            var expected2 = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[1];

            // act

            await ContentStories.ExportContent(ContentExportSystemUnderTest, "aut", name1, export, top : "10", skip : "0");

            var exportExists = File.Exists(export);

            exportExists.Should().BeTrue($"{nameof(SchemaExportRequest)} failed to export file");

            // todo : verify export content

            await SchemaClient.DeleteSchema("aut", name1);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
        public static async Task HandlerAsync(InvocationContext invocationContext, Uri server, string connectionString, CancellationToken cancellationToken = default)
        {
            var region = new Region(
                0,
                0,
                Console.WindowWidth,
                Console.WindowHeight,
                true);
            List <CurrentVersion> currentVersions = null;
            ISchemaClient         schemaClient    = new SchemaClient(server);

            try
            {
                // Base schema is required to run the schema migration tool.
                // This method also initializes the database if not initialized yet.
                await BaseSchemaRunner.EnsureBaseSchemaExistsAsync(connectionString, cancellationToken);

                // If InstanceSchema table is just created(as part of baseSchema), it takes a while to insert a version record
                // since the Schema job polls and upserts at the specified interval in the service.
                await BaseSchemaRunner.EnsureInstanceSchemaRecordExistsAsync(connectionString, cancellationToken);

                currentVersions = await schemaClient.GetCurrentVersionInformationAsync(cancellationToken);
            }
            catch (SchemaManagerException ex)
            {
                CommandUtils.PrintError(ex.Message);
                return;
            }
            catch (HttpRequestException)
            {
                CommandUtils.PrintError(string.Format(Resources.RequestFailedMessage, server));
                return;
            }

            var tableView = new TableView <CurrentVersion>
            {
                Items = currentVersions,
            };

            tableView.AddColumn(
                cellValue: currentVersion => currentVersion.Id,
                header: new ContentView("Version"));

            tableView.AddColumn(
                cellValue: currentVersion => currentVersion.Status,
                header: new ContentView("Status"));

            tableView.AddColumn(
                cellValue: currentVersion => string.Join(", ", currentVersion.Servers),
                header: new ContentView("Servers"));

            var consoleRenderer = new ConsoleRenderer(
                invocationContext.Console,
                mode: invocationContext.BindingContext.OutputMode(),
                resetAfterRender: true);

            using (var screen = new ScreenView(renderer: consoleRenderer))
            {
                screen.Child = tableView;
                screen.Render(region);
            }
        }
Пример #22
0
 protected override void BeginProcessing()
 {
     if (string.IsNullOrEmpty(SchemaName)) throw new PSArgumentException("SchemaName is required.");
     base.BeginProcessing();
     schemaClient = new SchemaClient(ConnectionString, SchemaName);
 }
        public static async Task HandlerAsync(string connectionString, Uri server, MutuallyExclusiveType exclusiveType, bool force, CancellationToken cancellationToken = default)
        {
            ISchemaClient schemaClient = new SchemaClient(server);

            if (force && !EnsureForce())
            {
                return;
            }

            try
            {
                // Base schema is required to run the schema migration tool.
                // This method also initializes the database if not initialized yet.
                await BaseSchemaRunner.EnsureBaseSchemaExistsAsync(connectionString, cancellationToken);

                // If InstanceSchema table is just created(as part of baseSchema), it takes a while to insert a version record
                // since the Schema job polls and upserts at the specified interval in the service.
                await BaseSchemaRunner.EnsureInstanceSchemaRecordExistsAsync(connectionString, cancellationToken);

                availableVersions = await schemaClient.GetAvailabilityAsync(cancellationToken);

                // If the user hits apply command multiple times in a row, then the service schema job might not poll the updated available versions
                // so there are retries to give it a fair amount of time.
                int attemptCount = 1;

                await Policy.Handle <SchemaManagerException>()
                .WaitAndRetryAsync(
                    retryCount: RetryAttempts,
                    sleepDurationProvider: (retryCount) => RetrySleepDuration,
                    onRetry: (exception, retryCount) =>
                {
                    Console.WriteLine(string.Format(Resources.RetryCurrentSchemaVersion, attemptCount++, RetryAttempts));
                })
                .ExecuteAsync(token => FetchUpdatedAvailableVersionsAsync(schemaClient, connectionString, token), cancellationToken);

                if (availableVersions.Count == 1)
                {
                    CommandUtils.PrintError(Resources.AvailableVersionsDefaultErrorMessage);
                    return;
                }

                // Removes the current version since the first available version is always the current version which is already applied.
                availableVersions.RemoveAt(0);

                var targetVersion = exclusiveType.Next == true?availableVersions.First().Id:
                                    exclusiveType.Latest == true?availableVersions.Last().Id:
                                    exclusiveType.Version;

                availableVersions = availableVersions.Where(availableVersion => availableVersion.Id <= targetVersion)
                                    .ToList();

                // Checking the specified version is not out of range of available versions
                if (availableVersions.Count < 1 || targetVersion < availableVersions.First().Id || targetVersion > availableVersions.Last().Id)
                {
                    throw new SchemaManagerException(string.Format(Resources.SpecifiedVersionNotAvailable, targetVersion));
                }

                if (!force)
                {
                    await ValidateVersionCompatibility(schemaClient, availableVersions.Last().Id, cancellationToken);
                }

                if (availableVersions.First().Id == 1)
                {
                    // Upgrade schema directly to the latest schema version
                    Console.WriteLine(string.Format(Resources.SchemaMigrationStartedMessage, availableVersions.Last().Id));

                    string script = await GetScriptAsync(schemaClient, 1, availableVersions.Last().ScriptUri, cancellationToken);
                    await UpgradeSchemaAsync(connectionString, availableVersions.Last().Id, script, cancellationToken);

                    return;
                }

                foreach (AvailableVersion availableVersion in availableVersions)
                {
                    int executingVersion = availableVersion.Id;

                    Console.WriteLine(string.Format(Resources.SchemaMigrationStartedMessage, executingVersion));

                    if (!force)
                    {
                        attemptCount = 1;

                        await Policy.Handle <SchemaManagerException>()
                        .WaitAndRetryAsync(
                            retryCount: RetryAttempts,
                            sleepDurationProvider: (retryCount) => RetrySleepDuration,
                            onRetry: (exception, retryCount) =>
                        {
                            Console.WriteLine(string.Format(Resources.RetryCurrentVersions, attemptCount++, RetryAttempts));
                        })
                        .ExecuteAsync(token => ValidateInstancesVersionAsync(schemaClient, executingVersion, token), cancellationToken);
                    }

                    string script = await GetScriptAsync(schemaClient, executingVersion, availableVersion.ScriptUri, cancellationToken, availableVersion.DiffUri);

                    await UpgradeSchemaAsync(connectionString, executingVersion, script, cancellationToken);
                }
            }
            catch (Exception ex) when(ex is SchemaManagerException || ex is InvalidOperationException)
            {
                CommandUtils.PrintError(ex.Message);
                return;
            }
            catch (HttpRequestException)
            {
                CommandUtils.PrintError(string.Format(Resources.RequestFailedMessage, server));
                return;
            }
            catch (Exception ex)
            {
                if (ex is SqlException || ex is ExecutionFailureException)
                {
                    CommandUtils.PrintError(string.Format(Resources.QueryExecutionErrorMessage, ex.Message));
                    return;
                }

                if (ex is SchemaManagerException || ex is InvalidOperationException)
                {
                    CommandUtils.PrintError(ex.Message);
                    return;
                }

                throw;
            }
        }
        public static async Task HandlerAsync(InvocationContext invocationContext, Uri server, CancellationToken cancellationToken)
        {
            var region = new Region(
                0,
                0,
                Console.WindowWidth,
                Console.WindowHeight,
                true);

            List <AvailableVersion> availableVersions = null;
            ISchemaClient           schemaClient      = new SchemaClient(server);

            try
            {
                availableVersions = await schemaClient.GetAvailabilityAsync(cancellationToken);

                // To ensure that schema version null/0 is not printed
                if (availableVersions.First().Id == 0)
                {
                    availableVersions.RemoveAt(0);
                }
            }
            catch (SchemaManagerException ex)
            {
                CommandUtils.PrintError(ex.Message);
                return;
            }
            catch (HttpRequestException)
            {
                CommandUtils.PrintError(string.Format(Resources.RequestFailedMessage, server));
                return;
            }

            var tableView = new TableView <AvailableVersion>
            {
                Items = availableVersions,
            };

            tableView.AddColumn(
                cellValue: availableVersion => availableVersion.Id,
                header: new ContentView("Version"));

            tableView.AddColumn(
                cellValue: availableVersion => availableVersion.ScriptUri,
                header: new ContentView("Script"));

            tableView.AddColumn(
                cellValue: availableVersion => string.IsNullOrEmpty(availableVersion.DiffUri) ? "N/A" : availableVersion.DiffUri,
                header: new ContentView("Diff"));

            var consoleRenderer = new ConsoleRenderer(
                invocationContext.Console,
                mode: invocationContext.BindingContext.OutputMode(),
                resetAfterRender: true);

            using (var screen = new ScreenView(renderer: consoleRenderer))
            {
                screen.Child = tableView;
                screen.Render(region);
            }
        }