public override void Write(IStringBuilder stringBuilder, string indent)
            {
                if (string.IsNullOrEmpty(Name))
                {
                    throw new Exception("You can not add a JavaScript class with no name");
                }

                if (string.IsNullOrEmpty(Body))
                {
                    throw new Exception("You can not add a JavaScript class with no body");
                }

                stringBuilder.Append(indent);

                stringBuilder.Append("var ");
                stringBuilder.Append(Name);
                stringBuilder.AppendLine(" = function () {");

                foreach (var line in Body.Replace("\r", "").Split('\n'))
                {
                    stringBuilder.Append(indent);
                    stringBuilder.Append("  ");
                    stringBuilder.AppendLine(line);
                }

                stringBuilder.Append(indent);
                stringBuilder.AppendLine("}();");
            }
            public void Write(IStringBuilder stringBuilder)
            {
                if (_elements == null)
                {
                    return;
                }

                var hasNamespace = !string.IsNullOrEmpty(NamespaceName);

                if (hasNamespace)
                {
                    stringBuilder.AppendLine(Line1());
                    stringBuilder.AppendLine(Line2());
                }

                foreach (var element in _elements)
                {
                    stringBuilder.AppendLine(string.Empty);
                    element.Write(stringBuilder, hasNamespace ? "  " : string.Empty);
                }

                if (hasNamespace)
                {
                    stringBuilder.AppendLine(string.Empty);

                    foreach (var element in _elements.Where(e => e.IsPublic && !string.IsNullOrEmpty(e.Name)))
                    {
                        stringBuilder.AppendLine("  exported." + element.Name + " = " + element.Name + ";");
                    }

                    stringBuilder.AppendLine(LineN2());
                    stringBuilder.AppendLine(LineN1());
                    stringBuilder.AppendLine(string.Empty);
                }
            }
Ejemplo n.º 3
0
            public override void Write(IStringBuilder stringBuilder, string indent)
            {
                stringBuilder.Append(indent);

                if (string.IsNullOrEmpty(Name))
                {
                    if (!string.IsNullOrEmpty(InitializationExpression))
                    {
                        stringBuilder.Append(InitializationExpression);
                    }
                }
                else
                {
                    stringBuilder.Append(string.IsNullOrEmpty(Type) ? "var" : Type);
                    stringBuilder.Append(' ');
                    stringBuilder.Append(Name);
                    if (!string.IsNullOrEmpty(InitializationExpression))
                    {
                        stringBuilder.Append(" = ");
                        stringBuilder.Append(InitializationExpression);
                    }
                }

                stringBuilder.AppendLine(";");
            }
Ejemplo n.º 4
0
 public override void ToStringBuilder(IStringBuilder writer)
 {
     writer.Append(Selector);
     writer.Append(" { ");
     writer.Append(Styles);
     writer.AppendLine(" }");
 }
Ejemplo n.º 5
0
 public override void ToStringBuilder(IStringBuilder writer)
 {
     if (!string.IsNullOrEmpty(Text))
     {
         writer.AppendLine(Text);
     }
 }
Ejemplo n.º 6
0
            public override void Write(IStringBuilder stringBuilder, string indent)
            {
                stringBuilder.Append(indent);

                if (string.IsNullOrEmpty(Name))
                {
                    stringBuilder.Append("function (");
                }
                else if (IsPublic)
                {
                    if (string.IsNullOrEmpty(Type))
                    {
                        stringBuilder.Append("var ");
                    }
                    else
                    {
                        stringBuilder.Append(Type);
                        stringBuilder.Append(' ');
                    }
                    stringBuilder.Append(Name);
                    stringBuilder.Append(" = function (");
                }
                else
                {
                    stringBuilder.Append("function ");
                    stringBuilder.Append(Name);
                    stringBuilder.Append(" (");
                }

                if (!string.IsNullOrEmpty(Parameters))
                {
                    stringBuilder.Append(Parameters);
                }

                stringBuilder.AppendLine(") {");

                foreach (var line in Body.Replace("\r", "").Split('\n'))
                {
                    stringBuilder.Append(indent);
                    stringBuilder.Append("  ");
                    stringBuilder.AppendLine(line);
                }

                stringBuilder.Append(indent);
                stringBuilder.AppendLine(string.IsNullOrEmpty(Name) ? "}();" : "}");
            }
Ejemplo n.º 7
0
 public static IStringBuilder AppendLine(this IStringBuilder sb, int indent, string message)
 {
     if (indent > 0)
     {
         AppendTabSpaces(sb, indent);
     }
     sb.AppendLine(message);
     return(sb);
 }
Ejemplo n.º 8
0
 public override void ToStringBuilder(IStringBuilder writer)
 {
     if (!string.IsNullOrEmpty(Comment))
     {
         writer.Append("/* ");
         writer.Append(Comment);
         writer.AppendLine(" */");
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Print the matrix to the output stream. Line the elements up in columns.
 /// Use the format object, and right justify within columns of width
 /// characters. Note that is the matrix is to be read back in, you probably
 /// will want to use a NumberFormat that is set to US Locale.
 /// </summary>
 /// <param name="output">the output stream.</param>
 /// <param name="width">Column width.</param>
 public void Print(IStringBuilder output, int width)
 {
     output.AppendLine(); // start on new line.
     for (int i = 0; i < m; ++i)
     {
         for (int j = 0; j < n; j++)
         {
             string s       = A[i, j].ToString();                   // format the number
             int    padding = System.Math.Max(1, width - s.Length); // At _least_ 1 space
             for (int k = 0; k < padding; ++k)
             {
                 output.Append(' ');
             }
             output.Append(s);
         }
         output.AppendLine();
     }
     output.AppendLine(); // end with blank line.
 }
Ejemplo n.º 10
0
            public override void Write(IStringBuilder stringBuilder, string indent)
            {
                stringBuilder.Append(indent);
                switch (CommentStyle)
                {
                case CommentStyle.SingleLineC:
                    stringBuilder.Append("// ");
                    stringBuilder.AppendLine(Comment);
                    break;

                case CommentStyle.MultiLineC:
                    stringBuilder.Append("/* ");
                    stringBuilder.Append(Comment);
                    stringBuilder.AppendLine(" */");
                    break;

                case CommentStyle.Xml:
                    stringBuilder.Append("<!-- ");
                    stringBuilder.Append(Comment);
                    stringBuilder.AppendLine(" -->");
                    break;
                }
            }
Ejemplo n.º 11
0
        public void Generate(IStringBuilder sb, Namespace @namespace, ulong revision, Schema schema)
        {
            sb.AppendLine("using System;");
            sb.AppendLine("using System.ComponentModel;");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using System.Data;");
            sb.AppendLine("using System.Linq;");
            sb.AppendLine("using System.Text;");
            sb.AppendLine("using egregore.Data;");
            sb.AppendLine("using egregore.Data.Attributes;");
            sb.AppendLine();

            sb.OpenNamespace($"{@namespace.Value}.V{revision}");

            sb.AppendLine($"public sealed class {schema.Name} : {nameof(IRecord<object>)}<{schema.Name}>");
            sb.AppendLine("{");

            sb.Indent++;
            {
                sb.AppendLine("[ReadOnly(true)]");
                sb.AppendLine("public Guid Uuid { get; set; }");

                sb.AppendLine("[ReadOnly(true)]");
                sb.AppendLine("public ulong TimestampV1 { get; set; }");

                sb.AppendLine("[ReadOnly(true)]");
                sb.AppendLine("public ulong TimestampV2 { get; set; }");

                foreach (var property in schema.Properties)
                {
                    if (property.IsRequired)
                    {
                        sb.AppendLine("[Required]");
                    }

                    sb.AppendLine($"public {property.Type} {property.Name} {{ get; set; }}");
                }

                sb.AppendLine();
                sb.AppendLine("public Record ToRecord()");
                sb.AppendLine("{");
                sb.AppendLine($"    var record = new Record {{ Type = \"{schema.Name}\" }};");
                sb.AppendLine("    record.Uuid = Uuid;");
                sb.AppendLine("    record.TimestampV1 = TimestampV1;");
                sb.AppendLine("    record.TimestampV2 = TimestampV2;");
                for (var i = 0; i < schema.Properties.Count; i++)
                {
                    var property = schema.Properties[i];
                    sb.AppendLine(
                        $"    record.Columns.Add(new RecordColumn({i}, \"{property.Name}\", \"{property.Type}\", {property.Name}?.ToString()));");
                }

                sb.AppendLine("    return record;");
                sb.AppendLine("}");

                sb.AppendLine();
                sb.AppendLine($"public {schema.Name} ToModel(Record record)");
                sb.AppendLine("{");
                sb.AppendLine($"    var model = new {schema.Name}();");
                sb.AppendLine("    model.Uuid = record.Uuid;");
                sb.AppendLine("    model.TimestampV1 = record.TimestampV1;");
                sb.AppendLine("    model.TimestampV2 = record.TimestampV2;");
                foreach (var property in schema.Properties)
                {
                    sb.AppendLine(
                        $"    var value = record.Columns.SingleOrDefault(x => x.Name.Equals(\"{property.Name}\", StringComparison.OrdinalIgnoreCase))?.Value;");
                    sb.AppendLine(
                        $"    model.{property.Name} = ({property.Type})(value == default ? default : Convert.ChangeType(value, typeof({property.Type})));");
                }

                sb.AppendLine("    return model;");
                sb.AppendLine("}");
            }
            sb.Indent--;


            sb.AppendLine("}");
            sb.CloseNamespace();
        }
Ejemplo n.º 12
0
 public void AppendText()
 {
     _sb.AppendLine(LINE);
 }
 public override void Write(IStringBuilder stringBuilder, string indent)
 {
     stringBuilder.Append(indent);
     stringBuilder.AppendLine(Text);
 }
 public void Run()
 {
     _sb.AppendLine(LINE);
 }