private void WriteDefinition() { string metadataPath = System.IO.Path.Combine(this.Path, AnnotationStoreCommon.GetDefinitionFileName(this.Name) + this.Extension); using (var file = File.CreateText(metadataPath)) using (var writer = new JsonTextWriter(file)) { this.Serializer.Serialize(writer, this.definition); } }
/// <summary> /// Initializes a new instance of the <see cref="AnnotationStoreReader"/> class. /// </summary> /// <param name="name">The name of the application that generated the persisted files, or the root name of the files</param> /// <param name="path">The directory in which the main persisted file resides or will reside, or null to create a volatile data store</param> public AnnotationStoreReader(string name, string path) : base(name, path, AnnotationStoreCommon.DefaultExtension) { // load definition string metadataPath = System.IO.Path.Combine(this.Path, AnnotationStoreCommon.GetDefinitionFileName(this.Name) + this.Extension); using (var file = File.OpenText(metadataPath)) using (var reader = new JsonTextReader(file)) { this.definition = this.Serializer.Deserialize <AnnotatedEventDefinition>(reader); } }
private void WriteDefinition() { string metadataPath = System.IO.Path.Combine(this.Path, AnnotationStoreCommon.GetDefinitionFileName(this.Name) + this.Extension); using (var file = File.CreateText(metadataPath)) using (var writer = new JsonTextWriter(file)) using (var validatingWriter = new JSchemaValidatingWriter(writer)) { validatingWriter.Schema = JSchema.Parse(AnnotationStoreCommon.DefinitionSchema, this.Resolver); validatingWriter.ValidationEventHandler += (s, e) => throw new InvalidDataException(e.Message); this.Serializer.Serialize(validatingWriter, this.definition); } }
/// <summary> /// Initializes a new instance of the <see cref="AnnotationStoreReader"/> class. /// </summary> /// <param name="name">The name of the application that generated the persisted files, or the root name of the files</param> /// <param name="path">The directory in which the main persisted file resides or will reside, or null to create a volatile data store</param> public AnnotationStoreReader(string name, string path) : base(name, path, AnnotationStoreCommon.DataSchema, AnnotationStoreCommon.DefaultExtension, AnnotationStoreCommon.PreloadSchemas) { // load definition string metadataPath = System.IO.Path.Combine(this.Path, AnnotationStoreCommon.GetDefinitionFileName(this.Name) + this.Extension); using (var file = File.OpenText(metadataPath)) using (var reader = new JsonTextReader(file)) using (var validatingReader = new JSchemaValidatingReader(reader)) { validatingReader.Schema = JSchema.Parse(AnnotationStoreCommon.DefinitionSchema, this.Resolver); validatingReader.ValidationEventHandler += (s, e) => throw new InvalidDataException(e.Message); this.definition = this.Serializer.Deserialize <AnnotatedEventDefinition>(validatingReader); } }