Beispiel #1
0
        public static void StartDiskWatcher(Data.Models.WebSite WebSite)
        {
            if (!WebSite.EnableDiskSync)
            {
                return;
            }

            if (!watchers.ContainsKey(WebSite.Id))
            {
                lock (_lockobject)
                {
                    if (!watchers.ContainsKey(WebSite.Id))
                    {
                        var hash = Lib.Security.Hash.ComputeGuidIgnoreCase(WebSite.DiskSyncFolder);

                        if (PathHash.Contains(hash))
                        {
                            return;
                        }

                        try
                        {
                            IOHelper.EnsureDirectoryExists(WebSite.DiskSyncFolder);
                        }
                        catch (Exception)
                        {
                            return;
                        }

                        FileSystemWatcher watcher = new System.IO.FileSystemWatcher(WebSite.DiskSyncFolder);

                        watcher.IncludeSubdirectories = true;

                        watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.DirectoryName;

                        DiskSyncManager manager = DiskSyncHelper.GetSyncManager(WebSite.Id);

                        watcher.Changed += new FileSystemEventHandler(manager.OnChanged);
                        watcher.Created += new FileSystemEventHandler(manager.OnChanged);
                        watcher.Deleted += new FileSystemEventHandler(manager.OnChanged);
                        watcher.Renamed += new RenamedEventHandler(manager.OnRenamed);

                        watcher.EnableRaisingEvents = true;

                        watchers[WebSite.Id] = watcher;

                        PathHash.Add(hash);
                    }
                }
            }
        }
Beispiel #2
0
 public static DiskSyncManager GetSyncManager(Guid WebSiteId)
 {
     if (!ManagerCache.ContainsKey(WebSiteId))
     {
         lock (_locker)
         {
             if (!ManagerCache.ContainsKey(WebSiteId))
             {
                 var newmanager = new DiskSyncManager(WebSiteId);
                 ManagerCache[WebSiteId] = newmanager;
             }
         }
     }
     return(ManagerCache[WebSiteId]);
 }