private void ShowDisplay(FileChanged changeEvt)
 {
     foreach (var change in changeEvt.Changes)
     {
         Console.WriteLine($"{change}");
     }
 }
Esempio n. 2
0
        private void FileChangedHandler(string filename, DateTime when)
        {
            var lsfile = FindLspFile(filename, when);

            lsfile?.OnFileChanged(lsfile, when);
            FileChanged?.Invoke(lsfile, when);
        }
Esempio n. 3
0
        private void RecursivelyChangeTimeStamp(Folder folder, DateTime newDt)
        {
            // Change this folder.
            var diBefore = new DirectoryInfo(folder.FolderInfo.FullName);

            folder.FolderInfo.CreationTime   = newDt;
            folder.FolderInfo.LastAccessTime = newDt;
            folder.FolderInfo.LastWriteTime  = newDt;

            DirectoryChanged?.Invoke(diBefore, folder.FolderInfo);

            // Change files in this folder.
            foreach (var file in folder.Files)
            {
                var fiBefore = new FileInfo(file.FullName);

                file.CreationTime   = newDt;
                file.LastAccessTime = newDt;
                file.LastWriteTime  = newDt;

                FileChanged.Invoke(fiBefore, file);
            }

            // Change files in subfolders.
            foreach (var subfolder in folder.SubFolders)
            {
                RecursivelyChangeTimeStamp(subfolder, newDt);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Fires all associated FileChanged delegates.
 /// </summary>
 public void OnChanged(object sender, FileSystemEventArgs e)
 {
     foreach (FileSystemEventHandler handler in FileChanged.GetInvocationList())
     {
         handler.Invoke(sender, e);
     }
 }
        public void Dispose()
        {
            var previousFilePath = FilePath;

            DisposeInternal();
            FileChanged?.Invoke(this, new FileChangedEventArgs(null, previousFilePath));
        }
Esempio n. 6
0
        private void OnChanged(object source, FileSystemEventArgs e)
        {
            if (FileChanged != null)
            {
                DateTime lastWriteTime = new DateTime();
                if (e.FullPath.IsFile())
                {
                    lastWriteTime = new FileInfo(e.FullPath).LastWriteTime;
                }
                else if (e.FullPath.IsFolder())
                {
                    lastWriteTime = new DirectoryInfo(e.FullPath).LastWriteTime;
                }

                if (ChangeTimes.ContainsKey(e.FullPath))
                {
                    if (lastWriteTime - ChangeTimes[e.FullPath] > TimeSpan.FromMilliseconds(1))
                    {
                        FileChanged.Invoke(e.FullPath);
                    }
                }
                else
                {
                    FileChanged.Invoke(e.FullPath);
                }

                ChangeTimes[e.FullPath] = lastWriteTime;
            }
        }
Esempio n. 7
0
 private void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
 {
     if (FileChanged != null)
     {
         FileChanged.Invoke();
     }
 }
Esempio n. 8
0
        public void FSWTest()
        {
            string tempDir = Path.GetTempPath();
            string file1   = Path.Combine(tempDir, "test1.meeptest");

            var Watcher = new FileChanges
            {
                Path   = tempDir,
                Filter = "*.meeptest"
            };

            Message   lastReceived = null;
            Exception lastEx       = null;

            using (IDisposable subscription = Watcher.Pipeline.Subscribe <Message>(
                       msg => lastReceived = msg,
                       ex => lastEx = ex,
                       () => Console.WriteLine("Pipeline completed")))
            {
                File.Create(file1);
                System.Threading.Thread.Sleep(300);
                Assert.NotNull(lastReceived);
                Assert.Null(lastEx);

                Assert.IsType(typeof(FileChanged), lastReceived);
                FileChanged change = lastReceived as FileChanged;
                Assert.Equal(file1, change.FullPath);
                Assert.Equal(WatcherChangeTypes.Created, change.ChangeType);
            }


            File.Delete(file1);
        }
Esempio n. 9
0
        private void OnFileSystemItemChanged(object sender, FileSystemEventArgs e)
        {
            var  path        = e.FullPath;
            bool isDirectory = Path.GetExtension(path) == "";

            FileEventArgs eventArgs = new FileEventArgs()
            {
                FullPath = e.FullPath,
                ItemType = isDirectory ? FileEventItemType.Folder : FileEventItemType.File
            };

            switch (e.ChangeType)
            {
            case WatcherChangeTypes.Changed:
                eventArgs.Operation = FileEventOperation.Changed;
                break;

            case WatcherChangeTypes.Created:
                eventArgs.Operation = FileEventOperation.Created;
                if (isDirectory)
                {
                    _folders.Add(path);
                }
                else
                {
                    _files.Add(path);
                }
                break;

            case WatcherChangeTypes.Deleted:
                eventArgs.Operation = FileEventOperation.Deleted;
                if (isDirectory)
                {
                    _folders.Remove(path);
                }
                else
                {
                    _files.Remove(path);
                }
                break;

            case WatcherChangeTypes.Renamed:
                eventArgs.Operation = FileEventOperation.Renamed;
                var args = (RenamedEventArgs)e;
                if (isDirectory)
                {
                    _folders.Remove(args.OldFullPath);
                    _folders.Add(path);
                }
                else
                {
                    _files.Remove(args.OldFullPath);
                    _files.Add(path);
                }
                break;
            }

            FileChanged?.Invoke(this, eventArgs);
        }
Esempio n. 10
0
 private void OnChangedInternal(object source, FileSystemEventArgs e)
 {
     // Ignoring temp files from apps like visual studio
     if (!ShouldIgnoreFile(e.FullPath))
     {
         FileChanged?.Invoke(e.FullPath);
     }
 }
        public virtual void OnFileChanged(string fileName)
        {
            FileChangedEventArgs e = new FileChangedEventArgs {
                FileName = fileName
            };

            FileChanged?.Invoke(this, e);
        }
        private void Watcher_Changed(object sender, FileSystemEventArgs e)
        {
            if (ExceceptionPaths.Contains(e.FullPath))
            {
                return;
            }

            FileChanged?.Invoke(e.FullPath);
        }
Esempio n. 13
0
 protected virtual void OnFileChanged(FileChangedEventArgs args)
 {
     args.FileInfo.Refresh();
     if (args.FileInfo.LastWriteTimeUtc > _lastUpdate)
     {
         _lastUpdate = args.FileInfo.LastWriteTimeUtc;
         FileChanged?.Invoke(this, args);
     }
 }
        /// <summary>
        /// начинает контроль за заданной папкой
        /// </summary>
        /// <param name="path">путь к папке</param>
        public void StartControl(object path)
        {
            string _path = path as string;

            controlDirectorySize = DirSize(new DirectoryInfo(_path));
            fileList             = InitFileList(_path);
            directoryList        = InitDirectoryList(_path);
            while (true)
            {
                if (controlDirectorySize != DirSize(new DirectoryInfo(_path))) // если размер папки изменился
                {
                    if (!CheckDirectoryChange(_path))                          // если в контролируемую директорию не было добавлено или удалено ПАПКУ
                    {
                        List <File> currentlist = InitFileList(_path);
                        if (fileList.Count < currentlist.Count) //если файл был добавлен
                        {
                            foreach (var item in currentlist)
                            {
                                if (!ContainsItem(fileList, item))
                                {
                                    FileAdded.Invoke(item);
                                    if (Synchronaizer.IsDisableChangeFolder)
                                    {
                                        System.IO.File.Delete(item.Path);
                                        FileRemoved.Invoke(item);
                                    }
                                }
                            }
                        }
                        else if (fileList.Count > currentlist.Count) // если файл был удален
                        {
                            foreach (var item in fileList)
                            {
                                if (!ContainsItem(currentlist, item))
                                {
                                    FileRemoved.Invoke(item);
                                }
                            }
                        }

                        else // размер файла был изменен
                        {
                            for (int i = 0; i < currentlist.Count; i++)
                            {
                                if (fileList[i].Size != currentlist[i].Size) // дизнаемся размер которого файла было изменено
                                {
                                    FileChanged.Invoke(fileList[i]);
                                }
                            }
                        }
                        controlDirectorySize = DirSize(new DirectoryInfo(_path));
                        fileList             = InitFileList(_path);
                    }
                }
                Thread.Sleep(CheckInterval); // интервал проверки
            }
        }
Esempio n. 15
0
            int IVsFreeThreadedFileChangeEvents2.FilesChanged(uint cChanges, string[] rgpszFile, uint[] rggrfChange)
            {
                for (var i = 0; i < cChanges; i++)
                {
                    FileChanged?.Invoke(this, rgpszFile[i]);
                }

                return(VSConstants.S_OK);
            }
Esempio n. 16
0
        public static async Task ChangeFile(StorageFile file)
        {
            var data = await file.OpenAsync(FileAccessMode.Read);

            BitmapImage image = new BitmapImage();

            image.SetSource(data);
            FileChanged?.Invoke(null, new ImageFileChangeEventArgs(data, image));
        }
Esempio n. 17
0
            int IVsFreeThreadedFileChangeEvents2.DirectoryChangedEx2(string pszDirectory, uint cChanges, string[] rgpszFile, uint[] rggrfChange)
            {
                for (int i = 0; i < cChanges; i++)
                {
                    FileChanged?.Invoke(this, rgpszFile[i]);
                }

                return(VSConstants.S_OK);
            }
Esempio n. 18
0
        private void FireEvent(string path)
        {
            FileChanged evt = Changed;

            if (evt != null)
            {
                evt(path);
            }
        }
Esempio n. 19
0
        private Task <Unit> OnChanged(FileSystemEventArgs eventArgs, CancellationToken cancellationToken)
        {
            _logger.LogTrace("Publishing changed event");
            var @event = new FileChanged {
                Path = eventArgs.Name
            };

            return(Publish(_publisher, @event, cancellationToken));
        }
Esempio n. 20
0
        void Enter(FileSystemInfo obj)
        {
            var d = obj as DirectoryInfo;

            if (d != null)
            {
                m_source.Current = d;
            }
            FileChanged?.Invoke(obj);
        }
 void fileWatcher_Changed(object sender, FileSystemEventArgs e)
 {
     ThreadManager.invoke(() =>
     {
         if (FileChanged != null)
         {
             FileChanged.Invoke(e.Name, false);
         }
     });
 }
Esempio n. 22
0
        protected virtual bool OnFileChanged(TranslationFile selectedFile)
        {
            if (FileChanged != null)
            {
                var cancel = FileChanged.Invoke(selectedFile);
                return(cancel);
            }

            return(false);
        }
Esempio n. 23
0
 private void fire(MFile kind, string name, int total, int progressed)
 {
     FileChanged?.Invoke(new DownloadFileChangedEventArgs()
     {
         FileKind            = kind,
         FileName            = name,
         TotalFileCount      = total,
         ProgressedFileCount = progressed
     });
 }
Esempio n. 24
0
        public void Load(string path)
        {
            _path  = path;
            _files = LoadData(_path);

            FilesChanged?.Invoke(this, new FilesChangedEventArgs(_files));

            foreach (var file in _files)
            {
                FileChanged?.Invoke(this, new FileChangedEventArgs(file));
            }
        }
Esempio n. 25
0
        public void RemoveTag(string fileName, string tag)
        {
            var file = GetFile(fileName);

            if (file.Tags.Contains(tag))
            {
                file.Tags.Remove(tag);
            }

            SaveData(_path, _files);
            FileChanged?.Invoke(this, new FileChangedEventArgs(file));
        }
        protected virtual bool OnFileChanged(TranslationFile selectedFile)
        {
            if (FileChanged != null)
            {
                var cancel = FileChanged.Invoke(selectedFile);
                tvGameFiles.BeforeSelect -= tvGameFiles_BeforeSelect;
                tvGameFiles.Focus();
                tvGameFiles.BeforeSelect += tvGameFiles_BeforeSelect;
                return(cancel);
            }

            return(false);
        }
Esempio n. 27
0
        static void Main(string[] args)
        {
            Console.WriteLine("Type the path of the file");
            var filePath = Console.ReadLine();

            var fileObserver        = new FileObservable(filePath);
            var fileChangedObserver = new FileChanged();

            fileObserver.Subscribe(fileChangedObserver);

            Console.WriteLine("Start edditing your file");
            Console.ReadLine();
        }
Esempio n. 28
0
        public DBFileWatch(string filePath = @"C:\Users\kenne\Documents\Dev Projects\TestDirectory", string filefilter = "*?.db")
        {
            var watcher = new FileSystemWatcher
            {
                Path = filePath,
                IncludeSubdirectories = true,
                NotifyFilter          = NotifyFilters.LastWrite,
                Filter = filefilter,
                EnableRaisingEvents = true
            };

            watcher.Changed += (sender, args) => { FileChanged?.Invoke(args.FullPath); };
        }
Esempio n. 29
0
        public CMLauncher(MinecraftPath mc)
        {
            this.MinecraftPath = mc;

            GameFileCheckers = new FileCheckerCollection();
            FileDownloader   = new AsyncParallelDownloader();
            VersionLoader    = new DefaultVersionLoader(MinecraftPath);

            pFileChanged = new Progress <DownloadFileChangedEventArgs>(
                e => FileChanged?.Invoke(e));
            pProgressChanged = new Progress <ProgressChangedEventArgs>(
                e => ProgressChanged?.Invoke(this, e));
        }
Esempio n. 30
0
        private void NotifyFileChanged()
        {
            string fileName;

            if (Path.Equals(string.Empty))
            {
                fileName = string.Empty;
            }
            else
            {
                fileName = new System.IO.FileInfo(Path).Name;
            }
            FileChanged?.Invoke(fileName);
        }
Esempio n. 31
0
 public void SubscribeToChanges(FileChanged changed)
 {
 }
Esempio n. 32
0
		public void SubscribeToChanges (FileChanged changed)
		{
            _subscribers.Add(changed);
		}