Ejemplo n.º 1
0
 public override void SerializeNodeValue(double value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     if (index != 0)
     {
         context.Append(",");
     }
     context.Append($@"""{key}"":{value}");
 }
Ejemplo n.º 2
0
 public override void SerializeNodeValue(string value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     if (index != 0)
     {
         context.Append(",");
     }
     context.Append($@"""{key}"":""{Sanitize(value)}""");
 }
Ejemplo n.º 3
0
 public override void SerializeNodeValue(bool value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     if (index != 0)
     {
         context.Append(",");
     }
     context.Append($@"""{key}"":{value.ToString().ToLower()}");
 }
Ejemplo n.º 4
0
 public override void SerializeBlockBegin(IConfigurationSerializationContext <string> context, int index)
 {
     if (index != 0)
     {
         context.Append(",");
     }
     context.Append($@"""{context.GetCurrentScope()}"": {{");
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Serializes a list of configuration nodes.
        ///
        /// For each child node to be serialized, the index should be incremented. Serializing a list node will
        /// enter a new block, and thus block headers and footers are written at the beginning and end of
        /// serialization of this node respectively.
        /// </summary>
        /// <param name="node">The list of configuration nodes represented as a <see cref="ListConfigurationNode"/></param>
        /// <param name="context">The serialization context.</param>
        /// <param name="index">The position or index of the given node within the current block in the context.</param>
        protected void SerializeNode(ListConfigurationNode node, IConfigurationSerializationContext <T> context, int index)
        {
            // Ignore pseudo-targets
            if (!node.Key.StartsWith("#"))
            {
                context.EnterScope(node.Key);
                this.SerializeBlockBegin(context, index);
            }

            int childIndex = 0;

            foreach (var childNode in node.Value)
            {
                this.SerializeNode(childNode, context, childIndex);
                childIndex++;
            }

            if (!node.Key.StartsWith("#"))
            {
                this.SerializeBlockEnd(context, index);
                context.ExitScope();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Serialize a <see cref="IAbstractConfigurationNode"/> with the given context.
        /// </summary>
        /// <param name="node">The node to serialize.</param>
        /// <param name="context">The serialization context.</param>
        /// <param name="index">The position or index of the given node within the current block in the context.</param>
        public void SerializeNode(IAbstractConfigurationNode node,
                                  IConfigurationSerializationContext <T> context, int index = 0)
        {
            switch (node)
            {
            case ListConfigurationNode listNode:
                this.SerializeNode(listNode, context, index);
                break;

            case StringConfigurationNode stringNode:
                this.SerializeNode(stringNode, context, index);
                break;

            case BooleanConfigurationNode boolNode:
                this.SerializeNode(boolNode, context, index);
                break;

            case IntegralConfigurationNode intNode:
                this.SerializeNode(intNode, context, index);
                break;

            case DecimalConfigurationNode decNode:
                this.SerializeNode(decNode, context, index);
                break;

            case DeviceCapabilityElementConfigurationNode ctrlNode:
                this.SerializeNode(ctrlNode, context, index);
                break;

            case EnumConfigurationNode enumNode:
                this.SerializeNode(enumNode, context, index);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Write the header to the serialized stream.
 /// </summary>
 /// <param name="context">The serialization context.</param>
 public virtual void SerializeFooter(IConfigurationSerializationContext <T> context)
 {
     return;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Serializes the value of a <see cref="EnumConfigurationNode"/>. Override this when implementing a serializer.
 /// </summary>
 /// <param name="controllerElementValue">The value of the node</param>
 /// <param name="value">
 /// The raw value of the node as the string representation of the element consistent with the
 /// <see cref="IDeviceInputMapping"/> the syntax tree was originally serialized with.</param>
 /// <param name="key">The key of the node.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 public abstract void SerializerNodeValue(ControllerElement controllerElementValue, string value, string key, IConfigurationSerializationContext <T> context, int index);
Ejemplo n.º 9
0
 public override void SerializeFooter(IConfigurationSerializationContext <string> context)
 {
     context.Append("}");
 }
Ejemplo n.º 10
0
 public override void SerializerNodeValue(ControllerElement controllerElementValue, string value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     context.AppendLine($"<{key}>{value}</{key}>");
 }
Ejemplo n.º 11
0
 public override void SerializeBlockEnd(IConfigurationSerializationContext <string> context, int index)
 {
     // todo: sanitize
     context.AppendLine($"</{context.GetCurrentScope()}>");
 }
 public override void SerializeNodeValue(string value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     context.AppendLine($"{key}={value}");
 }
 public override void SerializeBlockBegin(IConfigurationSerializationContext <string> context, int index)
 {
     context.AppendLine($"[{String.Join('.', context.GetFullScope())}]");
 }
Ejemplo n.º 14
0
 public override void SerializerNodeValue(ControllerElement controllerElementValue, string value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     if (index != 0)
     {
         context.Append(",");
     }
     context.Append($@"""{key}"":""{value}""");
 }
Ejemplo n.º 15
0
 public override void SerializeBlockEnd(IConfigurationSerializationContext <string> context, int index)
 {
     context.Append("}");
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Serialize a marker or footer where a block or section ends in the serialized stream.
 /// </summary>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 public abstract void SerializeBlockEnd(IConfigurationSerializationContext <T> context, int index);
Ejemplo n.º 17
0
 /// <summary>
 /// Serializes a configuration node that encapsulates a decimal value, implemented as a <see cref="double"/>.
 ///
 /// Contrary to the name, this is not implemented as a <see cref="decimal"/>, and IEEE 754 floating point semantics
 /// for double precision floating point numbers should be taken into account.
 /// </summary>
 /// <param name="node">The node to serialize.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 protected void SerializeNode(DecimalConfigurationNode node, IConfigurationSerializationContext <T> context, int index)
 {
     this.SerializeNodeValue(node.Value, node.Key, context, index);
 }
 public override void SerializeBlockEnd(IConfigurationSerializationContext <string> context, int index)
 {
     return;
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Serializes a configuration node that encapsulates an <see cref="Enum"/> value.
 /// </summary>
 /// <param name="node">The node to serialize.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 protected void SerializeNode(EnumConfigurationNode node, IConfigurationSerializationContext <T> context, int index)
 {
     this.SerializeNodeValue((node as AbstractConfigurationNode <Enum>).Value, node.Value, node.Key, context, index);
 }
Ejemplo n.º 20
0
 public override void SerializeFooter(IConfigurationSerializationContext <string> context)
 {
     context.AppendLine($"</{this.RootElementName}>");
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Serializes a configuration node that encapsulates a <see cref="ControllerElement"/>.
 ///
 /// This is only used when serializing syntax trees that came from <see cref="IInputTemplate"/>.
 /// </summary>
 /// <param name="node">The node to serialize.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 protected void SerializeNode(DeviceCapabilityElementConfigurationNode node, IConfigurationSerializationContext <T> context, int index)
 {
     this.SerializeNodeValue((node as AbstractConfigurationNode <DeviceCapability>).Value, node.Value, node.Key, context, index);
 }
Ejemplo n.º 22
0
 public override void SerializeNodeValue(double value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     context.AppendLine($"<{key}>{value}</{key}>");
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Serializes the value of a <see cref="StringConfigurationNode"/>. Override this when implementing a serializer.
 /// </summary>
 /// <param name="value">The raw value of the node.</param>
 /// <param name="key">The key of the node.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 public abstract void SerializeNodeValue(string value, string key, IConfigurationSerializationContext <T> context, int index);
Ejemplo n.º 24
0
 public static void AppendLine(this IConfigurationSerializationContext <string> @this, string content)
 {
     @this.Append($"{content}{Environment.NewLine}");
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Serializes a configuration node that encapsulates a <see cref="ControllerElement"/>.
 ///
 /// This is only used when serializing syntax trees that came from <see cref="IInputTemplate"/>.
 /// </summary>
 /// <param name="node">The node to serialize.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 protected void SerializeNode(ControllerElementConfigurationNode node, IConfigurationSerializationContext <T> context, int index)
 {
     this.SerializeNodeValue((node as AbstractConfigurationNode <ControllerElement>).Value, node.Value, node.Key, context, index);
 }