Пример #1
0
        public InspectorDetail(Inspector inspector)
        {
            InitializeComponent();
            this.inspector = inspector;

            App.ActualInspectorDetail = this;
            this.Owner = App.Inspectors;
        }
Пример #2
0
        public InspectorDetail()
        {
            InitializeComponent();
            inspector = new Inspector { Path = "Seleccione una carpeta para rastrear" };

            App.ActualInspectorDetail = this;
            this.Owner = App.Home;
        }
        private void FillRulesAux(Inspector fInspector)
        {
            var inspector = fInspector as FileInspector;

            if (!inspector.Enable.HasValue || !inspector.CheckPeriod.HasValue)
                return;

            inspector.ImageEnable = inspector.Enable.Value ? @"/Resources/play.png" : @"/Resources/pausa.png";

            inspector.CheckPeriodText = InspectorDetail.GetPeriodText(inspector.CheckPeriod.Value) + " ";

            inspector.RulesAux = new List<InspectorHelper>(3);

            var queryRule = from rule in inspector.Rules.Value
                             where rule.RuleType.Equals((int)RuleFile.TypeFileRule.FileName)
                             select rule;

            var inspHelper = new InspectorHelper
                                 {
                                     CountRuleType = queryRule.Count(),
                                     Type = RuleFile.TypeFileRule.FileName,
                                     ImagePath = @"/images/icon_ruleFileName.png"
                                 };

            inspector.RulesAux.Add(inspHelper);

            queryRule = from rule in inspector.Rules.Value
                        where rule.RuleType.Equals((int)RuleFile.TypeFileRule.Extension)
                         select rule;

            inspHelper = new InspectorHelper
                             {
                                 CountRuleType = queryRule.Count(),
                                 Type = RuleFile.TypeFileRule.Extension,
                                 ImagePath = @"/images/icon_ruleFileExtension.png"
                             };

            inspector.RulesAux.Add(inspHelper);

            queryRule = from rule in inspector.Rules.Value
                        where rule.RuleType.Equals((int)RuleFile.TypeFileRule.Date)
                         select rule;

            inspHelper = new InspectorHelper
                             {
                                 CountRuleType = queryRule.Count(),
                                 Type = RuleFile.TypeFileRule.Date,
                                 ImagePath = @"/images/icon_ruleFileDate.png"
                             };

            inspector.RulesAux.Add(inspHelper);
        }
Пример #4
0
        private void FillRulesAux(Inspector inspector)
        {
            if (inspector.Enable)
            {
                inspector.ImageEnable = @"/Resources/play.png";
            }
            else
            {
                inspector.ImageEnable = @"/Resources/pausa.png";
            }

            inspector.CheckPeriodText = InspectorDetail.GetPeriodText(inspector.CheckPeriod) + " ";

            inspector.RulesAux = new List<InspectorHelper>(3);

            var queryRule = from rule in inspector.Rules
                             where rule.RuleType.Equals((int)RuleFile.TypeFileRule.FileName)
                             select rule;

            InspectorHelper inspHelper = new InspectorHelper();
            inspHelper.CountRuleType = queryRule.Count();
            inspHelper.Type = RuleFile.TypeFileRule.FileName;
            inspHelper.ImagePath = @"/images/icon_ruleFileName.png";

            inspector.RulesAux.Add(inspHelper);

            queryRule = from rule in inspector.Rules
                        where rule.RuleType.Equals((int)RuleFile.TypeFileRule.Extension)
                         select rule;

            inspHelper = new InspectorHelper();
            inspHelper.CountRuleType = queryRule.Count();
            inspHelper.Type = RuleFile.TypeFileRule.Extension;
            inspHelper.ImagePath = @"/images/icon_ruleFileExtension.png";

            inspector.RulesAux.Add(inspHelper);

            queryRule = from rule in inspector.Rules
                        where rule.RuleType.Equals((int)RuleFile.TypeFileRule.Date)
                         select rule;

            inspHelper = new InspectorHelper();
            inspHelper.CountRuleType = queryRule.Count();
            inspHelper.Type = RuleFile.TypeFileRule.Date;
            inspHelper.ImagePath = @"/images/icon_ruleFileDate.png";

            inspector.RulesAux.Add(inspHelper);
        }
Пример #5
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;
        }
Пример #6
0
        private void pnlNewInspector_MouseUp(object sender, MouseButtonEventArgs e)
        {
            var inspector = new Inspector { Path = "Seleccione una carpeta para rastrear" };

            InspectorDetail inspDetail = new InspectorDetail(inspector);
            inspDetail.ShowDialog();

            inspector = inspDetail.inspector;

            InspectorsRefresh(inspector, true);
        }
Пример #7
0
 public void UpdateWork(Inspector insp)
 {
     RemoveWork(insp);
     AddWork(insp);
 }
Пример #8
0
        public void RemoveWork(Inspector insp)
        {
            if (insp.InspectorId.HasValue && Sonar != null && Sonar.ContainsKey(insp.InspectorId.Value))
            {
                BackgroundWorker work = Sonar[insp.InspectorId.Value];
                work.CancelAsync();

                Sonar.Remove(insp.InspectorId.Value);
            }
        }
Пример #9
0
        public void AddWork(Inspector insp)
        {
            var work = new BackgroundWorker();

            work.WorkerReportsProgress = true;
            work.WorkerSupportsCancellation = true;

            work.DoWork += new DoWorkEventHandler(bw_DoWork);
            work.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
            work.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

            Sonar.Add(insp.InspectorId.Value, work);

            if (SonarActivo)
            {
                work.RunWorkerAsync(insp);
            }
        }
Пример #10
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);
        }
Пример #11
0
        public void RemoveWork(Inspector insp)
        {
            BackgroundWorker work = Sonar[insp.InspectorId];
            work.CancelAsync();

            Sonar.Remove(insp.InspectorId);
        }
        private void InspectorsRefresh(Inspector inspector, Boolean added = false)
        {
            var lstInspectors = new List<Inspector>();

            if (inspector == null)
            {
                IPersistence<FileInspector> servInspF = new Persistence<FileInspector>();

                lstInspectors.AddRange(servInspF.GetEntities(new FileInspector(){Enable = null}));
                lstInspectors.ForEach(FillRulesAux);

                IPersistence<ServiceInspector> servInspV = new Persistence<ServiceInspector>();

                lstInspectors.AddRange(servInspV.GetEntities());
            }
            else
            {
                lstInspectors = (List<Inspector>)lstVInspectors.ItemsSource;

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

            lstVInspectors.ItemsSource = null;
            lstVInspectors.ItemsSource = lstInspectors;
        }