Beispiel #1
0
        public static DataAccessResponseType PurgePlatform()
        {
            DataAccessResponseType response = new DataAccessResponseType();

            //We only allow purging on local, debug & stage
            if (Sahara.Core.Settings.Environment.Current.ToLower() == "production")
            {
                response.isSuccess    = false;
                response.ErrorMessage = "Cannot purge a production version of the platform";

                return(response);
            }
            else if (Sahara.Core.Settings.Environment.Current.ToLower() != "staging" && Sahara.Core.Settings.Environment.Current.ToLower() != "stage" && Sahara.Core.Settings.Environment.Current.ToLower() != "debug" && Sahara.Core.Settings.Environment.Current.ToLower() != "test" && Sahara.Core.Settings.Environment.Current.ToLower() != "testing" && Sahara.Core.Settings.Environment.Current.ToLower() != "local")
            {
                response.isSuccess    = false;
                response.ErrorMessage = "Can only purge a stage, test, debug or local version of the platform";

                return(response);
            }
            else
            {
                //Deprovision All Accounts:
                DeprovisionAllAccounts();

                //Clear Stripe Plans:
                var stripeManager = new StripeManager();
                var planIDs       = stripeManager.GetPlanIDs();
                foreach (string planID in planIDs)
                {
                    stripeManager.DeletePlan(planID);
                }

                //Delete All SQL Databases:
                DeleteAllSQLDatabases();

                //Clear Platform Storage Accounts:
                ClearPlatformStorageAccounts();

                /*======================================
                 *  Delete AccountPartition Document Database
                 * ========================================*/

                /*  RETIRED ---*/

                //var client = Sahara.Core.Settings.Azure.DocumentDB.DocumentClients.AccountDocumentClient;
                var databasename = Sahara.Core.Settings.Azure.DocumentDB.AccountPartitionDatabaseId;

                Database accountDatabase = Sahara.Core.Settings.Azure.DocumentDbClients.AccountDocumentClient.CreateDatabaseQuery().Where(db => db.Id == databasename).ToArray().FirstOrDefault();
                if (accountDatabase != null)
                {
                    //Create if not exists
                    accountDatabase = Sahara.Core.Settings.Azure.DocumentDbClients.AccountDocumentClient.DeleteDatabaseAsync(accountDatabase.SelfLink).Result;
                }



                /*======================================
                 *  FLUSH ALL REDIS CACHES
                 * ========================================*/

                var redisEndpoints = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetEndPoints(true);
                var redisServer    = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetServer(redisEndpoints[0]);

                redisServer.FlushAllDatabases();


                /*
                 * var platformEndpoints = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.PlatformManager_Multiplexer.GetEndPoints(true);
                 * var platformServer = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.PlatformManager_Multiplexer.GetServer(platformEndpoints[0]);
                 *
                 * var accountEndpoints = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetEndPoints(true);
                 * var accountServer = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetServer(accountEndpoints[0]);
                 *
                 * platformServer.FlushAllDatabases();
                 * accountServer.FlushAllDatabases();
                 */



                /*================================================================
                 *  DELETE ALL AZURE SEARCH DATASOURCES, INDEXES & INDEXERS (LEGACY USING SINGLE PLAN)
                 * ==================================================================
                 *
                 * SearchServiceClient searchServiceClient = Settings.Azure.Search.AccountsSearchServiceClient;
                 *
                 * //Delete all search indexes
                 * var indexList = searchServiceClient.Indexes.List();
                 * foreach (Microsoft.Azure.Search.Models.Index index in indexList.Indexes)
                 * {
                 *  searchServiceClient.Indexes.Delete(index.Name);
                 * }
                 *
                 * //Delete all search indexers
                 * var indexerList = searchServiceClient.Indexers.List();
                 * foreach (Microsoft.Azure.Search.Models.Indexer indexer in indexerList.Indexers)
                 * {
                 *  searchServiceClient.Indexers.Delete(indexer.Name);
                 * }
                 *
                 * //Delete all search datasources
                 * var dataSourcesList = searchServiceClient.DataSources.List();
                 * foreach (Microsoft.Azure.Search.Models.DataSource datasource in dataSourcesList.DataSources)
                 * {
                 *  searchServiceClient.DataSources.Delete(datasource.Name);
                 * }*/



                /*==============================================================================
                 *  DELETE ALL AZURE SEARCH DATASOURCES, INDEXES & INDEXERS (LOOP THROUGH ALL)
                 * =============================================================================*/

                //Refresh and get list:
                var searchPartitions = Settings.Azure.Search.RefreshSearchPartitions();

                foreach (var searchPartition in searchPartitions)
                {
                    SearchServiceClient searchServiceClient = Settings.Azure.Search.GetSearchPartitionClient(searchPartition.Name);

                    //Delete all search indexes
                    var indexList = searchServiceClient.Indexes.List();
                    foreach (Microsoft.Azure.Search.Models.Index index in indexList.Indexes)
                    {
                        searchServiceClient.Indexes.Delete(index.Name);
                    }

                    //Delete all search indexers
                    var indexerList = searchServiceClient.Indexers.List();
                    foreach (Microsoft.Azure.Search.Models.Indexer indexer in indexerList.Indexers)
                    {
                        searchServiceClient.Indexers.Delete(indexer.Name);
                    }

                    //Delete all search datasources
                    var dataSourcesList = searchServiceClient.DataSources.List();
                    foreach (Microsoft.Azure.Search.Models.DataSource datasource in dataSourcesList.DataSources)
                    {
                        searchServiceClient.DataSources.Delete(datasource.Name);
                    }
                }



                /*======================================
                 *   SEND BACK RESULTS
                 * ========================================*/

                response.isSuccess      = true;
                response.SuccessMessage = "Platform has been purged.";

                return(response);
            }
        }