Exemplo n.º 1
0
 public static void Using <T>(this T client, Action <T> work)
     where T : ICommunicationObject
 {
     try
     {
         work(client);
         client.Close();
     }
     catch (CommunicationException e)
     {
         LogTextHelper.WriteLine(e.ToString());
         client.Abort();
     }
     catch (TimeoutException e)
     {
         LogTextHelper.WriteLine(e.ToString());
         client.Abort();
     }
     catch (Exception e)
     {
         LogTextHelper.WriteLine(e.ToString());
         client.Abort();
         throw;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 获取QueryString中的数据
        /// </summary>
        public static bool ValidUrlGetData()
        {
            bool result = false;

            for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; i++)
            {
                result = HasInjectionData(HttpContext.Current.Request.QueryString[i].ToString());
                if (result)
                {
                    LogTextHelper.Info("检测出GET恶意数据: 【" + HttpContext.Current.Request.QueryString[i].ToString() + "】 URL: 【" + HttpContext.Current.Request.RawUrl + "】来源: 【" + HttpContext.Current.Request.UserHostAddress + "】");
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 获取服务启动类型 2为自动 3为手动 4 为禁用
 /// </summary>
 /// <param name="serviceName"></param>
 /// <returns></returns>
 public static string GetServiceStartType(string serviceName)
 {
     try
     {
         RegistryKey regist            = Registry.LocalMachine;
         RegistryKey sysReg            = regist.OpenSubKey("SYSTEM");
         RegistryKey currentControlSet = sysReg.OpenSubKey("CurrentControlSet");
         RegistryKey services          = currentControlSet.OpenSubKey("Services");
         RegistryKey servicesName      = services.OpenSubKey(serviceName, true);
         return(servicesName.GetValue("Start").ToString());
     }
     catch (Exception ex)
     {
         LogTextHelper.Error(ex);
         return(string.Empty);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 修改服务的启动项 2为自动,3为手动
 /// </summary>
 /// <param name="startType"></param>
 /// <param name="serviceName"></param>
 /// <returns></returns>
 public static bool ChangeServiceStartType(int startType, string serviceName)
 {
     try
     {
         RegistryKey regist            = Registry.LocalMachine;
         RegistryKey sysReg            = regist.OpenSubKey("SYSTEM");
         RegistryKey currentControlSet = sysReg.OpenSubKey("CurrentControlSet");
         RegistryKey services          = currentControlSet.OpenSubKey("Services");
         RegistryKey servicesName      = services.OpenSubKey(serviceName, true);
         servicesName.SetValue("Start", startType);
     }
     catch (Exception ex)
     {
         LogTextHelper.Error(ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 5
0
        /// <summary>
        /// 附件的BASE64编码字符串
        /// </summary>
        /// <param name="path">附件路径</param>
        private string AttachmentB64Str(string path)
        {
            FileStream fs;

            try
            {
                fs = new FileStream(path, System.IO.FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            catch (Exception ex)
            {
                errmsg += "要附加的文件不存在" + enter;
                LogTextHelper.Error(errmsg, ex);

                return(Base64Encode("要附加的文件:" + path + "不存在"));
            }
            int fl = (int)fs.Length;

            byte[] barray = new byte[fl];
            fs.Read(barray, 0, fl);
            fs.Close();
            return(B64StrLine(Convert.ToBase64String(barray)));
        }
Exemplo n.º 6
0
 /// <summary>
 /// 停止服务
 /// </summary>
 /// <param name="serviseName"></param>
 /// <returns></returns>
 public static bool StopService(string serviseName)
 {
     try
     {
         ServiceController service = new ServiceController(serviseName);
         if (service.Status == ServiceControllerStatus.Stopped)
         {
             return(true);
         }
         else
         {
             TimeSpan timeout = TimeSpan.FromMilliseconds(1000 * 10);
             service.Stop();
             service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
         }
     }
     catch (Exception ex)
     {
         LogTextHelper.Error(ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 7
0
        private static void InternalRegisterFileAssociations(
            bool unregister, string progId, bool registerInHKCU,
            string appId, string openWith, string[] extensions)
        {
            string Arguments = string.Format("{0} {1} {2} \"{3}\" {4} {5}",
                                             progId,         // 0
                                             registerInHKCU, // 1
                                             appId,          // 2
                                             openWith,
                                             unregister,
                                             string.Join(" ", extensions));

            try
            {
                Process(Arguments.Split(' '));
            }
            catch (Win32Exception e)
            {
                if (e.NativeErrorCode == 1223) // 1223: The operation was canceled by the user.
                {
                    LogTextHelper.Info("该操作已经被用户取消");
                }
            }
        }