/// <remarks/>
 public void InstallApplicationAsync(InstallationInfo inst, object userState)
 {
     if ((this.InstallApplicationOperationCompleted == null))
     {
         this.InstallApplicationOperationCompleted = new System.Threading.SendOrPostCallback(this.OnInstallApplicationOperationCompleted);
     }
     this.InvokeAsync("InstallApplication", new object[] {
         inst
     }, this.InstallApplicationOperationCompleted, userState);
 }
        public static int InstallApplication(InstallationInfo inst)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // check package
            int packageCheck = SecurityContext.CheckPackage(inst.PackageId, DemandPackage.IsActive);
            if (packageCheck < 0) return packageCheck;

            // install application
            WebApplicationsInstaller installer = new WebApplicationsInstaller();
            return installer.InstallWebApplication(inst);
        }
Пример #3
0
        public static int InstallApplication(InstallationInfo inst)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(inst.PackageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // install application
            WebApplicationsInstaller installer = new WebApplicationsInstaller();

            return(installer.InstallWebApplication(inst));
        }
Пример #4
0
        private void RollbackInstallation(InstallationInfo inst)
        {
            // remove virtual dir
            if (inst[PROPERTY_VDIR_CREATED] != null)
            {
                // delete virtual directory
                WebServerController.DeleteVirtualDirectory(inst.WebSiteId, inst.VirtualDir);

                // delete folder
                FilesController.DeleteFiles(inst.PackageId, new string[] { inst[PROPERTY_CONTENT_PATH] });
            }

            // remove database
            if (inst[PROPERTY_DATABASE_CREATED] != null)
            {
                DatabaseServerController.DeleteSqlDatabase(inst.DatabaseId);
            }

            // remove database user
            if (inst[PROPERTY_USER_CREATED] != null)
            {
                DatabaseServerController.DeleteSqlUser(inst.UserId);
            }
        }
        private void RollbackInstallation(InstallationInfo inst)
        {
            // remove virtual dir
            if (inst[PROPERTY_VDIR_CREATED] != null)
            {
                // delete virtual directory
                WebServerController.DeleteVirtualDirectory(inst.WebSiteId, inst.VirtualDir);

                // delete folder
                FilesController.DeleteFiles(inst.PackageId, new string[] { inst[PROPERTY_CONTENT_PATH] });
            }

            // remove database
            if (inst[PROPERTY_DATABASE_CREATED] != null)
                DatabaseServerController.DeleteSqlDatabase(inst.DatabaseId);

            // remove database user
            if (inst[PROPERTY_USER_CREATED] != null)
                    DatabaseServerController.DeleteSqlUser(inst.UserId);
        }
        private string ExpandVariables(string str, InstallationInfo inst)
        {
            str = ReplaceTemplateVariable(str, "installer.contentpath", inst[PROPERTY_CONTENT_PATH]);
            str = ReplaceTemplateVariable(str, "installer.website", webSiteName);
            str = ReplaceTemplateVariable(str, "installer.virtualdir", inst.VirtualDir);

            string fullWebPath = webSiteName;
            if (!String.IsNullOrEmpty(inst.VirtualDir))
                fullWebPath += "/" + inst.VirtualDir;

            // try to load domain info
            DomainInfo domain = ServerController.GetDomain(webSiteName);
            string fullWebPathPrefix = (domain != null && domain.IsSubDomain) ? "" : "www.";

            // app URLs
            if (appUrls == null)
            {
                // read web pointers
                List<DomainInfo> sitePointers = WebServerController.GetWebSitePointers(inst.WebSiteId);
                StringBuilder sb = new StringBuilder();
                sb.Append("<urls>");
                sb.Append("<url value=\"").Append(fullWebPath).Append("\"/>");
                foreach (DomainInfo pointer in sitePointers)
                {
                    string pointerWebPath = pointer.DomainName;
                    if (!String.IsNullOrEmpty(inst.VirtualDir))
                        pointerWebPath += "/" + inst.VirtualDir;
                    sb.Append("<url value=\"").Append(pointerWebPath).Append("\"/>");
                }
                sb.Append("</urls>");
                appUrls = sb.ToString();
            }
            str = ReplaceTemplateVariable(str, "installer.appurls", appUrls);

            string slashVirtualDir = "";
            if (!String.IsNullOrEmpty(inst.VirtualDir))
                slashVirtualDir = "/" + inst.VirtualDir;

            str = ReplaceTemplateVariable(str, "installer.slashvirtualdir", slashVirtualDir);
            str = ReplaceTemplateVariable(str, "installer.website.www", fullWebPathPrefix + webSiteName);
            str = ReplaceTemplateVariable(str, "installer.fullwebpath", fullWebPath);
            str = ReplaceTemplateVariable(str, "installer.fullwebpath.www", fullWebPathPrefix + fullWebPath);
            //Replace ObjectQualifierNormalized which is not defined on portal
            str = ReplaceTemplateVariable(str, "ObjectQualifierNormalized", "");
			
			/*
			 * Application installer variable 'installer.database.server' is obsolete 
			 * and should not be used to install Application Packs.
			 * Instead, please use the following two variables:
			 *  - installer.database.server.external - defines external database address
			 *  - installer.database.server.internal - defines internal database address
			 * 
			 * See TFS Issue 952 for details.
			 */
			//apply external database address
			str = ReplaceTemplateVariable(str, "installer.database.server",
                ((serverIpAddressExternal != null) ? serverIpAddressExternal : ""));
			str = ReplaceTemplateVariable(str, "installer.database.server.external",
				((serverIpAddressExternal != null) ? serverIpAddressExternal : String.Empty));

			//apply internal database address
			str = ReplaceTemplateVariable(str, "installer.database.server.internal",
				((serverIpAddressInternal != null) ? serverIpAddressInternal : String.Empty));

            str = ReplaceTemplateVariable(str, "installer.database", inst.DatabaseName);
            str = ReplaceTemplateVariable(str, "installer.database.user", inst.Username);
            str = ReplaceTemplateVariable(str, "installer.database.password",
                ((inst.Password != null) ? inst.Password : ""));
            foreach (string[] pair in inst.PropertiesArray)
                str = ReplaceTemplateVariable(str, pair[0], pair[1]);
            return str;
        }
        private int RunScenario(string scenarioPath, InstallationInfo inst, bool throwExceptions)
        {
            // load XML document
            XmlDocument docScenario = new XmlDocument();
            docScenario.Load(scenarioPath);

            // go through "check" section
            XmlNode nodeCheck = docScenario.SelectSingleNode("//check");
            if (nodeCheck != null)
            {
                foreach (XmlNode nodeStep in nodeCheck.ChildNodes)
                {
                    if (nodeStep.Name == "fileExists")
                    {
                        /*
                        // check if the specified file exists
                        string fileName = nodeStep.Attributes["path"].Value;
                        fileName = ExpandVariables(fileName, inst);
                        if (fileName.StartsWith("\\"))
                        {
                            fileName = fileName.Substring(1);
                        }
                        //get full path to instal folder
                        PackageInfo package = PackageController.GetPackage(inst.PackageId);
                        string fullPath = Path.Combine(GetFullPathToInstallFolder(package.UserId), fileName);
                        if (os.FileExists(fullPath))
                            return BusinessErrorCodes.ERROR_WEB_INSTALLER_TARGET_WEBSITE_UNSUITABLE;
                         */
                    }
                    else if (nodeStep.Name == "sql")
                    {
                        string cmdText = nodeStep.InnerText;
                        cmdText = ExpandVariables(cmdText, inst);

                        DataSet dsResults = sql.ExecuteSqlQuery(inst.DatabaseName, cmdText);
                        if (dsResults.Tables[0].Rows.Count > 0)
                            return BusinessErrorCodes.ERROR_WEB_INSTALLER_TARGET_DATABASE_UNSUITABLE;
                    }
                }
            }

            // go through "commands" section
            XmlNode nodeCommands = docScenario.SelectSingleNode("//commands");
            if (nodeCommands != null)
            {
                foreach (XmlNode nodeCommand in nodeCommands.ChildNodes)
                {
                    if (nodeCommand.Name == "processFile")
                    {
                        // process remote file
                        string fileName = nodeCommand.Attributes["path"].Value;
                        fileName = ExpandVariables(fileName, inst);

                        byte[] fileBinaryContent = FilesController.GetFileBinaryContent(inst.PackageId, fileName);
                        if (fileBinaryContent == null)
                            throw new Exception("Could not process scenario file: " + fileName);

                        string fileContent = Encoding.UTF8.GetString(fileBinaryContent);
                        fileContent = ExpandVariables(fileContent, inst);

                        FilesController.UpdateFileBinaryContent(inst.PackageId, fileName,
                            Encoding.UTF8.GetBytes(fileContent));
                    }
                    else if (nodeCommand.Name == "runSql")
                    {
                        string cmdText = nodeCommand.InnerText;
                        if (nodeCommand.Attributes["path"] != null)
                        {
                            // load SQL from file
                            string sqlPath = Path.Combine(app.Folder, nodeCommand.Attributes["path"].Value);

                            if (!File.Exists(sqlPath))
                                continue;

                            StreamReader reader = new StreamReader(sqlPath);
                            cmdText = reader.ReadToEnd();
                            reader.Close();
                        }

                        bool run = true;
                        if (nodeCommand.Attributes["dependsOnProperty"] != null)
                        {
                            string[] propNames = nodeCommand.Attributes["dependsOnProperty"].Value.Split(',');
                            foreach (string propName in propNames)
                            {
                                if (inst[propName.Trim()] == null)
                                {
                                    run = false;
                                    break;
                                }
                            }
                        }

                        if (run)
                        {
                            try
                            {
                                cmdText = ExpandVariables(cmdText, inst);
                                sql.ExecuteSqlNonQuerySafe(inst.DatabaseName, inst.Username, inst.Password, cmdText);
                            }
                            catch (Exception ex)
                            {
                                if (throwExceptions)
                                    throw ex;
                            }
                        }
                    }
                }
            }
            return 0;
        }
Пример #8
0
        private int RunScenario(string scenarioPath, InstallationInfo inst, bool throwExceptions)
        {
            // load XML document
            XmlDocument docScenario = new XmlDocument();

            docScenario.Load(scenarioPath);

            // go through "check" section
            XmlNode nodeCheck = docScenario.SelectSingleNode("//check");

            if (nodeCheck != null)
            {
                foreach (XmlNode nodeStep in nodeCheck.ChildNodes)
                {
                    if (nodeStep.Name == "fileExists")
                    {
                        /*
                         * // check if the specified file exists
                         * string fileName = nodeStep.Attributes["path"].Value;
                         * fileName = ExpandVariables(fileName, inst);
                         * if (fileName.StartsWith("\\"))
                         * {
                         *  fileName = fileName.Substring(1);
                         * }
                         * //get full path to instal folder
                         * PackageInfo package = PackageController.GetPackage(inst.PackageId);
                         * string fullPath = Path.Combine(GetFullPathToInstallFolder(package.UserId), fileName);
                         * if (os.FileExists(fullPath))
                         *  return BusinessErrorCodes.ERROR_WEB_INSTALLER_TARGET_WEBSITE_UNSUITABLE;
                         */
                    }
                    else if (nodeStep.Name == "sql")
                    {
                        string cmdText = nodeStep.InnerText;
                        cmdText = ExpandVariables(cmdText, inst);

                        DataSet dsResults = sql.ExecuteSqlQuery(inst.DatabaseName, cmdText);
                        if (dsResults.Tables[0].Rows.Count > 0)
                        {
                            return(BusinessErrorCodes.ERROR_WEB_INSTALLER_TARGET_DATABASE_UNSUITABLE);
                        }
                    }
                }
            }

            // go through "commands" section
            XmlNode nodeCommands = docScenario.SelectSingleNode("//commands");

            if (nodeCommands != null)
            {
                foreach (XmlNode nodeCommand in nodeCommands.ChildNodes)
                {
                    if (nodeCommand.Name == "processFile")
                    {
                        // process remote file
                        string fileName = nodeCommand.Attributes["path"].Value;
                        fileName = ExpandVariables(fileName, inst);

                        byte[] fileBinaryContent = FilesController.GetFileBinaryContent(inst.PackageId, fileName);
                        if (fileBinaryContent == null)
                        {
                            throw new Exception("Could not process scenario file: " + fileName);
                        }

                        string fileContent = Encoding.UTF8.GetString(fileBinaryContent);
                        fileContent = ExpandVariables(fileContent, inst);

                        FilesController.UpdateFileBinaryContent(inst.PackageId, fileName,
                                                                Encoding.UTF8.GetBytes(fileContent));
                    }
                    else if (nodeCommand.Name == "runSql")
                    {
                        string cmdText = nodeCommand.InnerText;
                        if (nodeCommand.Attributes["path"] != null)
                        {
                            // load SQL from file
                            string sqlPath = Path.Combine(app.Folder, nodeCommand.Attributes["path"].Value);

                            if (!File.Exists(sqlPath))
                            {
                                continue;
                            }

                            StreamReader reader = new StreamReader(sqlPath);
                            cmdText = reader.ReadToEnd();
                            reader.Close();
                        }

                        bool run = true;
                        if (nodeCommand.Attributes["dependsOnProperty"] != null)
                        {
                            string[] propNames = nodeCommand.Attributes["dependsOnProperty"].Value.Split(',');
                            foreach (string propName in propNames)
                            {
                                if (inst[propName.Trim()] == null)
                                {
                                    run = false;
                                    break;
                                }
                            }
                        }

                        if (run)
                        {
                            try
                            {
                                cmdText = ExpandVariables(cmdText, inst);
                                sql.ExecuteSqlNonQuerySafe(inst.DatabaseName, inst.Username, inst.Password, cmdText);
                            }
                            catch (Exception ex)
                            {
                                if (throwExceptions)
                                {
                                    throw ex;
                                }
                            }
                        }
                    }
                }
            }
            return(0);
        }
        private void InstallApplication()
        {
            if (!Page.IsValid)
                return;

            InstallationInfo inst = new InstallationInfo();
            inst.PackageId = packageId;
            inst.ApplicationId = PanelRequest.ApplicationID;
            inst.WebSiteId = Utils.ParseInt(ddlWebSite.SelectedValue, 0);
            inst.VirtualDir = directoryName.Text;
            inst.DatabaseGroup = ddlDatabaseGroup.SelectedValue;
            inst.DatabaseId = Utils.ParseInt(ddlDatabase.SelectedValue, 0);
            inst.DatabaseName = databaseName.Text;
            inst.UserId = Utils.ParseInt(ddlUser.SelectedValue, 0);
            inst.Username = databaseUser.Text;
            inst.Password = databasePassword.Password;

            // get app settings
            try
            {
                if (settings != null)
                {
                    settings.GetSettings(inst);
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage("APPINSTALLER_GET_SETTINGS", ex);
            }

            // install application
            try
            {
                int result = ES.Services.ApplicationsInstaller.InstallApplication(inst);
                if (result < 0)
                {
                    ShowResultMessage(result);
                    return;
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage("APPINSTALLER_INSTALL_APP", ex);
                return;
            }

            Response.Redirect(EditUrl("ApplicationID", PanelRequest.ApplicationID, "complete",
                PortalUtils.SPACE_ID_PARAM + "=" + PanelSecurity.PackageId.ToString()));
        }
 public int InstallApplication(InstallationInfo inst)
 {
     object[] results = this.Invoke("InstallApplication", new object[] {
                 inst});
     return ((int)(results[0]));
 }
 /// <remarks/>
 public void InstallApplicationAsync(InstallationInfo inst, object userState)
 {
     if ((this.InstallApplicationOperationCompleted == null))
     {
         this.InstallApplicationOperationCompleted = new System.Threading.SendOrPostCallback(this.OnInstallApplicationOperationCompleted);
     }
     this.InvokeAsync("InstallApplication", new object[] {
                 inst}, this.InstallApplicationOperationCompleted, userState);
 }
 /// <remarks/>
 public void InstallApplicationAsync(InstallationInfo inst)
 {
     this.InstallApplicationAsync(inst, null);
 }
Пример #13
0
        public int InstallWebApplication(InstallationInfo inst)
        {
            // place log record
            TaskManager.StartTask("APP_INSTALLER", "INSTALL_APPLICATION", inst.PackageId);

            TaskManager.WriteParameter("Virtual directory", inst.VirtualDir);
            TaskManager.WriteParameter("Database group", inst.DatabaseGroup);

            try
            {
                // get application info
                app = GetApplication(inst.PackageId, inst.ApplicationId);

                BackgroundTask topTask = TaskManager.TopTask;

                topTask.ItemName = app.Name;

                TaskController.UpdateTask(topTask);

                // check web site for existance
                WebSite webSite = WebServerController.GetWebSite(inst.WebSiteId);

                if (webSite == null)
                {
                    return(BusinessErrorCodes.ERROR_WEB_INSTALLER_WEBSITE_NOT_EXISTS);
                }

                TaskManager.WriteParameter("Web site", webSite.Name);

                webSiteName = webSite.Name;
                siteId      = webSite.SiteId;

                // change web site properties if required
                if (String.IsNullOrEmpty(inst.VirtualDir))
                {
                    ChangeVirtualDirectoryProperties(webSite, app.WebSettings);
                    WebServerController.UpdateWebSite(webSite);
                }

                // get OS service
                int osId = PackageController.GetPackageServiceId(inst.PackageId, "os");
                os = new OS.OperatingSystem();
                ServiceProviderProxy.Init(os, osId);

                // get remote content path
                contentPath = webSite.ContentPath;

                // create virtual dir if required
                if (!String.IsNullOrEmpty(inst.VirtualDir))
                {
                    // check if the required virtual dir already exists
                    contentPath = Path.Combine(contentPath, inst.VirtualDir);

                    WebVirtualDirectory vdir = null;
                    int result = WebServerController.AddVirtualDirectory(inst.WebSiteId, inst.VirtualDir, contentPath);
                    if (result == BusinessErrorCodes.ERROR_VDIR_ALREADY_EXISTS)
                    {
                        // the directory alredy exists
                        vdir = WebServerController.GetVirtualDirectory(
                            inst.WebSiteId, inst.VirtualDir);

                        contentPath = vdir.ContentPath;
                    }
                    else
                    {
                        vdir = WebServerController.GetVirtualDirectory(
                            inst.WebSiteId, inst.VirtualDir);

                        inst[PROPERTY_VDIR_CREATED] = "True";
                    }

                    // change virtual directory properties if required
                    ChangeVirtualDirectoryProperties(vdir, app.WebSettings);
                    WebServerController.UpdateVirtualDirectory(inst.WebSiteId, vdir);
                }

                // deploy application codebase ZIP and then unpack it
                string codebasePath       = app.Codebase;
                string remoteCodebasePath = Path.Combine(contentPath, Path.GetFileName(app.Codebase));

                // make content path absolute
                string absContentPath = FilesController.GetFullPackagePath(inst.PackageId, contentPath);

                // save content path
                inst[PROPERTY_CONTENT_PATH]          = contentPath;
                inst[PROPERTY_ABSOLUTE_CONTENT_PATH] = absContentPath;

                // copy ZIP to the target server
                FileStream stream        = File.OpenRead(codebasePath);
                int        BUFFER_LENGTH = 5000000;

                byte[] buffer    = new byte[BUFFER_LENGTH];
                int    readBytes = 0;
                while (true)
                {
                    readBytes = stream.Read(buffer, 0, BUFFER_LENGTH);

                    if (readBytes < BUFFER_LENGTH)
                    {
                        Array.Resize <byte>(ref buffer, readBytes);
                    }

                    FilesController.AppendFileBinaryChunk(inst.PackageId, remoteCodebasePath, buffer);

                    if (readBytes < BUFFER_LENGTH)
                    {
                        break;
                    }
                }



                // unpack codebase
                inst[PROPERTY_INSTALLED_FILES] = String.Join(";",
                                                             FilesController.UnzipFiles(inst.PackageId, new string[] { remoteCodebasePath }));

                // delete codebase zip
                FilesController.DeleteFiles(inst.PackageId, new string[] { remoteCodebasePath });

                // check/create databases
                if (!String.IsNullOrEmpty(inst.DatabaseGroup) &&
                    String.Compare(inst.DatabaseGroup, "None", true) != 0)
                {
                    // database
                    if (inst.DatabaseId == 0)
                    {
                        TaskManager.WriteParameter("Database name", inst.DatabaseName);

                        // we should create a new database
                        SqlDatabase db = new SqlDatabase();
                        db.PackageId    = inst.PackageId;
                        db.Name         = inst.DatabaseName;
                        inst.DatabaseId = DatabaseServerController.AddSqlDatabase(db, inst.DatabaseGroup);
                        if (inst.DatabaseId < 0)
                        {
                            // rollback installation
                            RollbackInstallation(inst);

                            // return error
                            return(inst.DatabaseId); // there was an error when creating database
                        }

                        inst[PROPERTY_DATABASE_CREATED] = "True";
                    }
                    else
                    {
                        // existing database
                        SqlDatabase db = DatabaseServerController.GetSqlDatabase(inst.DatabaseId);
                        inst.DatabaseName = db.Name;

                        TaskManager.WriteParameter("Database name", inst.DatabaseName);
                    }

                    SqlUser user = null;
                    // database user
                    if (inst.UserId == 0)
                    {
                        TaskManager.WriteParameter("Database user", inst.Username);

                        // NEW USER
                        user           = new SqlUser();
                        user.PackageId = inst.PackageId;
                        user.Name      = inst.Username;
                        user.Databases = new string[] { inst.DatabaseName };
                        user.Password  = inst.Password;
                        inst.UserId    = DatabaseServerController.AddSqlUser(user, inst.DatabaseGroup);
                        if (inst.UserId < 0)
                        {
                            // rollback installation
                            RollbackInstallation(inst);

                            // return error
                            return(inst.UserId); // error while adding user
                        }

                        inst[PROPERTY_USER_CREATED] = "True";
                    }
                    else
                    {
                        // EXISTING USER
                        user          = DatabaseServerController.GetSqlUser(inst.UserId);
                        inst.Username = user.Name;

                        TaskManager.WriteParameter("Database user", inst.Username);

                        List <string> databases = new List <string>();
                        databases.AddRange(user.Databases);

                        if (!databases.Contains(inst.DatabaseName))
                        {
                            databases.Add(inst.DatabaseName);

                            user.Databases = databases.ToArray();
                            DatabaseServerController.UpdateSqlUser(user);
                        }
                    }

                    // check connectivity with SQL Server and credentials provided
                    // load user item
                    int sqlServiceId = PackageController.GetPackageServiceId(inst.PackageId, inst.DatabaseGroup);
                    sql = new DatabaseServer();
                    ServiceProviderProxy.Init(sql, sqlServiceId);

                    if (!sql.CheckConnectivity(inst.DatabaseName, inst.Username,
                                               inst.Password))
                    {
                        // can't connect to the database
                        RollbackInstallation(inst);

                        return(BusinessErrorCodes.ERROR_WEB_INSTALLER_CANT_CONNECT_DATABASE);
                    }

                    // read SQL server settings
                    StringDictionary settings = ServerController.GetServiceSettings(sqlServiceId);
                    serverIpAddressExternal = settings["ExternalAddress"];
                    if (settings.ContainsKey("InternalAddress"))
                    {
                        serverIpAddressInternal = settings["InternalAddress"];
                    }
                }

                // ********* RUN INSTALL SCENARIO ***********
                int scriptResult = RunInstallScenario(inst);
                if (scriptResult < 0)
                {
                    // rollback installation
                    RollbackInstallation(inst);

                    // return error
                    return(scriptResult);
                }

                // add new installation to the database
                return(0);
            }
            catch (Exception ex)
            {
                // rollback installation
                RollbackInstallation(inst);

                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Пример #14
0
        private string ExpandVariables(string str, InstallationInfo inst)
        {
            str = ReplaceTemplateVariable(str, "installer.contentpath", inst[PROPERTY_CONTENT_PATH]);
            str = ReplaceTemplateVariable(str, "installer.website", webSiteName);
            str = ReplaceTemplateVariable(str, "installer.virtualdir", inst.VirtualDir);

            string fullWebPath = webSiteName;

            if (!String.IsNullOrEmpty(inst.VirtualDir))
            {
                fullWebPath += "/" + inst.VirtualDir;
            }

            // try to load domain info
            DomainInfo domain            = ServerController.GetDomain(webSiteName);
            string     fullWebPathPrefix = (domain != null && domain.IsSubDomain) ? "" : "www.";

            // app URLs
            if (appUrls == null)
            {
                // read web pointers
                List <DomainInfo> sitePointers = WebServerController.GetWebSitePointers(inst.WebSiteId);
                StringBuilder     sb           = new StringBuilder();
                sb.Append("<urls>");
                sb.Append("<url value=\"").Append(fullWebPath).Append("\"/>");
                foreach (DomainInfo pointer in sitePointers)
                {
                    string pointerWebPath = pointer.DomainName;
                    if (!String.IsNullOrEmpty(inst.VirtualDir))
                    {
                        pointerWebPath += "/" + inst.VirtualDir;
                    }
                    sb.Append("<url value=\"").Append(pointerWebPath).Append("\"/>");
                }
                sb.Append("</urls>");
                appUrls = sb.ToString();
            }
            str = ReplaceTemplateVariable(str, "installer.appurls", appUrls);

            string slashVirtualDir = "";

            if (!String.IsNullOrEmpty(inst.VirtualDir))
            {
                slashVirtualDir = "/" + inst.VirtualDir;
            }

            str = ReplaceTemplateVariable(str, "installer.slashvirtualdir", slashVirtualDir);
            str = ReplaceTemplateVariable(str, "installer.website.www", fullWebPathPrefix + webSiteName);
            str = ReplaceTemplateVariable(str, "installer.fullwebpath", fullWebPath);
            str = ReplaceTemplateVariable(str, "installer.fullwebpath.www", fullWebPathPrefix + fullWebPath);
            //Replace ObjectQualifierNormalized which is not defined on portal
            str = ReplaceTemplateVariable(str, "ObjectQualifierNormalized", "");

            /*
             * Application installer variable 'installer.database.server' is obsolete
             * and should not be used to install Application Packs.
             * Instead, please use the following two variables:
             *  - installer.database.server.external - defines external database address
             *  - installer.database.server.internal - defines internal database address
             *
             * See TFS Issue 952 for details.
             */
            //apply external database address
            str = ReplaceTemplateVariable(str, "installer.database.server",
                                          ((serverIpAddressExternal != null) ? serverIpAddressExternal : ""));
            str = ReplaceTemplateVariable(str, "installer.database.server.external",
                                          ((serverIpAddressExternal != null) ? serverIpAddressExternal : String.Empty));

            //apply internal database address
            str = ReplaceTemplateVariable(str, "installer.database.server.internal",
                                          ((serverIpAddressInternal != null) ? serverIpAddressInternal : String.Empty));

            str = ReplaceTemplateVariable(str, "installer.database", inst.DatabaseName);
            str = ReplaceTemplateVariable(str, "installer.database.user", inst.Username);
            str = ReplaceTemplateVariable(str, "installer.database.password",
                                          ((inst.Password != null) ? inst.Password : ""));
            foreach (string[] pair in inst.PropertiesArray)
            {
                str = ReplaceTemplateVariable(str, pair[0], pair[1]);
            }
            return(str);
        }
        public int InstallWebApplication(InstallationInfo inst)
        {
            // place log record
            TaskManager.StartTask("APP_INSTALLER", "INSTALL_APPLICATION");
            TaskManager.WriteParameter("Virtual directory", inst.VirtualDir);
            TaskManager.WriteParameter("Database group", inst.DatabaseGroup);
            TaskManager.ItemId = inst.PackageId;

            try
            {
                // get application info
                app = GetApplication(inst.PackageId, inst.ApplicationId);

                TaskManager.ItemName = app.Name;

                // check web site for existance
                WebSite webSite = WebServerController.GetWebSite(inst.WebSiteId);

                if (webSite == null)
                    return BusinessErrorCodes.ERROR_WEB_INSTALLER_WEBSITE_NOT_EXISTS;

				TaskManager.WriteParameter("Web site", webSite.Name);

                webSiteName = webSite.Name;
                siteId = webSite.SiteId;

                // change web site properties if required
                if (String.IsNullOrEmpty(inst.VirtualDir))
                {
                    ChangeVirtualDirectoryProperties(webSite, app.WebSettings);
                    WebServerController.UpdateWebSite(webSite);
                }

                // get OS service
                int osId = PackageController.GetPackageServiceId(inst.PackageId, "os");
                os = new OS.OperatingSystem();
                ServiceProviderProxy.Init(os, osId);

                // get remote content path
                contentPath = webSite.ContentPath;

                // create virtual dir if required
                if (!String.IsNullOrEmpty(inst.VirtualDir))
                {
                    // check if the required virtual dir already exists
                    contentPath = Path.Combine(contentPath, inst.VirtualDir);

                    WebVirtualDirectory vdir = null;
                    int result = WebServerController.AddVirtualDirectory(inst.WebSiteId, inst.VirtualDir, contentPath);
                    if (result == BusinessErrorCodes.ERROR_VDIR_ALREADY_EXISTS)
                    {
                        // the directory alredy exists
                        vdir = WebServerController.GetVirtualDirectory(
                            inst.WebSiteId, inst.VirtualDir);

                        contentPath = vdir.ContentPath;
                    }
                    else
                    {
                        vdir = WebServerController.GetVirtualDirectory(
                            inst.WebSiteId, inst.VirtualDir);

                        inst[PROPERTY_VDIR_CREATED] = "True";
                    }

                    // change virtual directory properties if required
                    ChangeVirtualDirectoryProperties(vdir, app.WebSettings);
                    WebServerController.UpdateVirtualDirectory(inst.WebSiteId, vdir);
                }

                // deploy application codebase ZIP and then unpack it
                string codebasePath = app.Codebase;
                string remoteCodebasePath = Path.Combine(contentPath, Path.GetFileName(app.Codebase));

                // make content path absolute
                string absContentPath = FilesController.GetFullPackagePath(inst.PackageId, contentPath);

                // save content path
                inst[PROPERTY_CONTENT_PATH] = contentPath;
                inst[PROPERTY_ABSOLUTE_CONTENT_PATH] = absContentPath;

                // copy ZIP to the target server
                FileStream stream = File.OpenRead(codebasePath);
                int BUFFER_LENGTH = 5000000;

                byte[] buffer = new byte[BUFFER_LENGTH];
                int readBytes = 0;
                while (true)
                {
                    readBytes = stream.Read(buffer, 0, BUFFER_LENGTH);

                    if (readBytes < BUFFER_LENGTH)
                        Array.Resize<byte>(ref buffer, readBytes);

                    FilesController.AppendFileBinaryChunk(inst.PackageId, remoteCodebasePath, buffer);

                    if (readBytes < BUFFER_LENGTH)
                        break;
                }


                
                // unpack codebase
                inst[PROPERTY_INSTALLED_FILES] = String.Join(";",
                   FilesController.UnzipFiles(inst.PackageId, new string[] { remoteCodebasePath }));
                
                // delete codebase zip
                FilesController.DeleteFiles(inst.PackageId, new string[] { remoteCodebasePath });

                // check/create databases
                if (!String.IsNullOrEmpty(inst.DatabaseGroup) &&
                    String.Compare(inst.DatabaseGroup, "None", true) != 0)
                {
                    // database
                    if (inst.DatabaseId == 0)
                    {
                        TaskManager.WriteParameter("Database name", inst.DatabaseName);

                        // we should create a new database
                        SqlDatabase db = new SqlDatabase();
                        db.PackageId = inst.PackageId;
                        db.Name = inst.DatabaseName;
                        inst.DatabaseId = DatabaseServerController.AddSqlDatabase(db, inst.DatabaseGroup);
                        if (inst.DatabaseId < 0)
                        {
                            // rollback installation
                            RollbackInstallation(inst);

                            // return error
                            return inst.DatabaseId; // there was an error when creating database
                        }

                        inst[PROPERTY_DATABASE_CREATED] = "True";
                    }
                    else
                    {
                        // existing database
                        SqlDatabase db = DatabaseServerController.GetSqlDatabase(inst.DatabaseId);
                        inst.DatabaseName = db.Name;

                        TaskManager.WriteParameter("Database name", inst.DatabaseName);
                    }

                    SqlUser user = null;
                    // database user
                    if (inst.UserId == 0)
                    {
                        TaskManager.WriteParameter("Database user", inst.Username);

                        // NEW USER
                        user = new SqlUser();
                        user.PackageId = inst.PackageId;
                        user.Name = inst.Username;
                        user.Databases = new string[] { inst.DatabaseName };
                        user.Password = inst.Password;
                        inst.UserId = DatabaseServerController.AddSqlUser(user, inst.DatabaseGroup);
                        if (inst.UserId < 0)
                        {
                            // rollback installation
                            RollbackInstallation(inst);

                            // return error
                            return inst.UserId; // error while adding user
                        }

                        inst[PROPERTY_USER_CREATED] = "True";
                    }
                    else
                    {
                        // EXISTING USER
                        user = DatabaseServerController.GetSqlUser(inst.UserId);
                        inst.Username = user.Name;

                        TaskManager.WriteParameter("Database user", inst.Username);

                        List<string> databases = new List<string>();
                        databases.AddRange(user.Databases);

                        if (!databases.Contains(inst.DatabaseName))
                        {
                            databases.Add(inst.DatabaseName);

                            user.Databases = databases.ToArray();
                            DatabaseServerController.UpdateSqlUser(user);
                        }
                    }

                    // check connectivity with SQL Server and credentials provided
                    // load user item
                    int sqlServiceId = PackageController.GetPackageServiceId(inst.PackageId, inst.DatabaseGroup);
                    sql = new DatabaseServer();
                    ServiceProviderProxy.Init(sql, sqlServiceId);

                    if (!sql.CheckConnectivity(inst.DatabaseName, inst.Username,
                        inst.Password))
                    {
                        // can't connect to the database
                        RollbackInstallation(inst);

                        return BusinessErrorCodes.ERROR_WEB_INSTALLER_CANT_CONNECT_DATABASE;
                    }

                    // read SQL server settings
                    StringDictionary settings = ServerController.GetServiceSettings(sqlServiceId);
                    serverIpAddressExternal = settings["ExternalAddress"];
					if (settings.ContainsKey("InternalAddress"))
					{
						serverIpAddressInternal = settings["InternalAddress"];
					}
                }

                // ********* RUN INSTALL SCENARIO ***********
                int scriptResult = RunInstallScenario(inst);
                if (scriptResult < 0)
                {
                    // rollback installation
                    RollbackInstallation(inst);

                    // return error
                    return scriptResult;
                }

                // add new installation to the database
                return 0;
            }
            catch (Exception ex)
            {
                // rollback installation
                RollbackInstallation(inst);

                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
 /// <remarks/>
 public System.IAsyncResult BeginInstallApplication(InstallationInfo inst, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("InstallApplication", new object[] {
                 inst}, callback, asyncState);
 }
 public int InstallApplication(InstallationInfo inst)
 {
     return WebApplicationsInstaller.InstallApplication(inst);
 }
Пример #18
0
 public int InstallApplication(InstallationInfo inst)
 {
     return(WebApplicationsInstaller.InstallApplication(inst));
 }
 /// <remarks/>
 public void InstallApplicationAsync(InstallationInfo inst)
 {
     this.InstallApplicationAsync(inst, null);
 }
 private int RunInstallScenario(InstallationInfo inst)
 {
     string scenarioPath = Path.Combine(app.Folder, "Install.xml");
     return RunScenario(scenarioPath, inst, true);
 }
 /// <remarks/>
 public System.IAsyncResult BeginInstallApplication(InstallationInfo inst, System.AsyncCallback callback, object asyncState)
 {
     return(this.BeginInvoke("InstallApplication", new object[] {
         inst
     }, callback, asyncState));
 }
Пример #22
0
        private int RunInstallScenario(InstallationInfo inst)
        {
            string scenarioPath = Path.Combine(app.Folder, "Install.xml");

            return(RunScenario(scenarioPath, inst, true));
        }