Ejemplo n.º 1
0
 public static void ResetCounters()
 {
     try
     {
         foreach (PerformanceCounter counter in m_sigleton.Values)
         {
             counter.RawValue = 0;
         }
     }
     catch (Exception ex)
     {
         SystemLogger.WriteOnConsoleAsync(true, "ResetCounters Error: " + ex.ToString(), ConsoleColor.Red, ConsoleColor.Black, true);
     }
 }
Ejemplo n.º 2
0
 public static void DecrementCounter(string counterName)
 {
     try
     {
         if (m_sigleton.ContainsKey(counterName))
         {
             m_sigleton[counterName].Decrement();
         }
     }
     catch (Exception ex)
     {
         SystemLogger.WriteOnConsoleAsync(true, "DecrementCounter Error: " + ex.ToString(), ConsoleColor.Red, ConsoleColor.Black, true);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sendAllOnce">false to send mail for each recipients</param>
        /// <param name="resendInFailure">try sending if failure occured</param>
        /// <param name="async">commit async process</param>
        /// <param name="from">sender mail</param>
        /// <param name="to">recipient mail</param>
        /// <param name="cc"></param>
        /// <param name="subject"></param>
        /// <param name="displayName"></param>
        /// <param name="messageBody">message text</param>
        /// <param name="attachedFile">stream that includes attached file contents</param>
        public static bool Send(bool sendAllOnce, bool resendInFailure, bool async, string from, string to, string[] cc, string subject, string displayName, string messageBody, Stream attachedFile)
        {
            //bool isFirstTime = false;
            try
            {
                MailMessage msg = new MailMessage();
                msg.Sender = new MailAddress(from);
                //msg.Priority = (MailPriority)Enum.Parse(typeof(MailPriority),ConfigurationManager.AppSettings.Get("SMTPPriority"));
                msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                msg.From    = new MailAddress(from);
                msg.Subject = subject;
                msg.Body    = messageBody;
                if (attachedFile != null)
                {
                    //msg.Attachments.Add(new Attachment(attachedFile,));

                    msg.Attachments.Add(new Attachment(attachedFile, "ErrorScreenShot.bmp"));
                }
                if (sendAllOnce)
                {
                    if (cc != null && cc.Length > 0)
                    {
                        foreach (string rec in cc)
                        {
                            if (rec == string.Empty)
                            {
                                continue;
                            }
                            msg.CC.Add(rec);
                        }
                    }
                    msg.To.Add(to);
                    if (async)
                    {
                        m_smtpClient.SendAsync(msg, null);
                    }
                    else
                    {
                        m_smtpClient.Send(msg);
                    }
                }
                else
                {
                    MailAddressCollection mac = new MailAddressCollection();
                    if (cc != null && cc.Length != 0)
                    {
                        foreach (string rec in cc)
                        {
                            mac.Add(rec);
                        }
                    }
                    mac.Add(to);
                    SendOneByOne(sendAllOnce, msg, mac);
                }
                return(true);
            }
            catch (Exception ex)
            {
                SystemLogger.WriteOnConsoleAsync(true, string.Format("Error sending mail ({0}) : {1}", subject, ex.Message), ConsoleColor.Red, ConsoleColor.Black, true);
                StackFrame sf = new StackFrame(true);
                if (resendInFailure)
                {
                    //if (!isFirstTime)
                    //{
                    //    isFirstTime = true;
                    //    //Send(sendAllOnce, resendInFailure, async, from, to, cc, subject, displayName, messageBody, attachedFile);
                    //}
                    //else
                    //{
                    //    logError(sf, "error sending message");
                    //    return false;
                    //}
                }
                else
                {
                    logError(sf, "error sending message");
                }
                return(false);
            }
        }