예제 #1
0
        /// <inheritdoc />
        public virtual bool Process()
        {
            try {
                SpeakCache = OriginalContent.FromYaml <TTemplate>();
            }
            catch {
                return(false);
            }

            return(true);
        }
예제 #2
0
        /// <inheritdoc />
        public virtual async Task <bool> ProcessAsync()
        {
            try {
                SpeakCache = await OriginalContent.FromYamlAsync <TTemplate>();
            }
            catch {
                return(false);
            }

            return(true);
        }
예제 #3
0
        /// <summary>
        /// Serialise the original content to a compressed stream.
        /// <see cref="HttpContent.SerializeToStreamAsync(Stream, TransportContext)"/>
        /// </summary>
        /// <exception cref="ArgumentNullException">stream is null.</exception>
        protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            Stream compressedStream = Compressor.Compress(stream);

            return(OriginalContent.CopyToAsync(compressedStream).ContinueWith(task =>
            {
                if (compressedStream != null)
                {
                    compressedStream.Dispose();
                }
            }));
        }
예제 #4
0
        public async Task Write(Stream target, uint bufferSize)
        {
            using var compressed = Generator(target);

            await OriginalContent.Write(compressed, bufferSize);
        }
예제 #5
0
        public void Render()
        {
            if (!is_rendered)
            {
                var result = "";

                if (!string.IsNullOrEmpty(OriginalContent))
                {
                    if (argList.Count > 0)
                    {
                        char ch;
                        var  state      = 1;
                        var  i          = 0;
                        var  prev       = 0;
                        var  arg        = "";
                        var  breakWhile = false;
                        char?lastChar   = null;

                        while (i < OriginalContent.Length && !breakWhile)
                        {
                            if (lastChar != null)
                            {
                                ch       = lastChar.Value;
                                lastChar = null;
                            }
                            else
                            {
                                ch = OriginalContent[i];
                            }

                            switch (state)
                            {
                            case 1:
                                if (ch == '\\')
                                {
                                    state = 2;
                                }
                                else
                                if (ch == '{')
                                {
                                    state = 3;
                                    prev  = i;
                                }
                                else
                                {
                                    result += ch;
                                }
                                break;

                            case 2:
                                if (ch == '\\')
                                {
                                    result += ch;
                                    state   = 1;
                                }
                                else
                                if (ch == '{')
                                {
                                    result += ch;
                                    state   = 1;
                                }
                                else
                                if (ch == '}')
                                {
                                    result += ch;
                                    state   = 1;
                                }
                                else
                                {
                                    breakWhile = true;
                                }
                                break;

                            case 3:
                                if (char.IsLetterOrDigit(ch))
                                {
                                    state = 3;
                                }
                                else
                                if (ch == '}')
                                {
                                    if (i - prev - 1 > 0 && argList.Count > 0)
                                    {
                                        arg = OriginalContent.Substring(prev + 1, i - prev - 1);

                                        if (argList.ContainsKey(arg))
                                        {
                                            result += argList[arg];
                                        }
                                    }

                                    state = 1;
                                }
                                else
                                {
                                    breakWhile = true;
                                }
                                break;
                            }

                            if (lastChar == null)
                            {
                                i++;
                            }
                        }
                    }
                    else
                    {
                        result = OriginalContent;
                    }
                }
                is_rendered = true;
                Content     = result;
            }
        }