示例#1
0
        public string AppCreate(DeveloperInfo developerInfo, string appName, string siteName, byte appLanguage, int pipelineMode, string runtimeVersion)
        {
            IISProcess iisProcess = null;
            string fullSiteName = string.Empty;
            try
            {
                if (appName.Length < 1 || appName.Length > 20)
                {
                    return "应用名称需要1-20个字符!";
                }

                if (siteName.Length < 1 || siteName.Length > 20)
                {
                    return "应用标识需要1-20个字符!";
                }

                Match match = Regex.Match(siteName, @"^[a-zA-Z]+$");
                if (!match.Success)
                {
                    return "应用标识只能包含英文!";
                }

                ManagedPipelineMode managedPipelineMode = (ManagedPipelineMode)pipelineMode;

                fullSiteName = developerInfo.LoginName + "_" + siteName;
                string secondDomainName = DeveloperConfig.SystemDomain.Replace("www", fullSiteName);

                iisProcess = new IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName);
                if (iisProcess.SiteIsExists(fullSiteName))
                {
                    return "该站点在IIS中已经存在!";
                }

                if (IsAppExists(developerInfo.Id, appName, siteName))
                {
                    return "该应用在数据库中已经存在!";
                }

                iisProcess.AppPoolCreate(fullSiteName, runtimeVersion, managedPipelineMode);
                iisProcess.SiteCreate(fullSiteName, "http", "*:80:" + secondDomainName, fullSiteName);

                //写入数据库
                DbCommand cmd = _dataBaseAccess.CreateCommand();
                cmd.CommandText = "Proc_Apps_Create";

                DbParameter param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@DbPath";
                param.DbType = DbType.String;
                param.Value = iisProcess.DBPathGet(fullSiteName);
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@DbName";
                param.DbType = DbType.String;
                param.Value = fullSiteName;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@DbMaxSize";
                param.DbType = DbType.Int32;
                param.Value = developerInfo.DBSpaceTotal / 2; //因为有数据库日志
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@DbLoginName";
                param.DbType = DbType.String;
                param.Value = fullSiteName;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@DbLoginPass";
                param.DbType = DbType.String;
                param.Value = fullSiteName;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@DeveloperId";
                param.DbType = DbType.Int32;
                param.Value = developerInfo.Id;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@AppName";
                param.DbType = DbType.String;
                param.Value = appName;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@SiteName";
                param.DbType = DbType.String;
                param.Value = siteName;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@AppLanguage";
                param.DbType = DbType.Byte;
                param.Value = appLanguage;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@APipelineMode";
                param.DbType = DbType.Byte;
                param.Value = managedPipelineMode;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@ARuntimeVersion";
                param.DbType = DbType.String;
                param.Value = runtimeVersion;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@Domain";
                param.DbType = DbType.String;
                param.Value = string.Empty;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@SecondDomain";
                param.DbType = DbType.String;
                param.Value = secondDomainName;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@DiskSpaceNow";
                param.DbType = DbType.Int32;
                param.Value = developerInfo.SiteSpaceTotal;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@DBSpaceNow";
                param.DbType = DbType.Int32;
                param.Value = developerInfo.DBSpaceTotal;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@WebPath";
                param.DbType = DbType.String;
                param.Value = iisProcess.SitePathGet(fullSiteName);
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@IISName";
                param.DbType = DbType.String;
                param.Value = fullSiteName;
                cmd.Parameters.Add(param);

                param = _dataBaseAccess.CreateParameter();
                param.ParameterName = "@AMMXPath";
                param.DbType = DbType.String;
                param.Value = iisProcess.MMXPathGet(fullSiteName);
                cmd.Parameters.Add(param);

                _dataBaseAccess.ExecuteCommand(cmd);
            }
            catch (Exception)
            {
                if (iisProcess.SiteIsExists(fullSiteName))
                {
                    iisProcess.SiteDelete(fullSiteName, true);
                }
                throw;
            }

            return string.Empty;
        }
示例#2
0
        public void AppRemove(DeveloperInfo developerInfo, string siteName, int appId)
        {
            DbCommand cmd = _dataBaseAccess.CreateCommand();
            cmd.CommandText = "Proc_Apps_Remove";

            DbParameter param = _dataBaseAccess.CreateParameter();
            param.ParameterName = "@Id";
            param.DbType = DbType.Int32;
            param.Value = appId;
            cmd.Parameters.Add(param);

            _dataBaseAccess.ExecuteCommand(cmd);

            IISProcess iisProcess = new IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName);
            iisProcess.SiteDelete(siteName, true);
        }