private void OnFileCreated(object sender, FileEventArgs e) { Task.Factory.StartNew(() => { Status = WatcherStatus.GeneratingFiles; var nameParser = new NameParser(Path.GetFileName(e.File.FullName)); if (!ImageExtensions.Contains(nameParser.Extension, StringComparer.InvariantCultureIgnoreCase)) { Status = WatcherStatus.Watching; return; } if (!_filesCollections.ContainsKey(nameParser.Prefix)) { _filesCollections.Add(nameParser.Prefix, new List <IFile>()); } _filesCollections[nameParser.Prefix].Add(e.File); using (var stream = e.File.ReadFile()) { if (!_filesAnalyzer.IsLast(stream)) { Status = WatcherStatus.Watching; return; } } Status = WatcherStatus.SendingFiles; _filesExporter.Export(_filesCollections[nameParser.Prefix] .OrderBy(file => new NameParser(Path.GetFileName(e.File.FullName)).Number)); _filesCollections.Remove(nameParser.Prefix); Status = WatcherStatus.Watching; }); }
public static OrderType BuildOrderType(WatcherStatus watcherStatus) { switch (watcherStatus) { case WatcherStatus.Buy: return(OrderType.BuyLimit); case WatcherStatus.Sell: return(OrderType.SellMarket); default: throw new ArgumentOutOfRangeException(nameof(watcherStatus), watcherStatus, null); } }
public static OrderType BuildOrderType(WatcherStatus watcherStatus) { switch (watcherStatus) { case WatcherStatus.BUYING: return(OrderType.BUY); case WatcherStatus.SELLING: case WatcherStatus.BOUGHT: return(OrderType.SELL); default: throw new ArgumentOutOfRangeException(nameof(watcherStatus), watcherStatus, null); } }
public void StartListen() { _fileSystemWatcher.FileCreated += OnFileCreated; _fileSystemWatcher.StartWatching(); Status = WatcherStatus.Watching; }