private async void Window_Loaded(object sender, RoutedEventArgs e) { async Task <IClient> CreateClient() { var exists = File.Exists(SettingsPath); var settingsFile = exists ? Some(SettingsPath) : None <string>(); var storage = new SqliteStorage($"{nameof(Chatter)}.db"); var dispatcher = new SynchronizationDispatcher(TaskScheduler.FromCurrentSynchronizationContext(), Application.Current.Dispatcher); var result = await TryAsync(() => LinkFactory.CreateClientAsync(dispatcher, storage, settingsFile)).NoticeOnErrorAsync(); var client = result.UnwrapOrDefault(); if (exists == false && client != null) { client.Profile.Name = $"{Environment.UserName}@{Environment.MachineName}"; } if (result.IsError()) { Application.Current.Shutdown(); } return(client); } this.IsEnabled = false; using var _0 = Disposable.Create(() => this.IsEnabled = true); this.client = App.CurrentClient ?? await CreateClient(); this.DataContext = this.client?.Profile; }
private async void Window_Opened(object sender, EventArgs e) { this.AddHandler(Button.ClickEvent, Button_Click); async Task <IClient> CreateClient() { var exists = File.Exists(SettingsPath); var settingsFile = exists ? Some(SettingsPath) : None <string>(); var storage = new SqliteStorage($"{nameof(Chatter)}.db"); var dispatcher = new SynchronizationDispatcher(Dispatcher.UIThread); var result = await TryAsync(() => LinkFactory.CreateClientAsync(dispatcher, storage, settingsFile)).NoticeOnErrorAsync(); var client = result.UnwrapOrDefault(); if (exists == false && client != null) { client.Profile.Name = $"{Environment.UserName}@{Environment.MachineName}"; } if (result.IsError()) { this.Close(); } return(client); } this.IsEnabled = false; using var _0 = Disposable.Create(() => this.IsEnabled = true); client = App.CurrentClient ?? await CreateClient(); DataContext = client?.Profile; }
private void AttachBrowser() { lock (this.syncObj) { foreach (InternetExplorer ie in IE.FindAll()) { if (this.browserList.Contains(ie)) { continue; } this.AttachWindow(((IHTMLDocument2)ie.Document).parentWindow); ie.DocumentComplete += delegate(object disp, ref object url) { if (false == this.IsRecording) { return; } IHTMLDocument2 doc = ie.Document; Uri u = new Uri(doc.url); SynchronizationDispatcher.Invoke(() => { do { Thread.Sleep(500); }while (!IE.IsReadyStateComplete(ie)); //this.OnCommandRecording("assertTitle", doc.title); //this.OnCommandRecording("assertLocation", u.AbsolutePath); this.AttachWindow(((IHTMLDocument2)ie.Document).parentWindow); }); }; } } }
public void OnCommandRecording(string command, string target = "", string value = "") { Log.Logger.DebugFormat("command = {0}, {1}, {2}", command, target, value); if (false == this.IsRecording) { return; } if (null == this.CommandRecording) { return; } if (string.IsNullOrWhiteSpace(command)) { throw new ArgumentNullException("command"); } SynchronizationDispatcher.Invoke(() => { this.CommandRecording(this, new CommandRecorderEventArgs(command, target, value)); }); }