public void SetRule(RuleFile rule) { this.rule = (RuleFileDate)rule; dateFirst.SelectedDate = this.rule.DateFirst; dateLast.SelectedDate = this.rule.DateLast; }
public static RuleFile GetFileRule(RuleFile.TypeFileRule type) { RuleFile res = null; switch (type) { case RuleFile.TypeFileRule.Date: res = new RuleFileDate(); break; case RuleFile.TypeFileRule.Extension: res = new RuleFileExtension(); break; case RuleFile.TypeFileRule.FileName: res = new RuleFileName(); break; } if (res != null) { res.RuleType = (int)type; } return(res); }
public RuleFile GetRule() { if (rule == null) { rule = new RuleFileDate(); } rule.DateFirst = dateFirst.SelectedDate.Value; rule.DateLast = dateLast.SelectedDate.Value; return(rule); }
private void SaveRule() { Boolean typeChoose = false; RuleFile ruleAux = null; if (rbtDate.IsChecked.HasValue && rbtDate.IsChecked.Value) { ruleAux = new RuleFileDate(); ruleAux.RuleType = (int)RuleFile.TypeFileRule.Date; ruleAux.ImagePath = @"/images/icon_ruleFileDate.png"; typeChoose = true; } else if (rbtExtension.IsChecked.HasValue && rbtExtension.IsChecked.Value) { ruleAux = new RuleFileExtension(); ruleAux.RuleType = (int)RuleFile.TypeFileRule.Extension; ruleAux.ImagePath = @"/images/icon_ruleFileExtension.png"; typeChoose = true; } else if (rbtName.IsChecked.HasValue && rbtName.IsChecked.Value) { ruleAux = new RuleFileName(); ruleAux.RuleType = (int)RuleFile.TypeFileRule.FileName; ruleAux.ImagePath = @"/images/icon_ruleFileName.png"; typeChoose = true; } if (!typeChoose) { MessageBox.Show("Necesita especificar el tipo de la regla"); return; } RuleControl rControl = (RuleControl)pnlExtensionControl.Children[0]; rule = rControl.GetRule(); rule.RuleType = ruleAux.RuleType; rule.ImagePath = ruleAux.ImagePath; rule.Name = txtName.Text; this.Close(); }
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); }