Example #1
0
        public static DataAccessResponseType ProvisionPlatform(string FirstName, string LastName, string Email, string password)
        {
            // Begin timing task
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            DataAccessResponseType response = new DataAccessResponseType();

            if (!isPlatformInitialized())
            {
                //Generate Databases & Schemas
                PlatformInitialization platformInitialization = new PlatformInitialization();
                response = platformInitialization.InitializePlatform();

                if (response.isSuccess)
                {
                    try
                    {
                        //Create initial Platform User & Assign to SuperAdmin Role
                        var createUserResult = PlatformUserManager.CreatePlatformUser(Email, FirstName, LastName, password, Sahara.Core.Settings.Platform.Users.Authorization.Roles.SuperAdmin);
                        if (createUserResult.isSuccess)
                        {
                            //Replicate Payment Plans to Stripe Account:
                            //StripeInitialization.SeedPaymentPlans();
                            var stripePlansResponse = PaymentPlanManager.DuplicatePlansToStripe();

                            if (!stripePlansResponse.isSuccess)
                            {
                                response.isSuccess    = false;
                                response.ErrorMessage = "An error occured when creating Stripe plans";
                                return(response);
                            }


                            /*======================================
                             *   Create 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.CreateDatabaseAsync(new Database {
                                    Id = databasename
                                }).Result;
                            }



                            /*======================================
                             *   Clear all logs ()
                             * ========================================*/

                            //PlatformLogManager.ClearLogs();

                            /*======================================
                             *   Log Initilization of Platform
                             * ========================================*/

                            stopwatch.Stop();

                            PlatformLogManager.LogActivity(
                                CategoryType.Platform,
                                ActivityType.Platform_Initialized,
                                "Platform initilized by: " + FirstName + " " + LastName + " (" + Email + ")",
                                "Initialization took " + String.Format("{0:0,0.00}", TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds).TotalMinutes) + " minute(s) to complete"
                                );


                            response.isSuccess      = true;
                            response.SuccessMessage = "Platform has been successfully initialized and '" + Email + "' has been registered as the initial platform administrator.";
                        }
                    }
                    catch (Exception e)
                    {
                        response.isSuccess    = false;
                        response.ErrorMessage = e.Message;
                        try
                        {
                            response.ErrorMessages.Add(e.InnerException.Message);
                        }
                        catch
                        {
                        }
                    }
                }

                return(response);
            }
            else
            {
                response.isSuccess    = false;
                response.ErrorMessage = "Platform is already initialized.";
                response.ErrorMessages.Add("If you are attempting to create a new installation on this envionemnt: You must first clear all platfrom components manually.");

                return(response);
            }
        }