static void Main(string[] args) { Tracing.Tracer t = Tracing.Tracer.Instance; RightFAXServersSection rightFAXServersSection = ConfigurationManager.GetSection("RightFAXServers") as RightFAXServersSection; RightFAXServersCollection rightFAXServersCollection = rightFAXServersSection.RightFAXServers; MailBoxSection mailBoxSection = ConfigurationManager.GetSection("MailBoxes") as MailBoxSection; MailBoxCollection mailBoxCollection = mailBoxSection.MailBoxes; RightFAX rightFAX = new RightFAX(); // iterate through the servers // and then inside, iterate through the mailboxes. foreach (RightFAXServersElement rfse in rightFAXServersCollection) { Console.WriteLine("RightFAXServersElement = " + rfse.ToString()); rightFAX.Open(rfse.ServerName, rfse.UserName, rfse.Password); foreach (MailBoxElement mbe in mailBoxCollection) { if (rfse.ServerName == mbe.ServerName) { rightFAX.ProcessMailBox(mbe); } } rightFAX.Close(); } }
private void Process() { if (_monitor.Processing == false) { // we are not currently processing. return; } RightFAXServersSection rightFAXServersSection = ConfigurationManager.GetSection("RightFAXServers") as RightFAXServersSection; RightFAXServersCollection rightFAXServersCollection = rightFAXServersSection.RightFAXServers; MailBoxSection mailBoxSection = ConfigurationManager.GetSection("MailBoxes") as MailBoxSection; MailBoxCollection mailBoxCollection = mailBoxSection.MailBoxes; RightFAX rightFAX = new RightFAX(); // iterate through the servers // and then inside, iterate through the mailboxes. foreach (RightFAXServersElement rfse in rightFAXServersCollection) { Trace.WriteLine("RightFAXServersElement = " + rfse.ToString()); rightFAX.Open(rfse.ServerName, rfse.UserName, rfse.Password); foreach (MailBoxElement mbe in mailBoxCollection) { if (_monitor.Processing == false) { // we are not currently processing. rightFAX.Close(); return; } if (rfse.ServerName == mbe.ServerName) { rightFAX.ProcessMailBox(mbe); } } rightFAX.Close(); } }
public static async Task LoadPriceLists() { ProvidersSection providersSection = (ProvidersSection)ConfigurationManager.GetSection("PricelistProviders"); MailBoxSection mailSection = (MailBoxSection)ConfigurationManager.GetSection("MailConfig"); var mailBox = mailSection.MailBoxes.Count > 1 ? throw new ConfigurationErrorsException("Указано более одного почтового ящика") : mailSection.MailBoxes[0]; System.Console.WriteLine("Чтение прайс листов с электронной почты."); System.Console.WriteLine("Сисок постащиков."); foreach (ProviderElement provider in providersSection.Providers) { System.Console.WriteLine(provider.Name); } System.Console.WriteLine($"Адрес почтового сервера: {mailBox.ServerUrl}"); var mailBoxOptions = new MailBoxOptions(); FillUserCredentials(mailBoxOptions); mailBoxOptions.Port = mailBox.Port; mailBoxOptions.ImapServerUrl = mailBox.ServerUrl; Action <ProgressOptions> progressOptionsFunc = progressOptions => System.Console.WriteLine(progressOptions.Message); using (var mailHelper = new MailHelper(mailBoxOptions)) { var i = 0; var connected = false; for (; i < 3 && !connected; i++) { try { await mailHelper.Connect(new Progress <ProgressOptions>(progressOptionsFunc)); connected = true; } catch (MailAuthenticationException e) { System.Console.WriteLine(e.Message); FillUserCredentials(mailHelper.MailOptions); } } if (!connected) { throw new ApplicationException("Превышен лимит попыток подключений"); } var dbh = new DbHelper(); await dbh.ClearPriceListsTable(new Progress <ProgressOptions>(progressOptionsFunc)); List <Task <List <PriceItem> > > getMessagesTasks = new List <Task <List <PriceItem> > >(); foreach (ProviderElement providersSectionProvider in providersSection.Providers) { var progress = new Progress <ProgressOptions>(progressOptionsFunc); ; getMessagesTasks.Add(mailHelper.GetMessages(new ProviderOptions { Name = providersSectionProvider.Name, ColumnDefinitions = providersSectionProvider.ToDictionary() }, progress)); } await Task.WhenAll(getMessagesTasks).ContinueWith(_ => { foreach (var messagesTask in getMessagesTasks) { dbh.WritePriceLists(messagesTask.Result, new Progress <ProgressOptions>(progressOptionsFunc)); } }); } }