コード例 #1
0
ファイル: ss_configuration.cs プロジェクト: zhangrl/Hunter3
 public void CreateConfig()
 {
     try
     {
         XDocument x_config = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
         x_config.Add(
             new XElement(s_root,
                          new XElement(s_action, new XAttribute(a_mode, "monitor"), new XAttribute(a_interval, "1000"), new XAttribute(a_process, "4")),
                          new XElement(s_database, new XAttribute(a_ip, "127.0.0.1"), new XAttribute(a_usr, "root"), new XAttribute(a_pwd, "pwd"), new XAttribute(a_db, "db_specimen")),
                          new XElement(s_dir, new XAttribute(a_source, "D:\\"), new XAttribute(a_dest, "D:\\"), new XAttribute(a_cache, "500"), new XAttribute(a_sharepath, "您的共享路径")),
                          new XElement(s_type,
                                       new XElement(s_match, new XAttribute(a_ext, ".doc"), new XAttribute(a_ksotype, "wps"))
                                       )
                          )
             );
         x_config.Save(mConfigPath);
         mlog.Log_i("This is first time you run this application. We just made a config file for you. Please modify it and restart this application again.");
         Console.ReadKey(true);
     }
     catch (Exception e)
     {
         AppLogHelper.Log_i(String.Format("{0, 76}", new String('-', 36)));
         mlog.Log_e("Create Config File Failed: " + mConfigPath + " -> " + e.Message);
     }
 }
コード例 #2
0
ファイル: ss_configuration.cs プロジェクト: zhangrl/Hunter3
        public bool LoadConfig(out bool exitApplication)
        {
            exitApplication = false;
            try
            {
                if (!File.Exists(mConfigPath))
                {
                    CreateConfig();
                    exitApplication = true;
                    return(true);
                }

                XDocument x_config = XDocument.Load(mConfigPath);
                XElement  x_root   = x_config.Element(s_root);
                mMode     = x_root.Element(s_action).Attribute(a_mode).Value;
                mInterval = int.Parse(x_root.Element(s_action).Attribute(a_interval).Value);
                mProcess  = int.Parse(x_root.Element(s_action).Attribute(a_process).Value);

                mRunningMode = mMode == "monitor" ? Mode.Monitor : Mode.Once;

                mIp        = x_root.Element(s_database).Attribute(a_ip).Value;
                mUsr       = x_root.Element(s_database).Attribute(a_usr).Value;
                mPwd       = x_root.Element(s_database).Attribute(a_pwd).Value;
                mDatabase  = x_root.Element(s_database).Attribute(a_db).Value;
                mDir_src   = x_root.Element(s_dir).Attribute(a_source).Value;
                mDir_dest  = x_root.Element(s_dir).Attribute(a_dest).Value;
                mSharePath = x_root.Element(s_dir).Attribute(a_sharepath).Value;
                mCache     = int.Parse(x_root.Element(s_dir).Attribute(a_cache).Value);

                foreach (var match in x_root.Element(s_type).Elements(s_match))
                {
                    if (!mDicType.ContainsKey(match.Attribute(a_ext).Value))
                    {
                        mDicType.Add(match.Attribute(a_ext).Value.ToLower(), match.Attribute(a_ksotype).Value);
                    }
                }

                mConnection = new MySqlDBConnection(mIp, mDatabase, mUsr, mPwd, AppLogHelper.Log);

                if (!mConnection.TestOpenClose())
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception e)
            {
                AppLogHelper.Log_i(String.Format("{0, 76}", new String('-', 36)));
                mlog.Log_e("Parse Config File Failed: " + mConfigPath + " -> " + e.Message);
                return(false);
            }
        }
コード例 #3
0
 public void ParseDirectory()
 {
     FileInfo[] files = null;
     try
     {
         if (!Directory.Exists(mConfig.DirectorySource))
         {
             Directory.CreateDirectory(mConfig.DirectorySource);
         }
         files = new DirectoryInfo(mConfig.DirectorySource).GetFiles("*.*", SearchOption.AllDirectories);
     } catch (Exception e) {
         AppLogHelper.Log_i(String.Format("{0, 76}", new String('-', 36)));
         mLog.Log_e("Parse Directory Failed: (" + mConfig.DirectorySource + ")" + e.Message);
     }
     try{
         int           threadNum = 0;
         List <String> Md5List   = new List <String>();
         foreach (var file in files)
         {
             while (threadNum >= mConfig.Process)
             {
                 Thread.Sleep(100);
             }
             Thread t = new Thread(new ParameterizedThreadStart(( object fullname) =>
             {
                 try
                 {
                     FileOperate(fullname.ToString(), Md5List);
                 }
                 catch { }
                 finally
                 {
                     threadNum--;
                 }
             }));
             threadNum++;
             t.Start(file.FullName);
         }
     }
     catch (Exception e)
     {
         AppLogHelper.Log_i(String.Format("{0, 76}", new String('-', 36)));
         mLog.Log_e("Parse Directory Failed: " + e.Message);
     }
 }