protected void Page_Load(object sender, EventArgs e) { DeveloperInfo developerInfo = new DeveloperInfo(); developerInfo.Id = 110; developerInfo.Name = "开发商"; developerInfo.LoginName = "TakeWin"; developerInfo.SiteSpaceTotal = 100; developerInfo.DBSpaceTotal = 100; Session["DeveloperInfo"] = developerInfo; Response.Write("已成功登陆"); }
public void SpaceStatistic_Update(DeveloperInfo developerInfo, int appId, double siteSpaceUsed, double dbSpaceUsed) { DbCommand cmd = _dataBaseAccess.CreateCommand(); cmd.CommandText = "Proc_Apps_SpaceStatistic_Update"; DbParameter param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@AppId"; param.DbType = DbType.Int32; param.Value = appId; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@ADiskSpaceNow"; param.DbType = DbType.Decimal; param.Value = siteSpaceUsed; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@ADBSpaceNow"; param.DbType = DbType.Decimal; param.Value = dbSpaceUsed; cmd.Parameters.Add(param); _dataBaseAccess.ExecuteCommand(cmd); }
public string SiteIpSecuritySet(DeveloperInfo developerInfo, string siteName, int appId, byte isAllowUnlisted, string ipConfig) { List<IPSecurity> listIPSecurity = new List<IPSecurity>(); if (!string.IsNullOrEmpty(ipConfig.Trim())) { string[] ipconfigs = ipConfig.Split(new char[] { '|' }, StringSplitOptions.None); foreach (string ipconfig in ipconfigs) { string[] errorRecord = ipconfig.Replace(",", ",").Split(new char[] { ',' }, StringSplitOptions.None); IPSecurity ipSecurity = new IPSecurity(); ipSecurity.IPAddress = errorRecord[0].Trim(); ipSecurity.SubNetMask = errorRecord[1].Trim(); ipSecurity.IsAllow = errorRecord[2] == "1"; listIPSecurity.Add(ipSecurity); } } IISProcess iisProcess = new IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName); iisProcess.SiteIpSecuritySet(siteName, Convert.ToBoolean(isAllowUnlisted), listIPSecurity); DbCommand cmd = _dataBaseAccess.CreateCommand(); cmd.CommandText = "Proc_Apps_SiteIpSecurity_Update"; DbParameter param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@AppId"; param.DbType = DbType.Int32; param.Value = appId; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@IsAllowAccessUnConfig"; param.DbType = DbType.Byte; param.Value = isAllowUnlisted; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@IPSecurity"; param.DbType = DbType.String; param.Value = ipConfig; cmd.Parameters.Add(param); _dataBaseAccess.ExecuteCommand(cmd); return string.Empty; }
/// <returns>返回结果为MB</returns> public double Site_SpaceUsed_Get(DeveloperInfo developerInfo, string siteName) { double directorySpaceUsed = 0; string developerPhysicalPath = Path.Combine(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName); string sitePhysicalPath = Path.Combine(developerPhysicalPath, siteName); string webPhysicalPath = Path.Combine(sitePhysicalPath, "IISSite"); string logPhysicalPath = Path.Combine(sitePhysicalPath, "IISLog"); FileSizeHelper fileSizeHelper = new FileSizeHelper(); directorySpaceUsed += fileSizeHelper.GetDirectorySpaceUsed(webPhysicalPath); directorySpaceUsed += fileSizeHelper.GetDirectorySpaceUsed(logPhysicalPath); double result = directorySpaceUsed * 1.0 / 1048576; return result; }
public string SiteDefaultPageSet(DeveloperInfo developerInfo, string siteName, int appId, string defaultPages) { List<string> listDefaultPage = new List<string>(); if (!string.IsNullOrEmpty(defaultPages.Trim())) { string[] pages = defaultPages.Split(new char[] { '|' }, StringSplitOptions.None); listDefaultPage = new List<string>(pages); } IISProcess iisProcess = new IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName); iisProcess.SiteDefaultPageSet(siteName, listDefaultPage); DbCommand cmd = _dataBaseAccess.CreateCommand(); cmd.CommandText = "Proc_Apps_SiteDefaultPage_Update"; DbParameter param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@AppId"; param.DbType = DbType.Int32; param.Value = appId; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@DefaultPages"; param.DbType = DbType.String; param.Value = defaultPages; cmd.Parameters.Add(param); _dataBaseAccess.ExecuteCommand(cmd); return string.Empty; }
public string SiteErrorPageSet(DeveloperInfo developerInfo, string siteName, int appId, string errorPage) { List<CustomErrorPage> listCustomErrorPage = new List<CustomErrorPage>(); if (!string.IsNullOrEmpty(errorPage.Trim())) { string[] pages = errorPage.Split(new char[] { '|' }, StringSplitOptions.None); foreach (string page in pages) { string[] errorRecord = page.Replace(",", ",").Split(new char[] { ',' }, StringSplitOptions.None); CustomErrorPage customErrorPage = new CustomErrorPage(); customErrorPage.StatusCode = int.Parse(errorRecord[0].Trim()); customErrorPage.CustomerWebRelativePath = errorRecord[1].Trim(); listCustomErrorPage.Add(customErrorPage); } } IISProcess iisProcess = new IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName); iisProcess.SiteErrorPageSet(siteName, listCustomErrorPage); DbCommand cmd = _dataBaseAccess.CreateCommand(); cmd.CommandText = "Proc_Apps_SiteErrorPage_Update"; DbParameter param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@AppId"; param.DbType = DbType.Int32; param.Value = appId; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@CustomErrorPage"; param.DbType = DbType.String; param.Value = errorPage; cmd.Parameters.Add(param); _dataBaseAccess.ExecuteCommand(cmd); return string.Empty; }
public string SiteClientCacheSet(DeveloperInfo developerInfo, string siteName, int appId, string expires) { ClientCatch clientCatch = new ClientCatch(); clientCatch.CacheControlMode = string.IsNullOrEmpty(expires) ? CacheControlMode.DisableCache : CacheControlMode.UseExpires; if (!string.IsNullOrEmpty(expires)) { clientCatch.HttpExpires = DateTime.Parse(expires); } IISProcess iisProcess = new IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName); iisProcess.SiteClientCacheSet(siteName, clientCatch); DbCommand cmd = _dataBaseAccess.CreateCommand(); cmd.CommandText = "Proc_Apps_SiteClientCache_Update"; DbParameter param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@AppId"; param.DbType = DbType.Int32; param.Value = appId; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@ClientCache"; param.DbType = DbType.String; param.Value = expires; cmd.Parameters.Add(param); _dataBaseAccess.ExecuteCommand(cmd); return string.Empty; }
public string SiteCompressionSet(DeveloperInfo developerInfo, string siteName, int appId, bool isStaticCompression, bool isDynamicCompression) { UrlCompression urlCompression = new UrlCompression(); urlCompression.IsStaticCompression = isStaticCompression; urlCompression.IsDynamicCompression = isDynamicCompression; IISProcess iisProcess = new IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName); iisProcess.SiteCompressionSet(siteName, urlCompression); DbCommand cmd = _dataBaseAccess.CreateCommand(); cmd.CommandText = "Proc_Apps_SiteCompression_Update"; DbParameter param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@AppId"; param.DbType = DbType.Int32; param.Value = appId; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@IsStaticCompression"; param.DbType = DbType.Boolean; param.Value = isStaticCompression; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@IsDynamicCompression"; param.DbType = DbType.Boolean; param.Value = isDynamicCompression; cmd.Parameters.Add(param); _dataBaseAccess.ExecuteCommand(cmd); return string.Empty; }
public string SiteBindSet(DeveloperInfo developerInfo, string siteName, int appId, string defaultDomain, string customDomain) { if (defaultDomain.ToLower() == customDomain.ToLower()) { return "自定义域名不能与默认分配域名相同!"; } //验证自定义域名不要与其他相同 DbCommand cmd = _dataBaseAccess.CreateCommand(); cmd.CommandText = "Proc_Apps_SiteBind_Validate"; DbParameter param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@AppId"; param.DbType = DbType.Int32; param.Value = appId; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@CustomDomain"; param.DbType = DbType.String; param.Value = customDomain.ToLower(); cmd.Parameters.Add(param); DataTable dt = _dataBaseAccess.GetDataTable(cmd); if (dt.Rows.Count > 0) { return "该自定义域名已被绑定!"; } //更新IIS IISProcess iisProcess = new IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName); List<SiteBind> listSiteBind = new List<SiteBind>(); listSiteBind.Add(new SiteBind() { BindingProtocol = "http", BindingInformation = "*:80:" + defaultDomain }); if (!string.IsNullOrEmpty(customDomain.Trim())) { listSiteBind.Add(new SiteBind() { BindingProtocol = "http", BindingInformation = "*:80:" + customDomain }); } iisProcess.SiteBindSet(siteName, listSiteBind); //更新数据库 cmd = _dataBaseAccess.CreateCommand(); cmd.CommandText = "Proc_Apps_SiteBind_Update"; cmd.Parameters.Clear(); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@AppId"; param.DbType = DbType.Int32; param.Value = appId; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@DefaultDomain"; param.DbType = DbType.String; param.Value = defaultDomain.ToLower(); cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@CustomDomain"; param.DbType = DbType.String; param.Value = customDomain.ToLower(); cmd.Parameters.Add(param); _dataBaseAccess.ExecuteCommand(cmd); return string.Empty; }
/// <returns>返回结果为MB</returns> public int DB_SpaceUsed_Get(DeveloperInfo developerInfo, string siteName) { long directorySpaceUsed = 0; string developerPhysicalPath = Path.Combine(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName); string sitePhysicalPath = Path.Combine(developerPhysicalPath, siteName); string dbPhysicalPath = Path.Combine(sitePhysicalPath, "DB"); FileSizeHelper fileSizeHelper = new FileSizeHelper(); directorySpaceUsed += fileSizeHelper.GetDirectorySpaceUsed(dbPhysicalPath); return (int)Math.Ceiling(directorySpaceUsed * 1.0 / 1048576); }
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; }
public string DbBackup(DeveloperInfo developerInfo, string siteName) { string developerPhysicalPath = Path.Combine(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName); string sitePhysicalPath = Path.Combine(developerPhysicalPath, siteName); string backupPath = Path.Combine(sitePhysicalPath, siteName + ".bak"); DbCommand cmd = _dataBaseAccess.CreateCommand(); cmd.CommandText = "Proc_DB_DynamicBackup"; DbParameter param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@DbName"; param.DbType = DbType.String; param.Value = siteName; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@BackupPath"; param.DbType = DbType.String; param.Value = backupPath; cmd.Parameters.Add(param); _dataBaseAccess.ExecuteCommand(cmd); return backupPath; }
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); }