protected FileBasedFunctionProvider(string name, string folder)
        {
            _name = name;

            VirtualPath  = folder;
            PhysicalPath = PathUtil.Resolve(VirtualPath);

            if (!C1Directory.Exists(PhysicalPath))
            {
                return;
            }

            string folderToWatch = PhysicalPath;

            try
            {
                if (ReparsePointUtils.DirectoryIsReparsePoint(folderToWatch))
                {
                    folderToWatch = ReparsePointUtils.GetDirectoryReparsePointTarget(folderToWatch);
                }

                _watcher = new C1FileSystemWatcher(folderToWatch, "*")
                {
                    IncludeSubdirectories = true
                };

                _watcher.Created += Watcher_OnChanged;
                _watcher.Deleted += Watcher_OnChanged;
                _watcher.Changed += Watcher_OnChanged;
                _watcher.Renamed += Watcher_OnChanged;

                _watcher.EnableRaisingEvents = true;
            }
            catch (Exception ex)
            {
                Log.LogWarning(LogTitle, "Failed to create a file system watcher for path '{0}'", folderToWatch);
                Log.LogWarning(LogTitle, ex);
            }
        }
Пример #2
0
        public MasterPagePageTemplateProvider(string name, string templatesDirectoryVirtualPath, string addNewTemplateLabel, Type addNewTemplateWorkflow)
        {
            _providerName = name;
            _templatesDirectoryVirtualPath = templatesDirectoryVirtualPath;
            _templatesDirectory            = PathUtil.Resolve(_templatesDirectoryVirtualPath);

            AddNewTemplateLabel    = addNewTemplateLabel;
            AddNewTemplateWorkflow = addNewTemplateWorkflow;

            Verify.That(C1Directory.Exists(_templatesDirectory), "Folder '{0}' does not exist", _templatesDirectory);

            string folderToWatch = _templatesDirectory;

            try
            {
                if (ReparsePointUtils.DirectoryIsReparsePoint(folderToWatch))
                {
                    folderToWatch = ReparsePointUtils.GetDirectoryReparsePointTarget(folderToWatch);
                }

                _watcher = new C1FileSystemWatcher(folderToWatch, FileWatcherMask)
                {
                    IncludeSubdirectories = true
                };

                _watcher.Created += Watcher_OnChanged;
                _watcher.Deleted += Watcher_OnChanged;
                _watcher.Changed += Watcher_OnChanged;
                _watcher.Renamed += Watcher_OnChanged;

                _watcher.EnableRaisingEvents = true;
            }
            catch (Exception ex)
            {
                Log.LogWarning(LogTitle, "Failed to create a file system watcher for directory '{0}'. Provider: {1}", folderToWatch, name);
                Log.LogWarning(LogTitle, ex);
            }
        }