コード例 #1
0
		private async void CheckLogDirectory()
		{
			if (logDirectory == null | logDirectory == "")
			{
				MessageBox.Show("Error: No log directory is specified, please do so before attempting to go on duty.");
				return;
			}

			if (!Directory.Exists(Settings.Default.NetLogPath))
			{
				MessageBox.Show("Error: Couldn't find E:D Netlog directory: " + Settings.Default.NetLogPath +
								". Please ensure that it is correct in Settings.");
				return;
			}

			StatusDisplay.Text = "Beginning to watch " + logDirectory + " for changes...";
			if (watcher == null)
			{
				watcher = new FileSystemWatcher();
				watcher.Path = logDirectory;
				watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName |
										NotifyFilters.DirectoryName | NotifyFilters.Size;
				watcher.Filter = "*.log";
				watcher.Changed += OnChanged;
				watcher.Created += OnChanged;
				watcher.Deleted += OnChanged;
				watcher.Renamed += OnRenamed;
				watcher.EnableRaisingEvents = true;
			}

			DirectoryInfo tempDir = new DirectoryInfo(logDirectory);
			logFile = (from f in tempDir.GetFiles("*.log") orderby f.LastWriteTime descending select f).First();
			AppendStatus("Started watching file " + logFile.FullName);
			CheckClientConn(logFile.FullName);
			List<KeyValuePair<string, string>> logindata = new List<KeyValuePair<string, string>>();
			logindata.Add(new KeyValuePair<string, string>("email", "*****@*****.**"));
			logindata.Add(new KeyValuePair<string, string>("password", "password"));
			apworker = new APIWorker();
			AppendStatus("Call to APIworker returning :" + apworker.connectAPI());
			object col = await apworker.sendAPI("login", logindata);
			AppendStatus("Login returned: " + col);
			apworker.InitWs();
			apworker.OpenWs();
			ReadLogfile(logFile.FullName);
			apworker.ws.MessageReceived += websocketClient_MessageReceieved;
			myTravelLog = new List<TravelLog>();
		}