Esempio n. 1
0
 public void AddFile(FileModel aFile)
 {
     if (!IsValid)
     {
         return;
     }
     lock (lockObject)
     {
         files[aFile.FileName.ToUpper()] = aFile;
         OnFileAdded?.Invoke(aFile);
     }
 }
Esempio n. 2
0
 private void OnWatcherFileChanged(object source, FileSystemEventArgs e)
 {
     log.Info($"File: {e.FullPath} {e.ChangeType}");
     if (e.ChangeType == WatcherChangeTypes.Deleted)
     {
         var status = StatusList.FirstOrDefault(s => s.SourceFile == e.FullPath);
         if (status != null && status.Status == StatusEnum.NotSynched)
         {
             StatusList.Remove(status);
             OnFileDeleted?.Invoke(this, e);
         }
     }
     else if (e.ChangeType == WatcherChangeTypes.Created)
     {
         OnFileAdded?.Invoke(this, e);
     }
 }
Esempio n. 3
0
        public FileTransferManager()
        {
            _watcher          = new FileSystemWatcher(Preferences.SyncDirectory);
            _watcher.Created += (o, e) => OnFileAdded?.Invoke(this, e.FullPath);
            _watcher.Renamed += (o, e) => OnFileAdded?.Invoke(this, e.FullPath);
            _watcher.Deleted += (o, e) => OnFileDeleted?.Invoke(this, e.FullPath);
            Task.Run(async() =>
            {
                while (true)
                {
                    try
                    {
                        _watcher.EnableRaisingEvents = true;
                        return;
                    }
                    catch { }
                    await Task.Delay(500);
                    _watcher.Path = Preferences.SyncDirectory;
                }
            });

            _manager = BackgroundCopyManager.Connect();

            if (ConfigurationManager.AppSettings.AllKeys.Contains(Preferences.FileServerUriKey))
            {
                Preferences.FileServerUri = ConfigurationManager.AppSettings[Preferences.FileServerUriKey];
            }

            _downloadOperations = new ObservableDictionary <string, ITransferOperation>();
            _uploadOperations   = new ObservableDictionary <string, ITransferOperation>();
            TransferOperations  = new ConcatenatedObservableDictionary <string, ITransferOperation>(_downloadOperations, _uploadOperations);

            _timerTransfer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(500)
            };
            _timerTransfer.Tick += TimerTransfer_Tick;
            _timerTransfer.Start();
        }