Exemplo n.º 1
0
        public ResponseCreator CreateResponseCreator(Endpoint endpoint)
        {
            ResponseCreator responseCreator = null;

            if (literal != null)
            {
                responseCreator = new LiteralResponse(literal, endpoint);
            }
            else if (file != null)
            {
                responseCreator = new FileResponse(file, endpoint); // Path.Combine(rootDir, file)); ;
            }
            else if (script != null)
            {
                responseCreator = new FileDynamicResponseCreator(script, endpoint);
            }
            else if (forward != null)
            {
                responseCreator = new ForwardResponseCreator(forward, endpoint)
                {
                    ProxyUrl = proxy, StripPath = strippath
                };
            }
            else
            {
                throw new NotImplementedException();
            }

            responseCreator.SetDelayFromConfigValue(delay);

            if (responseCreator is SimpleResponseCreator simpleResponseCreator)
            {
                simpleResponseCreator.ContentType = contenttype;
                if (replacements != null)
                {
                    simpleResponseCreator.Replacements = (
                        from jsonreplacement in replacements
                        select new BodyReplacement {
                        SearchTerm = jsonreplacement.search, ReplacementTerm = jsonreplacement.replace
                    }
                        ).ToArray();
                }
                else
                {
                    simpleResponseCreator.Replacements = new BodyReplacement[0];
                }

                Debug.Assert(simpleResponseCreator.Encoding == Encoding.UTF8);
                if (charset != null)
                {
                    simpleResponseCreator.Encoding = Encoding.GetEncoding(charset);
                }
                simpleResponseCreator.SetStatusCodeFromString(statuscode);
            }

            return(responseCreator);
        }
Exemplo n.º 2
0
        public ResponseCreator CreateResponseCreator(string rootDir)
        {
            ResponseCreator responseCreator = null;

            if (literal != null)
            {
                responseCreator = new LiteralResponse(literal);
            }
            else if (file != null)
            {
                responseCreator = new FileResponse(Path.Combine(rootDir, file));;
            }
            else if (script != null)
            {
                responseCreator = new FileDynamicResponseCreator(Path.Combine(rootDir, script));
            }
            else if (assembly != null)
            {
                responseCreator = new AssemblyResponseCreator
                {
                    AssemblyFilename = Path.Combine(rootDir, assembly),
                    ClassName        = @class,
                    MethodName       = method,
                };
            }
            else if (forward != null)
            {
                responseCreator = new ForwardResponseCreator(forward)
                {
                    ProxyUrl = proxy, StripPath = strippath
                };
            }
            else
            {
                throw new NotImplementedException();
            }
            responseCreator.Delay = delay;

            var simpleResponseCreator = responseCreator as SimpleResponseCreator;

            if (simpleResponseCreator != null)
            {
                simpleResponseCreator.ContentType = contenttype;
                if (replacements != null)
                {
                    simpleResponseCreator.Replacements = (
                        from jsonreplacement in replacements
                        select new BodyReplacement {
                        SearchTerm = jsonreplacement.search, ReplacementTerm = jsonreplacement.replace
                    }
                        ).ToArray();
                }
                else
                {
                    simpleResponseCreator.Replacements = new BodyReplacement[0];
                }

                Debug.Assert(simpleResponseCreator.Encoding == Encoding.UTF8);
                if (charset != null)
                {
                    simpleResponseCreator.Encoding = Encoding.GetEncoding(charset);
                }
            }

            return(responseCreator);
        }