Esempio n. 1
0
        /// <summary>
        /// 定时处理要备份的文件任务
        /// </summary>
        private void BackupFileTask()
        {
            while (IsStart)
            {
                if (ListTool.HasElements(BackupFiles))
                {
                    //获取要备份的文件列表并复制样本
                    List <string> temp;
                    lock (BackupFiles)
                    {
                        temp        = BackupFiles;
                        BackupFiles = new List <string>();
                    }

                    using (var db = new Muse())
                    {
                        foreach (var t in temp)
                        {
                            //要备份的文件存在
                            if (File.Exists(t))
                            {
                                //文件属于要备份的文件目录
                                string      filepath = DirTool.GetFilePath(t);
                                BackupPaths path     = Paths.FirstOrDefault(x => filepath.Contains(x.Path));
                                if (path != null)
                                {
                                    //文件的MD5码以前没有备份过
                                    string md5    = FileTool.GetMD5(t);
                                    bool   isback = db.Any <BackupFiles>(x => x.FullPath == t && x.Md5 == md5, null);
                                    if (!isback)
                                    {
                                        string pathname  = path.Path;                                                                           //备份文件夹路径
                                        string pathalias = path.Alias;                                                                          //备份文件夹别名
                                        string pathfile  = t.Substring(pathname.Length, t.Length - pathname.Length);                            //截取备份文件子目录(相对备份文件夹)
                                        string fileext   = "." + DateTimeConvert.CompactString(DateTime.Now) + Path.GetExtension(t);            //设置后缀
                                        string fullpath  = DirTool.Combine(R.Settings.FileBackup.FileManBackup, pathalias, pathfile + fileext); //组合路径

                                        //删除冗余
                                        DeleteExcess(t);
                                        //备份文件
                                        BackupFile(t, fullpath, md5);
                                        _FileCount++;
                                    }
                                }
                            }
                        }
                    }
                }
                Thread.Sleep(R.Settings.FileBackup.BACK_UP_INTERVAL);
            }
        }
Esempio n. 2
0
        private void 保存屏幕ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Bitmap screen = null;

            try
            {
                string file = DirTool.Combine(R.Paths.App, DateTimeConvert.CompactString(DateTime.Now) + ".jpg");
                screen = ScreenCapture.Capture();
                screen.Save(file, System.Drawing.Imaging.ImageFormat.Jpeg);
                ToastForm.Display("保存", "保存屏幕成功:" + Path.GetFileName(file), ToastForm.ToastType.info);
            }
            catch { ToastForm.Display("保存", "保存屏幕失败", ToastForm.ToastType.error); }
            finally
            {
                screen?.Dispose();
            }
        }