public string GetDisplayText(bool useCustom, dynamic doc, string customDocumentDisplayIdentifier, bool useDirectAccess = false)
 {
     if (useCustom && !string.IsNullOrWhiteSpace(customDocumentDisplayIdentifier))
     {
         try
         {
             string val;
             if (customDocumentDisplayIdentifier.Contains("{") && customDocumentDisplayIdentifier.Contains("}"))
             {
                 val = _documentPatternParser.ParsePattern(customDocumentDisplayIdentifier, doc, useDirectAccess);
             }
             else
             {
                 val = DynamicHelper.GetPropertyValue(doc, customDocumentDisplayIdentifier, useDirectAccess);
                 if (customDocumentDisplayIdentifier != "id")
                 {
                     val += string.Format(" [{0}]", DynamicHelper.GetPropertyValue(doc, "id", useDirectAccess));
                 }
             }
             if (!string.IsNullOrWhiteSpace(val))
             {
                 return(val);
             }
             return(doc.id);
         }
         catch (Exception)
         {
         }
     }
     return(doc.id);
 }
        public bool GetCustomDocumentDisplayIdentifier(
            List <dynamic> docs,
            Models.CustomDocumentListDisplay customListDisplay,
            string customDocumentDisplayIdentifier,
            out string customDisplayPattern,
            out string sortField,
            bool useDirectAccess = false)
        {
            customDisplayPattern = null;
            sortField            = "id";

            try
            {
                string testField;

                if (customListDisplay != null)
                {
                    customDisplayPattern = customListDisplay.DisplayPattern;
                    testField            = customListDisplay.SortBy;
                    sortField            = customListDisplay.SortBy;
                }
                else
                {
                    customDisplayPattern = customDocumentDisplayIdentifier;
                    testField            = customDisplayPattern;
                    sortField            = customDisplayPattern;
                }
                if (!string.IsNullOrWhiteSpace(testField))
                {
                    var useCustom = false;
                    var firstDoc  = docs.First();

                    try
                    {
                        var name = DynamicHelper.GetPropertyValue(firstDoc, testField, useDirectAccess);
                        useCustom = true;
                    }
                    catch (Exception) { }

                    return(useCustom);
                }
            }
            catch (Exception ex)
            {
                var m = ex;
            }
            return(false);
        }
示例#3
0
            public void Log <TException>(LogLevel logLevel, Func <string> messageFunc, TException exception)
                where TException : Exception
            {
                switch (logLevel)
                {
                case LogLevel.Debug:
                    if (DynamicHelper.GetPropertyValue <bool>(m_logger, "IsDebugEnabled"))
                    {
                        DynamicHelper.InvokeMethod(m_logger, "DebugException", messageFunc(), exception);
                    }
                    break;

                case LogLevel.Information:
                    if (DynamicHelper.GetPropertyValue <bool>(m_logger, "IsInfoEnabled"))
                    {
                        DynamicHelper.InvokeMethod(m_logger, "InfoException", messageFunc(), exception);
                    }
                    break;

                case LogLevel.Warning:
                    if (DynamicHelper.GetPropertyValue <bool>(m_logger, "IsWarnEnabled"))
                    {
                        DynamicHelper.InvokeMethod(m_logger, "WarnException", messageFunc(), exception);
                    }
                    break;

                case LogLevel.Error:
                    if (DynamicHelper.GetPropertyValue <bool>(m_logger, "IsErrorEnabled"))
                    {
                        DynamicHelper.InvokeMethod(m_logger, "ErrorException", messageFunc(), exception);
                    }
                    break;

                case LogLevel.Fatal:
                    if (DynamicHelper.GetPropertyValue <bool>(m_logger, "IsFatalEnabled"))
                    {
                        DynamicHelper.InvokeMethod(m_logger, "FatalException", messageFunc(), exception);
                    }
                    break;

                default:
                    if (DynamicHelper.GetPropertyValue <bool>(m_logger, "IsTraceEnabled"))
                    {
                        DynamicHelper.InvokeMethod(m_logger, "TraceException", messageFunc(), exception);
                    }
                    break;
                }
            }
            public void Log(LogLevel logLevel, Func <string> messageFunc)
            {
                switch (logLevel)
                {
                case LogLevel.Information:
                    if (DynamicHelper.GetPropertyValue <bool>(m_logger, "IsInfoEnabled"))
                    {
                        DynamicHelper.InvokeMethod(m_logger, "Info", messageFunc());
                    }
                    break;

                case LogLevel.Warning:
                    if (DynamicHelper.GetPropertyValue <bool>(m_logger, "IsWarnEnabled"))
                    {
                        DynamicHelper.InvokeMethod(m_logger, "Warn", messageFunc());
                    }
                    break;

                case LogLevel.Error:
                    if (DynamicHelper.GetPropertyValue <bool>(m_logger, "IsErrorEnabled"))
                    {
                        DynamicHelper.InvokeMethod(m_logger, "Error", messageFunc());
                    }
                    break;

                case LogLevel.Fatal:
                    if (DynamicHelper.GetPropertyValue <bool>(m_logger, "IsFatalEnabled"))
                    {
                        DynamicHelper.InvokeMethod(m_logger, "Fatal", messageFunc());
                    }
                    break;

                default:
                    if (DynamicHelper.GetPropertyValue <bool>(m_logger, "IsDebugEnabled"))
                    {
                        DynamicHelper.InvokeMethod(m_logger, "Debug", messageFunc());
                        // Log4Net doesn't have a 'Trace' level, so all Trace messages are written as 'Debug'
                    }
                    break;
                }
            }