コード例 #1
0
        public static void Main(string[] args)
        {
            if (!ValidateArgs(args))
            {
                return;
            }

            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);

            Configuration = builder.Build();

            IdentityConfiguration sourceConfig = new IdentityConfiguration
            {
                TablePrefix             = Configuration.GetSection("source:IdentityConfiguration:TablePrefix")?.Value,
                StorageConnectionString =
                    Configuration.GetSection("source:IdentityConfiguration:StorageConnectionString")?.Value,
                LocationMode = Configuration.GetSection("source:IdentityConfiguration:LocationMode")?.Value ??
                               string.Empty,
                UserTableName = Configuration.GetSection("source:IdentityConfiguration:UserTableName")?.Value ??
                                string.Empty,
                IndexTableName = Configuration.GetSection("source:IdentityConfiguration:IndexTableName")?.Value ??
                                 string.Empty,
                RoleTableName = Configuration.GetSection("source:IdentityConfiguration:RoleTableName")?.Value ??
                                string.Empty
            };

            IdentityConfiguration targetConfig = new IdentityConfiguration
            {
                TablePrefix             = Configuration.GetSection("target:IdentityConfiguration:TablePrefix")?.Value,
                StorageConnectionString =
                    Configuration.GetSection("target:IdentityConfiguration:StorageConnectionString")?.Value,
                LocationMode = Configuration.GetSection("target:IdentityConfiguration:LocationMode")?.Value ??
                               string.Empty,
                UserTableName = Configuration.GetSection("target:IdentityConfiguration:UserTableName")?.Value ??
                                string.Empty,
                IndexTableName = Configuration.GetSection("target:IdentityConfiguration:IndexTableName")?.Value ??
                                 string.Empty,
                RoleTableName = Configuration.GetSection("target:IdentityConfiguration:RoleTableName")?.Value ??
                                string.Empty
            };


            Console.WriteLine("MaxDegreeOfParallelism: {0}", iMaxDegreesParallel);
            Console.WriteLine("PageSize: {0}", iPageSize);
            Console.WriteLine("MigrateCommand: {0}", MigrateCommand);

            var migration = MigrationFactory.CreateMigration(MigrateCommand);

            using (IdentityCloudContext targetContext = new IdentityCloudContext(targetConfig))
            {
                Task.WhenAll(targetContext.IndexTable.CreateIfNotExistsAsync(),
                             targetContext.UserTable.CreateIfNotExistsAsync(),
                             targetContext.RoleTable.CreateIfNotExistsAsync()).Wait();
                Console.WriteLine($"Target IndexTable: {targetContext.IndexTable.Name}");
                Console.WriteLine($"Target UserTable: {targetContext.UserTable.Name}");
                Console.WriteLine($"Target RoleTable: {targetContext.RoleTable.Name}");

                string entityRecordName = "Users";

                using (IdentityCloudContext sourceContext = new IdentityCloudContext(sourceConfig))
                {
                    Console.WriteLine($"Source IndexTable: {sourceContext.IndexTable.Name}");
                    Console.WriteLine($"Source UserTable: {sourceContext.UserTable.Name}");
                    Console.WriteLine($"Source RoleTable: {sourceContext.RoleTable.Name}");

                    DateTime startLoad = DateTime.UtcNow;
                    //var allDataList = new List<DynamicTableEntity>(iPageSize);

                    TableQuery tq = migration.GetSourceTableQuery();

                    tq.TakeCount = iPageSize;
                    TableContinuationToken continueToken = new TableContinuationToken();

                    int iSkippedUserCount = 0;
                    int iSkippedPageCount = 0;
                    int iPageCounter      = 0;
                    while (continueToken != null)
                    {
                        DateTime batchStart = DateTime.UtcNow;

                        CloudTable sourceTable = sourceContext.UserTable;
                        if (MigrateCommand == MigrationFactory.Roles)
                        {
                            sourceTable      = sourceContext.RoleTable;
                            entityRecordName = "Role and Role Claims";
                        }
                        var sourceResults = sourceTable.ExecuteQuerySegmentedAsync(tq, continueToken).Result;
                        continueToken = sourceResults.ContinuationToken;


                        int batchCount = sourceResults.Count(migration.UserWhereFilter);
                        iUserTotal += batchCount;
                        iPageCounter++;

                        bool includePage = (iStartPage == -1 || iPageCounter >= iStartPage) && (iFinishPage == -1 || iPageCounter <= iFinishPage);

                        if (includePage)
                        {
                            if (migrateOption)
                            {
                                var name = entityRecordName;
                                migration.ProcessMigrate(targetContext, sourceContext, sourceResults.Results, iMaxDegreesParallel,
                                                         () =>
                                {
                                    Interlocked.Increment(ref iUserSuccessConvert);
                                    Console.WriteLine($"{name}(s) Complete: {iUserSuccessConvert}");
                                },
                                                         (exMessage) =>
                                {
                                    if (!string.IsNullOrWhiteSpace(exMessage))
                                    {
                                        userIdFailures.Add(exMessage);
                                    }
                                    Interlocked.Increment(ref iUserFailureConvert);
                                });
                            }
                        }
                        else
                        {
                            iSkippedPageCount++;
                            iSkippedUserCount += batchCount;
                        }

                        Console.WriteLine("Page: {2}{3}, {4} Batch: {1}: {0} seconds", (DateTime.UtcNow - batchStart).TotalSeconds, batchCount, iPageCounter, includePage ? string.Empty : "(Skipped)", entityRecordName);

                        //Are we done yet?
                        if (iFinishPage > 0 && iPageCounter >= iFinishPage)
                        {
                            break;
                        }
                    }


                    Console.WriteLine("");
                    Console.WriteLine("Elapsed time: {0} seconds", (DateTime.UtcNow - startLoad).TotalSeconds);
                    Console.WriteLine("Total {2} Skipped: {0}, Total Pages: {1}", iSkippedUserCount, iSkippedPageCount, entityRecordName);
                    Console.WriteLine("Total {2} To Convert: {0}, Total Pages: {1}", iUserTotal - iSkippedUserCount, iPageCounter - iSkippedPageCount, entityRecordName);

                    Console.WriteLine("");
                    if (migrateOption)
                    {
                        Console.WriteLine("Total {1} Successfully Converted: {0}", iUserSuccessConvert, entityRecordName);
                        Console.WriteLine("Total {1} Failed to Convert: {0}", iUserFailureConvert, entityRecordName);
                        if (iUserFailureConvert > 0)
                        {
                            Console.WriteLine($"{entityRecordName} Ids Failed:");
                            foreach (string s in userIdFailures)
                            {
                                Console.WriteLine(s);
                            }
                        }
                    }
                }
            }

            DisplayAnyKeyToExit();
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            if (!ValidateArgs(args))
            {
                return;
            }

            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);

            Configuration = builder.Build();

            IdentityConfiguration idconfig = new IdentityConfiguration();

            idconfig.TablePrefix             = Configuration.GetSection("IdentityAzureTable:IdentityConfiguration:TablePrefix").Value;
            idconfig.StorageConnectionString = Configuration.GetSection("IdentityAzureTable:IdentityConfiguration:StorageConnectionString").Value;
            idconfig.LocationMode            = Configuration.GetSection("IdentityAzureTable:IdentityConfiguration:LocationMode").Value;

            Console.WriteLine("MaxDegreeOfParallelism: {0}", iMaxdegreesparallel);
            Console.WriteLine("PageSize: {0}", iPageSize);
            Console.WriteLine("MigrateCommand: {0}", MigrateCommand);

            var migrateIndex = MigrationFactory.CreateMigration(MigrateCommand);

            using (IdentityCloudContext ic = new IdentityCloudContext(idconfig))
            {
                DateTime startLoad   = DateTime.UtcNow;
                var      allDataList = new List <DynamicTableEntity>(iPageSize);

                TableQuery tq = migrateIndex.GetUserTableQuery();

                tq.TakeCount = iPageSize;
                TableContinuationToken continueToken = new TableContinuationToken();

                int iSkippedUserCount = 0;
                int iSkippedPageCount = 0;
                int iPageCounter      = 0;
                while (continueToken != null)
                {
                    DateTime batchStart = DateTime.UtcNow;

                    var userResults = ic.UserTable.ExecuteQuerySegmentedAsync(tq, continueToken).Result;
                    continueToken = userResults.ContinuationToken;


                    int batchCount = userResults.Count(migrateIndex.UserWhereFilter);
                    iUserTotal += batchCount;
                    iPageCounter++;

                    bool includePage = (iStartPage == -1 || iPageCounter >= iStartPage) && (iFinishPage == -1 || iPageCounter <= iFinishPage);

                    if (includePage)
                    {
                        if (migrateOption)
                        {
                            migrateIndex.ProcessMigrate(ic, userResults.Results, iMaxdegreesparallel,
                                                        () =>
                            {
                                Interlocked.Increment(ref iUserSuccessConvert);
                            },
                                                        (exMessage) =>
                            {
                                if (!string.IsNullOrWhiteSpace(exMessage))
                                {
                                    userIdFailures.Add(exMessage);
                                }
                                Interlocked.Increment(ref iUserFailureConvert);
                            });
                        }
                    }
                    else
                    {
                        iSkippedPageCount++;
                        iSkippedUserCount += batchCount;
                    }

                    Console.WriteLine("Page: {2}{3}, Users Batch: {1}: {0} seconds", (DateTime.UtcNow - batchStart).TotalSeconds, batchCount, iPageCounter, includePage ? string.Empty : "(Skipped)");

                    //Are we done yet?
                    if (iFinishPage > 0 && iPageCounter >= iFinishPage)
                    {
                        break;
                    }
                }


                Console.WriteLine("");
                Console.WriteLine("Elapsed time: {0} seconds", (DateTime.UtcNow - startLoad).TotalSeconds);
                Console.WriteLine("Total Users Skipped: {0}, Total Pages: {1}", iSkippedUserCount, iSkippedPageCount);
                Console.WriteLine("Total Users To Convert: {0}, Total Pages: {1}", iUserTotal - iSkippedUserCount, iPageCounter - iSkippedPageCount);

                Console.WriteLine("");
                if (migrateOption)
                {
                    Console.WriteLine("Total Users Successfully Converted: {0}", iUserSuccessConvert);
                    Console.WriteLine("Total Users Failed to Convert: {0}", iUserFailureConvert);
                    if (iUserFailureConvert > 0)
                    {
                        Console.WriteLine("User Ids Failed:");
                        foreach (string s in userIdFailures)
                        {
                            Console.WriteLine(s);
                        }
                    }
                }
            }

            DisplayAnyKeyToExit();
        }