public async Task Exception() { learnedClassifier.Setup(item => item.Classify(It.IsAny <FileInfo>())).Throws <NullReferenceException>(); var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data"); ObservableCollection <MonitoringResult> target = new ObservableCollection <MonitoringResult>(); await instance.Start(target, TimeSpan.FromMilliseconds(1), CancellationToken.None); subject.OnNext(new FileSystemEventArgs(WatcherChangeTypes.Created, path, "x.pdf")); Thread.Sleep(500); Assert.AreEqual(0, target.Count); }
/// <summary> /// Constructor. If the file is persistent then register a Watcher /// <para/>- Initialize file system watcher /// </summary> /// <param name="fullName"></param> /// <param name="isChanged">Default=true</param> /// <param name="sqlTabPagesCntrl"></param> public SqlFile(SqlTabPagesCntrl sqlTabPagesCntrl, string fullName, bool isChanged = true) { _sqlTabPagesCntrl = sqlTabPagesCntrl; InitTabPageCaption(fullName, isChanged); ReadTime = DateTime.Now; // create FileMonitor _fileMonitor = new FileMonitor(_fullName); _fileMonitor.Change += OnChanged; if (IsPersistant) { _fileMonitor.Start(); } }
public void EventAboutNewFilesFired() { var fileMonitor = new FileMonitor(_tempDir, TimeSpan.FromMilliseconds(1), DateTime.MinValue); var eventReceived = new ManualResetEventSlim(false); NewFilesAppearedEventArgs eventArgs = null; fileMonitor.NewFilesAppeared += (sender, args) => { eventArgs = args; eventReceived.Set(); }; var fileName = Path.Combine(_tempDir, "Test.xml"); fileMonitor.Start(); using (File.Create(fileName)){} eventReceived.Wait(1000); CollectionAssert.AreEqual(new[]{fileName}, eventArgs.Files); }
public async Task TestMonitoring() { ObservableCollection <MonitoringResult> target = new ObservableCollection <MonitoringResult>(); await monitor.Start(target, TimeSpan.FromMilliseconds(1), CancellationToken.None).ConfigureAwait(false); Thread.Sleep(500); Assert.AreEqual(0, target.Count); var file = Path.Combine(path, "Test.pdf"); File.WriteAllText(file, "Test"); Thread.Sleep(500); Assert.AreEqual(1, target.Count); var targetDir = Path.Combine(TestContext.CurrentContext.TestDirectory, Guid.NewGuid().ToString()); Path.Combine(targetDir, "Out").EnsureDirectoryExistence(); target[0].ApplyChange(new DirectoryInfo(targetDir)); Assert.AreEqual(0, target.Count); File.WriteAllText(file, "Test"); Thread.Sleep(500); Assert.AreEqual(1, target.Count); }
static void Main(string[] args) { try { Console.WriteLine("MakeLove Automatic LOVE Build System"); Console.WriteLine("App Version {0}", typeof(Program).Assembly.GetName().Version.ToString()); Console.WriteLine("Core Version {0}", typeof(FileMonitor).Assembly.GetName().Version.ToString()); Console.WriteLine("Written by InstilledBee"); var monitor = new FileMonitor(ConfigHelper.SourcePath); monitor.OnFileChange += Monitor_OnFileChange; monitor.Start(); } catch (Exception ex) { Console.WriteLine("Unable to start application: {0}", ex.Message); } finally { Console.WriteLine("Press any key to quit."); Console.ReadKey(); } }
public MainWindow( ConfigModel configApp, ICollection <Card> allCards, MainWindowVM viewModel, ProcessMonitor processMonitor, LogFileZipper zipper, ServerApiCaller api, StartupShortcutManager startupManager, LogSplitter logSplitter, MtgaResourcesLocator resourcesLocator, FileMonitor fileMonitor, DraftCardsPicker draftHelper, ReaderMtgaOutputLog readerMtgaOutputLog, InGameTracker2 inMatchTracker, ExternalProviderTokenManager tokenManager, PasswordHasher passwordHasher, CacheSingleton <Dictionary <string, DraftRatings> > draftRatings, DraftHelperRunner draftHelperRunner) { // Set the config model reference ConfigModel = configApp; Reader = readerMtgaOutputLog; processMonitor.OnProcessMonitorStatusChanged += OnProcessMonitorStatusChanged; Zipper = zipper; Api = api; StartupManager = startupManager; LogSplitter = logSplitter; ResourcesLocator = resourcesLocator; FileMonitor = fileMonitor; fileMonitor.OnFileSizeChangedNewText += OnFileSizeChangedNewText; DraftHelper = draftHelper; //this.logProcessor = logProcessor; InGameTracker = inMatchTracker; TokenManager = tokenManager; PasswordHasher = passwordHasher; DraftRatings = draftRatings; DraftHelperRunner = draftHelperRunner; ResourcesLocator.LocateLogFilePath(ConfigModel); ResourcesLocator.LocateGameClientFilePath(ConfigModel); fileMonitor.SetFilePath(ConfigModel.LogFilePath); // Set the view model MainWindowVM = viewModel; // Set the data context to the view model DataContext = MainWindowVM; InitializeComponent(); WelcomeControl.Init(tokenManager); PlayingControl.Init(MainWindowVM); StatusBarTop.Init(this, MainWindowVM); ReadyControl.Init(ConfigModel.GameFilePath); DraftingControl.Init(allCards, MainWindowVM.DraftingVM); DraftingControl.SetPopupRatingsSource(ConfigModel.ShowLimitedRatings, ConfigModel.ShowLimitedRatingsSource); processMonitor.Start(new System.Threading.CancellationToken()); FileMonitor.Start(new System.Threading.CancellationToken()); var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(200) }; timer.Tick += (sender, e) => { MainWindowVM.SetCardsDraftFromBuffered(); MainWindowVM.SetCardsInMatchTrackingFromBuffered(); }; timer.Start(); var timerTokenRefresh = new DispatcherTimer { Interval = TimeSpan.FromMinutes(9) }; timerTokenRefresh.Tick += (sender, e) => { RefreshAccessToken(); }; timerTokenRefresh.Start(); }
/// <summary> /// Complete constructor /// </summary> public MainWindow(MainWindowVM viewModel) { mapper = viewModel.Mapper; ViewModel = viewModel; // Set the main window view model actions ViewModel.UploadLogAction = UploadLogAction; ViewModel.ShowOptionsAction = ShowOptionsWindow; ViewModel.LaunchArenaAction = LaunchArenaAction; ViewModel.ValidateUserAction = ValidateUserAction; // Set the resource locator ResourcesLocator = viewModel.ResourcesLocator; // Set the problem action ResourcesLocator.SetProblem = ViewModel.SetProblem; // Locate the log file ResourcesLocator.LocateLogFilePath(ViewModel.Config); // Locate the game path ResourcesLocator.LocateGameClientFilePath(ViewModel.Config); // Set the reference to the draft helper DraftHelperRunner = viewModel.DraftHelperRunner; Reader = viewModel.ReaderMtgaOutputLog; Api = viewModel.Api; StartupManager = viewModel.StartupManager; FileMonitor = viewModel.FileMonitor; FileMonitor.OnFileSizeChangedNewText += OnFileSizeChangedNewText; DraftHelper = viewModel.DraftHelper; //this.logProcessor = logProcessor; InGameTracker = viewModel.InMatchTracker; TokenManager = viewModel.TokenManager; PasswordHasher = viewModel.PasswordHasher; DraftRatings = viewModel.DraftRatings; FileMonitor.SetFilePath(ViewModel.Config.LogFilePath); // Set the data context to the view model DataContext = ViewModel; InitializeComponent(); PlayingControl.Init(ViewModel); DraftingControl.Init(ViewModel.DraftingVM, ViewModel.Config.LimitedRatingsSource); DraftingControl.SetPopupRatingsSource(ViewModel.Config.ShowLimitedRatings, ViewModel.Config.LimitedRatingsSource); // Set the process monitor status changed action viewModel.ProcessMonitor.OnProcessMonitorStatusChanged = OnProcessMonitorStatusChanged; // Start the process monitor without awaiting the task completion _ = viewModel.ProcessMonitor.Start(new System.Threading.CancellationToken()); // Start the file monitor without awaiting the task completion _ = FileMonitor.Start(new System.Threading.CancellationToken()); var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(200) }; timer.Tick += (sender, e) => { ViewModel.DraftingVM.SetCardsDraftFromBuffered(); ViewModel.InMatchState.SetInMatchStateFromBuffered(); }; timer.Start(); var timerTokenRefresh = new DispatcherTimer { Interval = TimeSpan.FromMinutes(9) }; timerTokenRefresh.Tick += (sender, e) => { RefreshAccessToken(); }; timerTokenRefresh.Start(); }
private void Start(object sender, RoutedEventArgs e) { var t = new Task(() => _monitor.Start()); t.Start(); }