Esempio n. 1
0
        private void InspectorsRefresh(Inspector inspector, Boolean added = false)
        {
            List<Inspector> lstInspectors = new List<Inspector>();

            if (inspector == null)
            {
                using (var db = new DataContext())
                {
                    lstInspectors = db.Inspectors.ToList();

                    lstInspectors.ForEach(insp => FillRulesAux(insp));
                }
            }
            else
            {
                lstInspectors = (List<Inspector>)lstVInspectors.ItemsSource;

                if (added)
                {
                    FillRulesAux(inspector);
                    lstInspectors.Add(inspector);
                }
                else
                    lstInspectors.Remove(inspector);
            }

            lstVInspectors.ItemsSource = null;
            lstVInspectors.ItemsSource = lstInspectors;
        }
Esempio n. 2
0
 public DataUtils(DataContext context)
 {
     this.context = context;
 }
Esempio n. 3
0
        private void pnlActDesactInspector_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (lstVInspectors.SelectedIndex != -1)
            {
                Inspector inspSelected = (Inspector)lstVInspectors.SelectedValue;

                using (var db = new DataContext())
                {
                    inspSelected.Enable = !inspSelected.Enable;

                    db.PersistEntity(inspSelected);
                    db.SaveChanges();
                }

                if (inspSelected.Enable)
                {
                    inspSelected.ImageEnable = @"/Resources/play.png";

                    App.Single.AddWork(inspSelected);
                }
                else
                {
                    inspSelected.ImageEnable = @"/Resources/pausa.png";

                    App.Single.RemoveWork(inspSelected);
                }

                List<Inspector> lstInspectors = (List<Inspector>)lstVInspectors.ItemsSource;

                lstVInspectors.ItemsSource = null;
                lstVInspectors.ItemsSource = lstInspectors;
            }
            else
            {
                MessageBox.Show("Por favor, seleccione un inspector de la lista");
            }
        }
Esempio n. 4
0
        private void pnlDeleteInspector_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (lstVInspectors.SelectedIndex != -1)
            {
                Inspector inspSelected = (Inspector)lstVInspectors.SelectedValue;

                using (var db = new DataContext())
                {
                    db.RemoveEntity(inspSelected);
                    App.Single.RemoveWork(inspSelected);

                    db.SaveChanges();
                }

                InspectorsRefresh(inspSelected);
            }
            else
            {
                MessageBox.Show("Por favor, seleccione un inspector de la lista");
            }
        }
Esempio n. 5
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            App.swriter = new StringWriter();
            Console.SetOut(App.swriter);

            log4net.Config.XmlConfigurator.Configure();

            RegistrarLog("<b>Inicializando la aplicación...</b>");

            SonarActivo = true;

            Sonar = new Dictionary<int, BackgroundWorker>();

            try
            {
                using (var db = new DataContext())
                {
                    var rastreadores = from insp in db.Inspectors
                                       where insp.Enable == true
                                       select insp;

                    foreach (var insp in rastreadores.ToList())
                    {
                        AddWork(insp);
                    }
                }
            }
            catch (Exception ex)
            {
                RegistrarLog("<b>Error al inicializar la aplicación: </b>" + ex.Message);
            }

            RegistrarLog("<b>Inicialización de la aplicación Finalizada</b>");
        }
Esempio n. 6
0
        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 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 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);
            }
        }
        private void pnlNewInspector_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (!optionPressed)
                return;

            using (var db = new DataContext())
            {
                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;
                }

                Boolean exist = true;

                if (inspector.InspectorId == 0)
                {
                    exist = false;
                }

                db.PersistEntity(inspector);
                db.SaveChanges();

                if (!exist)
                {
                    App.Single.AddWork(inspector);
                }
                else
                {
                    App.Single.UpdateWork(inspector);
                }
            }

            this.Close();
        }
Esempio n. 10
0
        private void pnlDeleteRule_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (lstVRules.SelectedIndex != -1)
            {
                RuleFile ruleSelected = (RuleFile)lstVRules.SelectedValue;

                using (var db = new DataContext())
                {
                    db.RemoveEntity(ruleSelected);
                    db.SaveChanges();

                    App.Single.UpdateWork(inspector);
                }

                RulesRefresh(ruleSelected);
            }
            else
            {
                System.Windows.MessageBox.Show("Por favor, seleccione una regla de la lista");
            }
        }
Esempio n. 11
0
        private void lstVRules_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (lstVRules.SelectedIndex != -1)
            {
                RuleFile ruleSelected = (RuleFile)lstVRules.SelectedValue;

                NewRule ruleDetail = new NewRule(ruleSelected);
                ruleDetail.ShowDialog();

                ruleSelected = ruleDetail.rule;

                using (var db = new DataContext())
                {
                    db.PersistEntity(ruleSelected);
                    db.SaveChanges();
                }

                App.Single.UpdateWork(inspector);

                List<RuleFile> lstRules = (List<RuleFile>)lstVRules.ItemsSource;

                lstVRules.ItemsSource = null;
                lstVRules.ItemsSource = lstRules;
            }
        }