public void ProcessRequest(HttpContext context)
        {
            string resultJSON = string.Empty;
            StringBuilder sbResult = new StringBuilder();

            try
            {
                DeveloperInfo developerInfo = HttpContext.Current.Session["DeveloperInfo"] as DeveloperInfo;

                string processType = context.Request["ProcessType"].ToString();
                string startDate = context.Request["StartDate"].ToString();
                string endDate = context.Request["EndDate"].ToString();

                if (processType == "GetDateList")
                {
                    List<string> listDate = Tools.GetDateList(startDate, endDate);

                    sbResult.Append("[");
                    foreach (string date in listDate)
                    {
                        sbResult.AppendFormat("\"{0}\",", date);
                    }
                    sbResult.Remove(sbResult.Length - 1, 1);

                    sbResult.Append("]");

                    resultJSON = sbResult.ToString();
                }
                else if (processType == "GetAccessData")
                {
                    string fullSiteName = context.Request["FullSiteName"].ToString();
                    List<string> listDate = Tools.GetDateList(startDate, endDate);

                    IISProcess iisProcess = new IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName);
                    List<int> listAccessData = iisProcess.IISWebLogAccessCountGet(fullSiteName, listDate);

                    sbResult.Append("[");
                    foreach (int accessDate in listAccessData)
                    {
                        sbResult.AppendFormat("{0},", accessDate);
                    }
                    sbResult.Remove(sbResult.Length - 1, 1);
                    sbResult.Append("]");

                    resultJSON = sbResult.ToString();
                }

                context.Response.Write(resultJSON);
            }
            catch (Exception ex)
            {
                Tools.LogWrite(ex.ToString());
                resultJSON = Tools.ExecResultToJSON(false, ex.Message);
                context.Response.Write(resultJSON);
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                IISProcess iisProcess = new IISProcess("f:\\saas", "Takewin");

                iisProcess.ApplicationAdd("TakeWin_SMS", "App2", "f:\\Movie2");
                // iisProcess.SiteCreate("110_MYSite1", "http", "*:80:", "110_MYSite1");

                // int  recordAmount = 0;
                // int pageAmount = 0;
                //iisProcess.IISWebLogGet("110_MYSite1", "140601", "140620", 1, 3, out recordAmount, out pageAmount);
                // iisProcess.SiteAddBind("MYSite", "http", "192.168.0.1:80:www.baidu.com");
                // iisProcess.SiteReStart("MYSite");

                //List<IPSecurity> listIPSecurity = new List<IPSecurity>();
                //listIPSecurity.Add(new IPSecurity() { IPAddress = "127.0.0.1", SubNetMask = "255.255.255.255", IsAllow = false });
                //iisProcess.SiteIpSecuritySet("TakeWin_SMS", true, listIPSecurity);

                //List<SiteBind> listSiteBind = new List<SiteBind>();
                //listSiteBind.Add(new SiteBind() { BindingProtocol="http", BindingInformation="*:80:www.161.com" });
                //listSiteBind.Add(new SiteBind() { BindingProtocol = "http", BindingInformation = "*:80:www.164.com" });
                //iisProcess.SiteBindSet("MySite", listSiteBind);

                //ClientCatch clientCatch = new ClientCatch() { CacheControlMode = CacheControlMode.DisableCache, HttpExpires = DateTime.Parse("2015-01-01") };
                //iisProcess.SiteClientCacheSet("MySite", clientCatch);

                //clientCatch = iisProcess.SiteClientCacheGet("MySite");
                //tbResult.Text = clientCatch.CacheControlMode.ToString();

              //  List<CustomErrorPage> listCustomErrorPage = new List<CustomErrorPage>();
              // listCustomErrorPage.Add(new CustomErrorPage() { StatusCode = 401, CustomerWebRelativePath = "/temp/error.htm" });
               //listCustomErrorPage.Add(new CustomErrorPage() { StatusCode = 404, CustomerWebRelativePath = "/temp/error.htm" });
               // iisProcess.SiteErrorPageSet("TakeWin_SMS", listCustomErrorPage);

                //listCustomErrorPage =  iisProcess.SiteErrorPageGet("MySite");

               //  string siteId = iisProcess.SiteIdGet("110_MYSite2");

               //  WindowsLogProcess windowsLogProcess = new WindowsLogProcess();
               //  int recordAmount = 0;
               //  int pageAmount = 0;
                // windowsLogProcess.EventLogGet(siteId, "2014-06-01", "2014-06-30", 1, 10, out recordAmount, out pageAmount);

               // FileSizeHelper fileSizeHelper = new FileSizeHelper();
               //tbResult.Text = fileSizeHelper.GetDirectorySize("F:\\saas").ToString();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            string resultJSON = string.Empty;
            string result = string.Empty;

            try
            {
                DeveloperInfo developerInfo = HttpContext.Current.Session["DeveloperInfo"] as DeveloperInfo;
                string fullSiteName = context.Request["FullSiteName"].ToString();
                string logType = context.Request["LogType"].ToString();
                string startDate = context.Request["StartDate"].ToString();
                string endDate = context.Request["EndDate"].ToString();

                int pageNumber = int.Parse(context.Request["page"]);
                int pageSize = int.Parse(context.Request["rows"]);

                int recordAmount = 0;
                int pageAmount = 0;

                DataTable dt = null;

                if (logType == "IISLog")
                {
                    IISProcess iisSProcess = new BLL.IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName);

                    startDate = DateTime.Parse(startDate).ToString("yyMMdd");
                    endDate = DateTime.Parse(endDate).ToString("yyMMdd");

                    dt= iisSProcess.IISWebLogGet(fullSiteName, startDate, endDate, pageNumber, pageSize, out recordAmount, out pageAmount);
               }
                else if (logType == "WindowsLog")
                {
                   IISProcess iisSProcess = new BLL.IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName);
                   string siteId = iisSProcess.SiteIdGet(fullSiteName);

                    WindowsLogProcess windowsLogProcess = new WindowsLogProcess();
                    dt = windowsLogProcess.EventLogGet(siteId, startDate, endDate, pageNumber, pageSize, out recordAmount, out pageAmount);
                }

                string contentJSON = JsonConvert.SerializeObject(dt, new DataTableToJosnConverter());
                resultJSON = Tools.QueryResultToJSON(contentJSON, recordAmount);

                context.Response.Write(resultJSON);
            }
            catch (Exception ex)
            {
                Tools.LogWrite(ex.ToString());
                resultJSON = Tools.ExecResultToJSON(false, ex.Message);
                context.Response.Write(resultJSON);
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            string resultJSON = string.Empty;

            try
            {
                DeveloperInfo developerInfo = HttpContext.Current.Session["DeveloperInfo"] as DeveloperInfo;
                string fullSiteName = context.Request["FullSiteName"].ToString();

                IISProcess iisSProcess = new BLL.IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName);

                iisSProcess.SiteReStart(fullSiteName);

                resultJSON = Tools.ExecResultToJSON(true, "重启站点成功!");
                context.Response.Write(resultJSON);
            }
            catch (Exception ex)
            {
                Tools.LogWrite(ex.ToString());
                resultJSON = Tools.ExecResultToJSON(false, ex.Message);
                context.Response.Write(resultJSON);
            }
        }
Example #5
0
        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;
        }
Example #6
0
        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;
        }
Example #7
0
        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;
        }
Example #8
0
        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;
        }
Example #9
0
        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;
        }
Example #10
0
        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;
        }
Example #11
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;
        }
Example #12
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);
        }