Пример #1
0
        private static void OnFileCreated(FileSystemEventArgs e, WatchedLocationActionType actionType)
        {
            try {
                //TODO: fix this
                //NOTE: this (sometimes) will not work when downloading the same file right after it was deleted
                //at least for ~70MB file
                //File.Delete() sadly just marks file to be deleted and calling File.Exists() right after File.Delete() will return true (at least when e.g. downloading file in the browser)
                if (!File.Exists(e.FullPath))
                {
                    //HACKS, ALL THE WAY
                    logger.Debug($"Waiting for file {e.FullPath} to be creeated!");
                    Thread.Sleep(1000);
                    OnFileCreated(e, actionType);
                }

                switch (actionType)
                {
                case WatchedLocationActionType.Nothing:
                    break;

                case WatchedLocationActionType.Delete:
                    if (File.Exists(e.FullPath))
                    {
                        logger.Debug($"File {e.FullPath} created! Removing the file.");
                        File.Delete(e.FullPath);
                        logger.Debug($"File {e.FullPath} removed!");
                    }
                    break;
                }
            }
            catch (Exception exc) {
                logger.Debug($"Exception occured in the OnFileCreated event! {exc}");
            }
        }
        public void AddWatchedLocationAndFile(string locationPath, string fileName, WatchedLocationActionType actionType)
        {
            try {
                var watchedLocation = new WatchedLocation {
                    Id         = Guid.NewGuid(),
                    Path       = locationPath,
                    FileName   = fileName,
                    ActionType = actionType
                };

                this.repository.Save(watchedLocation);
            }
            catch (Exception e) {
                this.logger.Debug($"Failed to add new watched location! Path '{locationPath}' - file name {fileName}. {e}");
                throw;
            }
        }
Пример #3
0
 private void ActionsCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     this.Action = (WatchedLocationActionType)this.ActionsCombobox.SelectedItem;
 }
Пример #4
0
 public void AddLocationToObservedLocationsList(string path, string fileName, WatchedLocationActionType actionType)
 {
     this.locationsListService.AddWatchedLocationAndFile(path, fileName, actionType);
 }