コード例 #1
0
        public string Format(object value, bool indentMsg)
        {
            ChoStringMsgBuilder msg = new ChoStringMsgBuilder();

            if (((IDictionary)value).Count == 0)
            {
                msg.Append(ChoString.EmptyString);
            }
            else
            {
                msg.AppendLine();
                if (indentMsg)
                {
                    msg.AppendLine("[");
                    foreach (object token in ((IDictionary)value).Keys)
                    {
                        msg.AppendFormatLine(String.Format("{0} - {1}", ChoObject.ToString(token), ChoObject.ToString(((IDictionary)value)[token])));
                    }
                    msg.Append("]");
                }
                else
                {
                    foreach (object token in ((Hashtable)value).Keys)
                    {
                        msg.AppendLine(token.ToString());
                    }
                }
            }

            return(msg.ToString());
        }
コード例 #2
0
            public string ReplaceProperty(string propertyName, string format, object context)
            {
                //try
                //{
                object output    = null;
                string codeBlock = propertyName.Trim();

                if (!codeBlock.Contains(";") && !codeBlock.StartsWith("return"))
                {
                    codeBlock = "return {0};".FormatString(codeBlock);
                }

                using (ChoCodeDomProvider cs = new ChoCodeDomProvider(new string[] { codeBlock }))
                    output = cs.ExecuteFunc(context);

                return(ChoObject.ToString(output, format));
                //}
                //catch (ChoFatalApplicationException)
                //{
                //    throw;
                //}
                //catch (Exception ex)
                //{
                //    return ChoPropertyManager.FormatException(propertyName, ex);
                //}
            }
コード例 #3
0
        public string Format(object value, bool indentMsg)
        {
            ChoStringMsgBuilder msg = new ChoStringMsgBuilder();

            if (((Array)value).Length == 0)
            {
                msg.AppendLine(ChoString.EmptyString);
            }
            else
            {
                if (indentMsg)
                {
                    msg.AppendLine("[");
                    foreach (object token in (Array)value)
                    {
                        msg.AppendFormatLine(ChoObject.ToString(token));
                    }
                    msg.AppendLine("]");
                }
                else
                {
                    foreach (object token in (Array)value)
                    {
                        msg.AppendLine(ChoObject.ToString(token));
                    }
                }
            }

            return(msg.ToString());
        }
コード例 #4
0
        public string Format(object value, bool indentMsg)
        {
            ChoStringMsgBuilder msg = new ChoStringMsgBuilder();

            if (((Hashtable)value).Count == 0)
            {
                msg.Append(ChoString.EmptyString);
            }
            else
            {
                msg.AppendLine();
                if (indentMsg)
                {
                    msg.AppendLine("[");
                    foreach (object token in ((Hashtable)value).Values)
                    {
                        msg.AppendFormatLine(ChoObject.ToString(token));
                    }
                    msg.Append("]");
                }
                else
                {
                    foreach (object token in ((Hashtable)value).Values)
                    {
                        msg.AppendLine(ChoObject.ToString(token));
                    }
                }
            }

            return(msg.ToString());
        }
コード例 #5
0
 public string ReplaceProperty(string propertyName, string format)
 {
     //try
     //{
     //return ChoString.ToString(ChoString.Evaluate(_target, propertyName));
     return(ChoObject.ToString(ChoString.Evaluate(_target, propertyName), format));
     //}
     //catch (Exception ex)
     //{
     //    return ChoPropertyManager.FormatException(propertyName, ex);
     //}
 }
コード例 #6
0
ファイル: ChoUniqueArray.cs プロジェクト: lanicon/Cinchoo
        private bool IsExists(ArrayList list, object element)
        {
            foreach (object item in list)
            {
                if (item.Equals(element))
                {
                    ChoStringMsgBuilder msg = new ChoStringMsgBuilder("Duplicate entry found");
                    msg.AppendFormatLine(ChoObject.ToString(element));

                    ChoTrace.Debug(msg.ToString());
                    return(true);
                }
            }

            return(false);
        }
コード例 #7
0
            public string ReplaceProperty(string propertyName, string format)
            {
                //try
                //{
                object output    = null;
                string className = "ChoClass_{0}".FormatString(ChoRandom.NextRandom(0, Int32.MaxValue));
                string statement = String.Format("public class {0} {{ public object Execute() {{ return {1}; }} }}", className, propertyName);

                using (Microsoft.CSharp.CSharpCodeProvider foo =
                           new Microsoft.CSharp.CSharpCodeProvider())
                {
                    var res = foo.CompileAssemblyFromSource(_compilerParameters, statement);

                    if (res.Errors.Count > 0)
                    {
                        StringBuilder errors = new StringBuilder();
                        foreach (CompilerError CompErr in res.Errors)
                        {
                            errors.AppendFormat("Line number {0}, Error Number: {1}, {2}{3}", CompErr.Line, CompErr.ErrorNumber, CompErr.ErrorText, Environment.NewLine);
                        }

                        throw new ChoApplicationException("Exception compiling dynamic statement {1}{1}{0}{1}{1}{2}".FormatString(
                                                              propertyName, Environment.NewLine, errors.ToString()));
                    }

                    var type = res.CompiledAssembly.GetType(className);
                    var obj  = Activator.CreateInstance(type);

                    output = type.GetMethod("Execute").Invoke(obj, new object[] { });
                }

                return(ChoObject.ToString(output, format));
                //}
                //catch (Exception ex)
                //{
                //    return ChoPropertyManager.FormatException(propertyName, ex);
                //}
            }
コード例 #8
0
 public override string ToString()
 {
     return(ChoObject.ToString(this));
 }
コード例 #9
0
        public static string ToString(Exception exception, NameValueCollection additionalInfo)
        {
            ChoGuard.ArgumentNotNull(exception, "Exception");

            // Create StringBuilder to maintain publishing information.
            StringBuilder info = new StringBuilder();

            #region Record the contents of the AdditionalInfo collection
            // Record the contents of the AdditionalInfo collection.
            if (additionalInfo != null)
            {
                // Record General information.
                info.AppendFormat("{0}General Information {0}{1}{0}Additional Info:", Environment.NewLine, _textSeparator);

                foreach (string i in additionalInfo)
                {
                    info.AppendFormat("{0}{1}: {2}", Environment.NewLine, i, additionalInfo.Get(i));
                }
            }
            #endregion

            if (exception == null)
            {
                info.AppendFormat("{0}{0}No Exception object has been provided.{0}", Environment.NewLine);
            }
            else
            {
                #region Loop through each exception class in the chain of exception objects
                // Loop through each exception class in the chain of exception objects.
                Exception currentException  = exception; // Temp variable to hold InnerException object during the loop.
                int       intExceptionCount = 1;         // Count variable to track the number of exceptions in the chain.
                do
                {
                    // Write title information for the exception object.
                    info.AppendFormat("{0}{0}{1}) Exception Information{0}{2}", Environment.NewLine, intExceptionCount.ToString(), _textSeparator);
                    info.AppendFormat("{0}Exception Type: {1}", Environment.NewLine, currentException.GetType().FullName);

                    #region Loop through the public properties of the exception object and record their value
                    // Loop through the public properties of the exception object and record their value.
                    PropertyInfo[]      aryPublicProperties = currentException.GetType().GetProperties();
                    NameValueCollection currentAdditionalInfo;
                    foreach (PropertyInfo p in aryPublicProperties)
                    {
                        // Do not log information for the InnerException or StackTrace. This information is
                        // captured later in the process.
                        if (p.Name != "InnerException" && p.Name != "StackTrace")
                        {
                            if (p.GetValue(currentException, null) == null)
                            {
                                info.AppendFormat("{0}{1}: NULL", Environment.NewLine, p.Name);
                            }
                            else
                            {
                                // Loop through the collection of AdditionalInformation if the exception type is a ChoAApplicationException.
                                if (p.Name == "AdditionalInformation" && currentException is ChoApplicationException)
                                {
                                    // Verify the collection is not null.
                                    if (p.GetValue(currentException, null) != null)
                                    {
                                        // Cast the collection into a local variable.
                                        currentAdditionalInfo = (NameValueCollection)p.GetValue(currentException, null);

                                        // Check if the collection contains values.
                                        if (currentAdditionalInfo.Count > 0)
                                        {
                                            info.AppendFormat("{0}AdditionalInformation:", Environment.NewLine);

                                            // Loop through the collection adding the information to the string builder.
                                            for (int i = 0; i < currentAdditionalInfo.Count; i++)
                                            {
                                                info.AppendFormat("{0}{1}: {2}", Environment.NewLine, currentAdditionalInfo.GetKey(i), currentAdditionalInfo[i]);
                                            }
                                        }
                                    }
                                }
                                // Otherwise just write the ToString() value of the property.
                                else
                                {
                                    object value = p.GetValue(currentException, null);
                                    if (value is ICollection)
                                    {
                                        info.AppendFormat("{0}{1}: {0}", Environment.NewLine, p.Name);
                                        foreach (object item in (IEnumerable)value)
                                        {
                                            if (item is Exception)
                                            {
                                                info.AppendLine((item as Exception).ToString().Indent());
                                                //info.AppendLine(ChoApplicationException.ToString(item as Exception).Indent());
                                            }
                                            else
                                            {
                                                info.AppendLine(ChoObject.ToString(item).Indent());
                                            }
                                        }
                                    }
                                    else
                                    {
                                        info.AppendFormat("{0}{1}: {2}", Environment.NewLine, p.Name, p.GetValue(currentException, null));
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                    #region Record the Exception StackTrace
                    // Record the StackTrace with separate label.
                    if (currentException.StackTrace != null)
                    {
                        info.AppendFormat("{0}{0}StackTrace Information{0}{1}", Environment.NewLine, _textSeparator);
                        info.AppendFormat("{0}{1}", Environment.NewLine, currentException.StackTrace);
                    }
                    #endregion

                    // Reset the temp exception object and iterate the counter.
                    currentException = currentException.InnerException;
                    intExceptionCount++;
                } while (currentException != null);
                #endregion
            }

            info.AppendFormat("{0}{1}", Environment.NewLine, ChoTrace.SEPARATOR);

            return(info.ToString());
        }