public ActionResult Create(ReportDataSourceModel model) { using (Muse db = new Muse()) { model.Id = Guid.NewGuid(); model.CreateUser = User.Identity.Name; int flag = db.Add(model, true); if (flag > 0) { return(RedirectToAction("Index")); } else { return(View()); } } //try //{ // // TODO: Add insert logic here // return RedirectToAction("Index"); //} //catch //{ // return View(); //} }
private void GetFileToDatabase() { var drives = FileQueryEngine.GetReadyNtfsDrives().OrderBy(x => x.Name); if (ListTool.HasElements(drives)) { foreach (var drive in drives) { NewFileCount = 0; //if (!drive.Name.Contains("J")) continue;//测试只读取D盘 //if (drive.Name.Contains("D")) continue;//测试时跳过D盘 //if (drive.Name.Contains("F")) continue;//测试时跳过F盘 using (var db = new Muse()) { //检测磁盘是否格式化,如果格式化则清空USN记录 DateTime dt1 = DriveTool.GetLastFormatTime(drive.Name); var ds = db.Get <UsnDrives>(x => x.Name == drive.Name, null); if ((ds == null) || (ds != null && ds.LastFormatTime != dt1.ToString())) { var deleteSql = db.Context.Database.ExecuteSqlCommand("DELETE FROM usnfiles WHERE drive = @p0;", drive.Name); if (ds == null) { db.Add(new UsnDrives() { Name = drive.Name, LastFormatTime = dt1.ToString() }); } else { ds.LastFormatTime = dt1.ToString(); db.Update(ds, true); } } //查询上次读取到的位置(最后一条记录) ulong filenumber = 0; long usn = 0; if (db.Any <UsnFiles>(x => x.Drive == drive.Name, null)) { int lastId = db.Do <UsnFiles>().Where(x => x.Drive == drive.Name).Max(x => x.Id); UsnFiles lastRec = db.Get <UsnFiles>(x => x.Id == lastId, null); usn = lastRec.Usn; filenumber = NumberStringTool.ToUlong(lastRec.Number); //usn = db.Do<UsnFiles>().Where(x => x.Drive == drive.Name).Max(x => x.Usn); //string filenumberstr = db.Do<UsnFiles>().Where(x => x.Drive == drive.Name).Max(x => x.Number); //filenumber = NumberStringTool.ToUlong(filenumberstr); } //从上次FileNumber记录开始读取 var usnOperator = new UsnOperator(drive); usnOperator.GetEntries(usn, filenumber, GetFileToDatabaseEvent, 1000); } } } }
public static void Start() { if (IsStart) { return; } IsStart = true; Task.Factory.StartNew(() => { //设置退出条件 while (!Token.IsCancellationRequested) { //队列中存在元素 if (Queue.Any()) { //循环进行操作 for (int i = 0; i < Queue.Count; i++) { try { if (Queue.TryDequeue(out string file)) { R.Log.v("💗💗💗 准备处理文件:" + file); var pic = PictureReorganize.CreateModel(file); if (pic != null) { R.Log.v("图片信息读取成功"); using (Muse db = new Muse("pictures")) { if (db.Any <Pictures>(x => x.MD5 == pic.MD5 && x.SHA1 == pic.SHA1, null)) { R.Log.v("图片已入库,不需要在重复保存了,即将删除"); FileTool.Delete(file); } else { R.Log.v("图片未入库,准备入库并分类保存"); db.Add(pic); pic = PictureReorganize.AddLocationInfo(file, pic); pic = PictureReorganize.AddContentInfo(file, pic); PictureReorganize.ReorganizePicture(file, R.Paths.Pictures, pic); } } } } } catch { } } } Sleep.S(Interval); } }); }
private void Form1_Load(object sender, EventArgs e) { using (Muse db = new Muse()) { Pigs pig = new Pigs() { Id = Guid.NewGuid().ToString(), Age = 10, Name = "Tom" }; db.Add(pig); } }
public ActionResult AddOption(ReportOptionModel model) { using (Muse db = new Muse()) { model.Id = Guid.NewGuid(); int flag = db.Add(model, true); if (flag > 0) { return(RedirectToAction("Details", new { id = model.ReportPageModelId })); } else { return(View()); } } }
private void BtAddPath_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择要备份的文件夹"; if (dialog.ShowDialog() == DialogResult.OK) { string selPath = dialog.SelectedPath; //获取选中的目录 string path = DirTool.Combine(selPath, "\\"); //格式化选中的目录 string name = DirTool.GetPathName(selPath); //获取目录名称 List <BackupPaths> clashPath = R.Services.FBS.Paths.Where(x => x.Path.Contains(path) || path.Contains(x.Path)).ToList(); //查询冲突项 if (ListTool.HasElements(clashPath)) { string cp = ""; clashPath.ForEach(x => cp += (x.Path + ";")); //存在重合目录 MessageBox.Show(string.Format("您当前选择路径:{0},与之前选择的目录:{1},存在嵌套包含关系,请先从备份目录中移除,然后重新添加。", path, cp)); } else { UIEnableButton(false); Task.Factory.StartNew(() => { using (var db = new Muse()) { if (!db.Do <BackupPaths>().Any(x => x.Path == path)) { BackupPaths bp = new BackupPaths() { Path = path, Alias = Guid.NewGuid().ToString() }; if (db.Add(bp) > 0) { R.Services.FBS.Paths.Add(bp); //添加到列表 R.Services.FBS.AddToWatcherPath(bp.Path); //添加到监听 UIDgvPathAdd(name, null); //添加到列表UI } } } UIEnableButton(true); }); } } }
public ActionResult Create(ReportDataSetModel model) { using (Muse db = new Muse()) { model.Id = Guid.NewGuid(); model.CreateUser = User.Identity.Name; int flag = db.Add(model, true); if (flag > 0) { return(RedirectToAction("Index")); } else { return(View()); } } }
private void BtAdd_Click(object sender, EventArgs e) { FaultLogs fl = new FaultLogs() { Ip = TbIp.Text, Phone = TbPhone.Text, Address = TbAddress.Text, Problem = TbProblem.Text, Solution = TbSolution.Text, Postscript = TbPostscript.Text, System = CbSystem.Text, CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), IsFinish = CbIsFinish.Checked, FinishTime = CbIsFinish.Checked ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : "", }; UICleanInput(); Task.Factory.StartNew(() => { UIAddButton(false); using (var db = new Muse()) { db.Add(fl); var fls = db.Do <FaultLogs>().SqlQuery("SELECT * FROM faultlogs WHERE createtime LIKE @p0", DateTime.Now.ToString("yyyy-MM-dd") + "%"); if (ListTool.HasElements(fls)) { foreach (var f in fls) { UIAddRow(f); } } } UIAddButton(true); }); }
/// <summary> /// 备份文件 /// </summary> /// <param name="path"></param> /// <param name="newpath"></param> private void BackupFile(string path, string newpath, string md5) { using (var db = new Muse()) { try { if (DirTool.Create(DirTool.GetFilePath(newpath))) { string lastwritetime = DateTimeConvert.StandardString(File.GetLastWriteTime(path)); File.Copy(path, newpath, true); db.Add(new BackupFiles() { FullPath = path, BackupFullPath = newpath, Size = FileTool.Size(path), BackupTime = DateTimeConvert.StandardString(DateTime.Now), LastWriteTime = lastwritetime, Md5 = md5, }); } } catch (Exception e) { } } }