Esempio n. 1
0
        static void ConvertCompany(IConfigurator configurator, bool isAsp, CompanyInfo company)
        {
            try
            {
                using (DBTransaction tran = DBHelper2.DBHelper.BeginTransaction())
                {
                    // Load SMTP settings
                    SmtpSettings smtpSettings = SmtpSettings.Load(company.Database);

                    // Synchronize IM groups
                    // Update portal DB
                    // Copy data from main DB to portal DB
                    NameValueCollection replace = new NameValueCollection();
                    replace["SET XACT_ABORT ON"] = string.Empty;
                    replace["{MainDB}"] = Settings.SqlDatabase;
                    replace["{PortalDB}"] = company.Database;
                    replace["{CompanyId}"] = company.OldId.ToString(CultureInfo.InvariantCulture);
                    UpdateDatabase(company.Database, ScriptType.SqlPortal, replace);

                    // Copy code to separate folder
                    // Update portal web.config
                    // Create ISAPI extension
                    // Create portal application pool
                    // Create IM application pool
                    // Create web site
                    // Update ibn.config
                    int port = (string.IsNullOrEmpty(company.Port) ? 80 : int.Parse(company.Port, CultureInfo.InvariantCulture));
                    string applicationPool = null;
                    if (isAsp)
                        applicationPool = RegistrySettings.ReadString("ApplicationPoolType" + company.CompanyType.ToString(CultureInfo.InvariantCulture));

                    company.Id = configurator.CreateCompanyForDatabase(company.Database, company.Created, company.IsActive, company.Host, string.Empty, port, applicationPool, false);

                    // Save company settings
                    string previousDatabase = DBHelper2.DBHelper.Database;
                    try
                    {
                        DBHelper2.DBHelper.Database = company.Database;

                        // Save company images to portal database
                        SaveCompanyParameter(DBHelper2.DBHelper, "portal.company_logo", company.CompanyLogo);
                        SaveCompanyParameter(DBHelper2.DBHelper, "portal.homepage.image", company.HomePageImage);

                        // Save scheme, host and port to database
                        SaveCompanyParameter(DBHelper2.DBHelper, "system.scheme", "http");
                        SaveCompanyParameter(DBHelper2.DBHelper, "system.host", company.Host);
                        SaveCompanyParameter(DBHelper2.DBHelper, "system.port", company.Port);

                        // Save SMTP settings
                        smtpSettings.Save();

                        // Set database state to "Ready"
                        DBHelper2.DBHelper.RunText("UPDATE [DatabaseVersion] SET [State]=6");
                    }
                    finally
                    {
                        DBHelper2.DBHelper.Database = previousDatabase;
                    }

                    tran.Commit();
                }
            }
            catch
            {
                #region Undo changes

                // Delete company
                if (!string.IsNullOrEmpty(company.Id))
                {
                    try
                    {
                        configurator.DeleteCompany(company.Id, false);
                    }
                    catch
                    {
                    }
                }

                #endregion

                throw;
            }
        }
Esempio n. 2
0
        private static CompanyInfo[] LoadServerConfig(XmlDocument serverConfigDocument, string companyId)
        {
            List<CompanyInfo> list = new List<CompanyInfo>();

            string query = "/configuration/companies/company";
            if (!string.IsNullOrEmpty(companyId))
                query = string.Concat(query, "[@id='", companyId, "']");

            foreach (XmlNode node in serverConfigDocument.SelectNodes(query))
            {
                CompanyInfo company = new CompanyInfo();
                company.LoadGeneralInfo(node);
                list.Add(company);
            }

            return list.ToArray();
        }
Esempio n. 3
0
        private CompanyInfo CreateCompanyForDatabase(XmlDocument serverConfigDocument, string database, string defaultLocale, DateTime created, bool isActive, string host, string iisIPAddress, int iisPort, string iisApplicationPool, bool createClientScripts)
        {
            string directoryName = BuildUniqueName(host, GetDirectories());
            string targetPath = Path.Combine(_codePath, directoryName);
            string webPath = Path.Combine(targetPath, "Web");
            string webCommonName = GetDefaultWebName(host);

            IIisManager iisManager = IisManager.Create(webPath);
            bool x64 = iisManager.Is64Bit();
            string[] sites = iisManager.ListSites();
            string[] pools = iisManager.ListApplicationPools();
            string siteName = BuildUniqueName(webCommonName, sites);

            CompanyInfo company = new CompanyInfo();
            company.Created = created;
            company.IsActive = isActive;
            company.IsScheduleServiceEnabled = true;
            company.Scheme = "http";
            company.Host = host;
            company.Port = (iisPort != 80 ? iisPort.ToString(CultureInfo.InvariantCulture) : string.Empty);
            company.Database = database;
            company.CodePath = Path.Combine("Code", directoryName);
            company.Language.Locale = defaultLocale;

            bool directoryCopied = false;
            bool isapiExtensionCreated = false;
            bool imPoolCreated = false;

            try
            {
                // Copy code to new directory
                CopyDirectory(_sourcePath, targetPath);
                directoryCopied = true;

                // Get code version
                FileVersionInfo version = FileVersionInfo.GetVersionInfo(Path.Combine(webPath, @"Portal\bin\Mediachase.IBN.Business.dll"));
                company.CodeVersion = version.FileBuildPart;

                // Allow writing to directories
                SetWritePermissions(webPath, WebName.IMDownload);
                SetWritePermissions(webPath, @"Portal\Admin\Log\Error");
                SetWritePermissions(webPath, @"Portal\Layouts\Images\Charts");

                // Update web.config
                string connectionString = SqlServerSettings.BuildConnectionString(AuthenticationType.SqlServer, _sqlServer, company.Database, _sqlPortalUser, _sqlPortalPassword);
                UpdateWebConfig(Path.Combine(webPath, "Portal"), connectionString, company.Id, Path.Combine(webPath, WebName.IMDownload));

                // Create ISAPI extension
                isapiExtensionCreated = iisManager.AddIsapiExtension(webCommonName);

                if (iisManager.IsApplicationPoolSupported)
                {
                    // Create IM application pool
                    company.IMPool = BuildUniqueName(webCommonName + " IM", pools);
                    iisManager.CreateApplicationPool(company.IMPool, false);
                    imPoolCreated = true;

                    // Create portal application pool
                    if (string.IsNullOrEmpty(iisApplicationPool))
                    {
                        company.PortalPool = BuildUniqueName(webCommonName + " Portal", pools);
                        iisManager.CreateApplicationPool(company.PortalPool, true);
                        company.IsPortalPoolCreated = true;
                    }
                    else
                        company.PortalPool = iisApplicationPool;
                }

                // Create web site
                company.SiteId = iisManager.CreateCompanySite(siteName, iisIPAddress, iisPort, host, x64, company.IMPool, company.PortalPool);

                // Register ASP.NET 2.0
                if (iisManager.IisVersion < 7)
                {
                    string windir = System.Environment.ExpandEnvironmentVariables(@"%SystemRoot%");
                    string regiis = string.Format(CultureInfo.InvariantCulture, @"{0}\Microsoft.NET\Framework{1}\v2.0.50727\aspnet_regiis.exe", windir, x64 ? "64" : "");

                    if (_registerAspNet)
                        StartProcess(regiis, string.Format(CultureInfo.InvariantCulture, "-s w3svc/{0}/", company.SiteId));

                    if (createClientScripts)
                        StartProcess(regiis, "-c");
                }

                // Start web site
                try
                {
                    iisManager.StartSite(company.SiteId);
                }
                catch (Exception ex)
                {
                    Log.WriteException("CreateCompanyForDatabase", ex);
                }

                // Update ibn.config
                company.SaveGeneralInfo(serverConfigDocument);
            }
            catch
            {
                #region Undo changes

                // Delete web site
                try
                {
                    if (company.SiteId > 0)
                        iisManager.DeleteSite(company.SiteId);
                }
                catch
                {
                }

                if (iisManager.IsApplicationPoolSupported)
                {
                    // Delete portal application pool
                    try
                    {
                        if (company.IsPortalPoolCreated)
                            iisManager.DeleteApplicationPool(company.PortalPool);
                    }
                    catch
                    {
                    }

                    // Delete IM application pool
                    try
                    {
                        if (imPoolCreated)
                            iisManager.DeleteApplicationPool(company.IMPool);
                    }
                    catch
                    {
                    }
                }

                // Delete ISAPI extension
                try
                {
                    if (isapiExtensionCreated)
                        iisManager.DeleteIsapiExtension();
                }
                catch
                {
                }

                // Delete code directory
                try
                {
                    if (directoryCopied)
                        Directory.Delete(targetPath, true);
                }
                catch
                {
                }

                #endregion

                throw;
            }

            return company;
        }