Exemplo n.º 1
0
        private FileScanManager(MiirorItem mi)
        {
            miirorItem = mi;

            FilterList = new List<string>();
            ReserveList = new List<string>();
        }
Exemplo n.º 2
0
        public void AddMonitor(MiirorItem mi)
        {
            iMiror imi = null;

            if (string.IsNullOrEmpty(mi.Identity))
            {
                mi.Identity = mi.GetMD5Hash();
                imi = new iMiror(mi);
                imi.CallBack += new CallBackEventHandler(OnCallBackEvent);
                mirorGrp.Add(imi);
            }
            else
            {
                int index = FindIndex(mi);

                if (index > -1)
                {
                    mi.Identity = mi.GetMD5Hash();
                    mirorGrp[index].Dispose();
                    imi = new iMiror(mi);
                    imi.CallBack += new CallBackEventHandler(OnCallBackEvent);
                    mirorGrp[index] = imi;
                }
            }
        }
Exemplo n.º 3
0
        public MiirorItem ShowModel()
        {
            bool? result = ShowDialog();

            if (result.HasValue && !result.Value)
            {
                mi = new MiirorItem();
            }

            return mi;
        }
Exemplo n.º 4
0
        public iMiror(MiirorItem mi)
        {
            MirorItem = mi;

            if (0 < mi.Filtered.Length)
            {
                if (mi.Filtered.StartsWith("~"))
                {
                    FilterList.AddRange(mi.Filtered.Substring(1).Split('|'));
                }
                else
                {
                    ReserveList.AddRange(mi.Filtered.Split('|'));
                }
            }

            try
            {
                fsm = FileScanManager.GetInstance(mi);
                fsm.FilterList = FilterList;
                fsm.ReserveList = ReserveList;
                if (mi.IsWorking)
                {
                    DoLooseScan();
                    SystemWatch(true);
                }
            }
            catch (IOException IOex)
            {
                Log.GetInstance().WriteLog(IOex.Message);
                Stop();
            }
            catch (Exception ex)
            {
                Log.GetInstance().WriteLog(ex.Message);
            }
            finally
            {
                timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
                timer.Interval = WATCH_SPAN;
                if (mi.IsWorking)
                {
                    timer.Enabled = true;
                    timer.Start();
                }
            }
        }
Exemplo n.º 5
0
        public static bool SynchFileEntry(FileItem file, MiirorItem mi)
        {
            PathManager pm = PathManager.GetInstance(mi);
            bool result = false;

            try
            {
                string targetPath = pm.ConvertPath(file.NewFile);

                switch (file.ChangeType)
                {
                    case IO.WatcherChangeTypes.Changed:
                        if ((ZlpIOHelper.GetFileAttributes(file.NewFile) & FileAttributes.Offline) == FileAttributes.Offline
                         || (ZlpIOHelper.FileExists(targetPath) && (ZlpIOHelper.GetFileAttributes(targetPath) & FileAttributes.Offline) == FileAttributes.Offline))
                        {
                            return false;
                        }

                        if (IsDirectory(targetPath, file.NewFile))
                        {
                            CreateDirectory(targetPath);
                        }
                        else
                        {
                            ZlpIOHelper.CopyFile(file.NewFile, targetPath, true);
                        }

                        break;
                    case IO.WatcherChangeTypes.Deleted:
                        if ((ZlpIOHelper.GetFileAttributes(targetPath) & FileAttributes.Offline) == FileAttributes.Offline)
                        {
                            return false;
                        }

                        if (IsDirectory(targetPath))
                        {
                            ZlpIOHelper.DeleteDirectory(targetPath, true);
                        }
                        else
                        {
                            ZlpIOHelper.DeleteFile(targetPath);
                        }

                        break;
                    case IO.WatcherChangeTypes.Renamed:
                        ZlpIOHelper.MoveDirectory(pm.ConvertPath(file.OldFile), targetPath);

                        break;
                }

                result = true;
            }
            catch (Exception ex)
            {
                result = false;
                throw ex;
            }

            return result;
        }
Exemplo n.º 6
0
        private List<FileItem> CompareFSO(List<string> source, List<string> target, WatcherChangeTypes changeType)
        {
            List<FileItem> results = new List<FileItem>();
            string targetFile = "";
            int index = 0;
            string idxFile = "";

            try
            {
                MiirorItem mi = new MiirorItem()
                {
                    Identity = miirorItem.Identity,
                    IsFolder = miirorItem.IsFolder,
                    Source = (changeType == WatcherChangeTypes.Deleted) ? miirorItem.Target : miirorItem.Source,
                    Target = (changeType == WatcherChangeTypes.Deleted) ? miirorItem.Source : miirorItem.Target
                };

                PathManager pm = PathManager.GetInstance(mi);
                foreach (string entry in source)
                {
                    try
                    {
                        targetFile = pm.ConvertPath(entry);
                        //index = target.FindIndex(e => e.ToLower() == targetFile.ToLower());
                        idxFile = target.AsParallel().FirstOrDefault(e => e.ToLower() == targetFile.ToLower());
                        //if (index == -1)
                        if (idxFile.Length == 0)
                        {
                            results.Add(new FileItem() { ChangeType = changeType, NewFile = (changeType == WatcherChangeTypes.Deleted) ? targetFile : entry, OldFile = "" });
                        }
                        else
                        {
                            if (changeType == WatcherChangeTypes.Changed)
                            {
                                //if (new ZlpFileInfo(entry).LastWriteTime > new ZlpFileInfo(targetFile).LastWriteTime)
                                if (ZlpIOHelper.GetFileLastWriteTime(entry) > ZlpIOHelper.GetFileLastWriteTime(targetFile))
                                {
                                    results.Add(new FileItem() { ChangeType = WatcherChangeTypes.Changed, NewFile = entry, OldFile = "" });
                                }
                            }
                        }
                    }
                    catch (Exception xxx)
                    {
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.GetInstance().WriteLog(ex.Message);
                throw ex;
            }

            return results;
        }
Exemplo n.º 7
0
 public static FileScanManager GetInstance(MiirorItem mi)
 {
     return new FileScanManager(mi);
 }
Exemplo n.º 8
0
        private void UpdateMonitorList(MiirorItem mi)
        {
            mirorGroup.AddMonitor(mi);

            mi.Identity = mi.GetMD5Hash();
            int index = MiSettings.MonitorList.FindIndex(m => m.Identity == mi.Identity);

            if (index > -1)
            {
                MiSettings.MonitorList[index] = mi;
            }
            else
            {
                MiSettings.MonitorList.Add(mi);
            }
        }
Exemplo n.º 9
0
 void mirorGroup_CallBack(MiirorItem mi, bool isTimerOn, bool isWatcherOn)
 {
     BindListBox();
 }
Exemplo n.º 10
0
 private int FindIndex(MiirorItem mi)
 {
     return mirorGrp.FindIndex(m => m.MirorItem.Identity == mi.Identity);
 }
Exemplo n.º 11
0
        public void Stop()
        {
            timer.Stop();
            timer.Enabled = false;
            SystemWatch(false);
            MirorItem = new MiirorItem()
            {
                Filtered = MirorItem.Filtered,
                Identity = MirorItem.Identity,
                IsFolder = MirorItem.IsFolder,
                IsWorking = false,
                IsRecursive = MirorItem.IsRecursive,
                Source = MirorItem.Source,
                Target = MirorItem.Target
            };

            OnCallBackEvent(MirorItem, timer.Enabled, fsw.EnableRaisingEvents);
        }
Exemplo n.º 12
0
        public void Start()
        {
            if (!fsw.EnableRaisingEvents)
            {
                try
                {
                    fsw = new FileSystemWatcher();
                    SystemWatch(true);
                }
                catch (IOException IOex)
                {
                    Log.GetInstance().WriteLog(IOex.Message);
                    Stop();
                    return;
                }
                catch (Exception ex)
                {
                    Log.GetInstance().WriteLog(ex.Message);
                    return;
                }
            }

            timer.Enabled = true;
            timer.Start();
            MirorItem = new MiirorItem()
            {
                Filtered = MirorItem.Filtered,
                Identity = MirorItem.Identity,
                IsFolder = MirorItem.IsFolder,
                IsWorking = true,
                IsRecursive = MirorItem.IsRecursive,
                Source = MirorItem.Source,
                Target = MirorItem.Target
            };
        }