Example #1
0
 public IAspInfo GetAspInfo()
 {
     using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.Read))
     {
         return AspInfo.Load(serverConfig.LoadDocument());
     }
 }
Example #2
0
        public void DeleteCompany(string companyId, bool deleteDatabase)
        {
            string context = "Delete Company";
            string companyCodePath = null;

            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();

                CompanyInfo company = CompanyInfo.LoadGeneralInfo(serverConfigDocument, companyId);
                if (company != null)
                {
                    context += (": " + company.Host);

                    companyCodePath = Path.Combine(InstallPath, company.CodePath);

                    // Delete web site
                    try
                    {
                        DeleteCompanyWeb(company, context);
                    }
                    catch (IisManagerException ex)
                    {
                        Log.WriteException(context, ex);
                    }

                    // Delete database
                    if (deleteDatabase)
                    {
                        try
                        {
                            DeleteDatabase(company.Database);
                        }
                        catch (Exception ex)
                        {
                            Log.WriteException(context, ex);
                        }
                    }

                    // Update ibn.config
                    try
                    {
                        company.DeleteGeneralInfo(serverConfigDocument);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteException(context, ex);
                    }
                }

                serverConfig.SaveDocument(serverConfigDocument);
            }

            // Rename the code directory if it wasn't deleted
            try
            {
                if (!string.IsNullOrEmpty(companyCodePath) && Directory.Exists(companyCodePath))
                {
                    string codeDirectory = Path.GetDirectoryName(companyCodePath);
                    string codeName = Path.GetFileName(companyCodePath);
                    string deletedCodePath = Path.Combine(codeDirectory, "_deleted_" + codeName);
                    Directory.Move(companyCodePath, deletedCodePath);
                }
            }
            catch (Exception ex)
            {
                Log.WriteException(context, ex);
            }
        }
Example #3
0
        public void EnableScheduleService(string companyId, bool isEnabled)
        {
            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();

                CompanyInfo company = CompanyInfo.LoadGeneralInfo(serverConfigDocument, companyId);
                if (company != null)
                {
                    // Update ibn.config
                    company.IsScheduleServiceEnabled = isEnabled;
                    company.SaveGeneralInfo(serverConfigDocument);
                }

                serverConfig.SaveDocument(serverConfigDocument);
            }
        }
Example #4
0
        public string CreateCompanyForDatabase(string database, DateTime created, bool isActive, string host, string iisIPAddress, int iisPort, string iisApplicationPool, bool createClientScripts)
        {
            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();

                ValidatePortalsCount(serverConfigDocument);
                ValidateHostName(serverConfigDocument, host, null, true);
                host = host.ToLowerInvariant();

                string defaultLocale;
                try
                {
                    _dbHelper.Database = database;
                    LanguageInfo language = new LanguageInfo();
                    language.Load(_dbHelper);
                    defaultLocale = language.Locale;
                }
                finally
                {
                    _dbHelper.Database = null;
                }

                string port = (iisPort != 80 ? iisPort.ToString(CultureInfo.InvariantCulture) : string.Empty);

                CompanyInfo company;

                using (DBTransaction transaction = _dbHelper.BeginTransaction())
                {
                    // Update database
                    _dbHelper.Database = database;
                    Portal.SetPortalParameterValue(_dbHelper, "system.isactive", isActive.ToString());
                    Portal.SetPortalParameterValue(_dbHelper, "system.scheme", "http");
                    Portal.SetPortalParameterValue(_dbHelper, "system.host", host);
                    Portal.SetPortalParameterValue(_dbHelper, "system.port", port);

                    company = CreateCompanyForDatabase(serverConfigDocument, database, defaultLocale, created, isActive, host, iisIPAddress, iisPort, iisApplicationPool, createClientScripts);

                    transaction.Commit();
                }

                serverConfig.SaveDocument(serverConfigDocument);

                return company.Id;
            }
        }
Example #5
0
        public void DeleteAspSite(bool deleteDatabase)
        {
            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            using (SafeXmlDocument schedulerConfig = new SafeXmlDocument(_schedulerConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();
                XmlDocument schedulerConfigDocument = schedulerConfig.LoadDocument();

                string context = "Delete ASP Site";

                // Load settings
                AspInfo aspSettings = AspInfo.Load(serverConfigDocument);

                // Delete record from ScheduleService.exe.config
                try
                {
                    aspSettings.DeleteWebServiceUri(schedulerConfigDocument);
                }
                catch (Exception ex)
                {
                    Log.WriteException(context, ex);
                }

                // Delete web
                try
                {
                    DeleteAspWeb(aspSettings, context);
                }
                catch (IisManagerException ex)
                {
                    Log.WriteException(context, ex);
                }

                // Delete database
                if (deleteDatabase)
                {
                    try
                    {
                        DeleteDatabase(aspSettings.Database);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteException(context, ex);
                    }
                }

                // Update ibn.config
                try
                {
                    AspInfo.Delete(serverConfigDocument);
                }
                catch (Exception ex)
                {
                    Log.WriteException(context, ex);
                }

                schedulerConfig.SaveDocument(schedulerConfigDocument);
                serverConfig.SaveDocument(serverConfigDocument);
            }
        }
Example #6
0
        public IConfigurationParameter[] ListCompanyProperties(string companyId)
        {
            IConfigurationParameter[] result = new IConfigurationParameter[] { };

            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.Read))
            {
                CompanyInfo company = CompanyInfo.LoadExtendedInfo(serverConfig.LoadDocument(), companyId, _dbHelper);
                if (company != null)
                {
                    try
                    {
                        _dbHelper.Database = company.Database;
                        result = Portal.ListPortalParameters(_dbHelper);
                    }
                    finally
                    {
                        _dbHelper.Database = null;
                    }
                }
            }

            return result;
        }
Example #7
0
        public void ActivateCompany(string companyId, bool isActive, bool updateAspDatabase)
        {
            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();

                AspInfo aspInfo = AspInfo.Load(serverConfigDocument);
                CompanyInfo company = CompanyInfo.LoadExtendedInfo(serverConfigDocument, companyId, _dbHelper);

                if (company != null)
                {
                    try
                    {
                        using (DBTransaction transaction = _dbHelper.BeginTransaction())
                        {
                            // Update company database
                            _dbHelper.Database = company.Database;
                            Portal.SetPortalParameterValue(_dbHelper, "system.isactive", isActive.ToString());

                            // Update ASP database
                            if (updateAspDatabase && aspInfo != null)
                            {
                                _dbHelper.Database = aspInfo.Database;
                                _dbHelper.RunSP("ASP_COMPANY_UPDATE_IS_ACTIVE"
                                    , DBHelper.MP("@company_uid", SqlDbType.UniqueIdentifier, new Guid(company.Id))
                                    , DBHelper.MP("@is_active", SqlDbType.Bit, isActive)
                                    );
                            }

                            // Update ibn.config
                            company.IsActive = isActive;
                            company.SaveGeneralInfo(serverConfigDocument);

                            transaction.Commit();
                        }
                    }
                    finally
                    {
                        _dbHelper.Database = null;
                    }
                }

                serverConfig.SaveDocument(serverConfigDocument);
            }
        }
Example #8
0
        public string ChangeCompanyApplicationPool(string companyId, string poolName)
        {
            string newPool = null;

            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();

                CompanyInfo company = CompanyInfo.LoadGeneralInfo(serverConfigDocument, companyId);
                if (company != null)
                {
                    string oldPool = company.PortalPool;
                    bool oldPoolCreated = company.IsPortalPoolCreated;

                    // Update IIS
                    IIisManager iisManager = IisManager.Create(_aspPath);
                    newPool = ChangeApplicationPool(iisManager, company.SiteId, oldPool, oldPoolCreated, poolName, GetDefaultWebName(company.Host));

                    // Update ibn.config
                    company.PortalPool = newPool;
                    company.IsPortalPoolCreated = (newPool != poolName);

                    company.SaveGeneralInfo(serverConfigDocument);
                }

                serverConfig.SaveDocument(serverConfigDocument);
            }

            return newPool;
        }
Example #9
0
 public bool CheckIfHostIsRegistered(string host)
 {
     using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.Read))
     {
         return ValidateHostName(serverConfig.LoadDocument(), host, null, false);
     }
 }
Example #10
0
        public string ChangeAspApplicationPool(string poolName)
        {
            string newPool = null;

            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();

                AspInfo aspInfo = AspInfo.Load(serverConfigDocument);
                if (aspInfo != null)
                {
                    string oldPool = aspInfo.ApplicationPool;
                    bool oldPoolCreated = aspInfo.IsApplicationPoolCreated;

                    // Update IIS
                    IIisManager iisManager = IisManager.Create(_aspPath);
                    newPool = ChangeApplicationPool(iisManager, aspInfo.SiteId, oldPool, oldPoolCreated, poolName, ConstDefaultAspName);

                    // Update ibn.config
                    aspInfo.ApplicationPool = newPool;
                    aspInfo.IsApplicationPoolCreated = (newPool != poolName);

                    aspInfo.Save(serverConfigDocument);
                }

                serverConfig.SaveDocument(serverConfigDocument);
            }

            return newPool;
        }
Example #11
0
        public void ChangeCompanyAddress(string companyId, string scheme, string host, string port, bool updateAspDatabase)
        {
            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();

                AspInfo aspInfo = AspInfo.Load(serverConfigDocument);
                CompanyInfo company = CompanyInfo.LoadExtendedInfo(serverConfigDocument, companyId, _dbHelper);

                if (company != null)
                {
                    string oldHost = company.Host;
                    ValidateHostName(serverConfigDocument, host, oldHost, true);
                    host = host.ToLowerInvariant();
                    int oldPort = CalculatePortNumber(company.Port);
                    int newPort = CalculatePortNumber(port);

                    string codeRoot = Path.Combine(InstallPath, company.CodePath);
                    string webPath = Path.Combine(codeRoot, "Web");
                    IIisManager iisManager = IisManager.Create(webPath);

                    bool bindingChanged = false;

                    try
                    {
                        using (DBTransaction transaction = _dbHelper.BeginTransaction())
                        {
                            // Update company database
                            _dbHelper.Database = company.Database;
                            Portal.SetPortalParameterValue(_dbHelper, "system.scheme", scheme);
                            Portal.SetPortalParameterValue(_dbHelper, "system.host", host);
                            Portal.SetPortalParameterValue(_dbHelper, "system.port", port);

                            // Update ASP database
                            if (updateAspDatabase && aspInfo != null)
                            {
                                _dbHelper.Database = aspInfo.Database;
                                _dbHelper.RunSP("ASP_COMPANY_UPDATE_DOMAIN"
                                    , DBHelper.MP("@company_uid", SqlDbType.UniqueIdentifier, new Guid(company.Id))
                                    , DBHelper.MP("@domain", SqlDbType.NVarChar, 255, host)
                                    );
                            }

                            // Update bindings
                            bindingChanged = iisManager.ChangeBinding(company.SiteId, oldHost, oldPort, host, newPort);

                            // Update ibn.config
                            company.Scheme = scheme;
                            company.Host = host;
                            company.Port = port;
                            company.SaveGeneralInfo(serverConfigDocument);

                            transaction.Commit();
                        }
                    }
                    catch
                    {
                        try
                        {
                            // Roll back bindings
                            if (bindingChanged)
                                iisManager.ChangeBinding(company.SiteId, host, newPort, oldHost, oldPort);
                        }
                        catch
                        {
                        }

                        throw;
                    }
                    finally
                    {
                        _dbHelper.Database = null;
                    }
                }

                serverConfig.SaveDocument(serverConfigDocument);
            }
        }
Example #12
0
        public void ChangeAspAddress(string scheme, string host, string port)
        {
            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();

                AspInfo aspInfo = AspInfo.Load(serverConfigDocument);
                if (aspInfo != null)
                {
                    string oldHost = aspInfo.Host;
                    ValidateHostName(serverConfigDocument, host, oldHost, true);
                    host = host.ToLowerInvariant();
                    int oldPort = CalculatePortNumber(aspInfo.Port);
                    int newPort = CalculatePortNumber(port);

                    // Update ibn.config
                    aspInfo.Scheme = scheme;
                    aspInfo.Host = host;
                    aspInfo.Port = port;
                    aspInfo.Save(serverConfigDocument);

                    // Update bindings
                    IIisManager iisManager = IisManager.Create(_aspPath);
                    iisManager.ChangeBinding(aspInfo.SiteId, oldHost, oldPort, host, newPort);
                }

                serverConfig.SaveDocument(serverConfigDocument);
            }
        }
Example #13
0
 public bool CanDeleteAspSite()
 {
     using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.Read))
     {
         AspInfo aspSettings = AspInfo.Load(serverConfig.LoadDocument());
         return (aspSettings != null);
     }
 }
Example #14
0
        public bool CanCreateAspSite()
        {
            bool canCreate;

            try
            {
                int allowedPortalsCount = License.PortalsCount;
                canCreate = (allowedPortalsCount < 0 || allowedPortalsCount > 1);
            }
            catch (LicenseExpiredException)
            {
                canCreate = false;
            }

            if (canCreate)
            {
                using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.Read))
                {
                    AspInfo aspSettings = AspInfo.Load(serverConfig.LoadDocument());
                    canCreate = (aspSettings == null);
                }
            }

            return canCreate;
        }
Example #15
0
 public ICompanyInfo GetCompanyInfo(string companyId)
 {
     using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.Read))
     {
         return CompanyInfo.LoadExtendedInfo(serverConfig.LoadDocument(), companyId, _dbHelper);
     }
 }
Example #16
0
        public void CreateAspSite(string host, string iisIPAddress, int iisPort, string iisApplicationPool)
        {
            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            using (SafeXmlDocument schedulerConfig = new SafeXmlDocument(_schedulerConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();
                XmlDocument schedulerConfigDocument = schedulerConfig.LoadDocument();

                ValidateHostName(serverConfigDocument, host, null, true);
                host = host.ToLowerInvariant();

                string context = "Create ASP Site";

                string database = null;
                bool databaseCreated = false;
                AspInfo aspSettings = null;

                try
                {
                    CreateSqlUser(_sourceToolsPath);

                    // Create database
                    string prospectiveDatabaseName = string.Concat(IbnConst.ProductFamilyShort, IbnConst.VersionMajorMinor, "ASP");
                    database = BuildUniqueName(prospectiveDatabaseName, GetDatabases(prospectiveDatabaseName));
                    CreateAspDatabase(database);
                    databaseCreated = true;

                    try
                    {
                        _dbHelper.Database = database;

                        // Create database structure
                        SqlExecuteScript("2CreateStructure.sql", _aspScriptsPath, _dbHelper, null);

                        // Add data to database
                        SqlExecuteScript("3AddData.sql", _aspScriptsPath, _dbHelper, null);

                        // Update database version
                        FileVersionInfo fileVersion = FileVersionInfo.GetVersionInfo(Path.Combine(_aspPath, @"bin\Mediachase.Ibn.WebAsp.dll"));
                        Version version = new Version(fileVersion.FileVersion);
                        NameValueCollection replace = new NameValueCollection();
                        replace["{MajorVersion}"] = version.Major.ToString(CultureInfo.InvariantCulture);
                        replace["{MinorVersion}"] = version.Minor.ToString(CultureInfo.InvariantCulture);
                        replace["{BuildNumber}"] = version.Build.ToString(CultureInfo.InvariantCulture);
                        SqlExecuteScript("version.sql", _sourceToolsPath, _dbHelper, replace);

                        // Update database state
                        _dbHelper.RunText("UPDATE [DatabaseVersion] SET [State]=6");
                    }
                    finally
                    {
                        _dbHelper.Database = null;
                    }

                    // Create web site
                    aspSettings = CreateAspSiteForDatabase(serverConfigDocument, schedulerConfigDocument, database, host, iisIPAddress, iisPort, iisApplicationPool);

                    // Disable custom SQL reports
                    RegistrySettings.WriteString(ConstDisableCustomSqlReport, bool.TrueString);
                }
                catch
                {
                    #region Undo changes

                    // Delete web
                    try
                    {
                        if (aspSettings != null)
                            DeleteAspWeb(aspSettings, context);
                    }
                    catch
                    {
                    }

                    // Delete database
                    try
                    {
                        if (databaseCreated)
                            DeleteDatabase(database);
                    }
                    catch
                    {
                    }

                    #endregion

                    throw;
                }

                schedulerConfig.SaveDocument(schedulerConfigDocument);
                serverConfig.SaveDocument(serverConfigDocument);
            }
        }
Example #17
0
        public ICompanyInfo[] ListCompanies(bool includeDatabaseInfo)
        {
            CompanyInfo[] companies = null;

            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.Read))
            {
                companies = CompanyInfo.ListCompanies(serverConfig.LoadDocument());
            }

            if (companies != null && includeDatabaseInfo)
            {
                foreach (CompanyInfo company in companies)
                    company.LoadExtendedInfo(_dbHelper);
            }

            return companies;
        }
Example #18
0
        public string CreateCompany(string companyName, string host, string defaultLocale, bool isActive
			, string iisIPAddress, int iisPort, string iisApplicationPool
			, string adminAccountName, string adminPassword, string adminFirstName, string adminLastName, string adminEmail)
        {
            string context = "Create Company: " + host;

            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();

                ValidatePortalsCount(serverConfigDocument);
                ValidateHostName(serverConfigDocument, host, null, true);
                host = host.ToLowerInvariant();

                CompanyInfo company = null;

                string commonName = host;
                string database = null;
                bool databaseCreated = false;

                try
                {
                    CreateSqlUser(_sourceToolsPath);

                    // Create database
                    string prospectiveDatabaseName = BuildDatabaseName(commonName);
                    database = BuildUniqueName(prospectiveDatabaseName, GetDatabases(prospectiveDatabaseName));
                    string port = (iisPort != 80 ? iisPort.ToString(CultureInfo.InvariantCulture) : string.Empty);
                    CreateCompanyDatabase(_sourceToolsPath, database
                        , companyName, "http", host, port
                        , defaultLocale, isActive
                        , adminAccountName, adminPassword, adminFirstName, adminLastName, adminEmail);
                    databaseCreated = true;

                    // Create web site
                    company = CreateCompanyForDatabase(serverConfigDocument, database, defaultLocale, DateTime.UtcNow, isActive, host, iisIPAddress, iisPort, iisApplicationPool, true);
                }
                catch
                {
                    #region Undo changes

                    // Delete web
                    try
                    {
                        if (company != null)
                            DeleteCompanyWeb(company, context);
                    }
                    catch
                    {
                    }

                    // Delete database
                    try
                    {
                        if (databaseCreated)
                            DeleteDatabase(database);
                    }
                    catch
                    {
                    }

                    #endregion

                    throw;
                }

                serverConfig.SaveDocument(serverConfigDocument);

                return company.Id;
            }
        }
Example #19
0
 public void SetCompanyPropertyValue(string companyId, string propertyName, string propertyValue)
 {
     using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.Read))
     {
         CompanyInfo company = CompanyInfo.LoadExtendedInfo(serverConfig.LoadDocument(), companyId, _dbHelper);
         if (company != null)
         {
             try
             {
                 _dbHelper.Database = company.Database;
                 Portal.SetPortalParameterValue(_dbHelper, propertyName, propertyValue);
             }
             finally
             {
                 _dbHelper.Database = null;
             }
         }
     }
 }
Example #20
0
        public void UpdateCompanyVersion(string companyId)
        {
            using (SafeXmlDocument serverConfig = new SafeXmlDocument(_serverConfigPath, FileAccess.ReadWrite))
            {
                XmlDocument serverConfigDocument = serverConfig.LoadDocument();

                CompanyInfo company = CompanyInfo.LoadGeneralInfo(serverConfigDocument, companyId);
                if (company != null)
                {
                    // Get code version
                    string companyRoot = Path.Combine(InstallPath, company.CodePath);
                    FileVersionInfo version = FileVersionInfo.GetVersionInfo(Path.Combine(companyRoot, @"Web\Portal\bin\Mediachase.IBN.Business.dll"));

                    // Set code version
                    company.CodeVersion = version.FileBuildPart;

                    // Update ibn.config
                    company.SaveGeneralInfo(serverConfigDocument);
                }

                serverConfig.SaveDocument(serverConfigDocument);
            }
        }