コード例 #1
0
 private static FieldPath <string, string> GetOuterFieldsNames(
     Dictionary <int, string> typeNames, IEnumerable <Type> outerFields)
 {
     return(outerFields.Aggregate(
                default(FieldPath <string, string>), (p, f) => FieldPath <string, string> .Append(p, GetFieldNames(typeNames, f))));
 }
コード例 #2
0
 private static FieldPath <int, EmberId> GetOuterFieldsIds(IEnumerable <Type> outerFields) =>
 outerFields.Aggregate(
     default(FieldPath <int, EmberId>), (p, f) => FieldPath <int, EmberId> .Append(p, GetFieldIds(f)));
コード例 #3
0
        private void ToXmlCore(
            EmberReader reader, XmlWriter writer, FieldPath <int, EmberId> previousPath, int currentType)
        {
            while (reader.Read())
            {
                var nextType = reader.InnerNumber;

                if (nextType == InnerNumber.EndContainer)
                {
                    writer.WriteEndElement();
                    return;
                }

                var currentPath = Combine(previousPath, new Field <int, EmberId>(currentType, reader.OuterId));
                var fieldName   = this.GetFieldName(currentPath);

                switch (nextType)
                {
                case BerBoolean.InnerNumber:
                    var boolean = reader.ReadContentsAsBoolean();
                    WriteValue(writer, fieldName, BerBoolean.Name, boolean, (w, o) => w.WriteValue(o));
                    break;

                case BerInteger.InnerNumber:
                    var integer = reader.ReadContentsAsInt64();
                    WriteValue(writer, fieldName, BerInteger.Name, integer, (w, o) => w.WriteValue(o));
                    break;

                case BerReal.InnerNumber:
                    WriteValue(
                        writer, fieldName, BerReal.Name, reader.ReadContentsAsDouble(), (w, o) => w.WriteValue(o));
                    break;

                case BerUtf8String.InnerNumber:
                    string str;

                    try
                    {
                        str = XmlConvert.VerifyXmlChars(reader.ReadContentsAsString());
                    }
                    catch (XmlException)
                    {
                        str = "*** CONTAINS INVALID XML CHARACTERS ***";
                    }

                    switch (currentPath.ToString())
                    {
                    case "1073741825.C-1.C-6":
                    case "1073741825.C-1.C-7":
                    case "1073741825.C-1.C-17":
                    case "1073741833.C-1.C-6":
                    case "1073741833.C-1.C-7":
                    case "1073741833.C-1.C-17":
                    case "1073741827.C-1.C-4":
                    case "1073741834.C-1.C-4":
                    case "1073741837.C-1.C-11":
                    case "1073741841.C-1.C-11":
                        str = str.Replace("\n", Environment.NewLine);
                        break;

                    default:
                        // Intentionally do nothing
                        break;
                    }

                    WriteValue(writer, fieldName, BerUtf8String.Name, str, (w, o) => w.WriteValue(o));
                    break;

                case BerOctetstring.InnerNumber:
                    var bytes = reader.ReadContentsAsByteArray();
                    WriteValue(
                        writer, fieldName, BerOctetstring.Name, bytes, (w, o) => w.WriteBinHex(o, 0, o.Length));
                    break;

                case BerRelativeObjectIdentifier.InnerNumber:
                    var intOid = reader.ReadContentsAsInt32Array();
                    var oid    = string.Join(".", intOid.Select(e => e.ToString(InvariantCulture)));
                    WriteValue(writer, fieldName, BerRelativeObjectIdentifier.Name, oid, (w, o) => w.WriteValue(o));
                    break;

                case BerSequence.InnerNumber:
                    WriteStartContainer(writer, fieldName, BerSequence.Name);
                    this.ToXmlCore(reader, writer, currentPath, nextType);
                    break;

                case BerSet.InnerNumber:
                    WriteStartContainer(writer, fieldName, BerSet.Name);
                    this.ToXmlCore(reader, writer, currentPath, nextType);
                    break;

                default:
                    WriteStartContainer(writer, fieldName, this.GetTypeName(nextType));
                    this.ToXmlCore(reader, writer, currentPath, nextType);
                    break;
                }
            }
        }
コード例 #4
0
        private void FromXmlCore(
            XmlReader reader, EmberWriter writer, FieldPath <string, string> previousPath, string currentType)
        {
            if (reader.IsEmptyElement)
            {
                writer.WriteEndContainer();
                return;
            }

            while (ReadNext(reader))
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    writer.WriteEndContainer();
                    return;
                }

                if (reader.NodeType != XmlNodeType.Element)
                {
                    const string Format = "Unexpected Node Type: Encountered {0} while looking for {1}.";
                    throw new XmlException(
                              string.Format(InvariantCulture, Format, reader.NodeType, XmlNodeType.Element));
                }

                var currentPath = Combine(previousPath, new Field <string, string>(currentType, reader.Name));
                var fieldId     = this.GetFieldId(currentPath);

                if (reader.AttributeCount != 1)
                {
                    throw new XmlException(
                              "Unexpected Attribute Count: Each element must have exactly one type attribute.");
                }

                var nextType = reader.GetAttribute(0);

                switch (nextType)
                {
                case BerBoolean.Name:
                    writer.WriteValue(fieldId, ReadValue(reader, r => r.ReadContentAsBoolean()));
                    break;

                case BerInteger.Name:
                    writer.WriteValue(fieldId, ReadValue(reader, r => r.ReadContentAsLong()));
                    break;

                case BerOctetstring.Name:
                    WriteOctetstring(reader, writer, fieldId);
                    break;

                case BerReal.Name:
                    writer.WriteValue(fieldId, ReadValue(reader, r => r.ReadContentAsDouble()));
                    break;

                case BerUtf8String.Name:
                    var value = ReadValue(reader, r => r.ReadContentAsString(), string.Empty);

                    switch (currentPath.ToString())
                    {
                    case "Parameter.contents.formula":
                    case "Parameter.contents.enumeration":
                    case "Parameter.contents.schemaIdentifiers":
                    case "QualifiedParameter.contents.formula":
                    case "QualifiedParameter.contents.enumeration":
                    case "QualifiedParameter.contents.schemaIdentifiers":
                    case "Node.contents.schemaIdentifiers":
                    case "QualifiedNode.contents.schemaIdentifiers":
                    case "Matrix.contents.schemaIdentifiers":
                    case "QualifiedMatrix.contents.schemaIdentifiers":
                        value = value.Replace(Environment.NewLine, "\n");
                        break;

                    default:
                        // Intentionally do nothing
                        break;
                    }

                    writer.WriteValue(fieldId, value);
                    break;

                case BerRelativeObjectIdentifier.Name:
                    WriteRelativeObjectIdentifier(reader, writer, fieldId);
                    break;

                case BerSequence.Name:
                    writer.WriteStartSequence(fieldId);
                    this.FromXmlCore(reader, writer, currentPath, nextType);
                    break;

                case BerSet.Name:
                    writer.WriteStartSet(fieldId);
                    this.FromXmlCore(reader, writer, currentPath, nextType);
                    break;

                default:
                    writer.WriteStartApplicationDefinedType(fieldId, this.GetInnerNumber(nextType));
                    this.FromXmlCore(reader, writer, currentPath, nextType);
                    break;
                }
            }
        }
コード例 #5
0
 public bool Equals(FieldPath <TTypeId, TFieldId> other) =>
 this.field1.Equals(other.field1) && this.field2.Equals(other.field2) && this.field3.Equals(other.field3);