Exemplo n.º 1
0
        public void TimerMethod(object state)
        {
            string TmpPath      = Directory.GetCurrentDirectory();
            string ddiStartTime = ZhiLian.GetXmlDdiStartTime(TmpPath + "\\Config.xml");
//			string otherStartTime = ZhiLian.getXmlDdiStartTime(TmpPath+ "\\Other.xml");
//			Convert.ToDateTime(time).AddMinutes(10).ToString();

            //zidong()
            DateTime datetime1 = DateTime.Now;

//			ZhiLian.追加日志(Convert.ToDateTime(ddiStartTime,CultureInfo.InvariantCulture).ToString());
//			ZhiLian.追加日志(Convert.ToDateTime(ddiStartTime,CultureInfo.InvariantCulture).AddMinutes(10).ToString());
//			if (Convert.ToDateTime(datetime1.ToLongTimeString()) > Convert.ToDateTime("22:50:00")
//				& Convert.ToDateTime(datetime1.ToLongTimeString()) < Convert.ToDateTime("22:59:59")) {
            if (Convert.ToDateTime(datetime1.ToLongTimeString(), CultureInfo.InvariantCulture)
                > Convert.ToDateTime(ddiStartTime, CultureInfo.InvariantCulture)
                & Convert.ToDateTime(datetime1.ToLongTimeString(), CultureInfo.InvariantCulture)
                <= Convert.ToDateTime(ddiStartTime, CultureInfo.InvariantCulture).AddMinutes(10))
            {
//				object aa=null;
                AllTiqu();
//				GC.Collect();
//				AllFtp();
//				ZhiLian.XmlSqlcommand();
                ProjectLog1();
            }
//			if (!String.IsNullOrEmpty(rizhi)) {
//				ZhiLian.追加日志(rizhi);
//				rizhi = "";
//			}
        }
Exemplo n.º 2
0
        /// <summary>
        /// 校验文件SHA1值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
//			ZhiLian.追加日志("手动提取任务开始");
            Hidden();
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            // '设置文件类型
//			openFileDialog1.Filter = "xlsx files(*.xlsx)|*.xlsx";
            // '点了保存按钮进入
            if ((openFileDialog1.ShowDialog() == DialogResult.OK))
            {
                string localFilePath = null;
                localFilePath = openFileDialog1.FileName.ToString();
                ZhiLian.追加日志("");
                string sha1 = null;
                Task   t    = Task.Run(() => { sha1 = GetFileSHA1(localFilePath); });
                await  t;
//				t.Wait();
////				Task.WaitAll();
                t.Dispose();
                ZhiLian.追加日志("此文件SHA1值为:" + sha1);
            }
            ZhiLian.追加日志("");
            GC.Collect();

            ShowAll();
            //            ProjectLog();
            ProjectLog1();
        }
Exemplo n.º 3
0
 /// <summary>
 /// 将所有Config中的Job添加至toolStripComboBox1中
 /// </summary>
 private void XmlFactorynameadd()
 {
     try{
         string            TmpPath     = Directory.GetCurrentDirectory(); // + "\\config\\";
         string            xmlFilePath = TmpPath + "\\Config.xml";
         XmlDocument       xmlDoc      = new XmlDocument();
         XmlReaderSettings settings    = new XmlReaderSettings();
         settings.IgnoreComments = true;                //忽略文档里面的注释
         XmlReader reader = XmlReader.Create(xmlFilePath, settings);
         xmlDoc.Load(reader);
         //            doc.Load(xmlFilePath);
         //使用xpath表达式选择文档中所有的Job子节点
         XmlNodeList factoryNodeList = xmlDoc.SelectNodes(@"/Config/Job");
         if (factoryNodeList != null)
         {
             foreach (XmlNode factoryNode in factoryNodeList)
             {
                 //通过Attributes获得属性名字为name的属性
                 string name = factoryNode.Attributes["name"].Value;
                 toolStripComboBox1.Items.Add(name);
             }
         }
         reader.Close();
     }catch (Exception ex) {
         ZhiLian.追加日志(ex.Message);
     }
 }
Exemplo n.º 4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string logoimagePath = Application.StartupPath + @"\logo.png";

            if (System.IO.File.Exists(logoimagePath))
            {
                this.PictureBox1.Image = System.Drawing.Image.FromFile(logoimagePath);
            }
            this.BackColor       = System.Drawing.SystemColors.ControlLightLight;
            menuStrip1.BackColor = System.Drawing.SystemColors.ControlLightLight;
            menuStrip2.BackColor = System.Drawing.SystemColors.ControlLightLight;
            foreach (ToolStripItem aa in menuStrip1.Items)
            {
                aa.Margin = new System.Windows.Forms.Padding(5, 5, 5, 5);
            }
            toolStripComboBox1.Margin = new System.Windows.Forms.Padding(5, 5, 5, 5);
            button1.Visible           = false;
            textBox2.Visible          = false;
            hideitem();
            this.textBox1.Text = "程序正在运行中,请勿关闭";
//			this.textBox1.DeselectAll();
            this.textBox1.SelectionStart = 0;
            //this.MaximizeBox = false;
            新建导出目录();
            ZhiLian.追加日志("自动执行任务启动");
            //日志串(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " "  & "自动执行任务启动")
            //shoudong = 0
            StartTimer();
//			ZhiLian.XmlDDI();
//			Dfile=ZhiLian.DFile;
//			ZhiLian.Tpyy=XmlHelper.XmlDatabase();
        }
Exemplo n.º 5
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (objTimer != null)
     {
         objTimer.Dispose();
     }
     ZhiLian.追加日志("自动任务程序已关闭");
 }
Exemplo n.º 6
0
        /// <summary>
        /// 同步全部任务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            ZhiLian.追加日志("同步任务开始");
            Hidden();
            Task  t = Task.Run(() => { ZhiLian.XmlSync(); });
            await t;

            t.Dispose();
            ZhiLian.追加日志("同步任务执行完毕");
            //TextBox2.Visible = False
            ShowAll();
            //            ProjectLog();
            ProjectLog1();
        }
Exemplo n.º 7
0
        async void toolStripMenuItem12_Click(object sender, EventArgs e)
        {
            ZhiLian.追加日志("校验任务开始");
            Hidden();
            System.Threading.Timer Thread_Time;
            //启动
            Thread_Time = new System.Threading.Timer(Thread_Timer_Method, null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1));
            新建导出目录();
            Task  t = Task.Run(() => { ZhiLian.XmlCheck(); });
            await t;

            t.Dispose();
            //停止
              Thread_Time.Dispose();

            ZhiLian.追加日志("校验任务执行完毕");
            ShowAll();
            ProjectLog1();
        }
Exemplo n.º 8
0
        /// <summary>
        /// 提取单个任务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            ZhiLian.追加日志("同步任务开始");
            Hidden();
            string text = toolStripComboBox1.Text;

            if (string.IsNullOrEmpty(text) == false)
            {
                await Task.Run(() => { ZhiLian.XmlSync(text); });
            }
            else
            {
                MessageBox.Show("请选择需要提取的任务,再点击提取单个任务");
                ZhiLian.追加日志("未选择需要提取的任务家");
//				ZhiLian.追加日志("手动提取任务完毕");
//				return;
            }
            ZhiLian.追加日志("同步任务执行完毕");
            ShowAll();
            toolStripComboBox1.SelectedItem = null;
            GC.Collect();
//            ProjectLog();
            ProjectLog1();
        }
Exemplo n.º 9
0
 /// <summary>
 /// 查看配置信息
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void ToolStripMenuItem16Click(object sender, EventArgs e)
 {
     ZhiLian.GetXmlInfo();
 }
Exemplo n.º 10
0
 /// <summary>
 /// 全部Sync任务
 /// </summary>
 public static void AllSync()        //(object state)
 {
     ZhiLian.XmlSync();
 }
Exemplo n.º 11
0
        /// <summary>
        /// 所有提取任务
        /// </summary>
        private static void AllTiqu()        //(object state)
        {
//			ZhiLian.XmlDdi();
            ZhiLian.XmlSync();
            GC.Collect();
        }
Exemplo n.º 12
0
        public static void  DirectorySha1(string sourceDirName, string destDirName)
        {
            try
            {
                if (!Directory.Exists(destDirName))
                {
                    Directory.CreateDirectory(destDirName);
                    File.SetAttributes(destDirName, File.GetAttributes(sourceDirName));
                }
                if (destDirName[destDirName.Length - 1] != Path.DirectorySeparatorChar)
                {
                    destDirName = destDirName + Path.DirectorySeparatorChar;
                }
                string[] files = Directory.GetFiles(sourceDirName);
                foreach (string file in files)
                {
                    if (!File.Exists(destDirName + Path.GetFileName(file)))
                    {
                        ZhiLian.追加日志(Path.GetFileName(file) + " 备份目录无此文件,未进行校验");
                        ZhiLian.追加日志(Directory.GetCurrentDirectory() + "\\Log\\CheckError"
                                     + DateTime.Now.ToString("yyyyMM", CultureInfo.InvariantCulture) + ".log", file + " 备份目录无此文件,未进行校验");
                    }
                    else
                    {
                        FileInfo fi         = new FileInfo(file);
                        string   filelength = "";
                        if (fi.Length < 1024 * 1024)
                        {
                            filelength = fi.Length / 1024 + "KB";
                        }
                        else if (fi.Length >= 1024 * 1024 && fi.Length < 1024 * 1024 * 1024)
                        {
                            filelength = fi.Length / 1024 / 1024 + "MB";
                        }
                        else if (fi.Length >= 1024 * 1024 * 1024)
                        {
                            filelength = fi.Length / 1024 / 1024 / 1024 + "GB";
                        }
                        ZhiLian.追加日志(Path.GetFileName(file) + " 准备进行源文件SHA1校验,文件大小为" + filelength);
                        string sha1old = GetFileSHA1(file);
                        ZhiLian.追加日志(Path.GetFileName(file) + " 源文件SHA1值为:" + sha1old);
//	                    ZhiLian.追加日志(Path.GetFileName(file)+" 文件同步开始");
                        //                    File.Copy(file, destDirName + Path.GetFileName(file),true);
//	                    File.Copy(file, destDirName + Path.GetFileName(file));
//
//	                    ZhiLian.追加日志(Path.GetFileName(file)+" 文件同步成功,准备进行备份文件SHA1校验");
                        string sha1new = GetFileSHA1(destDirName + Path.GetFileName(file));
                        ZhiLian.追加日志(Path.GetFileName(file) + " 备份文件SHA1值为:" + sha1new);
                        if (sha1old == sha1new)
                        {
                            ZhiLian.追加日志(Path.GetFileName(file) + " 文件校验成功");
                        }
                        else
                        {
                            ZhiLian.追加日志(Path.GetFileName(file) + " 文件校验失败");
//	                        File.Move(destDirName + Path.GetFileName(file), destDirName + Path.GetFileName(file)+"文件校验失败");
                            ZhiLian.追加日志(Directory.GetCurrentDirectory() + "\\Log\\CheckError"
                                         + DateTime.Now.ToString("yyyyMM", CultureInfo.InvariantCulture) + ".log", file + " 文件校验失败");
                        }
//	                    File.SetAttributes(destDirName + Path.GetFileName(file), FileAttributes.Normal);
                        //                    total++;
                    }
                }

//				//超过标记天数删除修改日期最早的文件
//				while(Directory.GetFiles(destDirName).Length>delflag && delflag!=0){
//					string[] destfiles = Directory.GetFiles(destDirName);
//	                if(destfiles.Length>delflag){
//	                    int small=0;
//	                    for(int i=1;i<destfiles.Length;i++){
//	                        FileInfo fi = new FileInfo(destfiles[small]);
//	                        FileInfo fi1 = new FileInfo(destfiles[i]);
//
//	                        if(fi.LastWriteTime>fi1.LastWriteTime){
//	                            small=i;
//	                        }
//	                    }
//	                    ZhiLian.追加日志(Path.GetFileName(destfiles[small])+" 超过设置的备份文件数,自动删除日期最早的文件");
//	                    File.Delete(destfiles[small]);
//
//	                }
//				}
                string[] dirs = Directory.GetDirectories(sourceDirName);
                foreach (string dir in dirs)
                {
                    DirectorySha1(dir, destDirName + Path.GetFileName(dir));
                }
            }
            catch (Exception ex)
            {
                ZhiLian.追加日志(ex.Message);
            }
        }
Exemplo n.º 13
0
        public static void   CopyDirectory(string sourceDirName, string destDirName, int delflag)
        {
            try
            {
                if (!Directory.Exists(destDirName))
                {
                    Directory.CreateDirectory(destDirName);
                    File.SetAttributes(destDirName, File.GetAttributes(sourceDirName));
                }

                if (destDirName[destDirName.Length - 1] != Path.DirectorySeparatorChar)
                {
                    destDirName = destDirName + Path.DirectorySeparatorChar;
                }

                string[] files = Directory.GetFiles(sourceDirName);

                foreach (string file in files)
                {
                    if (File.Exists(destDirName + Path.GetFileName(file)))
//                      continue;
                    {
                        ZhiLian.追加日志(Path.GetFileName(file) + " 已进行过同步,本次无需同步");
                    }
                    else
                    {
                        FileInfo fi         = new FileInfo(file);
                        string   filelength = "";
                        if (fi.Length < 1024 * 1024)
                        {
                            filelength = fi.Length / 1024 + "KB";
                        }
                        else if (fi.Length >= 1024 * 1024 && fi.Length < 1024 * 1024 * 1024)
                        {
                            filelength = fi.Length / 1024 / 1024 + "MB";
                        }
                        else if (fi.Length >= 1024 * 1024 * 1024)
                        {
                            filelength = fi.Length / 1024 / 1024 / 1024 + "GB";
                        }
                        ZhiLian.追加日志(Path.GetFileName(file) + " 准备进行源文件SHA1校验,文件大小为" + filelength);
                        string sha1old = GetFileSHA1(file);
                        ZhiLian.追加日志(Path.GetFileName(file) + " 源文件SHA1值为:" + sha1old);
                        ZhiLian.追加日志(Path.GetFileName(file) + " 文件同步开始");
                        //                    File.Copy(file, destDirName + Path.GetFileName(file),true);
                        File.Copy(file, destDirName + Path.GetFileName(file));

                        ZhiLian.追加日志(Path.GetFileName(file) + " 文件同步成功,准备进行备份文件SHA1校验");
                        string sha1new = GetFileSHA1(destDirName + Path.GetFileName(file));
                        ZhiLian.追加日志(Path.GetFileName(file) + " 备份文件SHA1值为:" + sha1new);
                        if (sha1old == sha1new)
                        {
                            ZhiLian.追加日志(Path.GetFileName(file) + " 文件校验成功");
                        }
                        else
                        {
                            ZhiLian.追加日志(Path.GetFileName(file) + " 文件校验失败");
                            File.Move(destDirName + Path.GetFileName(file), destDirName + Path.GetFileName(file) + "文件校验失败");
                        }
                        File.SetAttributes(destDirName + Path.GetFileName(file), FileAttributes.Normal);
                        //                    total++;
                    }
                }

                //超过标记天数删除修改日期最早的文件
                while (Directory.GetFiles(destDirName).Length > delflag && delflag != 0)
                {
                    string[] destfiles = Directory.GetFiles(destDirName);
                    if (destfiles.Length > delflag)
                    {
                        int small = 0;
                        for (int i = 1; i < destfiles.Length; i++)
                        {
                            FileInfo fi  = new FileInfo(destfiles[small]);
                            FileInfo fi1 = new FileInfo(destfiles[i]);

                            if (fi.LastWriteTime > fi1.LastWriteTime)
                            {
                                small = i;
                            }
                        }
                        ZhiLian.追加日志(Path.GetFileName(destfiles[small]) + " 超过设置的备份文件数,自动删除日期最早的文件");
                        File.Delete(destfiles[small]);
                    }
                }
                string[] dirs = Directory.GetDirectories(sourceDirName);
                foreach (string dir in dirs)
                {
                    CopyDirectory(dir, destDirName + Path.GetFileName(dir), delflag);
                }
            }
            catch (Exception ex)
            {
                ZhiLian.追加日志(ex.Message);
            }
        }