/// <summary>
            /// Resolves the specified tag.
            /// </summary>
            /// <param name="context">The context.</param>
            /// <param name="chunk">The chunk.</param>
            /// <returns>An object that will be cached unless it is a <see cref="T:WebApplications.Utilities.Formatting.Resolution" />.</returns>
            public override object Resolve(FormatWriteContext context, FormatChunk chunk)
            {
                string key;

                // ReSharper disable once PossibleNullReferenceException
                switch (chunk.Tag.ToLowerInvariant())
                {
                case "default":
                case "verbose":
                    return(EnumerableElementVerboseFormat);

                case "xml":
                    return(EnumerableElementXMLFormat);

                case "json":
                    return(EnumerableElementJSONFormat);

                case "html":
                    return(EnumerableElementHTMLFormat);

                case "noline":
                    return(EnumerableElementNoLineFormat);

                case "key":
                    key = Translation.GetResource(
                        Resource,
                        context.FormatProvider as CultureInfo ?? Translation.DefaultCulture);
                    return(string.IsNullOrEmpty(key)
                            ? Resolution.Null
                            : key);

                case "keyxml":
                    key = Translation.GetResource(
                        Resource,
                        context.FormatProvider as CultureInfo ?? Translation.DefaultCulture);
                    return(string.IsNullOrEmpty(key)
                            ? Resolution.Null
                            : key.XmlEscape());

                case "keyxmltag":
                    key = Translation.GetResource(
                        Resource,
                        context.FormatProvider as CultureInfo ?? Translation.DefaultCulture);
                    return(string.IsNullOrEmpty(key)
                            ? Resolution.Null
                            : key.Replace(' ', '_'));

                case "value":
                    return(Values);

                case "valuexml":
                    return(Values.Select(v => v?.XmlEscape()));

                case "valuehtml":
                    return(Values.Select(v => v != null ? _newLineRegex.Replace(v.XmlEscape(), m => "<br/>" + m.Value) : null));

                default:
                    return(Resolution.Unknown);
                }
            }
        /// <summary>
        /// Resolves the specified tag.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="chunk">The chunk.</param>
        /// <returns>An object that will be cached unless it is a <see cref="T:WebApplications.Utilities.Formatting.Resolution" />.</returns>
        // ReSharper disable once CodeAnnotationAnalyzer
        public override object Resolve(FormatWriteContext context, FormatChunk chunk)
        {
            if (chunk.Tag == null)
            {
                throw new ArgumentException();
            }

            switch (chunk.Tag.ToLowerInvariant())
            {
            case "isvalid":
                return(IsValid ? Resolution.Empty : Resolution.Null);

            case "guid":
                return(Guid);

            case "host":
                return(Host);

            case "name":
                return(Name);

            case "fullname":
                return(FullName);

            case "pipe":
                return(Pipe);

            default:
                return(Resolution.Unknown);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Resolves the email subject format builder.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="chunk">The chunk.</param>
        /// <param name="logs">The logs.</param>
        /// <returns></returns>
        private object ResolveSubject(
            [NotNull] FormatWriteContext context,
            [NotNull] FormatChunk chunk,
            [NotNull] Log[] logs)
        {
            // ReSharper disable once PossibleNullReferenceException
            switch (chunk.Tag.ToLowerInvariant())
            {
            case "default":
                return(DefaultSubject);

            case FormatTagName:
                return(string.IsNullOrWhiteSpace(Name)
                        ? Resolution.Null
                        : Name);

            case FormatTagMore:
                int count = logs.Length - 1;
                return(count < 1
                        ? Resolution.Null
                        : new FuncResolvable(
                           (ctx, ch) => String.Equals(
                               ch.Tag,
                               FormatTagMoreCount,
                               StringComparison.InvariantCultureIgnoreCase)
                                ? count
                                : Resolution.Unknown));

            default:
                return(logs[0]?.Resolve(context, chunk) ?? Resolution.Unknown);
            }
        }
        /// <summary>
        /// Resolves the specified tag.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="chunk">The chunk.</param>
        /// <returns>An object that will be cached unless it is a <see cref="T:WebApplications.Utilities.Formatting.Resolution" />.</returns>
        // ReSharper disable once CodeAnnotationAnalyzer
        public override object Resolve(FormatWriteContext context, FormatChunk chunk)
        {
            // ReSharper disable once PossibleNullReferenceException
            switch (chunk.Tag.ToLowerInvariant())
            {
            case "name":
                return(Name);

            case "value":
                return(Value);

            default:
                return(Resolution.Unknown);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Resolves the specified tag.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="chunk">The chunk.</param>
        /// <returns>An object that will be cached unless it is a <see cref="T:WebApplications.Utilities.Formatting.Resolution" />.</returns>
        // ReSharper disable once CodeAnnotationAnalyzer
        public override object Resolve(FormatWriteContext context, FormatChunk chunk)
        {
            CultureInfo culture = context.FormatProvider as CultureInfo ?? Translation.DefaultCulture;
            string      key;

            // ReSharper disable once PossibleNullReferenceException
            switch (chunk.Tag.ToLowerInvariant())
            {
            case "default":
            case "verbose":
                return(VerboseFormat);

            case "xml":
                return(XMLFormat);

            case "json":
                return(JSONFormat);

            case "noline":
                return(NoLineFormat);

            case "key":
                key = Translation.GetResource(() => Resources.LogKeys_Context, culture);
                return(string.IsNullOrEmpty(key)
                        ? Resolution.Null
                        : key);

            case "keyxml":
                key = Translation.GetResource(() => Resources.LogKeys_Context, culture);
                return(string.IsNullOrEmpty(key)
                        ? Resolution.Null
                        : key.XmlEscape());

            case "keyxmltag":
                key = Translation.GetResource(() => Resources.LogKeys_Context, culture);
                return(string.IsNullOrEmpty(key)
                        ? Resolution.Null
                        : key.Replace(' ', '_'));

            case "value":
                // ReSharper disable once AssignNullToNotNullAttribute
                return(_context.Select(kvp => new ContextElement(kvp.Key, kvp.Value)).ToArray());

            default:
                return(Resolution.Unknown);
            }
        }
Beispiel #6
0
            /// <summary>
            /// Resolves the specified tag.
            /// </summary>
            /// <param name="context">The context.</param>
            /// <param name="chunk">The chunk.</param>
            /// <returns>An object that will be cached unless it is a <see cref="T:WebApplications.Utilities.Formatting.Resolution" />.</returns>
            // ReSharper disable once CodeAnnotationAnalyzer
            public override object Resolve(FormatWriteContext context, FormatChunk chunk)
            {
                // ReSharper disable once PossibleNullReferenceException
                switch (chunk.Tag.ToLowerInvariant())
                {
                case "default":
                case "verbose":
                    return(ElementVerboseFormat);

                case "xml":
                    return(ElementXMLFormat);

                case "json":
                    return(ElementJSONFormat);

                case "noline":
                    return(ElementNoLineFormat);

                case "key":
                    return(Key);

                case "keyxml":
                    return(Key.XmlEscape());

                case "keyxmltag":
                    return(Key.Replace(' ', '_'));

                case "value":
                    return(Value);

                case "valuexml":
                    return(Value.XmlEscape());

                case "valuejson":
                    return(Value == null ? "null" : Value.ToJSON());

                default:
                    return(Resolution.Unknown);
                }
            }
Beispiel #7
0
        /// <summary>
        /// Resolves the body email body format builder.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="chunk">The chunk.</param>
        /// <param name="logs">The logs.</param>
        /// <param name="isHtml">if set to <see langword="true" /> the body is HTML.</param>
        /// <returns></returns>
        private object ResolveBody(
            [NotNull] FormatWriteContext context,
            [NotNull] FormatChunk chunk,
            [NotNull] Log[] logs,
            bool isHtml)
        {
            // ReSharper disable once PossibleNullReferenceException
            switch (chunk.Tag.ToLowerInvariant())
            {
            case "default":
                return(isHtml ? DefaultBodyHtml : Log.VerboseFormat);

            case FormatTagName:
                return(string.IsNullOrWhiteSpace(Name)
                        ? Resolution.Null
                        : Name);

            case "logs":
                return(logs);

            default:
                return(logs[0]?.Resolve(context, chunk) ?? Resolution.Unknown);
            }
        }
        /// <summary>
        /// Resolves the specified tag.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="chunk">The chunk.</param>
        /// <returns>
        /// An object that will be cached unless it is a <see cref="T:WebApplications.Utilities.Formatting.Resolution" />.
        /// </returns>
        public override object Resolve(FormatWriteContext context, FormatChunk chunk)
        {
            Debug.Assert(chunk.Tag != null);
            switch (chunk.Tag.ToLowerInvariant())
            {
            case "name":
                return(Name);

            case "altnames":
                return(_names.Length > 1
                        ? _names.Skip(1)
                        : Resolution.Null);

            case "description":
                return(Description);

            case "parameters":
                object[] parameters = ArgumentParameters.Select(ResolveParameter).ToArray();
                return(parameters.Length > 0 ? parameters : Resolution.Null);

            default:
                return(Resolution.Unknown);
            }
        }
        /// <summary>
        /// Resolves the specified tag.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="chunk">The chunk.</param>
        /// <returns>An object that will be cached unless it is a <see cref="T:WebApplications.Utilities.Formatting.Resolution" />.</returns>
        // ReSharper disable once CodeAnnotationAnalyzer
        public override object Resolve(FormatWriteContext context, FormatChunk chunk)
        {
            // ReSharper disable once PossibleNullReferenceException
            switch (chunk.Tag.ToLowerInvariant())
            {
            case "default":
                return(VerboseFormat);

            case "short":
                return(ShortFormat);

            case "categoryname":
                return(CategoryName);

            case "instanceguid":
                return(InstanceGuid);

            case "info":
                return(_infoDictionary.Values.Count > 0 ? _infoDictionary.Values : Resolution.Null);

            default:
                return(Resolution.Unknown);
            }
        }
Beispiel #10
0
            /// <summary>
            /// Resolves the specified tag.
            /// </summary>
            /// <param name="context">The context.</param>
            /// <param name="chunk">The chunk.</param>
            /// <returns>A <see cref="Resolution" />.</returns>
            public override object Resolve(FormatWriteContext context, FormatChunk chunk)
            {
                // ReSharper disable once PossibleNullReferenceException
                switch (chunk.Tag.ToLowerInvariant())
                {
                case "verbose":
                    return(VerboseFormat);

                case "reversed":
                    return(ReversedFormat);

                case "key":
                    return(Key);

                case "value":
                    return(Value);

                case "position":
                    return(new Resolution(context.Position, true));

                case "!fill":
                    int length = Math.Min(
                        120,
                        context.Layout.Width.Value - context.Layout.FirstLineIndentSize.Value);
                    char          c    = !string.IsNullOrEmpty(chunk.Format) ? chunk.Format[0] : '-';
                    StringBuilder fill = new StringBuilder(length + context.Position < 1 ? 2 : 4);
                    if (context.Position > 0)
                    {
                        fill.AppendLine();
                    }
                    fill.AppendLine(new string(c, length));
                    // Note we have to replace control chunk with value chunk to write it out.
                    return(new Resolution(new FormatChunk(fill.ToString()), true));

                case "nest":
                    string k;
                    string v;
                    if (string.IsNullOrWhiteSpace(chunk.Format))
                    {
                        k = "UnspecKey";
                        v = "UnspecValue";
                    }
                    else
                    {
                        string[] split = chunk.Format.Split(new[] { ',' }, 2, StringSplitOptions.RemoveEmptyEntries);
                        if (split.Length < 1)
                        {
                            k = "UnspecKey";
                            v = "UnspecValue";
                        }
                        else if (split.Length < 2)
                        {
                            k = split[0];
                            v = "UnspecValue";
                        }
                        else
                        {
                            k = split[0];
                            v = split[1];
                        }
                    }
                    return(new RWTest(k, v));

                default:
                    return(Resolution.Unknown);
                }
            }
Beispiel #11
0
            /// <summary>
            /// Resolves the specified tag.
            /// </summary>
            /// <param name="context">The context.</param>
            /// <param name="chunk">The chunk.</param>
            /// <returns>An object that will be cached unless it is a <see cref="T:WebApplications.Utilities.Formatting.Resolution" />.</returns>
            // ReSharper disable once CodeAnnotationAnalyzer
            public override object Resolve(FormatWriteContext context, FormatChunk chunk)
            {
                // ReSharper disable once PossibleNullReferenceException
                switch (chunk.Tag.ToLowerInvariant())
                {
                case "default":
                case "verbose":
                    return(ElementVerboseFormat);

                case "xml":
                    return(ElementXMLFormat);

                case "json":
                    return(ElementJSONFormat);

                case "jsonfirst":
                    return(ElementJSONFirstFormat);

                case "html":
                    return(ElementHTMLFormat);

                case "noline":
                    return(ElementNoLineFormat);

                case "key":
                    string key = Translation.GetResource(
                        Resource,
                        context.FormatProvider as CultureInfo ?? Translation.DefaultCulture);
                    return(string.IsNullOrEmpty(key)
                            ? Resolution.Null
                            : key);

                case "keyxml":
                    string keyXml = Translation.GetResource(
                        Resource,
                        context.FormatProvider as CultureInfo ?? Translation.DefaultCulture);
                    return(string.IsNullOrEmpty(keyXml)
                            ? Resolution.Null
                            : keyXml.XmlEscape());

                case "keyxmltag":
                    string keyXmlTag = Translation.GetResource(
                        Resource,
                        context.FormatProvider as CultureInfo ?? Translation.DefaultCulture);
                    return(string.IsNullOrEmpty(keyXmlTag)
                            ? Resolution.Null
                            : keyXmlTag.Replace(' ', '_'));

                case "value":
                    return(Value);

                case "valuexml":
                    return(Value == null ? Resolution.Null : Value.XmlEscape());

                case "valuehtml":
                    return(Value == null ? Resolution.Null : _newLineRegex.Replace(Value.XmlEscape(), m => "<br/>" + m.Value));

                case "valuejson":
                    return(Value == null ? "null" : Value.ToString().ToJSON());

                default:
                    return(Resolution.Unknown);
                }
            }