示例#1
0
文件: Program.cs 项目: radtek/Cobox
        private static void FarazTestFunction1()
        {
            var toContinue = false;

            do
            {
                toContinue = false;
                Console.WriteLine(AffinityConfigurationMaster.GetDatabaseConnectionStringBuilder(DeploymentLocation.BtsFaraz).ToString());
                Exception         exception = null;
                TenantUserSession tenantUserSessionRaheel = null;
                TenantUserSession tenantUserSessionJunaid = null;
                AuthenticationManagement.SignIn(SessionType.Mvc, "kloud-soft.com", "raheel.khan", Sha.GenerateHash("audience", GlobalConstants.EncodingCryptography, GlobalConstants.AlgorithmHashShaKind), IPAddress.Loopback.ToString(), "User Agent", 0, "Session Id", out tenantUserSessionRaheel, out exception);
                AuthenticationManagement.SignIn(SessionType.Mvc, "kloud-soft.com", "junaid.sayed", Sha.GenerateHash("audience", GlobalConstants.EncodingCryptography, GlobalConstants.AlgorithmHashShaKind), IPAddress.Loopback.ToString(), "User Agent", 0, "Session Id", out tenantUserSessionJunaid, out exception);
                List <Folder> folders = null;
                using (var context = new ContextTenant(tenantUserSessionRaheel.Tenant.DatabaseConnectionString))
                {
                    folders = context.Folders.Include(x => x.FolderUsers).ToList();
                    Console.WriteLine(FolderManagement.ValidateUserFolderRightsHirarchy(15, folders, 1).ToString());
                }
                Console.WriteLine("press 'y' to continue");
                var read = Console.ReadKey();
                if (read.KeyChar.ToString().ToLower() == "y")
                {
                    toContinue = true;
                    Console.Clear();
                }
            } while (toContinue);
        }
示例#2
0
        //====================================================================================================
        // Constructors.
        //====================================================================================================

        public ContextMaster(bool proxyCreationEnabled = false, bool lazyLoadingEnabled = false, DeploymentLocation?deploymentLocation = null)
            : base(AffinityConfigurationMaster.GetDatabaseConnectionStringBuilder(deploymentLocation ?? AffinityConfiguration.DeploymentLocation).ConnectionString, proxyCreationEnabled, lazyLoadingEnabled)
            //: base(AffinityConfigurationMaster.DatabaseConnectionString, proxyCreationEnabled, lazyLoadingEnabled)
        {
            // Not allowed for databases created outside of EF.
            //this.ObjectContext.CommandTimeout = TimeSpan.FromSeconds(60).Seconds;
        }
示例#3
0
文件: Program.cs 项目: radtek/Cobox
        private static void UpdateLiveTenantDatabases(IEnumerable <string> productionDomainsToBeUpdated)
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.Write($"----------------------------------------------------------------------------------------------------");
            Console.WriteLine();
            Console.WriteLine();
            Console.Write($"UpdateLiveTenantDatabases.");

            Uri uri;
            var encoding           = Encoding.UTF8;
            var tenantsMasterLive  = new List <Tenant>();
            var tenantsMasterLocal = new List <Tenant>();
            // var builderTenantLive = new SqlConnectionStringBuilder();
            var builderTenantLocal = new SqlConnectionStringBuilder();
            //var builderMasterLive = AffinityConfigurationMaster.GetDatabaseConnectionStringBuilder(DeploymentLocation.Live);
            var builderMasterLocal = AffinityConfigurationMaster.GetDatabaseConnectionStringBuilder(AffinityConfiguration.DeploymentLocation);

            if
            (
                (productionDomainsToBeUpdated.Any())
                &&
                (
                    productionDomainsToBeUpdated.All
                    (
                        d =>
                        (!string.IsNullOrWhiteSpace(d)) &&
                        (Uri.CheckHostName(d) == UriHostNameType.Dns) &&
                        (Uri.TryCreate(d, UriKind.RelativeOrAbsolute, out uri)) &&
                        (!uri.IsAbsoluteUri) &&
                        (!uri.UserEscaped)
                    )
                )
            )
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.Write($"Domains selected to be updated:");
                Console.WriteLine();
                Console.Write(string.Join(Environment.NewLine, productionDomainsToBeUpdated.Select(d => $" - {d}")));
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.Write($"Either no domains were passed in, or at least one of the domains");
                Console.WriteLine();
                Console.Write($"was empty, null or invalid. Domains should be in the form of: [xyz.com].");
                Console.WriteLine();
                Console.WriteLine();
                Console.Write($"The utility will now return.");

                return;
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.Write($"WARNING: This action cannot be undone!");
            Console.WriteLine();
            Console.Write($"Press [Y] to run the action, any other key to cancel: ");

            var consoleKeyInfo = Console.ReadKey(intercept: true);

            if (consoleKeyInfo.Key == ConsoleKey.Y)
            {
                Console.Write("Y");
                Console.WriteLine();
                Console.WriteLine();
                Console.Write($"WARNING: Once again, this action cannot be undone!");
                Console.WriteLine();
                Console.Write($"Press [Y] to run the action, any other key to cancel: ");

                consoleKeyInfo = Console.ReadKey(intercept: true);

                if (consoleKeyInfo.Key == ConsoleKey.Y)
                {
                    Console.Write("Y");
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.Write($"Well, you WERE warned! Continuing script execution...");
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.Write($"Script execution cancelled. Phew!!!");

                    return;
                }
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.Write($"Script execution cancelled. Phew!!!");

                return;
            }

            Program.InitializeLocalDatabases();

            var fileScript = new FileInfo(Assembly.GetExecutingAssembly().Location);

            fileScript = new FileInfo(Path.Combine(fileScript.Directory.FullName, @"..\..\..\HouseOfSynergy.AffinityDms.Library\Database\Script Schema Drop Create Data Insert.sql"));
            if (!fileScript.Exists)
            {
                throw (new FileNotFoundException($"File not found: {fileScript.FullName}.", fileScript.FullName));
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.Write($"Getting live tenants from master...");
            using (var contextMasterLive = new ContextMaster(deploymentLocation: DeploymentLocation.Live))
            {
                tenantsMasterLive = contextMasterLive.Tenants.ToList();
            }

            var validDomains   = tenantsMasterLive.ConvertAll(t => t.Domain);
            var invalidDomains = productionDomainsToBeUpdated.Where(d => !validDomains.Contains(d));

            Console.WriteLine();
            Console.Write($"Domains found in the master database:");
            Console.WriteLine();
            Console.Write(string.Join(Environment.NewLine, validDomains.Select(d => $" - {d}")));

            if (invalidDomains.Any())
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.Write($"The following domains do not exist in the master database:");
                Console.WriteLine();
                Console.Write(string.Join(Environment.NewLine, invalidDomains.Select(d => $" - {d}")));
                Console.WriteLine();
                Console.WriteLine();
                Console.Write($"The utility will now return.");

                return;
            }

            tenantsMasterLive = tenantsMasterLive.Where(t => productionDomainsToBeUpdated.Contains(t.Domain)).ToList();

            Console.WriteLine();
            Console.WriteLine();
            Console.Write($"Updating live tenants...");
            foreach (var tenantMasterLive in tenantsMasterLive)
            {
                var tenantTenantLive       = tenantMasterLive.Clone();
                var databaseNameTenantLive = new SqlConnectionStringBuilder(tenantMasterLive.DatabaseConnectionString).InitialCatalog;

                Console.WriteLine();
                Console.WriteLine();
                Console.Write($"Tenant: [{tenantMasterLive.Domain}].");

                using (var contextMasterLocal = new ContextMaster())
                {
                    var tenantMasterLocal = contextMasterLocal.Tenants.SingleOrDefault(t => t.Domain.ToLower() == tenantMasterLive.Domain.ToLower());

                    builderTenantLocal = new SqlConnectionStringBuilder(tenantMasterLocal.DatabaseConnectionString);
                }

                // Generate Drop, Create & Seed Script.
                //builderTenantLocal = new SqlConnectionStringBuilder()
                //{
                //    DataSource = @"BENZFARAZ-PC\SQLEXPRESS",
                //    InitialCatalog = "AffinityDmsTenant_0000000000000000002",
                //    IntegratedSecurity = true,
                //    UserID = @"sa",
                //    Password = @"123456",
                //    MultipleActiveResultSets = false,
                //    PersistSecurityInfo = true
                //};

                // Generate Drop, Create & Seed Script.
                builderTenantLocal = new SqlConnectionStringBuilder()
                {
                    DataSource = @"Lenovo",
                    //DataSource = @"HOSLAPTOPHP\MSSQLS2016EXP",
                    InitialCatalog     = "AffinityDmsTenant_0000000000000000001",
                    IntegratedSecurity = true,
                    //UserID = @"",
                    //Password = @"",
                    //MultipleActiveResultSets = false,
                    PersistSecurityInfo = true
                };

                Program.GenerateScript(builderTenantLocal, databaseNameTenantLive, fileScript, encoding);

                Console.WriteLine();
                Console.WriteLine();
                Console.Write($"Execute script against the respective live tenant.");
                using (var contextTenantLive = new ContextTenant(tenantTenantLive.DatabaseConnectionString))
                {
                    var script = File.ReadAllText(fileScript.FullName, encoding);

                    var t = contextTenantLive.Tenants.ToList();

                    contextTenantLive.Database.CommandTimeout = 30 * 60;
                    contextTenantLive.Database.ExecuteSqlCommand(script);
                }

                Console.WriteLine();
                Console.WriteLine();
                Console.Write($"Correcting script parameters.");
                using (var contextTenantLive = new ContextTenant(tenantTenantLive.DatabaseConnectionString))
                {
                    tenantTenantLive.Id         = 1; // To update the single tenant row.
                    tenantTenantLive.TenantType = EntityMasterTenantType.Tenant;

                    contextTenantLive.Tenants.Attach(tenantTenantLive);
                    contextTenantLive.SaveChanges();
                }
            }
        }