Пример #1
0
 public IMailServerSettings GetMailSettings()
 {
     return(SettingsController.GetMailSettings());
 }
Пример #2
0
        private async Task SendMailAsync(string fileName)
        {
            bool workerInUse = false;

            try
            {
                if (ConsoleLogEnabled)
                {
                    Console.WriteLine("Reading mail from " + fileName);
                }

                SerializableMailMessage message = null;

                try
                {
                    message = ReadMailFromFile(fileName);
                }
                catch (FileNotFoundException)
                {
                    MarkSkipped(fileName);
                    return;
                }

                Interlocked.Increment(ref _concurrentWorkers);
                workerInUse = true;

                if (ConsoleLogEnabled)
                {
                    Console.WriteLine("Sending " + fileName + " task to worker");
                }

                var mailSettings = message.MailSettings;
                if (mailSettings == null || mailSettings.IsEmpty)
                {
                    mailSettings = SettingsController.GetMailSettings();
                }

                var success = await SenderFactory.SendMailAsync(message, mailSettings);

                if (!success)
                {
                    if (ConsoleLogEnabled)
                    {
                        Console.WriteLine("No mail server name, skipping " + fileName);
                    }

                    MarkSkipped(fileName);
                }
                else
                {
                    if (ConsoleLogEnabled)
                    {
                        Console.WriteLine("Sent mail for " + fileName);
                    }

                    MarkSent(fileName);
                }

                if (ConsoleLogEnabled)
                {
                    Console.WriteLine("Releasing worker from " + fileName + " task");
                }

                // Task ended, decrement counter and pulse to the Coordinator thread
                Interlocked.Decrement(ref _concurrentWorkers);
                workerInUse = false;

                lock (_actionMonitor)
                {
                    Monitor.Pulse(_actionMonitor);
                }
            }
            catch (Exception ex)
            {
                if (ConsoleLogEnabled)
                {
                    if (ConsoleLogExceptions)
                    {
                        Console.WriteLine("Exception thrown for " + fileName + ":\n    " +
                                          ex.Message.ToString().Replace("\n", "\n    "));
                    }

                    Console.WriteLine("Task failed for " + fileName);
                }

                if (Properties.Settings.Default.LogErrorsToOs)
                {
                    using (var eventLog = new EventLog("Application"))
                    {
                        eventLog.Source = "Application";
                        eventLog.WriteEntry(
                            "Failed to send mail from queue.\n\n" + ex.Message + "\n\n" + ex.StackTrace,
                            EventLogEntryType.Warning);
                    }
                }

                if (workerInUse)
                {
                    // Decrement counter and pulse to the Coordinator thread
                    Interlocked.Decrement(ref _concurrentWorkers);
                }

                try { MarkFailed(fileName); }
                catch { }

                lock (_actionMonitor)
                {
                    Monitor.Pulse(_actionMonitor);
                }
            }
        }
Пример #3
0
 public void SetMailSettings(IMailServerSettings settings)
 {
     SettingsController.SetMailSettings(settings);
 }