public async Task ReadSubFolders(TreeNode rootFolder) { if (!(rootFolder.Tag is IMailFolder rootMailFolder)) { return; } var serverFolders = await rootMailFolder.GetSubfoldersAsync(); foreach (var serverFolder in serverFolders) { try { if (!serverFolder.IsOpen) { await serverFolder.OpenAsync(FolderAccess.ReadWrite); } } catch (Exception ex) { NewLogMessage?.Invoke(this, $"{DateTime.Now}: ReadMails Exception: {ex.Message}."); } var nodeTree = await CreateOrUppdate(serverFolder); rootFolder.Nodes.Add(nodeTree); serverFolder.MessageFlagsChanged += ServerFolder_MessageFlagsChanged; serverFolder.CountChanged += ServerFolder_CountChanged; serverFolder.Opened += ServerFolder_Opened; serverFolder.UnreadChanged += ServerFolder_UnreadChanged; await ReadSubFolders(nodeTree); } }
private void OnClientDisconnected(object sender, DisconnectedEventArgs e) { ConnectionState(this, false); NewLogMessage?.Invoke(this, $"{DateTime.Now}: Disconected."); if (!e.IsRequested) { ReconnectAsync(); } }
private void ServerFolder_Opened(object sender, EventArgs e) { if (sender is IMailFolder mailFolder) { NewLogMessage?.Invoke(this, $"{DateTime.Now}: {mailFolder.FullName} folder openned"); } else { NewLogMessage?.Invoke(this, $"{DateTime.Now}: Uncnown folder openned"); } }
private void ServerFolder_UnreadChanged(object sender, EventArgs e) { NewLogMessage?.Invoke(this, $"{DateTime.Now}: New Unread message."); if (sender is IMailFolder rootMailFolder) { UpdateForm(this, new Action(() => { CreateOrUppdate(rootMailFolder).ContinueWith((t) => ReadMails(t.Result)); })); } }
private void ServerFolder_MessageFlagsChanged(object sender, MessageFlagsChangedEventArgs e) { done?.Cancel(); NewLogMessage?.Invoke(this, $"{DateTime.Now}: Message Number: {e.Index} flags changed."); if (sender is IMailFolder rootMailFolder) { UpdateForm(this, new Action(() => { CreateOrUppdate(rootMailFolder).ContinueWith((t) => ReadMails(t.Result)); })); } }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { string s; if (formatter != null) { s = string.Format("Level:{0}\t\t{1}", logLevel, formatter(state, exception)); } else { s = string.Format("Level:{0}\t\t{1}", logLevel, state?.ToString(), exception?.Message); } NewLogMessage?.Invoke(this, s); }
public async Task ReconnectAsync() { // TODO: SSL validation Client.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; try { await Client.ConnectAsync(host, port, options); await Client.AuthenticateAsync(Credentials); } catch (Exception ex) { NewLogMessage?.Invoke(this, $"{DateTime.Now}: {ex.Message}"); } if (Client.Capabilities.HasFlag(ImapCapabilities.UTF8Accept)) { await Client.EnableUTF8Async(); } if (folders == null) { folders = new Dictionary <IMailFolder, TreeNode>(); var folder = Client.GetFolder(Client.PersonalNamespaces[0]); rootNode = new TreeNode() { Name = "root", Text = host, Tag = folder }; folders.Add(folder, rootNode); Stopwatch stopWhatch = new Stopwatch(); stopWhatch.Start(); await ReadSubFolders(rootNode); stopWhatch.Stop(); NewLogMessage?.Invoke(this, $"{DateTime.Now}: {host} folders readed by {stopWhatch.ElapsedMilliseconds} ms."); UpdateFoldersTree?.Invoke(this, rootNode); } }
public async Task WaitForNewMessagesAsync() { if (Client.Capabilities.HasFlag(ImapCapabilities.Idle)) { NewLogMessage?.Invoke(this, $"{DateTime.Now}: Idle Mode."); using (done = new CancellationTokenSource(new TimeSpan(0, 9, 0))) await Client.IdleAsync(done.Token, cancel.Token); NewLogMessage?.Invoke(this, $"{DateTime.Now}: Normal Mode."); } else { NewLogMessage?.Invoke(this, $"{DateTime.Now}: Idle Mode."); await Task.Delay(new TimeSpan(0, 1, 0), cancel.Token); await Client.NoOpAsync(cancel.Token); NewLogMessage?.Invoke(this, $"{DateTime.Now}: Normal Mode."); } }
public async Task ReadMails(TreeNode rootFolder) { if (!(rootFolder.Tag is IMailFolder rootMailFolder)) { return; } Stopwatch stopWhatch = new Stopwatch(); stopWhatch.Start(); var mailsTask = rootMailFolder.FetchAsync(0, -1, SummaryItems); foreach (var message in await mailsTask) { TreeNode messageNode; if (!rootFolder.Nodes.ContainsKey(message.UniqueId.Id.ToString())) { messageNode = new TreeNode { Text = message.Envelope.Subject, Name = message.UniqueId.Id.ToString(), Tag = message }; rootFolder.Nodes.Add(messageNode); } else { messageNode = rootFolder.Nodes[message.UniqueId.Id.ToString()]; } if (!message.Flags.Value.HasFlag(MessageFlags.Seen)) { messageNode.NodeFont = BoldFont; } else { messageNode.NodeFont = RegularFont; } } stopWhatch.Stop(); NewLogMessage?.Invoke(this, $"{DateTime.Now}: {rootMailFolder.Name} folders mail readed by {stopWhatch.ElapsedMilliseconds} ms."); }
/// <summary> /// Raises the <see cref="NewLogMessage"/> event. /// </summary> /// <param name="logMessage">the message to raise.</param> private void OnLog(LogMessage logMessage) { if (logMessage == null) { return; } try { using (Logger.SuppressFirstChanceExceptionLogMessages()) { NewLogMessage?.Invoke(logMessage); } } catch (Exception) { //Swallow this exception //This is because if a subscriber throws an exception, creating a new log //might cause an infinite loop. } }
public void Status(string message) { NewLogMessage?.Invoke(this, new NewLogMessageEventArgs(message, LogType.Status)); }
public void Error(string message) { NewLogMessage?.Invoke(this, new NewLogMessageEventArgs(message, LogType.Error)); }
public void Warn(string message) { NewLogMessage?.Invoke(this, new NewLogMessageEventArgs(message, LogType.Warning)); }
public void Success(string message) { NewLogMessage?.Invoke(this, new NewBuildLogMessageEventArgs(message, BuildLogType.Success)); }
/// <summary> /// Add a new log message /// </summary> /// <param name="logLevel">The type of the message</param> /// <param name="message"></param> public static void Log(LogLevel logLevel, string message) { NewLogMessage?.Invoke(null, new NewLogMesssageEventArgs(message, logLevel)); }
private void Client_MetadataChanged(object sender, MetadataChangedEventArgs e) { NewLogMessage?.Invoke(this, $"{DateTime.Now}: {e.Metadata.Value}"); }
private void Client_Alert(object sender, AlertEventArgs e) { NewLogMessage?.Invoke(this, $"{DateTime.Now}: {e.Message}"); }
private void Client_Connected(object sender, ConnectedEventArgs e) { NewLogMessage?.Invoke(this, $"{DateTime.Now}: Connected."); ConnectionState(this, true); }
public static void Log(string s) { NewLogMessage?.Invoke(@"[Debug Log] " + s); }
protected void OnNewLogMessage(object sender, LoggerEventArgs e) { NewLogMessage?.Invoke(sender, e); }