Esempio n. 1
0
        /// <summary>
        /// SendEmailWithAttachment
        /// </summary>
        /// <param name="from">The mail from value.</param>
        /// <param name="subject">The mail subject value.</param>
        /// <param name="body">The mail body text.</param>
        /// <param name="destinations">The mail to destinations.</param>
        /// <param name="fullFilePaths">Semicolon delimited strings - file paths, or just one file path</param>
        public static void SendEmailWithAttachment(string from, string subject, string body, string destinations, string fullFilePaths)
        {
            //Check destination string isn't empty
            //If empty, no need to send anything
            if (destinations.Length == 0)
            {
                return;
            }

            try
            {
                var myMail         = new MailMessage(from, destinations, subject, body);
                var strAttachments = fullFilePaths.Split(';');
                foreach (var attachment in strAttachments.Select(t => new Attachment(t)))
                {
                    myMail.Attachments.Add(attachment);
                }
                SendMailMessage(myMail);
            }
            catch (Exception ex)
            {
                ErrorLog.LogError("SendEmailNotifications(): ERROR: " + (ex.InnerException == null ? ex.Message : ex.InnerException.Message), Component);
            }
        }
Esempio n. 2
0
 public virtual bool Start()
 {
     try
     {
         var performance = new PerformanceData
         {
             CallId    = CallId,
             UserId    = UserId,
             Server    = Environment.MachineName,
             Component = Component,
             Method    = Method,
             FrameName = Frame
         };
         performance.Insert();
         Id = performance.Id;
         return(true);
     }
     catch (Exception ex)
     {
         ErrorLog.LogError(ex, new CallingMethod());
         Id = 0;
         return(false);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Executes the method.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="parms">The parms.</param>
        /// <returns></returns>
        static public string ExecuteMethod(string method, string parms)
        {
            var results = String.Empty;

            try
            {
                const string delimiter           = ".";
                var          program             = method.Split(delimiter.ToCharArray(), 6, StringSplitOptions.RemoveEmptyEntries);
                object[]     requestedParameters = { parms };

                try
                {
                    ErrorLog.DebugLog(String.Format("ExecuteMethod entered for {0}", method), Source);
                    if (program.Length < 3)
                    {
                        throw new ArgumentException(String.Format("ExecuteMethod requires Assemby.Class.Method format: {0},", method));
                    }

                    var requestedAssembly = Assembly.Load(program[0]);
                    Assert.Test(requestedAssembly != null, string.Format("could not locate assembly: {0},", program[0]));

                    ErrorLog.DebugLog(String.Format("Assembly loaded: {0}", program[0]), Source);
                    var typeName = new StringBuilder();
                    for (var i = 0; i < (program.Length - 1); ++i)
                    {
                        if (i > 0)
                        {
                            typeName.Append(".");
                        }

                        typeName.Append(program[i]);
                    }
                    if (requestedAssembly != null)
                    {
                        var requestedType = requestedAssembly.GetType(typeName.ToString());
                        Assert.Test(requestedType != null, string.Format("could not locate assembly type: {0},", typeName));

                        ErrorLog.DebugLog(String.Format("Type loaded: {0}", typeName), Source);
                        const BindingFlags bf = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |
                                                BindingFlags.Static | BindingFlags.ExactBinding;

                        if (requestedType != null)
                        {
                            var    requestedConstructor = requestedType.GetConstructor(Type.EmptyTypes);
                            object request = null;
                            if (requestedConstructor != null)
                            {
                                request = requestedConstructor.Invoke(null);
                                Assert.Test(request != null, string.Format("could not Invoke: {0},", typeName));
                            }
                            var methodIndex = program.Length - 1;
                            ErrorLog.DebugLog(String.Format("Constructor Invoked: {0}", typeName), Source);

                            var classType = request == null ? requestedType : request.GetType();
                            var methInfo  = classType.GetMethod(program[methodIndex], bf, null, new[] { typeof(string) }, null);

                            Assert.Test(methInfo != null,
                                        string.Format("could not find method: {0} for type: {1},", program[methodIndex], typeName));

                            ErrorLog.DebugLog(String.Format("Method {0} retrieved.", program[methodIndex]), Source);
                            if (methInfo != null)
                            {
                                var returnObject = methInfo.Invoke(request, requestedParameters);
                                ErrorLog.DebugLog(String.Format("Method {0} Invoked.", program[methodIndex]), Source);

                                if (returnObject != null)
                                {
                                    results = returnObject as string;
                                }
                            }
                        }
                    }
                }
                catch (TargetInvocationException ex)
                {
                    throw ex.InnerException;
                }
            }
            catch (Exception ex)
            {
                var errorMessage = ex.Message.Substring(0, Math.Min(ex.Message.Length, 255));
                results = String.Format("<ERROR>{0}</ERROR>", errorMessage);
                ErrorLog.LogError(String.Format("Error in ExecuteMethod({0}): {1}", method, errorMessage), Source);
            }
            return(results);
        }