/// <summary> /// Creates an instance of <see cref="SdbSchemaData"/> using embedded streams for constraint data and simple types. /// </summary> /// <remarks> /// Constraint data are contained in a binary file that is defined as: /// /// <![CDATA[ /// [SdbDataHead][SdbClassIdToSchemaTypeIndex][SdbSchemaType][SdbParticleConstraint][SdbParticleChildrenIndex][SdbAttributeConstraint] /// ]]> /// /// Since the size of the arrays are different for different <paramref name="fileFormat"/>, these are all marshalled separately, with the information /// of offsets contained in <see cref="SdbDataHead"/>. These items are deserialized in this method, while <see cref="SerializeSdbData(Stream)"/> provides /// the infrastructure to serialize them back to a binary file in the correct order /// </remarks> /// <param name="fileFormat">The version to load</param> private SdbSchemaData(FileFormatVersions fileFormat) { if (!fileFormat.Any()) { throw new ArgumentOutOfRangeException(nameof(fileFormat)); } _fileFormat = fileFormat; using (var schema = GetStream(fileFormat, Constraints)) { var dataHead = SdbData.Deserialize <SdbDataHead>(schema); dataHead.Validate(); var length = (int)schema.Length; if (dataHead.End != length) { throw new InvalidDataException(); } ClassIdMap = SdbData.Deserialize <SdbClassIdToSchemaTypeIndex>(schema, dataHead.ClassIds); SchemaTypes = SdbData.Deserialize <SdbSchemaType>(schema, dataHead.SchemaType); Particles = SdbData.Deserialize <SdbParticleConstraint>(schema, dataHead.Particles); ParticleIndexes = SdbData.Deserialize <SdbParticleChildrenIndex>(schema, dataHead.ParticleChildren); Attributes = SdbData.Deserialize <SdbAttributeConstraint>(schema, dataHead.Attributes); } }
/// <summary> /// Throws an ArgumentOutOfRangeException if the specified FileFormatVersions is not supported. /// </summary> /// <param name="fileFormat">The specified FileFormatVersions.</param> /// <param name="parameterName">The name of the parameter for ArgumentOutOfRangeException.</param> /// <remarks> /// </remarks> internal static void ThrowExceptionIfFileFormatNotSupported(this FileFormatVersions fileFormat, string parameterName) { if (!fileFormat.Any()) { throw new ArgumentOutOfRangeException(parameterName, SR.Format(ExceptionMessages.FileFormatNotSupported, fileFormat)); } }
public BinarySdbSchemaDatas(FileFormatVersions fileFormat) { Debug.Assert(fileFormat.Any()); SdbDataHead = new SdbDataHead(); _fileFormat = fileFormat; var name = $"DocumentFormat.OpenXml.GeneratedCode.{fileFormat}.constraints"; #if DEBUG var names = typeof(ValidationResources).GetTypeInfo().Assembly.GetManifestResourceNames(); #endif using (var schema = typeof(ValidationResources).GetTypeInfo().Assembly.GetManifestResourceStream(name)) { if (schema == null) { var message = string.Format(System.Globalization.CultureInfo.CurrentUICulture, ExceptionMessages.FileFormatNotSupported, fileFormat); throw new ArgumentOutOfRangeException(nameof(fileFormat), message); } Load(schema); } }
/// <summary> /// Throws an ArgumentOutOfRangeException if the specified FileFormatVersions is not supported. /// </summary> /// <param name="fileFormat">The specified FileFormatVersions.</param> /// <param name="parameterName">The name of the parameter for ArgumentOutOfRangeException.</param> /// <remarks> /// </remarks> internal static void ThrowExceptionIfFileFormatNotSupported(this FileFormatVersions fileFormat, string parameterName) { if (!fileFormat.Any()) { var message = string.Format(CultureInfo.CurrentUICulture, ExceptionMessages.FileFormatNotSupported, fileFormat); throw new ArgumentOutOfRangeException(parameterName, message); } }
public BinarySdbSchemaDatas(FileFormatVersions fileFormat) { Debug.Assert(fileFormat.Any()); this.SdbDataHead = new SdbDataHead(); this._fileFormat = fileFormat; using (var schema = GetSchemaStream(fileFormat)) { this.Load(schema); } }
public static Stream GetSchemaStream(FileFormatVersions fileFormat) { switch (fileFormat) { case FileFormatVersions.Office2007: return(GetEmbeddedResource("O12SchemaConstraintDatas")); case FileFormatVersions.Office2010: return(GetEmbeddedResource("O14SchemaConstraintDatas")); case FileFormatVersions.Office2013: return(GetEmbeddedResource("O15SchemaConstraintDatas")); default: Debug.Assert(fileFormat.Any()); return(GetEmbeddedResource("O12SchemaConstraintDatas")); } }
internal static OpenXmlSimpleType[] CreatePossibleMembers(UnionValueRestriction unionValueRestriction, FileFormatVersions fileFormatVersion) { switch (fileFormatVersion) { case FileFormatVersions.Office2007: return(O12UnionHelper.CreatePossibleMembers(unionValueRestriction)); case FileFormatVersions.Office2010: return(O14UnionHelper.CreatePossibleMembers(unionValueRestriction)); case FileFormatVersions.Office2013: return(O15UnionHelper.CreatePossibleMembers(unionValueRestriction)); default: Debug.Assert(fileFormatVersion.Any()); break; } return(null); }
internal static OpenXmlSimpleType CreateTargetValueObject(RedirectedRestriction redirectedRestriction, FileFormatVersions fileFormatVersion) { switch (fileFormatVersion) { case FileFormatVersions.Office2007: return(O12UnionHelper.CreateTargetValueObject(redirectedRestriction)); case FileFormatVersions.Office2010: return(O14UnionHelper.CreateTargetValueObject(redirectedRestriction)); case FileFormatVersions.Office2013: return(O15UnionHelper.CreateTargetValueObject(redirectedRestriction)); default: Debug.Assert(fileFormatVersion.Any()); break; } return(null); }
private static Stream GetSchemaStream(FileFormatVersions fileFormat) { Stream GetEmbeddedResource(string name) { return(typeof(ValidationResources).GetTypeInfo().Assembly.GetManifestResourceStream($"DocumentFormat.OpenXml.GeneratedCode.{name}.bin")); } switch (fileFormat) { case FileFormatVersions.Office2007: return(GetEmbeddedResource("O12SchemaConstraintDatas")); case FileFormatVersions.Office2010: return(GetEmbeddedResource("O14SchemaConstraintDatas")); case FileFormatVersions.Office2013: return(GetEmbeddedResource("O15SchemaConstraintDatas")); default: Debug.Assert(fileFormat.Any()); return(GetEmbeddedResource("O12SchemaConstraintDatas")); } }
public void CheckAny(FileFormatVersions version, bool expected) { Assert.Equal(expected, version.Any()); }