Inheritance: IDisposable
Esempio n. 1
0
        private void GeneratePacketWriter(Schema packetSchema)
        {
            string packetWriterFilename = Path.Combine(m_outputDirectory, "PacketCesiumWriter.cs");
            using (CodeWriter writer = new CodeWriter(packetWriterFilename))
            {
                WriteGeneratedWarning(writer);
                writer.WriteLine();
                WriteNamespaces(writer, packetSchema);
                writer.WriteLine();

                writer.WriteLine("namespace {0}", m_configuration.Namespace);
                writer.OpenScope();

                WriteDescriptionAsClassSummary(writer, packetSchema);
                writer.WriteLine("public class PacketCesiumWriter : CesiumElementWriter");
                writer.OpenScope();

                WritePropertyNameConstants(writer, packetSchema);
                WritePropertyLazyFields(writer, packetSchema);
                WritePacketOpenClose(writer);
                WriteProperties(writer, packetSchema);

                writer.CloseScope();

                writer.CloseScope();
            }
        }
Esempio n. 2
0
        private void GenerateWriterClass(Schema schema)
        {
            if (m_writtenSchemas.Contains(schema))
                return;

            m_writtenSchemas.Add(schema);

            string writerFilename = Path.Combine(m_outputDirectory, schema.NameWithPascalCase + "CesiumWriter.cs");
            using (CodeWriter writer = new CodeWriter(writerFilename))
            {
                WriteGeneratedWarning(writer);
                writer.WriteLine();
                WriteNamespaces(writer, schema);
                writer.WriteLine();

                writer.WriteLine("namespace {0}", m_configuration.Namespace);
                writer.OpenScope();

                WriteDescriptionAsClassSummary(writer, schema);

                string defaultValueType = GetDefaultValueType(schema);

                if (defaultValueType != null)
                {
                    bool isInterpolatable = schema.Extends != null && schema.Extends.Name == "InterpolatableProperty";
                    if (isInterpolatable)
                        writer.WriteLine("public class {0}CesiumWriter : CesiumInterpolatableValuePropertyWriter<{1}, {0}CesiumWriter>", schema.NameWithPascalCase, defaultValueType);
                    else
                        writer.WriteLine("public class {0}CesiumWriter : CesiumValuePropertyWriter<{1}, {0}CesiumWriter>", schema.NameWithPascalCase, defaultValueType);
                }
                else
                {
                    writer.WriteLine("public class {0}CesiumWriter : CesiumPropertyWriter<{0}CesiumWriter>", schema.NameWithPascalCase);
                }

                writer.OpenScope();

                WritePropertyNameConstants(writer, schema);
                WritePropertyLazyFields(writer, schema);
                WriteConstructorsAndCloneMethod(writer, schema);
                WriteProperties(writer, schema);

                writer.CloseScope();

                writer.CloseScope();
            }
        }
Esempio n. 3
0
        private static void WritePacketOpenClose(CodeWriter writer)
        {
            WriteSummaryText(writer, "Writes the start of a new JSON object representing the packet.");
            writer.WriteLine("protected override void OnOpen()");
            writer.OpenScope();
            writer.WriteLine("Output.WriteStartObject();");
            writer.CloseScope();

            writer.WriteLine();

            WriteSummaryText(writer, "Writes the end of the JSON object representing the packet.");
            writer.WriteLine("protected override void OnClose()");
            writer.OpenScope();
            writer.WriteLine("Output.WriteEndObject();");
            writer.CloseScope();

            writer.WriteLine();
        }
Esempio n. 4
0
 public CodeScope(CodeWriter codeWriter)
 {
     m_codeWriter = codeWriter;
 }
 private static void WriteValue(CodeWriter writer, string openWriterName, string valueName, Property valueProperty, Property parentProperty, bool isExtension, string propertyName)
 {
     string value;
     string assertionValue;
     string assertionEpsilon;
     string valueType;
     GetUniqueValue(valueName, valueProperty, parentProperty, out value, out assertionValue, out assertionEpsilon, out valueType);
     writer.WriteLine("{0}.Write{1}({2});", openWriterName, valueProperty.NameWithPascalCase, value);
     WriteAssertion(writer, isExtension, "expect(e.{0}.getValue(date)).toEqual{1}({2}{3});",
                    propertyName,
                    assertionEpsilon == null ? "" : "Epsilon",
                    assertionValue,
                    assertionEpsilon == null ? "" : string.Format(", {0}", assertionEpsilon));
 }
Esempio n. 6
0
        private void WriteAsTypeMethods(CodeWriter writer, Schema schema)
        {
            if (schema.Properties == null)
                return;

            foreach (Property property in schema.Properties)
            {
                if (!property.IsValue)
                    continue;
                if (PropertyValueIsIntervals(property))
                    continue;

                OverloadInfo[] overloads = GetOverloadsForProperty(property);

                if (overloads[0].Parameters.Length != 1)
                    continue;

                OverloadInfo sampleOverload = FindSampledDataOverload(overloads);

                string interfaceName = "ICesiumValuePropertyWriter";
                if (sampleOverload != null)
                    interfaceName = "ICesiumInterpolatableValuePropertyWriter";

                WriteSummaryText(writer, string.Format("Returns a wrapper for this instance that implements <see cref=\"{0}{{T}}\" /> to write a value in <code>{1}</code> format.  Because the returned instance is a wrapper for this instance, you may call <see cref=\"ICesiumElementWriter.Close\" /> on either this instance or the wrapper, but you must not call it on both.", interfaceName, property.NameWithPascalCase));
                writer.WriteLine("/// <returns>The wrapper.</returns>");
                writer.WriteLine("public {0}<{1}> As{2}()",
                                 interfaceName,
                                 overloads[0].Parameters[0].Type,
                                 property.NameWithPascalCase);
                writer.OpenScope();
                writer.WriteLine("return m_as{0}.Value;", property.NameWithPascalCase);
                writer.CloseScope();
                writer.WriteLine();

                string adaptorName = "CesiumWriterAdaptor";
                if (sampleOverload != null)
                    adaptorName = "CesiumInterpolatableWriterAdaptor";

                writer.WriteLine("private {0}<{1}> Create{2}Adaptor()",
                                 interfaceName,
                                 overloads[0].Parameters[0].Type,
                                 property.NameWithPascalCase);
                writer.OpenScope();
                writer.WriteLine("return new {0}<{1}CesiumWriter, {2}>(",
                                 adaptorName,
                                 schema.NameWithPascalCase,
                                 overloads[0].Parameters[0].Type);
                if (sampleOverload != null)
                {
                    writer.WriteLine("    this, (me, value) => me.Write{0}(value), ({1}CesiumWriter me, IList<JulianDate> dates, IList<{2}> values, int startIndex, int length) => me.Write{0}(dates, values, startIndex, length));",
                                     property.NameWithPascalCase,
                                     schema.NameWithPascalCase,
                                     overloads[0].Parameters[0].Type);
                }
                else
                {
                    writer.WriteLine("    this, (me, value) => me.Write{0}(value));",
                                     property.NameWithPascalCase);
                }
                writer.CloseScope();
                writer.WriteLine();
            }
        }
Esempio n. 7
0
        private void WriteConstructorsAndCloneMethod(CodeWriter writer, Schema schema)
        {
            WriteSummaryText(writer, "Initializes a new instance.");
            writer.WriteLine("public {0}CesiumWriter(string propertyName)", schema.NameWithPascalCase);
            writer.WriteLine("    : base(propertyName)");
            writer.OpenScope();
            WriteAsTypeLazyInitialization(writer, schema);
            writer.CloseScope();
            writer.WriteLine();

            WriteSummaryText(writer, "Initializes a new instance as a copy of an existing instance.");
            writer.WriteLine("/// <param name=\"existingInstance\">The existing instance to copy.</param> ");
            writer.WriteLine("protected {0}CesiumWriter({0}CesiumWriter existingInstance)", schema.NameWithPascalCase);
            writer.WriteLine("    : base(existingInstance)");
            writer.OpenScope();
            WriteAsTypeLazyInitialization(writer, schema);
            writer.CloseScope();
            writer.WriteLine();

            writer.WriteLine("/// <inheritdoc />");
            writer.WriteLine("public override {0}CesiumWriter Clone()", schema.NameWithPascalCase);
            writer.OpenScope();
            writer.WriteLine("return new {0}CesiumWriter(this);", schema.NameWithPascalCase);
            writer.CloseScope();
            writer.WriteLine();
        }
Esempio n. 8
0
        private void WriteLeafProperty(CodeWriter writer, Schema schema, Property property, bool isFirstValueProperty)
        {
            OverloadInfo[] overloads = GetOverloadsForProperty(property);

            foreach (OverloadInfo overload in overloads)
            {
                WriteSummaryText(writer, string.Format("Writes the <code>{0}</code> property.  The <code>{0}</code> property specifies {1}", property.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
                foreach (ParameterInfo parameter in overload.Parameters)
                {
                    if (string.IsNullOrEmpty(parameter.Description))
                        continue;
                    WriteParameterText(writer, parameter.Name, parameter.Description);
                }

                writer.WriteLine("public void Write{0}({1})", property.NameWithPascalCase, overload.FormattedParameters);
                writer.OpenScope();
                if (overload.CallOverload != null)
                {
                    writer.WriteLine("Write{0}({1});", property.NameWithPascalCase, overload.CallOverload);
                }
                else
                {
                    writer.WriteLine("const string PropertyName = {0}PropertyName;", property.NameWithPascalCase);

                    if (schema.Name == "Packet")
                    {
                        writer.WriteLine("Output.WritePropertyName(PropertyName);");
                    }
                    else if (isFirstValueProperty && !overload.NeedsInterval)
                    {
                        // For the first value property only, if an overload is marked 
                        // as not needing an interval, because it writes a simple JSON 
                        // type (string, number, boolean), we can skip opening an interval 
                        // and just write the property value directly.
                        writer.WriteLine("if (IsInterval)");
                        writer.WriteLine("    Output.WritePropertyName(PropertyName);");
                    }
                    else
                    {
                        writer.WriteLine("OpenIntervalIfNecessary();");

                        if (overload.WritePropertyName)
                            writer.WriteLine("Output.WritePropertyName(PropertyName);");
                    }

                    writer.WriteLine(overload.WriteValue);
                }
                writer.CloseScope();
                writer.WriteLine();
            }
        }
Esempio n. 9
0
        private void WriteProperties(CodeWriter writer, Schema schema)
        {
            if (schema.Properties == null)
                return;

            bool isFirstValueProperty = true;

            foreach (Property property in schema.Properties)
            {
                if (PropertyValueIsIntervals(property))
                    WriteIntervalsProperty(writer, schema, property);
                else
                    WriteLeafProperty(writer, schema, property, property.IsValue && isFirstValueProperty);

                if (property.IsValue)
                    isFirstValueProperty = false;
            }
        }
Esempio n. 10
0
        private void WritePropertyNameConstants(CodeWriter writer, Schema schema)
        {
            if (schema.Properties == null)
                return;

            foreach (Property property in schema.Properties)
            {
                WriteSummaryText(writer, string.Format("The name of the <code>{0}</code> property.", property.Name));
                writer.WriteLine("public const string {0}PropertyName = \"{1}\";", property.NameWithPascalCase, property.Name);
                writer.WriteLine();
            }
        }
Esempio n. 11
0
 private void WriteSummaryText(CodeWriter writer, string text)
 {
     writer.WriteLine("/// <summary>");
     writer.WriteLine("/// {0}", text);
     writer.WriteLine("/// </summary>");
 }
Esempio n. 12
0
 private void WriteGeneratedWarning(CodeWriter writer)
 {
     writer.WriteLine("// This file was generated automatically by GenerateFromSchema.  Do NOT edit it.");
     writer.WriteLine("// https://github.com/AnalyticalGraphicsInc/czml-writer");
 }
Esempio n. 13
0
        private void WriteLeafProperty(CodeWriter writer, Schema schema, Property property, bool isFirstValueProperty)
        {
            OverloadInfo[] overloads = GetOverloadsForProperty(property);

            foreach (OverloadInfo overload in overloads)
            {
                WriteSummaryText(writer, string.Format("Writes the <code>{0}</code> property.  The <code>{0}</code> property specifies {1}", property.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
                foreach (ParameterInfo parameter in overload.Parameters)
                {
                    if (string.IsNullOrEmpty(parameter.Description))
                        continue;
                    WriteParameterText(writer, parameter.Name, parameter.Description);
                }
                writer.WriteLine("public void Write{0}({1})", isFirstValueProperty ? "Value" : property.NameWithPascalCase, overload.FormattedParameters);
                writer.OpenScope();
                if (overload.CallOverload != null)
                {
                    writer.WriteLine("Write{0}({1});", isFirstValueProperty ? "Value" : property.NameWithPascalCase, overload.CallOverload);
                }
                else
                {
                    // First the first value property only, if an overload has one parameter and that
                    // parameter is a simple JSON type (string, number, boolean), we can skip opening an
                    // interval and just write the property value directly.
                    if (isFirstValueProperty && overload.Parameters.Length == 1 &&
                        (overload.Parameters[0].Type == "string" || overload.Parameters[0].Type == "double" ||
                         overload.Parameters[0].Type == "int" || overload.Parameters[0].Type == "bool"))
                    {
                        writer.WriteLine("if (IsInterval)");
                        writer.WriteLine("    Output.WritePropertyName({0}PropertyName);", property.NameWithPascalCase);
                    }
                    else
                    {
                        writer.WriteLine("OpenIntervalIfNecessary();");
                        writer.WriteLine("Output.WritePropertyName({0}PropertyName);", property.NameWithPascalCase);
                    }
                    writer.WriteLine(overload.WriteValue);
                }
                writer.CloseScope();
                writer.WriteLine();
            }
        }
Esempio n. 14
0
        private void WritePropertyLazyFields(CodeWriter writer, Schema schema)
        {
            if (schema.Properties == null)
                return;

            foreach (Property property in schema.Properties)
            {
                if (!PropertyValueIsIntervals(property))
                    continue;

                writer.WriteLine("private readonly Lazy<{0}CesiumWriter> m_{1} = new Lazy<{0}CesiumWriter>(() => new {0}CesiumWriter({2}PropertyName), false);",
                    property.ValueType.NameWithPascalCase,
                    property.Name,
                    property.NameWithPascalCase);
            }

            writer.WriteLine();
        }
Esempio n. 15
0
        private void WriteNamespaces(CodeWriter writer, Schema schema)
        {
            if (schema.Properties == null)
                return;

            HashSet<string> namespaces = new HashSet<string>();

            foreach (Property property in schema.Properties)
            {
                OverloadInfo[] overloads = GetOverloadsForProperty(property);
                foreach (OverloadInfo overload in overloads)
                {
                    if (overload.Namespaces != null)
                    {
                        foreach (string ns in overload.Namespaces)
                        {
                            namespaces.Add(ns);
                        }
                    }
                }
            }

            foreach (string ns in namespaces)
            {
                writer.WriteLine("using {0};", ns);
            }
        }
        public override void Generate(Schema schema)
        {
            using (CodeWriter writer = new CodeWriter(Path.Combine(m_outputDirectory, "TestGenerateValidationDocument.cs")))
            {
                writer.WriteLine("// This file was generated automatically by GenerateFromSchema.  Do NOT edit it.");
                writer.WriteLine("// https://github.com/AnalyticalGraphicsInc/czml-writer");
                writer.WriteLine();

                writer.WriteLine("using System.Collections.Generic;");
                writer.WriteLine("using System.Diagnostics.CodeAnalysis;");
                writer.WriteLine("using System.Drawing;");
                writer.WriteLine("using System.IO;");
                writer.WriteLine("using CesiumLanguageWriter;");
                writer.WriteLine("using NUnit.Framework;");
                writer.WriteLine();

                writer.WriteLine("namespace {0}", "CesiumLanguageWriterTests");

                using (writer.OpenScope())
                {
                    writer.WriteLine("[TestFixture]");
                    writer.WriteLine("[SuppressMessage(\"ReSharper\", \"MemberCanBeMadeStatic.Local\")]");
                    writer.WriteLine("public class TestGenerateValidationDocument");

                    using (writer.OpenScope())
                    {
                        writer.WriteLine("private readonly JulianDate m_documentStartDate = new GregorianDate(2016, 6, 17, 12, 0, 0).ToJulianDate();");
                        writer.WriteLine("private readonly JulianDate m_documentStopDate = new GregorianDate(2016, 6, 17, 13, 0, 0).ToJulianDate();");

                        writer.WriteLine("private TextWriter m_streamWriter;");
                        writer.WriteLine("private TextWriter m_assertionsWriter;");
                        writer.WriteLine("private TextWriter m_extensionsAssertionsWriter;");
                        writer.WriteLine("private CesiumOutputStream m_output;");
                        writer.WriteLine("private CesiumStreamWriter m_writer;");

                        writer.WriteLine("private void WriteAssertionBoth(string s)");
                        using (writer.OpenScope())
                        {
                            writer.WriteLine("m_assertionsWriter.WriteLine(s);");
                            writer.WriteLine("m_extensionsAssertionsWriter.WriteLine(s);");
                        }

                        writer.WriteLine("private static IList<T> CreateList<T>(T t1, T t2)");
                        using (writer.OpenScope())
                        {
                            writer.WriteLine("return new List<T> { t1, t2 };");
                        }
                        writer.WriteLine("private static IList<T> CreateList<T>(params T[] ts)");
                        using (writer.OpenScope())
                        {
                            writer.WriteLine("return ts;");
                        }

                        writer.WriteLine("[Test]");
                        writer.WriteLine("public void GenerateValidationDocument()");

                        var schemaProperties = schema.Properties
                                                     .Where(p => p.Name != "clock" && p.Name != "availability" && !p.ValueType.IsSchemaFromType)
                                                     .ToList();

                        using (writer.OpenScope())
                        {
                            writer.WriteLine("using (m_streamWriter = new StreamWriter(\"ValidationDocument.czml\"))");
                            writer.WriteLine("using (m_assertionsWriter = new StreamWriter(\"ValidationDocumentAssertions.js\"))");
                            writer.WriteLine("using (m_extensionsAssertionsWriter = new StreamWriter(\"ValidationDocumentExtensionAssertions.js\"))");
                            using (writer.OpenScope())
                            {
                                WriteAssertionBoth(writer, "return CzmlDataSource.load('Data/CZML/ValidationDocument.czml').then(function(dataSource) {");
                                s_assertionIndent++;
                                WriteAssertionBoth(writer, "/*jshint -W120 */");
                                WriteAssertionBoth(writer, "var e;");
                                WriteAssertionBoth(writer, "var date;");
                                WriteAssertionBoth(writer, "var documentStartDate = JulianDate.fromIso8601('2016-06-17T12:00:00Z');");
                                WriteAssertionBoth(writer, "var documentStopDate = JulianDate.fromIso8601('2016-06-17T13:00:00Z');");

                                writer.WriteLine("m_output = new CesiumOutputStream(m_streamWriter) { PrettyFormatting = true };");
                                writer.WriteLine("m_writer = new CesiumStreamWriter();");

                                writer.WriteLine("m_output.WriteStartSequence();");

                                // Java has a limit on the size of a single method (65535 bytes) so we have to break up all this code in multiple methods

                                writer.WriteLine("WriteClock();");
                                writer.WriteLine("WriteConstantValues();");
                                writer.WriteLine("WriteReferenceValues();");
                                writer.WriteLine("WriteSampledValues();");

                                writer.WriteLine("m_output.WriteEndSequence();");

                                s_assertionIndent--;
                                WriteAssertionBoth(writer, "});");
                                s_assertionIndent++;
                            }
                        }

                        writer.WriteLine("private void WriteClock()");
                        using (writer.OpenScope())
                        {
                            writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                            using (writer.OpenScope())
                            {
                                writer.WriteLine("packet.WriteId(\"document\");");
                                writer.WriteLine("packet.WriteName(\"ValidationDocument\");");
                                writer.WriteLine("packet.WriteVersion(\"1.0\");");

                                writer.WriteLine("using (var clock = packet.OpenClockProperty())");
                                using (writer.OpenScope())
                                {
                                    writer.WriteLine("clock.WriteInterval(m_documentStartDate, m_documentStopDate);");
                                    WriteAssertion(writer, false, "expect(dataSource.clock.startTime).toEqual(documentStartDate);");
                                    WriteAssertion(writer, false, "expect(dataSource.clock.stopTime).toEqual(documentStopDate);");

                                    writer.WriteLine("clock.WriteCurrentTime(m_documentStartDate);");
                                    WriteAssertion(writer, false, "expect(dataSource.clock.currentTime).toEqual(documentStartDate);");

                                    writer.WriteLine("clock.WriteMultiplier(1.0);");
                                    WriteAssertion(writer, false, "expect(dataSource.clock.multiplier).toEqual(1.0);");

                                    writer.WriteLine("clock.WriteRange(ClockRange.Unbounded);");
                                    WriteAssertion(writer, false, "expect(dataSource.clock.clockRange).toEqual(ClockRange.UNBOUNDED);");

                                    writer.WriteLine("clock.WriteStep(ClockStep.SystemClockMultiplier);");
                                    WriteAssertion(writer, false, "expect(dataSource.clock.clockStep).toEqual(ClockStep.SYSTEM_CLOCK_MULTIPLIER);");
                                }
                            }
                        }

                        writer.WriteLine("private void WriteConstantValues()");
                        using (writer.OpenScope())
                        {
                            writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                            using (writer.OpenScope())
                            {
                                const string id = "Constant";
                                writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                WriteAssertionBoth(writer, "var constant = e = dataSource.entities.getById('Constant');");
                                WriteAssertionBoth(writer, "expect(e).toBeDefined();");
                                WriteAssertionBoth(writer, "date = JulianDate.now();");

                                // Write one packet with first value types for each property

                                foreach (var property in schemaProperties)
                                {
                                    string propertyName = property.Name;

                                    bool isExtension = !string.IsNullOrEmpty(property.ValueType.ExtensionPrefix);
                                    if (isExtension)
                                        propertyName = propertyName.Substring(property.ValueType.ExtensionPrefix.Length + 1);

                                    writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                    using (writer.OpenScope())
                                    {
                                        var properties = property.ValueType.Properties;

                                        var firstValueProperty = properties.FirstOrDefault(p => p.IsValue);
                                        if (firstValueProperty != null)
                                        {
                                            WriteValue(writer, "w", id, firstValueProperty, property, isExtension, propertyName);
                                        }
                                        else
                                        {
                                            foreach (var subProperty in properties.Where(p => !p.IsValue))
                                            {
                                                writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                using (writer.OpenScope())
                                                {
                                                    properties = subProperty.ValueType.Properties;
                                                    firstValueProperty = properties.FirstOrDefault(p => p.IsValue);

                                                    string subPropertyName = GetSubPropertyName(propertyName, subProperty);

                                                    if (firstValueProperty != null)
                                                    {
                                                        WriteValue(writer, "w2", id + property.Name, firstValueProperty, subProperty, isExtension, string.Format("{0}.{1}", propertyName, subPropertyName));
                                                    }
                                                    else if (subProperty.ValueType.Name.Contains("Material"))
                                                    {
                                                        Property materialProperty = properties.First();
                                                        writer.WriteLine("using (var m = w2.Open{0}Property())", materialProperty.NameWithPascalCase);
                                                        using (writer.OpenScope())
                                                        {
                                                            properties = materialProperty.ValueType.Properties;
                                                            foreach (var materialSubProperty in properties.Where(p => !p.IsValue))
                                                            {
                                                                writer.WriteLine("using (var m2 = m.Open{0}Property())", materialSubProperty.NameWithPascalCase);
                                                                using (writer.OpenScope())
                                                                {
                                                                    properties = materialSubProperty.ValueType.Properties;
                                                                    firstValueProperty = properties.FirstOrDefault(p => p.IsValue);
                                                                    if (firstValueProperty != null)
                                                                    {
                                                                        WriteValue(writer, "m2", id + property.Name + subProperty.Name + materialProperty.Name, firstValueProperty, materialSubProperty, isExtension, string.Format("{0}.{1}.{2}", propertyName, subPropertyName, materialSubProperty.Name));
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        var additionalProperties = subProperty.ValueType.AdditionalProperties;
                                                        if (additionalProperties != null)
                                                        {
                                                            writer.WriteLine("using (var a = w2.Open{0}Property(\"prop\"))", additionalProperties.ValueType.NameWithPascalCase);
                                                            using (writer.OpenScope())
                                                            {
                                                                foreach (var additionalProperty in additionalProperties.ValueType.Properties.Where(p => !p.IsValue))
                                                                {
                                                                    writer.WriteLine("using (var w3 = a.Open{0}Property())", additionalProperty.NameWithPascalCase);
                                                                    using (writer.OpenScope())
                                                                    {
                                                                        properties = additionalProperty.ValueType.Properties;
                                                                        firstValueProperty = properties.FirstOrDefault(p => p.IsValue);
                                                                        if (firstValueProperty != null)
                                                                        {
                                                                            WriteValue(writer, "w3", id + property.Name, firstValueProperty, additionalProperty, isExtension, string.Format("{0}.{1}.{2}.{3}", propertyName, subPropertyName, "prop", additionalProperty.Name));
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            writer.WriteLine("WriteConstantValuesIndividual();");
                        }

                        writer.WriteLine("private void WriteConstantValuesIndividual()");
                        using (writer.OpenScope())
                        {
                            // write other value types as individual packets
                            foreach (var property in schemaProperties)
                            {
                                writer.WriteLine("WriteConstantValuesIndividual{0}();", property.NameWithPascalCase);
                            }
                        }

                        foreach (var property in schemaProperties)
                        {
                            writer.WriteLine("private void WriteConstantValuesIndividual{0}()", property.NameWithPascalCase);
                            using (writer.OpenScope())
                            {
                                string propertyName = property.Name;

                                bool isExtension = !string.IsNullOrEmpty(property.ValueType.ExtensionPrefix);
                                if (isExtension)
                                    propertyName = propertyName.Substring(property.ValueType.ExtensionPrefix.Length + 1);

                                var properties = property.ValueType.Properties;
                                foreach (var valueProperty in properties.Where(p => p.IsValue && !p.ValueType.Name.StartsWith("Reference")).Skip(1))
                                {
                                    writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                    using (writer.OpenScope())
                                    {
                                        string id = string.Format("constant_{0}_{1}", property.Name, valueProperty.Name);
                                        writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                        WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                        writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                        using (writer.OpenScope())
                                        {
                                            WriteValue(writer, "w", id, valueProperty, property, isExtension, propertyName);
                                        }
                                    }
                                }

                                foreach (var subProperty in properties.Where(p => !p.IsValue))
                                {
                                    string subPropertyName = GetSubPropertyName(propertyName, subProperty);

                                    properties = subProperty.ValueType.Properties;

                                    foreach (var valueProperty in properties.Where(p => p.IsValue && !p.ValueType.Name.StartsWith("Reference")).Skip(1))
                                    {
                                        writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                        using (writer.OpenScope())
                                        {
                                            string id = string.Format("constant_{0}_{1}_{2}", property.Name, subPropertyName, valueProperty.Name);
                                            writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                            WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                            writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                            writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                            using (writer.OpenScope())
                                            {
                                                WriteValue(writer, "w2", id + property.Name, valueProperty, subProperty, isExtension, string.Format("{0}.{1}", propertyName, subPropertyName));
                                            }
                                        }
                                    }

                                    if (subProperty.ValueType.Name.Contains("Material"))
                                    {
                                        // write other values for the first material
                                        // then write first values for other materials
                                        // then write remaining values for other materials individually

                                        var firstMaterialProperty = properties.First();
                                        properties = firstMaterialProperty.ValueType.Properties;
                                        foreach (var materialSubProperty in properties.Where(p => !p.IsValue))
                                        {
                                            properties = materialSubProperty.ValueType.Properties;
                                            foreach (var valueProperty in properties.Where(p => p.IsValue && !p.ValueType.Name.StartsWith("Reference")).Skip(1))
                                            {
                                                writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                                using (writer.OpenScope())
                                                {
                                                    string id = string.Format("constant_{0}_{1}_{2}_{3}", propertyName, subPropertyName, firstMaterialProperty.Name, materialSubProperty.Name);
                                                    writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                                    WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                                    writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                                    writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                    writer.WriteLine("using (var m = w2.Open{0}Property())", firstMaterialProperty.NameWithPascalCase);
                                                    writer.WriteLine("using (var m2 = m.Open{0}Property())", materialSubProperty.NameWithPascalCase);
                                                    using (writer.OpenScope())
                                                    {
                                                        WriteValue(writer, "m2", id + property.Name + subProperty.Name + firstMaterialProperty.Name, valueProperty, materialSubProperty, isExtension, string.Format("{0}.{1}.{2}", propertyName, subPropertyName, materialSubProperty.Name));
                                                    }
                                                }
                                            }
                                        }

                                        properties = subProperty.ValueType.Properties;
                                        foreach (var materialProperty in properties.Skip(1))
                                        {
                                            writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                            using (writer.OpenScope())
                                            {
                                                string id = string.Format("material_{0}_{1}_{2}", propertyName, subProperty.Name, materialProperty.Name);
                                                writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                                WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                                writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                                writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                writer.WriteLine("using (var m = w2.Open{0}Property())", materialProperty.NameWithPascalCase);
                                                using (writer.OpenScope())
                                                {
                                                    properties = materialProperty.ValueType.Properties;
                                                    foreach (var materialSubProperty in properties.Where(p => !p.IsValue))
                                                    {
                                                        writer.WriteLine("using (var m2 = m.Open{0}Property())", materialSubProperty.NameWithPascalCase);
                                                        using (writer.OpenScope())
                                                        {
                                                            properties = materialSubProperty.ValueType.Properties;
                                                            var firstValueProperty = properties.FirstOrDefault(p => p.IsValue);
                                                            if (firstValueProperty != null)
                                                            {
                                                                WriteValue(writer, "m2", id + property.Name + subProperty.Name + materialProperty.Name, firstValueProperty, materialSubProperty, isExtension, string.Format("{0}.{1}.{2}", propertyName, subPropertyName, materialSubProperty.Name));
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        properties = subProperty.ValueType.Properties;
                                        foreach (var materialProperty in properties.Skip(1))
                                        {
                                            properties = materialProperty.ValueType.Properties;
                                            foreach (var materialSubProperty in properties.Where(p => !p.IsValue))
                                            {
                                                properties = materialSubProperty.ValueType.Properties;
                                                foreach (var valueProperty in properties.Where(p => p.IsValue && !p.ValueType.Name.StartsWith("Reference")).Skip(1))
                                                {
                                                    writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                                    using (writer.OpenScope())
                                                    {
                                                        string id = string.Format("constant_{0}_{1}_{2}_{3}", propertyName, subPropertyName, materialProperty.Name, materialSubProperty.Name);
                                                        writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                                        WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                                        writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                                        writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                        writer.WriteLine("using (var m = w2.Open{0}Property())", materialProperty.NameWithPascalCase);
                                                        writer.WriteLine("using (var m2 = m.Open{0}Property())", materialSubProperty.NameWithPascalCase);
                                                        using (writer.OpenScope())
                                                        {
                                                            WriteValue(writer, "m2", id + property.Name + subProperty.Name + materialProperty.Name, valueProperty, materialSubProperty, isExtension, string.Format("{0}.{1}.{2}", propertyName, subPropertyName, materialSubProperty.Name));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    var additionalProperties = subProperty.ValueType.AdditionalProperties;
                                    if (additionalProperties != null)
                                    {
                                        foreach (var additionalProperty in additionalProperties.ValueType.Properties.Where(p => !p.IsValue))
                                        {
                                            int i = 0;
                                            properties = additionalProperty.ValueType.Properties;
                                            foreach (var valueProperty in properties.Where(p => p.IsValue && !p.ValueType.Name.StartsWith("Reference")).Skip(1))
                                            {
                                                writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                                using (writer.OpenScope())
                                                {
                                                    string id = string.Format("constant_{0}_{1}_{2}_{3}", propertyName, subPropertyName, additionalProperties.ValueType.Name, additionalProperty.Name);
                                                    writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                                    WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                                    string propName = string.Format("{0}{1}", "prop", i++);
                                                    writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                                    writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                    writer.WriteLine("using (var a = w2.Open{0}Property(\"{1}\"))", additionalProperties.ValueType.NameWithPascalCase, propName);
                                                    writer.WriteLine("using (var w3 = a.Open{0}Property())", additionalProperty.NameWithPascalCase);
                                                    using (writer.OpenScope())
                                                    {
                                                        WriteValue(writer, "w3", id + property.Name + subProperty.Name, valueProperty, additionalProperty, isExtension, string.Format("{0}.{1}.{2}.{3}", propertyName, subPropertyName, propName, additionalProperty.Name));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        // create entities using references
                        writer.WriteLine("private void WriteReferenceValues()");
                        using (writer.OpenScope())
                        {
                            // write some positions and double values to use to create reference lists for position lists and double lists later

                            for (int i = 1; i <= 2; ++i)
                            {
                                writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                using (writer.OpenScope())
                                {
                                    string id = string.Format("ConstantPosition{0}", i);
                                    writer.WriteLine("packet.WriteId(\"{0}\");", id);
                                    WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('ConstantPosition{0}')).toBeDefined();", i);
                                    var property = schemaProperties.First(p => p.Name == "position");
                                    writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                    using (writer.OpenScope())
                                    {
                                        var properties = property.ValueType.Properties;
                                        var firstValueProperty = properties.FirstOrDefault(p => p.IsValue);
                                        WriteValue(writer, "w", id, firstValueProperty, property, false, property.Name);
                                    }
                                }
                                writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                using (writer.OpenScope())
                                {
                                    string id = string.Format("ConstantDouble{0}", i);
                                    writer.WriteLine("packet.WriteId(\"{0}\");", id);
                                    WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('ConstantDouble{0}')).toBeDefined();", i);
                                    var property = schemaProperties.First(p => p.Name == "billboard");
                                    var properties = property.ValueType.Properties;
                                    var subProperty = properties.First(p => p.Name == "scale");
                                    writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                    writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                    using (writer.OpenScope())
                                    {
                                        properties = subProperty.ValueType.Properties;
                                        var firstValueProperty = properties.FirstOrDefault(p => p.IsValue);
                                        WriteValue(writer, "w2", id + property.Name, firstValueProperty, subProperty, false, string.Format("{0}.{1}", property.Name, subProperty.Name));
                                    }
                                }
                            }

                            // write one big packet with references for everything
                            writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                            using (writer.OpenScope())
                            {
                                writer.WriteLine("packet.WriteId(\"Reference\");");

                                WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('Reference')).toBeDefined();");

                                foreach (var property in schemaProperties)
                                {
                                    string propertyName = property.Name;

                                    bool isExtension = !string.IsNullOrEmpty(property.ValueType.ExtensionPrefix);
                                    if (isExtension)
                                        propertyName = propertyName.Substring(property.ValueType.ExtensionPrefix.Length + 1);

                                    writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                    using (writer.OpenScope())
                                    {
                                        var properties = property.ValueType.Properties;
                                        if (properties.Any(p => p.ValueType.Name == "Reference"))
                                        {
                                            writer.WriteLine("w.WriteReference(new Reference(\"Constant\", \"{0}\"));", propertyName);
                                            WriteAssertion(writer, isExtension, "expect(e.{0}.getValue(date)).toEqual(constant.{0}.getValue(date));", propertyName);
                                        }
                                        else
                                        {
                                            foreach (var subProperty in properties.Where(p => !p.IsValue))
                                            {
                                                properties = subProperty.ValueType.Properties;

                                                string subPropertyName = GetSubPropertyName(propertyName, subProperty);

                                                if (properties.Any(p => p.ValueType.Name == "Reference"))
                                                {
                                                    writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                    using (writer.OpenScope())
                                                    {
                                                        writer.WriteLine("w2.WriteReference(new Reference(\"Constant\", CreateList(\"{0}\", \"{1}\")));", propertyName, subPropertyName);
                                                        WriteAssertion(writer, isExtension, "expect(e.{0}.{1}.getValue(date)).toEqual(constant.{0}.{1}.getValue(date));", propertyName, subPropertyName);
                                                    }
                                                }
                                                else if (properties.Any(p => p.ValueType.Name == "ReferenceList"))
                                                {
                                                    string targetId = "";
                                                    string[] referencePropertyNames = { };
                                                    if (subProperty.ValueType.Name == "PositionList")
                                                    {
                                                        targetId = "Position";
                                                        referencePropertyNames = new[] { "position" };
                                                    }
                                                    else if (subProperty.ValueType.Name == "DoubleList")
                                                    {
                                                        targetId = "Double";
                                                        referencePropertyNames = new[] { "billboard", "scale" };
                                                    }

                                                    writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                    using (writer.OpenScope())
                                                    {
                                                        writer.WriteLine("w2.WriteReferences(CreateList(new Reference(\"Constant{0}1\", CreateList({1})), new Reference(\"Constant{0}2\", CreateList({1}))));", targetId, string.Join(", ", referencePropertyNames.Select(n => string.Format("\"{0}\"", n))));
                                                        WriteAssertion(writer, isExtension, "expect(e.{0}.{1}.getValue(date)).toEqual([dataSource.entities.getById('Constant{2}1').{3}.getValue(date), dataSource.entities.getById('Constant{2}2').{3}.getValue(date)]);", propertyName, subPropertyName, targetId, string.Join(".", referencePropertyNames));
                                                    }
                                                }
                                                else if (subProperty.ValueType.Name.Contains("Material"))
                                                {
                                                    Property materialProperty = properties.First();
                                                    writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                    writer.WriteLine("using (var m = w2.Open{0}Property())", materialProperty.NameWithPascalCase);
                                                    using (writer.OpenScope())
                                                    {
                                                        properties = materialProperty.ValueType.Properties;
                                                        foreach (var materialSubProperty in properties.Where(p => !p.IsValue))
                                                        {
                                                            writer.WriteLine("using (var m2 = m.Open{0}Property())", materialSubProperty.NameWithPascalCase);
                                                            using (writer.OpenScope())
                                                            {
                                                                writer.WriteLine("m2.WriteReference(new Reference(\"Constant\", CreateList(\"{0}\", \"{1}\", \"{2}\")));", propertyName, subPropertyName, materialSubProperty.Name);
                                                                WriteAssertion(writer, isExtension, "expect(e.{0}.{1}.{2}.getValue(date)).toEqual(constant.{0}.{1}.{2}.getValue(date));", propertyName, subPropertyName, materialSubProperty.Name);
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    var additionalProperties = subProperty.ValueType.AdditionalProperties;
                                                    if (additionalProperties != null)
                                                    {
                                                        writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                        writer.WriteLine("using (var a = w2.Open{0}Property(\"referenceProp\"))", additionalProperties.ValueType.NameWithPascalCase);
                                                        using (writer.OpenScope())
                                                        {
                                                            foreach (var additionalProperty in additionalProperties.ValueType.Properties.Where(p => !p.IsValue))
                                                            {
                                                                writer.WriteLine("using (var w3 = a.Open{0}Property())", additionalProperty.NameWithPascalCase);
                                                                using (writer.OpenScope())
                                                                {
                                                                    writer.WriteLine("w3.WriteReference(new Reference(\"Constant\", CreateList(\"{0}\", \"{1}\", \"prop\", \"{2}\")));", propertyName, subPropertyName, additionalProperty.Name);
                                                                    WriteAssertion(writer, isExtension, "expect(e.{0}.{1}.referenceProp.{2}.getValue(date)).toEqual(constant.{0}.{1}.prop.{2}.getValue(date));", propertyName, subPropertyName, additionalProperty.Name);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            writer.WriteLine("WriteReferenceValuesIndividual();");
                        }

                        writer.WriteLine("private void WriteReferenceValuesIndividual()");
                        using (writer.OpenScope())
                        {
                            // write other materials as individual packets
                            foreach (var property in schemaProperties)
                            {
                                writer.WriteLine("WriteReferenceValuesIndividual{0}();", property.NameWithPascalCase);
                            }

                            // special case - velocity reference
                            writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                            using (writer.OpenScope())
                            {
                                writer.WriteLine("packet.WriteId(\"VelocityPosition\");");
                                WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('VelocityPosition')).toBeDefined();");
                                var property = schemaProperties.First(p => p.Name == "position");
                                writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                using (writer.OpenScope())
                                {
                                    // construct a position with specific velocity
                                    double dx = 1.0;
                                    double dy = 2.0;
                                    double dz = 3.0;
                                    double deltaTime = 60.0;

                                    double x1 = 1.0;
                                    double x2 = x1 + dx * deltaTime;

                                    double y1 = 2.0;
                                    double y2 = y1 + dy * deltaTime;

                                    double z1 = 3.0;
                                    double z2 = z1 + dz * deltaTime;

                                    string value1 = string.Format("new Cartesian({0}, {1}, {2})", x1, y1, z1);
                                    string assertionValue1 = string.Format("new Cartesian3({0}, {1}, {2})", x1, y1, z1);

                                    string value2 = string.Format("new Cartesian({0}, {1}, {2})", x2, y2, z2);
                                    string assertionValue2 = string.Format("new Cartesian3({0}, {1}, {2})", x2, y2, z2);

                                    writer.WriteLine("w.WriteCartesian(CreateList(m_documentStartDate, m_documentStartDate.AddSeconds({0})), CreateList({1}, {2}));", deltaTime, value1, value2);
                                    WriteAssertion(writer, false, "expect(e.position.getValue(documentStartDate)).toEqual({0});", assertionValue1);
                                    WriteAssertion(writer, false, "expect(e.position.getValue(JulianDate.addSeconds(documentStartDate, {0}, new JulianDate()))).toEqual({1});", deltaTime, assertionValue2);
                                }
                            }

                            foreach (var property in schemaProperties)
                            {
                                string propertyName = property.Name;

                                bool isExtension = !string.IsNullOrEmpty(property.ValueType.ExtensionPrefix);
                                if (isExtension)
                                    propertyName = propertyName.Substring(property.ValueType.ExtensionPrefix.Length + 1);

                                var properties = property.ValueType.Properties;

                                foreach (var subProperty in properties.Where(p => !p.IsValue))
                                {
                                    properties = subProperty.ValueType.Properties;
                                    if (properties.Any(p => p.Name == "velocityReference"))
                                    {
                                        writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                        using (writer.OpenScope())
                                        {
                                            string id = string.Format("velocityReference_{0}_{1}", propertyName, subProperty.Name);
                                            writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                            WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                            writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                            writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                            using (writer.OpenScope())
                                            {
                                                writer.WriteLine("w2.WriteVelocityReference(new Reference(\"VelocityPosition\", \"position\"));");

                                                double expectedX = 1.0;
                                                double expectedY = 2.0;
                                                double expectedZ = 3.0;
                                                bool isNormalized = subProperty.NameWithPascalCase == "AlignedAxis";
                                                if (isNormalized)
                                                {
                                                    NormalizeCartesian(ref expectedX, ref expectedY, ref expectedZ);
                                                }

                                                WriteAssertion(writer, isExtension, "expect(e.{0}.{1}.getValue(JulianDate.addSeconds(documentStartDate, 50, new JulianDate()))).toEqualEpsilon(new Cartesian3({2}, {3}, {4}), 1e-13);", propertyName, subProperty.Name, expectedX, expectedY, expectedZ);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        // write other materials as individual packets
                        foreach (var property in schemaProperties)
                        {
                            writer.WriteLine("private void WriteReferenceValuesIndividual{0}()", property.NameWithPascalCase);
                            using (writer.OpenScope())
                            {
                                string propertyName = property.Name;

                                bool isExtension = !string.IsNullOrEmpty(property.ValueType.ExtensionPrefix);
                                if (isExtension)
                                    propertyName = propertyName.Substring(property.ValueType.ExtensionPrefix.Length + 1);

                                var properties = property.ValueType.Properties;

                                foreach (var subProperty in properties.Where(p => !p.IsValue))
                                {
                                    string subPropertyName = GetSubPropertyName(propertyName, subProperty);

                                    if (subProperty.ValueType.Name.Contains("Material"))
                                    {
                                        properties = subProperty.ValueType.Properties;
                                        foreach (var materialProperty in properties.Skip(1))
                                        {
                                            writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                            using (writer.OpenScope())
                                            {
                                                string targetId = string.Format("material_{0}_{1}_{2}", propertyName, subProperty.Name, materialProperty.Name);
                                                string id = string.Format("reference_{0}_{1}_{2}", propertyName, subPropertyName, materialProperty.Name);

                                                writer.WriteLine("packet.WriteId(\"{0}\");", id);
                                                WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                                writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                                writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                writer.WriteLine("using (var m = w2.Open{0}Property())", materialProperty.NameWithPascalCase);
                                                using (writer.OpenScope())
                                                {
                                                    properties = materialProperty.ValueType.Properties;
                                                    foreach (var materialSubProperty in properties.Where(p => !p.IsValue))
                                                    {
                                                        writer.WriteLine("using (var m2 = m.Open{0}Property())", materialSubProperty.NameWithPascalCase);
                                                        using (writer.OpenScope())
                                                        {
                                                            writer.WriteLine("m2.WriteReference(new Reference(\"{0}\", CreateList(\"{1}\", \"{2}\", \"{3}\")));", targetId, propertyName, subPropertyName, materialSubProperty.Name);
                                                            WriteAssertion(writer, isExtension, "expect(e.{1}.{2}.{3}.getValue(date)).toEqual(dataSource.entities.getById('{0}').{1}.{2}.{3}.getValue(date));", targetId, propertyName, subPropertyName, materialSubProperty.Name);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        // test sampled properties
                        writer.WriteLine("private void WriteSampledValues()");
                        using (writer.OpenScope())
                        {
                            // Write one packet with first value types for each property

                            writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                            using (writer.OpenScope())
                            {
                                const string id = "Sampled";
                                writer.WriteLine("packet.WriteId(\"{0}\");", id);
                                WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('Sampled')).toBeDefined();");

                                foreach (var property in schemaProperties)
                                {
                                    string propertyName = property.Name;

                                    bool isExtension = !string.IsNullOrEmpty(property.ValueType.ExtensionPrefix);
                                    if (isExtension)
                                        propertyName = propertyName.Substring(property.ValueType.ExtensionPrefix.Length + 1);

                                    var properties = property.ValueType.Properties;
                                    if (property.IsInterpolatable)
                                    {
                                        writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                        using (writer.OpenScope())
                                        {
                                            var firstValueProperty = properties.First(p => p.IsValue && (p.ValueType.JsonTypes & JsonSchemaType.Array) == JsonSchemaType.Array);
                                            WriteValues(writer, "w", id, firstValueProperty, property, isExtension, propertyName);
                                        }
                                    }
                                    else
                                    {
                                        var subProperties = properties.Where(p => !p.IsValue && (p.IsInterpolatable || p.ValueType.Name.Contains("Material"))).ToList();
                                        if (subProperties.Any())
                                        {
                                            writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                            using (writer.OpenScope())
                                            {
                                                foreach (var subProperty in subProperties)
                                                {
                                                    properties = subProperty.ValueType.Properties;

                                                    string subPropertyName = GetSubPropertyName(propertyName, subProperty);
                                                    writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                    using (writer.OpenScope())
                                                    {
                                                        if (subProperty.IsInterpolatable)
                                                        {
                                                            var firstValueProperty = properties.First(p => p.IsValue && (p.ValueType.JsonTypes & JsonSchemaType.Array) == JsonSchemaType.Array);
                                                            WriteValues(writer, "w2", id + property.Name, firstValueProperty, subProperty, isExtension, string.Format("{0}.{1}", propertyName, subPropertyName));
                                                        }
                                                        else if (subProperty.ValueType.Name.Contains("Material"))
                                                        {
                                                            Property materialProperty = properties.First();
                                                            writer.WriteLine("using (var m = w2.Open{0}Property())", materialProperty.NameWithPascalCase);
                                                            using (writer.OpenScope())
                                                            {
                                                                properties = materialProperty.ValueType.Properties;
                                                                foreach (var materialSubProperty in properties.Where(p => p.IsInterpolatable))
                                                                {
                                                                    writer.WriteLine("using (var m2 = m.Open{0}Property())", materialSubProperty.NameWithPascalCase);
                                                                    using (writer.OpenScope())
                                                                    {
                                                                        properties = materialSubProperty.ValueType.Properties;
                                                                        var firstValueProperty = properties.First(p => p.IsValue && (p.ValueType.JsonTypes & JsonSchemaType.Array) == JsonSchemaType.Array);
                                                                        WriteValues(writer, "m2", id + property.Name + subProperty.Name + materialProperty.Name, firstValueProperty, materialSubProperty, isExtension, string.Format("{0}.{1}.{2}", propertyName, subPropertyName, materialSubProperty.Name));
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            writer.WriteLine("WriteSampledValuesIndividual();");
                        }

                        writer.WriteLine("private void WriteSampledValuesIndividual()");
                        using (writer.OpenScope())
                        {
                            // write other value types as individual packets

                            // split method into multiple methods
                            foreach (var property in schemaProperties)
                            {
                                writer.WriteLine("WriteSampledValuesIndividual{0}();", property.NameWithPascalCase);
                            }
                        }

                        foreach (var property in schemaProperties)
                        {
                            writer.WriteLine("private void WriteSampledValuesIndividual{0}()", property.NameWithPascalCase);
                            using (writer.OpenScope())
                            {
                                string propertyName = property.Name;

                                bool isExtension = !string.IsNullOrEmpty(property.ValueType.ExtensionPrefix);
                                if (isExtension)
                                    propertyName = propertyName.Substring(property.ValueType.ExtensionPrefix.Length + 1);

                                var properties = property.ValueType.Properties;

                                if (property.IsInterpolatable)
                                {
                                    foreach (var valueProperty in properties.Where(p => p.IsValue && (p.ValueType.JsonTypes & JsonSchemaType.Array) == JsonSchemaType.Array).Skip(1))
                                    {
                                        writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                        using (writer.OpenScope())
                                        {
                                            string id = string.Format("sampled_{0}_{1}", propertyName, valueProperty.Name);
                                            writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                            WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                            writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                            using (writer.OpenScope())
                                            {
                                                WriteValues(writer, "w", id, valueProperty, property, isExtension, propertyName);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (var subProperty in properties.Where(p => !p.IsValue))
                                    {
                                        string subPropertyName = GetSubPropertyName(propertyName, subProperty);

                                        properties = subProperty.ValueType.Properties;

                                        if (subProperty.IsInterpolatable)
                                        {
                                            foreach (var valueProperty in properties.Where(p => p.IsValue && (p.ValueType.JsonTypes & JsonSchemaType.Array) == JsonSchemaType.Array).Skip(1))
                                            {
                                                writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                                using (writer.OpenScope())
                                                {
                                                    string id = string.Format("sampled_{0}_{1}_{2}", propertyName, subPropertyName, valueProperty.Name);
                                                    writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                                    WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                                    writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                                    writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                    using (writer.OpenScope())
                                                    {
                                                        WriteValues(writer, "w2", id + property.Name, valueProperty, subProperty, isExtension, string.Format("{0}.{1}", propertyName, subPropertyName));
                                                    }
                                                }
                                            }
                                        }
                                        else if (subProperty.ValueType.Name.Contains("Material"))
                                        {
                                            // write other values for the first material
                                            // then write first values for other materials
                                            // then write remaining values for other materials individually

                                            var firstMaterialProperty = properties.First();
                                            properties = firstMaterialProperty.ValueType.Properties;
                                            foreach (var materialSubProperty in properties.Where(p => p.IsInterpolatable))
                                            {
                                                properties = materialSubProperty.ValueType.Properties;
                                                foreach (var valueProperty in properties.Where(p => p.IsValue && (p.ValueType.JsonTypes & JsonSchemaType.Array) == JsonSchemaType.Array).Skip(1))
                                                {
                                                    writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                                    using (writer.OpenScope())
                                                    {
                                                        string id = string.Format("sampled_{0}_{1}_{2}_{3}", propertyName, subPropertyName, firstMaterialProperty.Name, materialSubProperty.Name);
                                                        writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                                        WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                                        writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                                        writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                        writer.WriteLine("using (var m = w2.Open{0}Property())", firstMaterialProperty.NameWithPascalCase);
                                                        writer.WriteLine("using (var m2 = m.Open{0}Property())", materialSubProperty.NameWithPascalCase);
                                                        using (writer.OpenScope())
                                                        {
                                                            WriteValues(writer, "m2", id + property.Name + subProperty.Name + firstMaterialProperty.Name, valueProperty, materialSubProperty, isExtension, string.Format("{0}.{1}.{2}", propertyName, subPropertyName, materialSubProperty.Name));
                                                        }
                                                    }
                                                }
                                            }

                                            properties = subProperty.ValueType.Properties;
                                            foreach (var materialProperty in properties.Skip(1))
                                            {
                                                writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                                using (writer.OpenScope())
                                                {
                                                    string id = string.Format("sampled_{0}_{1}_{2}", propertyName, subPropertyName, materialProperty.Name);
                                                    writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                                    WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                                    writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                                    writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                    writer.WriteLine("using (var m = w2.Open{0}Property())", materialProperty.NameWithPascalCase);
                                                    using (writer.OpenScope())
                                                    {
                                                        properties = materialProperty.ValueType.Properties;
                                                        foreach (var materialSubProperty in properties.Where(p => p.IsInterpolatable))
                                                        {
                                                            writer.WriteLine("using (var m2 = m.Open{0}Property())", materialSubProperty.NameWithPascalCase);
                                                            using (writer.OpenScope())
                                                            {
                                                                properties = materialSubProperty.ValueType.Properties;
                                                                var firstValueProperty = properties.First(p => p.IsValue && (p.ValueType.JsonTypes & JsonSchemaType.Array) == JsonSchemaType.Array);
                                                                WriteValues(writer, "m2", id + property.Name + subProperty.Name + materialProperty.Name, firstValueProperty, materialSubProperty, isExtension, string.Format("{0}.{1}.{2}", propertyName, subPropertyName, materialSubProperty.Name));
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            properties = subProperty.ValueType.Properties;
                                            foreach (var materialProperty in properties.Skip(1))
                                            {
                                                properties = materialProperty.ValueType.Properties;
                                                foreach (var materialSubProperty in properties.Where(p => p.IsInterpolatable))
                                                {
                                                    properties = materialSubProperty.ValueType.Properties;
                                                    foreach (var valueProperty in properties.Where(p => p.IsValue && (p.ValueType.JsonTypes & JsonSchemaType.Array) == JsonSchemaType.Array).Skip(1))
                                                    {
                                                        writer.WriteLine("using (var packet = m_writer.OpenPacket(m_output))");
                                                        using (writer.OpenScope())
                                                        {
                                                            string id = string.Format("sampled_{0}_{1}_{2}_{3}", propertyName, subPropertyName, materialProperty.Name, materialSubProperty.Name);
                                                            writer.WriteLine("packet.WriteId(\"{0}\");", id);

                                                            WriteAssertionBoth(writer, "expect(e = dataSource.entities.getById('{0}')).toBeDefined();", id);

                                                            writer.WriteLine("using (var w = packet.Open{0}Property())", property.NameWithPascalCase);
                                                            writer.WriteLine("using (var w2 = w.Open{0}Property())", subProperty.NameWithPascalCase);
                                                            writer.WriteLine("using (var m = w2.Open{0}Property())", materialProperty.NameWithPascalCase);
                                                            writer.WriteLine("using (var m2 = m.Open{0}Property())", materialSubProperty.NameWithPascalCase);
                                                            using (writer.OpenScope())
                                                            {
                                                                WriteValues(writer, "m2", id + property.Name + subProperty.Name + materialProperty.Name, valueProperty, materialSubProperty, isExtension, string.Format("{0}.{1}.{2}", propertyName, subPropertyName, materialSubProperty.Name));
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 private static void WriteValues(CodeWriter writer, string openWriterName, string valueName, Property valueProperty, Property parentProperty, bool isExtension, string propertyName)
 {
     string value1;
     string assertionValue1;
     string assertionEpsilon1;
     string valueType1;
     GetUniqueValue(valueName + 1, valueProperty, parentProperty, out value1, out assertionValue1, out assertionEpsilon1, out valueType1);
     string value2;
     string assertionValue2;
     string assertionEpsilon2;
     string valueType2;
     GetUniqueValue(valueName + 2, valueProperty, parentProperty, out value2, out assertionValue2, out assertionEpsilon2, out valueType2);
     writer.WriteLine("{0}.Write{1}(CreateList(m_documentStartDate, m_documentStopDate), CreateList({3}, {4}));", openWriterName, valueProperty.NameWithPascalCase, valueType1, value1, value2);
     WriteAssertion(writer, isExtension, "expect(e.{0}.getValue(documentStartDate)).toEqual{1}({2}{3});",
                    propertyName,
                    assertionEpsilon1 == null ? "" : "Epsilon",
                    assertionValue1,
                    assertionEpsilon1 == null ? "" : string.Format(", {0}", assertionEpsilon1));
     WriteAssertion(writer, isExtension, "expect(e.{0}.getValue(documentStopDate)).toEqual{1}({2}{3});",
                    propertyName,
                    assertionEpsilon2 == null ? "" : "Epsilon",
                    assertionValue2,
                    assertionEpsilon2 == null ? "" : string.Format(", {0}", assertionEpsilon2));
 }
Esempio n. 18
0
        private void WriteNamespaces(CodeWriter writer, Schema schema)
        {
            HashSet<string> namespaces = new HashSet<string>();

            namespaces.Add(m_configuration.Namespace + ".Advanced");
            namespaces.Add(m_configuration.LazyNamespace);

            if (schema.Properties != null)
            {
                foreach (Property property in schema.Properties)
                {
                    OverloadInfo[] overloads = GetOverloadsForProperty(property);
                    foreach (OverloadInfo overload in overloads)
                    {
                        if (overload.Namespaces != null)
                        {
                            foreach (string ns in overload.Namespaces)
                            {
                                namespaces.Add(ns);
                            }
                        }
                    }

                    if (property.ValueType.Properties != null)
                    {
                        foreach (Property subProperty in property.ValueType.Properties)
                        {
                            OverloadInfo[] subOverloads = GetOverloadsForProperty(subProperty);
                            foreach (OverloadInfo overload in subOverloads)
                            {
                                if (overload.Namespaces != null)
                                {
                                    foreach (string ns in overload.Namespaces)
                                    {
                                        namespaces.Add(ns);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach (string ns in namespaces)
            {
                writer.WriteLine("using {0};", ns);
            }
        }
Esempio n. 19
0
 private static void WriteInheritDoc(CodeWriter writer)
 {
     writer.WriteLine("/// <inheritdoc />");
 }
Esempio n. 20
0
 private void WriteDescriptionAsClassSummary(CodeWriter writer, Schema packetSchema)
 {
     WriteSummaryText(
         writer,
         string.Format("Writes a <code>{0}</code> to a <see cref=\"CesiumOutputStream\" />.  A <code>{0}</code> {1}",
                       packetSchema.Name,
                       StringHelper.UncapitalizeFirstLetter(packetSchema.Description)));
 }
Esempio n. 21
0
 private static void WriteTypeParameterText(CodeWriter writer, string typeName, string description)
 {
     writer.WriteLine("/// <typeparam name=\"{0}\">{1}</typeparam>", typeName, description);
 }
Esempio n. 22
0
        private void WritePropertyLazyFields(CodeWriter writer, Schema schema)
        {
            if (schema.Properties == null)
                return;

            foreach (Property property in schema.Properties)
            {
                if (PropertyValueIsIntervals(property))
                {
                    writer.WriteLine("private readonly Lazy<{0}CesiumWriter> m_{1} = new Lazy<{0}CesiumWriter>(() => new {0}CesiumWriter({2}PropertyName), false);",
                                     property.ValueType.NameWithPascalCase,
                                     property.Name,
                                     property.NameWithPascalCase);
                }
                else if (property.IsValue)
                {
                    // Does this property have an overload to write sampled data?
                    // If so, it's interpolatable.
                    OverloadInfo[] overloads = GetOverloadsForProperty(property);
                    if (overloads[0].Parameters.Length == 1)
                    {
                        string interfaceName = "ICesiumValuePropertyWriter";
                        if (FindSampledDataOverload(overloads) != null)
                            interfaceName = "ICesiumInterpolatableValuePropertyWriter";

                        writer.WriteLine("private readonly Lazy<{0}<{1}>> m_as{2};",
                                         interfaceName,
                                         overloads[0].Parameters[0].Type,
                                         property.NameWithPascalCase);
                    }
                }
            }

            writer.WriteLine();
        }
Esempio n. 23
0
 private static void WriteReturnsText(CodeWriter writer, string description)
 {
     writer.WriteLine(string.Format("/// <returns>{0}</returns>", description));
 }
Esempio n. 24
0
        private void WriteIntervalsProperty(CodeWriter writer, Schema schema, Property property)
        {
            GenerateWriterClass(property.ValueType);

            WriteSummaryText(writer, string.Format("Gets the writer for the <code>{0}</code> property.  The returned instance must be opened by calling the <see cref=\"CesiumElementWriter.Open\"/> method before it can be used for writing.  The <code>{0}</code> property defines {1}",
                                                   property.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
            writer.WriteLine("public {0}CesiumWriter {1}Writer", property.ValueType.NameWithPascalCase, property.NameWithPascalCase);
            writer.OpenScope();
            writer.WriteLine("get {{ return m_{0}.Value; }}", property.Name);
            writer.CloseScope();
            writer.WriteLine();

            WriteSummaryText(writer, string.Format("Opens and returns the writer for the <code>{0}</code> property.  The <code>{0}</code> property defines {1}",
                                                   property.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
            writer.WriteLine("public {0}CesiumWriter Open{1}Property()", property.ValueType.NameWithPascalCase, property.NameWithPascalCase);
            writer.OpenScope();
            if (schema.Name != "Packet")
                writer.WriteLine("OpenIntervalIfNecessary();");
            writer.WriteLine("return OpenAndReturn({0}Writer);", property.NameWithPascalCase);
            writer.CloseScope();
            writer.WriteLine();

            if (property.ValueType.Properties != null)
            {
                bool isFirstValueProperty = true;
                foreach (Property nestedProperty in property.ValueType.Properties)
                {
                    if (!nestedProperty.IsValue)
                        continue;

                    OverloadInfo[] overloads = GetOverloadsForProperty(nestedProperty);

                    foreach (OverloadInfo overload in overloads)
                    {
                        WriteSummaryText(writer, string.Format("Writes a value for the <code>{0}</code> property as a <code>{1}</code> value.  The <code>{0}</code> property specifies {2}", property.Name, nestedProperty.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
                        foreach (ParameterInfo parameter in overload.Parameters)
                        {
                            if (string.IsNullOrEmpty(parameter.Description))
                                continue;
                            WriteParameterText(writer, parameter.Name, parameter.Description);
                        }

                        string subPropertyName = nestedProperty.NameWithPascalCase;
                        if (subPropertyName == property.NameWithPascalCase || isFirstValueProperty)
                            subPropertyName = "";

                        writer.WriteLine("public void Write{0}Property{1}({2})", property.NameWithPascalCase, subPropertyName, overload.FormattedParameters);
                        writer.OpenScope();

                        writer.WriteLine("using (var writer = Open{0}Property())", property.NameWithPascalCase);
                        writer.OpenScope();
                        writer.WriteLine("writer.Write{0}({1});", nestedProperty.NameWithPascalCase, string.Join(", ", Array.ConvertAll(overload.Parameters, p => p.Name)));
                        writer.CloseScope();

                        writer.CloseScope();
                        writer.WriteLine();
                    }

                    isFirstValueProperty = false;
                }
            }
        }
Esempio n. 25
0
        private void WritePropertyLazyFields(CodeWriter writer, Schema schema)
        {
            foreach (Property property in schema.Properties)
            {
                if (PropertyValueIsLeaf(property))
                {
                    if (property.IsValue)
                    {
                        // Does this property have an overload to write sampled data?
                        // If so, it's interpolatable.
                        IEnumerable<OverloadInfo> overloads = GetOverloadsForProperty(property);

                        OverloadInfo firstOverload = overloads.First();

                        if (firstOverload.Parameters.Length != 1)
                            continue;

                        string interfaceName = "ICesiumValuePropertyWriter";
                        if (FindSampledDataOverload(overloads) != null)
                            interfaceName = "ICesiumInterpolatableValuePropertyWriter";

                        string firstOverloadFirstParameterType = firstOverload.Parameters[0].Type;
                        writer.WriteLine("private readonly Lazy<{0}<{1}>> m_as{2};", interfaceName, firstOverloadFirstParameterType, property.NameWithPascalCase);
                    }
                }
                else
                {
                    writer.WriteLine("private readonly Lazy<{0}CesiumWriter> m_{1} = new Lazy<{0}CesiumWriter>(() => new {0}CesiumWriter({2}PropertyName), false);",
                        property.ValueType.NameWithPascalCase,
                        property.Name,
                        property.NameWithPascalCase);
                }
            }

            if (schema.Properties.Count > 0)
                writer.WriteLine();
        }
Esempio n. 26
0
 private void WriteParameterText(CodeWriter writer, string name, string description)
 {
     writer.WriteLine("/// <param name=\"{0}\">{1}</param>", name, description);
 }
Esempio n. 27
0
        private void WriteProperties(CodeWriter writer, Schema schema)
        {
            bool isFirstValueProperty = true;

            foreach (Property property in schema.Properties)
            {
                if (PropertyValueIsLeaf(property))
                    WriteLeafProperty(writer, schema, property, property.IsValue && isFirstValueProperty);
                else
                    WriteIntervalsProperty(writer, schema, property);

                if (property.IsValue)
                    isFirstValueProperty = false;
            }

            Property additionalProperties = schema.AdditionalProperties;
            if (additionalProperties != null)
            {
                Schema additionalPropertiesValueType = additionalProperties.ValueType;
                GenerateWriterClass(additionalPropertiesValueType);

                WriteSummaryText(writer, string.Format("Gets a new writer for a <code>{0}</code> property.  The returned instance must be opened by calling the <see cref=\"CesiumElementWriter.Open\"/> method before it can be used for writing.  A <code>{0}</code> property defines {1}", additionalPropertiesValueType.Name, additionalProperties.Description.UncapitalizeFirstLetter()));
                writer.WriteLine("public {0}CesiumWriter Get{0}Writer(string name)", additionalPropertiesValueType.NameWithPascalCase);
                using (writer.OpenScope())
                {
                    writer.WriteLine("return new {0}CesiumWriter(name);", additionalPropertiesValueType.NameWithPascalCase);
                }
                writer.WriteLine();

                WriteSummaryText(writer, string.Format("Opens and returns a new writer for a <code>{0}</code> property.  A <code>{0}</code> property defines {1}", additionalPropertiesValueType.Name, additionalProperties.Description.UncapitalizeFirstLetter()));
                WriteParameterText(writer, "name", "The name of the new property writer.");
                writer.WriteLine("public {0}CesiumWriter Open{0}Property(string name)", additionalPropertiesValueType.NameWithPascalCase);
                using (writer.OpenScope())
                {
                    writer.WriteLine("OpenIntervalIfNecessary();");
                    writer.WriteLine("return OpenAndReturn(new {0}CesiumWriter(name));", additionalPropertiesValueType.NameWithPascalCase);
                }
                writer.WriteLine();
            }
        }
Esempio n. 28
0
        private void WriteAsTypeLazyInitialization(CodeWriter writer, Schema schema)
        {
            if (schema.Properties == null)
                return;

            foreach (Property property in schema.Properties)
            {
                if (!property.IsValue)
                    continue;
                if (PropertyValueIsIntervals(property))
                    continue;

                OverloadInfo[] overloads = GetOverloadsForProperty(property);
                if (overloads[0].Parameters.Length != 1)
                    continue;

                OverloadInfo sampleOverload = FindSampledDataOverload(overloads);

                string interfaceName = "ICesiumValuePropertyWriter";
                if (sampleOverload != null)
                    interfaceName = "ICesiumInterpolatableValuePropertyWriter";

                writer.WriteLine("m_as{0} = new Lazy<{1}<{2}>>(Create{0}Adaptor, false);",
                                 property.NameWithPascalCase,
                                 interfaceName,
                                 overloads[0].Parameters[0].Type);
            }
        }
Esempio n. 29
0
        private void WriteConstructorsAndCloneMethod(CodeWriter writer, Schema schema)
        {
            WriteSummaryText(writer, "Initializes a new instance.");
            writer.WriteLine("public {0}CesiumWriter(string propertyName)", schema.NameWithPascalCase);
            writer.WriteLine("    : base(propertyName)");
            using (writer.OpenScope())
            {
                WriteAsTypeLazyInitialization(writer, schema);
            }
            writer.WriteLine();

            WriteSummaryText(writer, "Initializes a new instance as a copy of an existing instance.");
            WriteParameterText(writer, "existingInstance", "The existing instance to copy.");
            writer.WriteLine("protected {0}CesiumWriter({0}CesiumWriter existingInstance)", schema.NameWithPascalCase);
            writer.WriteLine("    : base(existingInstance)");
            using (writer.OpenScope())
            {
                WriteAsTypeLazyInitialization(writer, schema);
            }
            writer.WriteLine();

            WriteInheritDoc(writer);
            writer.WriteLine("public override {0}CesiumWriter Clone()", schema.NameWithPascalCase);
            using (writer.OpenScope())
            {
                writer.WriteLine("return new {0}CesiumWriter(this);", schema.NameWithPascalCase);
            }
            writer.WriteLine();
        }
Esempio n. 30
0
        private void WriteAsTypeMethods(CodeWriter writer, Schema schema)
        {
            foreach (Property property in schema.Properties)
            {
                if (!property.IsValue)
                    continue;
                if (PropertyValueIsLeaf(property))
                {
                    IEnumerable<OverloadInfo> overloads = GetOverloadsForProperty(property);
                    OverloadInfo firstOverload = overloads.First();

                    if (firstOverload.Parameters.Length != 1)
                        continue;

                    string firstOverloadFirstParameterType = firstOverload.Parameters[0].Type;

                    OverloadInfo sampleOverload = FindSampledDataOverload(overloads);

                    string interfaceName = "ICesiumValuePropertyWriter";
                    if (sampleOverload != null)
                        interfaceName = "ICesiumInterpolatableValuePropertyWriter";

                    WriteSummaryText(writer, string.Format("Returns a wrapper for this instance that implements <see cref=\"{0}{{T}}\" /> to write a value in <code>{1}</code> format.  Because the returned instance is a wrapper for this instance, you may call <see cref=\"ICesiumElementWriter.Close\" /> on either this instance or the wrapper, but you must not call it on both.", interfaceName, property.NameWithPascalCase));
                    WriteReturnsText(writer, "The wrapper.");
                    writer.WriteLine("public {0}<{1}> As{2}()", interfaceName, firstOverloadFirstParameterType, property.NameWithPascalCase);
                    using (writer.OpenScope())
                    {
                        writer.WriteLine("return m_as{0}.Value;", property.NameWithPascalCase);
                    }
                    writer.WriteLine();

                    string adaptorName = "CesiumWriterAdaptor";
                    if (sampleOverload != null)
                        adaptorName = "CesiumInterpolatableWriterAdaptor";

                    writer.WriteLine("private {0}<{1}> Create{2}Adaptor()", interfaceName, firstOverloadFirstParameterType, property.NameWithPascalCase);
                    using (writer.OpenScope())
                    {
                        string extraParameter = "";
                        if (sampleOverload != null)
                        {
                            extraParameter = string.Format(", (me, dates, values, startIndex, length) => me.Write{0}(dates, values, startIndex, length)", property.NameWithPascalCase);
                        }

                        writer.WriteLine("return new {0}<{1}CesiumWriter, {2}>(this, (me, value) => me.Write{3}(value){4});", adaptorName, schema.NameWithPascalCase, firstOverloadFirstParameterType, property.NameWithPascalCase, extraParameter);
                    }
                    writer.WriteLine();
                }
            }
        }
Esempio n. 31
0
 public CodeScope(CodeWriter codeWriter)
 {
     m_codeWriter = codeWriter;
 }