Пример #1
0
        internal void ProcessDiskEvent(WebSite website, DiskChangeEvent task)
        {
            var sitedb = website.SiteDb();

            if (task.ChangeType == DiskChangeType.Deleted)
            {
                this.DeleteFromDb(task.FullPath, sitedb);
                DiskSyncLog.DiskLogManager.Delete(task.FullPath, sitedb.WebSite.Id);
            }
            else
            {
                this.SyncToDb(task.FullPath, sitedb, null);
                DiskSyncLog.DiskLogManager.Add(task.FullPath, sitedb.WebSite.Id);
            }
        }
Пример #2
0
        public static List <DiskChangeEvent> QueryEvents(List <string> fullpath, Guid SiteId)
        {
            List <DiskChangeEvent> result = new List <DiskChangeEvent>();

            var store = GetSiteStore(SiteId);

            Dictionary <Guid, string> dict = new Dictionary <Guid, string>();

            foreach (var item in fullpath)
            {
                if (!string.IsNullOrWhiteSpace(item))
                {
                    var id = Lib.Security.Hash.ComputeGuidIgnoreCase(item);
                    dict[id] = item;
                }
            }

            var all = store.Filter.SelectAll();

            List <DiskFileLog> deleted = all.FindAll(o => !dict.ContainsKey(o.Id));

            List <string> updated = new List <string>();

            foreach (var item in dict)
            {
                if (System.IO.File.Exists(item.Value))
                {
                    var info = new System.IO.FileInfo(item.Value);

                    if (info != null)
                    {
                        var obj = store.get(item.Key);

                        if (obj == null || info.LastWriteTime > obj.LastModify)
                        {
                            updated.Add(item.Value);
                        }
                    }
                }
            }

            foreach (var item in deleted)
            {
                DiskChangeEvent del = new DiskChangeEvent();
                del.ChangeType = DiskChangeType.Deleted;
                del.FullPath   = item.FullPath;

                result.Add(del);
            }

            foreach (var item in updated)
            {
                DiskChangeEvent update = new DiskChangeEvent();
                update.ChangeType = DiskChangeType.Updated;
                update.FullPath   = item;

                result.Add(update);
            }

            foreach (var item in deleted)
            {
                store.delete(item.Id);
            }

            return(result);
        }
Пример #3
0
        /*
         * 0 = Unknown
         * 1 = No Root Directory
         * 2 = Removable Disk
         * 3 = Local Disk
         * 4 = Network Drive
         * 5 = Compact Disc
         * 6 = RAM Disk
         */

        private void Watcher_EventArrived(object sender, EventArrivedEventArgs e)
        {
            DriveChangedArgs a1 = new DriveChangedArgs();

            /*
             * int iDriveType = 0;
             * ManagementBaseObject mbo, obj;
             * mbo = (ManagementBaseObject)e.NewEvent;
             * obj = (ManagementBaseObject)mbo["TargetInstance"];
             * try
             * { iDriveType = int.Parse(obj["DriveType"].ToString()); }
             * catch
             * { iDriveType = 0; }
             * DriveChangedArgs a1 = new DriveChangedArgs
             * {
             *      DriveLetter = obj["Name"].ToString()
             * };
             * if (obj.ClassPath.ToString().ToLower().Contains("mapped") || iDriveType == 4)
             *      a1.InterfaceType = "MappedDrive";
             * if (obj.ClassPath.ToString().Contains("Win32_DiskDrive") || iDriveType == 4)
             * {
             *      try
             *      {
             *              a1.InterfaceType = obj["InterfaceType"].ToString();
             *      }
             *      catch
             *      {
             *              a1.InterfaceType = "unknown";
             *      }
             *      try
             *      {
             *              a1.DriveLetter = GetDriveLetterFromDisk(obj["Name"].ToString());
             *              if (!USBdic.ContainsKey(obj["Name"].ToString()))
             *              { USBdic.Add(obj["Name"].ToString(), a1.DriveLetter); }
             *      }
             *      catch
             *      {
             *              if (USBdic.ContainsKey(obj["Name"].ToString()))
             *              {
             *                      a1.DriveLetter = USBdic[obj["Name"].ToString()];
             *                      USBdic.Remove(obj["Name"].ToString());
             *              }
             *              else
             *                      a1.DriveLetter = "unknown";
             *      }
             * }
             * switch (mbo.ClassPath.ClassName)
             * {
             *      case "__InstanceCreationEvent":
             *              a1.ChangeType = DriveChangeType.Create;
             *              break;
             *      case "__InstanceDeletionEvent":
             *              a1.ChangeType = DriveChangeType.Remove;
             *              break;
             *      case "__InstanceModificationEvent":
             *              a1.ChangeType = DriveChangeType.MediaChange;
             *              break;
             *      default:
             *              a1.ChangeType = DriveChangeType.Other;
             *              break;
             * }
             */

            try
            {
                DiskChangeEvent.Invoke(a1);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Watchereventarrived(): " + ex);
            }
        }