Exemple #1
0
        static void UpdateCommon2(IAspInfo asp)
        {
            LogFile.WriteLine();
            LogFile.WriteLine("* Updating common components *");

            string commonRoot = Settings.InstallDir;

            try
            {
                int maxUpdateVersion = FindMaxUpdateVersion();
                Version version = new Version(IbnConst.FullVersion);
                int newCommonVersion = Math.Max(version.Build, maxUpdateVersion);

                // Update files
                UpdateFiles(Settings.CommonVersion, commonRoot, false);

                // Update configs
                UpdateConfigs(Settings.CommonVersion, null);

                // Update ASP database
                if (asp != null)
                {
                    string aspPath = Path.Combine(commonRoot, "Asp");
                    string connectionString = GetWebApplicationConnectionString(aspPath);
                    using (DataContext dataContext = new DataContext(connectionString))
                    using (DataContextSwitcher switcher = new DataContextSwitcher(dataContext))
                    using (TransactionScope transaction = dataContext.BeginTransaction())
                    {
                        UpdateDatabase(ScriptType.SqlAsp, asp.Database, null);

                        // Update common version in registry
                        Settings.UpdateCommonVersion(newCommonVersion);

                        transaction.Commit();
                    }
                }

                if (asp == null)
                {
                    // Update common version in registry
                    Settings.UpdateCommonVersion(newCommonVersion);
                }
            }
            catch (Exception ex)
            {
                LogFile.WriteLine("* Failed *");
                LogFile.WriteLine();
                LogFile.WriteLine(ex.ToString());
                LogFile.WriteLine();
                LogFile.WriteLine("Rollback started");

                #region Undo changes

                // Recover configs
                RecoverConfigs();

                // Recover files
                RecoverFiles(commonRoot);

                #endregion

                LogFile.WriteLine("Rollback finished");
                throw;
            }
            finally
            {
                // Delete backup files
                DeleteBackupFiles();
            }

            LogFile.WriteLine("* OK *");
        }
Exemple #2
0
        static void UpdateCompany2(IConfigurator configurator, string companyId, int companyIndex, int companiesCount, bool processServices)
        {
            string counter = string.Empty;
            if (companiesCount > 1)
                counter = string.Format(CultureInfo.InvariantCulture, " {0} of {1}", companyIndex, companiesCount);

            LogFile.WriteLine();
            LogFile.WriteLine("* Updating Company", counter, " *");
            LogFile.WriteFormatted("* Id: {0} *", companyId);

            // Load company info
            ICompanyInfo company = configurator.GetCompanyInfo(companyId);

            if (company == null)
                LogFile.WriteLine("* Company not found *");
            else
            {
                LogFile.WriteFormatted("* Host: {0} *", company.Host);

                string companyRoot = Path.Combine(configurator.InstallPath, company.CodePath);
                string webPath = Path.Combine(companyRoot, "Web");
                string portalPath = Path.Combine(webPath, "Portal");
                IIisManager iisManager = IisManager.Create(webPath);

                try
                {
                    ManageDemoDatabase(configurator, false, company.Host, company.Database);

                    string connectionString = GetWebApplicationConnectionString(portalPath);
                    using (DataContext dataContext = new DataContext(connectionString))
                    using (DataContextSwitcher switcher = new DataContextSwitcher(dataContext))
                    using (TransactionScope transaction = dataContext.BeginTransaction())
                    {
                        if (processServices)
                        {
                            // Disable ScheduleService for company
                            if (company.IsScheduleServiceEnabled)
                                DisableScheduleService(configurator, companyId);

                            if (iisManager.IisVersion > 5)
                            {
                                // IIS 6+: Stop web site
                                StopWebSite(iisManager, company.SiteId);

                                // IIS 6+: Stop portal pool
                                StopApplicationPool(iisManager, company.PortalPool);

                                // IIS 6+: Stop IM pool
                                StopApplicationPool(iisManager, company.IMPool);
                            }
                            else
                            {
                                // IIS 5: Stop IIS
                                StopIis();
                            }
                        }

                        // Update files
                        UpdateFiles(company.CodeVersion, companyRoot, true);

                        // Update configs
                        UpdateConfigs(company.CodeVersion, companyRoot);

                        if (company.DatabaseState == 6) // Ready
                            UpdateDatabase(ScriptType.SqlPortal, company.Database, companyRoot);
                        else
                            LogFile.WriteLine("* Company database is not ready *");

                        // Update company version in ibn.config
                        configurator.UpdateCompanyVersion(companyId);

                        if (processServices)
                        {
                            if (iisManager.IisVersion > 5)
                            {
                                // IIS 6+: Start IM pool
                                StartApplicationPool(iisManager, company.IMPool);
                                // IIS 6+: Start portal pool
                                StartApplicationPool(iisManager, company.PortalPool);
                                // Start web site
                                StartWebSite(iisManager, company.SiteId);
                            }
                            else
                            {
                                // IIS 5: Start IIS
                                StartIis();
                            }

                            // Enable ScheduleService for company
                            if (company.IsScheduleServiceEnabled)
                                EnableScheduleService(configurator, companyId);
                        }

                        transaction.Commit();
                    }
                }
                catch (Exception ex)
                {
                    LogFile.WriteLine("* Failed *");
                    LogFile.WriteLine();
                    LogFile.WriteLine(ex.ToString());
                    LogFile.WriteLine();
                    LogFile.WriteLine("Rollback started");

                    #region Undo changes

                    // Recover configs
                    RecoverConfigs();

                    // Recover files
                    RecoverFiles(companyRoot);

                    if (processServices)
                    {
                        if (iisManager.IisVersion > 5)
                        {
                            // IIS 6+: Start IM pool
                            try
                            {
                                StartApplicationPool(iisManager, company.IMPool);
                            }
                            catch { }

                            // IIS 6+: Start portal pool
                            try
                            {
                                StartApplicationPool(iisManager, company.PortalPool);
                            }
                            catch { }

                            // Start web site
                            try
                            {
                                StartWebSite(iisManager, company.SiteId);
                            }
                            catch { }
                        }
                        else
                        {
                            // IIS 5: Start IIS
                            try
                            {
                                StartIis();
                            }
                            catch { }
                        }

                        // Enable ScheduleService for company
                        if (company.IsScheduleServiceEnabled)
                            EnableScheduleService(configurator, companyId);
                    }

                    #endregion

                    LogFile.WriteLine("Rollback finished");
                    throw;
                }
                finally
                {
                    // Delete backup files
                    DeleteBackupFiles();
                }

                try
                {
                    ManageDemoDatabase(configurator, true, company.Host, company.Database);
                }
                catch (Exception ex)
                {
                    LogWriteFailed();
                    LogFile.WriteLine(ex.ToString());
                }

                LogFile.WriteLine("* OK *");
            }
        }
Exemple #3
0
        static void ManageDemoDatabase(IConfigurator configurator, bool backup, string host, string database)
        {
            if (!string.IsNullOrEmpty(Settings.DemoHosts) && !string.IsNullOrEmpty(Settings.DemoBackupDir))
            {
                bool process = false;

                string[] demoHosts = Settings.DemoHosts.Split(',');
                foreach (string demoHost in demoHosts)
                {
                    if (string.Compare(demoHost, host, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        process = true;
                        break;
                    }
                }

                if (process)
                {
                    string message;
                    string queryTemplate;
                    if (backup)
                    {
                        message = "Backing up database...";
                        queryTemplate = "BACKUP DATABASE [{0}] TO DISK='{1}' WITH INIT";
                    }
                    else
                    {
                        message = "Restoring database...";
                        queryTemplate = "RESTORE DATABASE [{0}] FROM DISK='{1}' WITH REPLACE";
                    }

                    string backupFile = Path.Combine(Settings.DemoBackupDir, database + ".bak");
                    string query = string.Format(CultureInfo.InvariantCulture, queryTemplate, database, backupFile);

                    LogFile.WriteLine(message);

                    using (DataContext dataContext = new DataContext(configurator.SqlSettings.AdminConnectionString))
                    using (DataContextSwitcher switcher = new DataContextSwitcher(dataContext))
                    {
                        SqlHelper.ExecuteReader(SqlContext.Current, CommandType.Text, query);
                        LogWriteOk();
                    }
                }
            }
        }