private void RulesRefresh(RuleFile rule_, Boolean added = false) { List<RuleFile> lstRules = new List<RuleFile>(); if (rule_ == null) { using (var db = new DataContext()) { db.AttachEntity(inspector); inspector.Rules.ToList().ForEach(rule => SetImageRule(rule)); lstRules = inspector.Rules.ToList(); } } else { lstRules = (List<RuleFile>)lstVRules.ItemsSource; if (added) { lstRules.Add(rule_); } else lstRules.Remove(rule_); } lstVRules.ItemsSource = null; lstVRules.ItemsSource = lstRules; }
private void ExecuteSonar(Inspector inspector, String prefix, BackgroundWorker worker) { DirectoryInfo dir = new DirectoryInfo(inspector.Path); var files = dir.GetFiles(); Boolean iniDB = false; try { bool attach = inspector.Rules != null; } catch (ObjectDisposedException objDispEx) { log.Debug("Iniciando BBDD en el sonar:" + objDispEx.Message); iniDB = true; } catch (Exception ex) { log.Debug("Iniciando BBDD en el sonar:" + ex.Message); iniDB = true; } if (iniDB) { using (var db = new DataContext()) { db.AttachEntity(inspector); inspector.Rules.ToList(); } } foreach (var rule in inspector.Rules) { switch ((RuleFile.TypeFileRule)rule.RuleType) { case RuleFile.TypeFileRule.Date: RuleFileDate ruleAuxD = rule as RuleFileDate; var qfilesD = from file in files where ruleAuxD.DateFirst < file.LastWriteTime && ruleAuxD.DateLast > file.LastWriteTime select file; files = qfilesD.ToArray(); break; case RuleFile.TypeFileRule.Extension: RuleFileExtension ruleAuxE = rule as RuleFileExtension; var qfilesE = from file in files where file.Extension.Contains(ruleAuxE.ExtensionPattern) select file; files = qfilesE.ToArray(); break; case RuleFile.TypeFileRule.FileName: RuleFileName ruleAux = rule as RuleFileName; var qfiles = from file in files where file.Name.Contains(ruleAux.NamePattern) select file; files = qfiles.ToArray(); break; } } RegistrarLog(prefix + "Ejecutando rastreador...", worker); foreach (var file in files) { if (inspector.Action == (int)Inspector.TypeActions.MoveSubDir) { String destName = inspector.SubDirAction + Path.DirectorySeparatorChar + file.Name; destName = destName.Substring(0, destName.Length - file.Extension.Length); String destNameAux = destName; int j = 1; while (File.Exists(destNameAux + file.Extension)) { destNameAux = destName + "-" + j.ToString(); j++; } RegistrarLog(prefix + "Moviendo fichero " + file.FullName + "...", worker); file.MoveTo(destNameAux + file.Extension); RegistrarLog(prefix + "Fichero movido correctamente a " + destNameAux, worker); } else { RegistrarLog(prefix + "Eliminando fichero " + file.FullName + "...", worker); file.Delete(); RegistrarLog(prefix + "Fichero eliminado correctamente", worker); } } RegistrarLog(prefix + "Fin de la ejecución del rastreador", worker); }
private void pnlNewRule_MouseUp(object sender, MouseButtonEventArgs e) { NewRule newRule = new NewRule(); newRule.ShowDialog(); if (newRule.rule != null) { RuleFile rule = newRule.rule; using (var db = new DataContext()) { db.AttachEntity(inspector); inspector.Rules.Add(rule); Boolean exist = true; if (inspector.InspectorId == 0) { inspector.Name = txtName.Text; inspector.Path = txtPath.Text; if (rbtMoveSubDir.IsChecked.HasValue && rbtMoveSubDir.IsChecked.Value) { inspector.Action = (int)Inspector.TypeActions.MoveSubDir; inspector.SubDirAction = txtPathAction.Text; } else { inspector.Action = (int)Inspector.TypeActions.DeleteFiles; inspector.SubDirAction = String.Empty; } db.PersistEntity(inspector); exist = false; } db.SaveChanges(); if(!exist) { App.Single.AddWork(inspector); } else { App.Single.UpdateWork(inspector); } } RulesRefresh(rule, true); } }