public static string Html(Func <int, int> random, int paragraphs, bool includeHeading, bool includeHeadAndBody)
        {
            var builder       = new StringBuilder();
            var innerEngine   = new InnerEngine(random);
            var waffleContent = innerEngine.GetContent(paragraphs, includeHeading);

            if (waffleContent.Heading != null)
            {
                if (includeHeadAndBody)
                {
                    builder.AppendLine(@$ "<html>
<head>
<title>{waffleContent.Heading.Title}</title>
Пример #2
0
        public static string Html(Func <int, int> random, int paragraphs, bool includeHeading, bool includeHeadAndBody)
        {
            var builder       = new StringBuilder();
            var innerEngine   = new InnerEngine(random);
            var waffleContent = innerEngine.GetContent(paragraphs, includeHeading);

            if (includeHeading)
            {
                if (includeHeadAndBody)
                {
                    builder.AppendLine("<html>");
                    builder.AppendLine("<head>");
                    builder.AppendFormat("<title>{0}</title>", waffleContent.Heading.Title);
                    builder.AppendLine();
                    builder.AppendLine("</head>");
                    builder.AppendLine("<body>");
                }

                builder.AppendFormat(@"<h1>{0}</h1>", waffleContent.Heading.Title);
                builder.AppendLine();
                builder.AppendLine($"<blockquote>\"{waffleContent.Heading.Quote}\"<br>");
                builder.AppendLine($"<cite>{waffleContent.Heading.Cite}</cite></blockquote>");
                builder.AppendLine($"<h2>{waffleContent.Heading.Buzz}</h2>");
            }

            foreach (var paragraph in waffleContent.Paragraphs)
            {
                builder.AppendLine("<p>");
                if (paragraph.Heading != null)
                {
                    builder.AppendLine($"<h2>{paragraph.Heading}</h2>");
                }

                builder.AppendLine(paragraph.Body);
                builder.AppendLine("</p>");
            }

            if (includeHeadAndBody)
            {
                builder.AppendLine("</body>");
                builder.Append("</html>");
            }

            return(builder.ToString());
        }
Пример #3
0
        public static string Text(Func <int, int> random, int paragraphs, bool includeHeading)
        {
            var builder       = new StringBuilder();
            var innerEngine   = new InnerEngine(random);
            var waffleContent = innerEngine.GetContent(paragraphs, includeHeading);

            if (includeHeading)
            {
                builder.AppendLine(waffleContent.Heading.Title);
                builder.AppendLine();
                builder.AppendLine($"\"{waffleContent.Heading.Quote}\"");
                builder.AppendLine();
                builder.AppendLine($" - {waffleContent.Heading.Cite}");
                builder.AppendLine();
                builder.AppendLine(waffleContent.Heading.Buzz);
                builder.AppendLine();
            }

            var lastIndex = waffleContent.Paragraphs.Count - 1;

            for (var index = 0; index < waffleContent.Paragraphs.Count; index++)
            {
                var paragraph = waffleContent.Paragraphs[index];
                if (paragraph.Heading != null)
                {
                    builder.AppendLine(paragraph.Heading);
                    builder.AppendLine();
                }

                builder.AppendLine(paragraph.Body);
                if (index != lastIndex)
                {
                    builder.AppendLine();
                }
            }

            return(builder.ToString());
        }
Пример #4
0
 /// <summary>
 /// Creates a pre-compiled script from embedded JS resource
 /// </summary>
 /// <param name="resourceName">The case-sensitive resource name without the namespace of the specified type</param>
 /// <param name="type">The type, that determines the assembly and whose namespace is used to scope
 /// the resource name</param>
 /// <returns>A pre-compiled script that can be executed by different instances of JS engine</returns>
 public virtual IPrecompiledScript PrecompileResource(string resourceName, Type type)
 {
     return(InnerEngine.PrecompileResource(resourceName, type));
 }
Пример #5
0
 /// <summary>
 /// Creates a pre-compiled script from JS code
 /// </summary>
 /// <param name="code">JS code</param>
 /// <param name="documentName">Document name</param>
 /// <returns>A pre-compiled script that can be executed by different instances of JS engine</returns>
 public virtual IPrecompiledScript Precompile(string code, string documentName)
 {
     return(InnerEngine.Precompile(code, documentName));
 }
Пример #6
0
 /// <summary>
 /// Collects the garbage
 /// </summary>
 public virtual void CollectGarbage()
 {
     InnerEngine.CollectGarbage();
 }
Пример #7
0
 /// <summary>
 /// Embeds a .NET type in the JS engine
 /// </summary>
 /// <param name="itemName">Name of the type</param>
 /// <param name="type">The type</param>
 /// <remarks>
 /// .NET types are exposed to script code in the form of objects whose properties and
 /// methods are bound to the type's static members.
 /// </remarks>
 public virtual void EmbedHostType(string itemName, Type type)
 {
     InnerEngine.EmbedHostType(itemName, type);
 }
Пример #8
0
 /// <summary>
 /// Removes a variable
 /// </summary>
 /// <param name="variableName">Variable name</param>
 public virtual void RemoveVariable(string variableName)
 {
     InnerEngine.RemoveVariable(variableName);
 }
Пример #9
0
 /// <summary>
 /// Gets a value of variable
 /// </summary>
 /// <typeparam name="T">Type of variable</typeparam>
 /// <param name="variableName">Variable name</param>
 /// <returns>Value of variable</returns>
 public virtual T GetVariableValue <T>(string variableName)
 {
     return(InnerEngine.GetVariableValue <T>(variableName));
 }
Пример #10
0
 /// <summary>
 /// Evaluates an expression
 /// </summary>
 /// <typeparam name="T">Type of result</typeparam>
 /// <param name="expression">JS expression</param>
 /// <param name="documentName">Document name</param>
 /// <returns>Result of the expression</returns>
 public virtual T Evaluate <T>(string expression, string documentName)
 {
     return(InnerEngine.Evaluate <T>(expression, documentName));
 }
Пример #11
0
 /// <summary>
 /// Evaluates an expression
 /// </summary>
 /// <typeparam name="T">Type of result</typeparam>
 /// <param name="expression">JS expression</param>
 /// <returns>Result of the expression</returns>
 public virtual T Evaluate <T>(string expression)
 {
     return(InnerEngine.Evaluate <T>(expression));
 }
Пример #12
0
 /// <summary>
 /// Evaluates an expression
 /// </summary>
 /// <param name="expression">JS expression</param>
 /// <param name="documentName">Document name</param>
 /// <returns>Result of the expression</returns>
 public virtual object Evaluate(string expression, string documentName)
 {
     return(InnerEngine.Evaluate(expression, documentName));
 }
Пример #13
0
 /// <summary>
 /// Evaluates an expression
 /// </summary>
 /// <param name="expression">JS expression</param>
 /// <returns>Result of the expression</returns>
 public virtual object Evaluate(string expression)
 {
     return(InnerEngine.Evaluate(expression));
 }
Пример #14
0
        public static string Title(Func <int, int> random)
        {
            var innerEngine = new InnerEngine(random);

            return(innerEngine.BuildTitle());
        }
Пример #15
0
 /// <summary>
 /// Сhecks for the existence of a variable
 /// </summary>
 /// <param name="variableName">Variable name</param>
 /// <returns>Result of check (true - exists; false - not exists</returns>
 public virtual bool HasVariable(string variableName)
 {
     return(InnerEngine.HasVariable(variableName));
 }
Пример #16
0
 /// <summary>
 /// Gets a value of variable
 /// </summary>
 /// <param name="variableName">Variable name</param>
 /// <returns>Value of variable</returns>
 public virtual object GetVariableValue(string variableName)
 {
     return(InnerEngine.GetVariableValue(variableName));
 }
Пример #17
0
 /// <summary>
 /// Executes a code
 /// </summary>
 /// <param name="code">JS code</param>
 public virtual void Execute(string code)
 {
     InnerEngine.Execute(code);
 }
Пример #18
0
 /// <summary>
 /// Sets a value of variable
 /// </summary>
 /// <param name="variableName">Variable name</param>
 /// <param name="value">Value of variable</param>
 public virtual void SetVariableValue(string variableName, object value)
 {
     InnerEngine.SetVariableValue(variableName, value);
 }
Пример #19
0
 /// <summary>
 /// Executes a code
 /// </summary>
 /// <param name="code">JS code</param>
 /// <param name="documentName">Document name</param>
 public virtual void Execute(string code, string documentName)
 {
     InnerEngine.Execute(code, documentName);
 }
Пример #20
0
 /// <summary>
 /// Embeds a .NET object in the JS engine
 /// </summary>
 /// <param name="itemName">Name of the item</param>
 /// <param name="value">Value of the item</param>
 /// <remarks>Allows to embed instances of simple classes (or structures) and delegates.</remarks>
 public virtual void EmbedHostObject(string itemName, object value)
 {
     InnerEngine.EmbedHostObject(itemName, value);
 }
Пример #21
0
 /// <summary>
 /// Executes a pre-compiled script
 /// </summary>
 /// <param name="precompiledScript">A pre-compiled script that can be executed by different
 /// instances of JS engine</param>
 public virtual void Execute(IPrecompiledScript precompiledScript)
 {
     InnerEngine.Execute(precompiledScript);
 }
Пример #22
0
 /// <summary>
 /// Interrupts script execution and causes the JS engine to throw an exception
 /// </summary>
 public virtual void Interrupt()
 {
     InnerEngine.Interrupt();
 }
Пример #23
0
 /// <summary>
 /// Executes a code from JS file
 /// </summary>
 /// <param name="path">Path to the JS file</param>
 /// <param name="encoding">Text encoding</param>
 public virtual void ExecuteFile(string path, Encoding encoding = null)
 {
     InnerEngine.ExecuteFile(path, encoding);
 }
Пример #24
0
 /// <summary>
 /// Creates a pre-compiled script from JS code
 /// </summary>
 /// <param name="code">JS code</param>
 /// <returns>A pre-compiled script that can be executed by different instances of JS engine</returns>
 public virtual IPrecompiledScript Precompile(string code)
 {
     return(InnerEngine.Precompile(code));
 }
Пример #25
0
 /// <summary>
 /// Executes a code from embedded JS resource
 /// </summary>
 /// <param name="resourceName">The case-sensitive resource name without the namespace of the specified type</param>
 /// <param name="type">The type, that determines the assembly and whose namespace is used to scope
 /// the resource name</param>
 public virtual void ExecuteResource(string resourceName, Type type)
 {
     InnerEngine.ExecuteResource(resourceName, type);
 }
Пример #26
0
 /// <summary>
 /// Creates a pre-compiled script from JS file
 /// </summary>
 /// <param name="path">Path to the JS file</param>
 /// <param name="encoding">Text encoding</param>
 /// <returns>A pre-compiled script that can be executed by different instances of JS engine</returns>
 public virtual IPrecompiledScript PrecompileFile(string path, Encoding encoding = null)
 {
     return(InnerEngine.PrecompileFile(path, encoding));
 }
Пример #27
0
 /// <summary>
 /// Executes a code from embedded JS resource
 /// </summary>
 /// <param name="resourceName">The case-sensitive resource name</param>
 /// <param name="assembly">The assembly, which contains the embedded resource</param>
 public virtual void ExecuteResource(string resourceName, Assembly assembly)
 {
     InnerEngine.ExecuteResource(resourceName, assembly);
 }
Пример #28
0
 /// <summary>
 /// Creates a pre-compiled script from embedded JS resource
 /// </summary>
 /// <param name="resourceName">The case-sensitive resource name</param>
 /// <param name="assembly">The assembly, which contains the embedded resource</param>
 /// <returns>A pre-compiled script that can be executed by different instances of JS engine</returns>
 public virtual IPrecompiledScript PrecompileResource(string resourceName, Assembly assembly)
 {
     return(InnerEngine.PrecompileResource(resourceName, assembly));
 }
Пример #29
0
 /// <summary>
 /// Calls a function
 /// </summary>
 /// <typeparam name="T">Type of function result</typeparam>
 /// <param name="functionName">Function name</param>
 /// <param name="args">Function arguments</param>
 /// <returns>Result of the function execution</returns>
 public virtual T CallFunction <T>(string functionName, params object[] args)
 {
     return(InnerEngine.CallFunction <T>(functionName, args));
 }