Exemple #1
0
        private void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            MirrorEventArgs args = new MirrorEventArgs();

            args.FSWname   = this.FriendlyName;
            args.TimeStamp = DateTime.Now;
            args.Info      = "Cronometro Detenido";
            DMinfoEvent(args);
            if (_IOlist.Count > 0)
            {
                List <SourceEventArgs> list = new List <SourceEventArgs>();
                lock (_IOlist)
                {
                    list.AddRange(_IOlist);
                    _IOlist.Clear();
                }

                updateMirror(list);
            }
        }
Exemple #2
0
        private void updateMirror(List <SourceEventArgs> list)
        {
            MirrorEventArgs args = new MirrorEventArgs();

            args.FSWname   = this.FriendlyName;
            args.TimeStamp = DateTime.Now;
            args.Action    = "Comienzo de la actualización en el espejo";
            args.Info      = list.Count.ToString() + " evento(s) para procesar";
            DMinfoEvent(args);

            string destination;
            List <SourceEventArgs> listF = new List <SourceEventArgs>();

            try
            {
                //--- Created ---//
                listF = list.Where(x => x.EventType == "Created").ToList();
                for (int i = 0; i < listF.Count; i++)
                {
                    destination = listF[i].Path.Replace(SourceDirectory, MirrorDirectory);
                    if (Directory.Exists(listF[i].Path))
                    {
                        Directory.CreateDirectory(destination);
                        IOmethods.CopyDirectoryRecursively(listF[i].Path, destination);
                        list.Remove(listF[i]);
                        // Remove all "Created" and "Changed" events of child folders and files from the master list
                        list = list.Where(s => (s.EventType == "Created" || s.EventType == "Changed") && s.Path.Contains(listF[i].Path) == false).ToList();
                        // Update the sublist of "Created events"
                        listF          = list.Where(x => x.EventType == "Created").ToList();
                        i             -= 1;
                        args           = new MirrorEventArgs();
                        args.FSWname   = this.FriendlyName;
                        args.Action    = "Create";
                        args.TimeStamp = DateTime.Now;
                        args.Info      = destination;
                        DMinfoEvent(args);
                    }
                    else
                    {
                        File.Copy(listF[i].Path, destination, true);
                        // Remove all "Changed" events for this file from the master list
                        list = list.Where(s => (s.EventType != "Changed" && s.Path != listF[i].Path)).ToList();
                        // Update the sublist of "Created events"
                        listF          = list.Where(x => x.EventType == "Created").ToList();
                        i             -= 1;
                        args           = new MirrorEventArgs();
                        args.FSWname   = this.FriendlyName;
                        args.Action    = "Create";
                        args.TimeStamp = DateTime.Now;
                        args.Info      = destination;
                        DMinfoEvent(args);
                    }
                }
            }
            catch (Exception x)
            {
                args           = new MirrorEventArgs();
                args.FSWname   = this.FriendlyName;
                args.TimeStamp = DateTime.Now;
                args.Action    = "Error";
                args.Info      = x.Message;
                DMerrorEvent(args);
            }
            try
            {
                //--- Changed ---//
                listF = list.Where(z => z.EventType == "Changed").ToList();
                listF = RemoveDuplicates(listF);
                foreach (SourceEventArgs f in listF)
                {
                    if (File.Exists(f.Path))
                    {
                        destination = f.Path.Replace(SourceDirectory, MirrorDirectory);
                        File.Copy(f.Path, destination, true);
                        args           = new MirrorEventArgs();
                        args.FSWname   = this.FriendlyName;
                        args.Action    = "Copy";
                        args.TimeStamp = DateTime.Now;
                        args.Info      = destination;
                        DMinfoEvent(args);
                    }
                }
            }
            catch (Exception x)
            {
                args           = new MirrorEventArgs();
                args.FSWname   = this.FriendlyName;
                args.TimeStamp = DateTime.Now;
                args.Action    = "Error";
                args.Info      = x.Message;
                DMerrorEvent(args);
            }
            try
            {
                //--- Renamed ---//
                listF = list.Where(x => x.EventType == "Renamed").ToList();
                foreach (SourceEventArgs f in listF)
                {
                    destination = f.Path.Replace(SourceDirectory, MirrorDirectory);
                    if (System.IO.Directory.Exists(f.OldPath.Replace(SourceDirectory, MirrorDirectory)))
                    {
                        string oldFPath = f.OldPath.Replace(SourceDirectory, MirrorDirectory);
                        string newFPath = f.Path.Replace(SourceDirectory, MirrorDirectory);
                        System.IO.Directory.Move(oldFPath, newFPath);
                    }
                    else
                    {
                        string oldFPath = f.OldPath.Replace(SourceDirectory, MirrorDirectory);
                        string newFPath = f.Path.Replace(SourceDirectory, MirrorDirectory);
                        System.IO.File.Move(oldFPath, newFPath);
                    }
                    args           = new MirrorEventArgs();
                    args.FSWname   = this.FriendlyName;
                    args.Action    = "Rename";
                    args.TimeStamp = DateTime.Now;
                    args.Info      = destination;
                    DMinfoEvent(args);
                }
            }
            catch (Exception x)
            {
                args           = new MirrorEventArgs();
                args.FSWname   = this.FriendlyName;
                args.TimeStamp = DateTime.Now;
                args.Action    = "Error";
                args.Info      = x.Message;
                DMerrorEvent(args);
            }
            try
            {
                //--- Deleted ---//
                listF = list.Where(x => x.EventType == "Deleted").ToList();
                foreach (SourceEventArgs f in listF)
                {
                    destination = f.Path.Replace(SourceDirectory, MirrorDirectory);
                    if (Directory.Exists(destination))
                    {
                        Directory.Delete(destination, true);
                    }
                    else
                    {
                        File.Delete(destination);
                    }
                    args           = new MirrorEventArgs();
                    args.FSWname   = this.FriendlyName;
                    args.Action    = "Delete";
                    args.TimeStamp = DateTime.Now;
                    args.Info      = destination;
                    DMinfoEvent(args);
                }
            }
            catch (Exception x)
            {
                args           = new MirrorEventArgs();
                args.FSWname   = this.FriendlyName;
                args.TimeStamp = DateTime.Now;
                args.Action    = "Error";
                args.Info      = x.Message;
                DMerrorEvent(args);
            }
            args           = new MirrorEventArgs();
            args.FSWname   = this.FriendlyName;
            args.TimeStamp = DateTime.Now;
            args.Action    = "Fin de la actualización en el espejo";
            DMinfoEvent(args);
        }