/// <summary> /// Outputs an EDMX artifact to the provided XmlWriter. /// </summary> /// <param name="model">Model to be written.</param> /// <param name="writer">XmlWriter the generated EDMX will be written to.</param> /// <param name="target">Target implementation of the EDMX being generated.</param> /// <param name="errors">Errors that prevented successful serialization, or no errors if serialization was successfull. </param> /// <returns>A value indicating whether serialization was successful.</returns> public static bool TryWriteEdmx(IEdmModel model, XmlWriter writer, EdmxTarget target, out IEnumerable<EdmError> errors) { EdmUtil.CheckArgumentNull(model, "model"); EdmUtil.CheckArgumentNull(writer, "writer"); errors = model.GetSerializationErrors(); if (errors.FirstOrDefault() != null) { return false; } Version edmxVersion = model.GetEdmxVersion(); if (edmxVersion != null) { if (!CsdlConstants.SupportedEdmxVersions.ContainsKey(edmxVersion)) { errors = new EdmError[] { new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmxVersion, Edm.Strings.Serializer_UnknownEdmxVersion) }; return false; } } else if (!CsdlConstants.EdmToEdmxVersions.TryGetValue(model.GetEdmVersion() ?? EdmConstants.EdmVersionLatest, out edmxVersion)) { errors = new EdmError[] { new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmVersion, Edm.Strings.Serializer_UnknownEdmVersion) }; return false; } IEnumerable<EdmSchema> schemas = new EdmModelSchemaSeparationSerializationVisitor(model).GetSchemas(); EdmxWriter edmxWriter = new EdmxWriter(model, schemas, writer, edmxVersion, target); edmxWriter.WriteEdmx(); errors = Enumerable.Empty<EdmError>(); return true; }
void VerifyResult(string[] inputText, string expectedResult, EdmxTarget target, Action <IEdmModel> visitModel) { IEdmModel model; IEnumerable <EdmError> errors; List <XmlReader> readers = new List <XmlReader>(); foreach (string s in inputText) { readers.Add(XmlReader.Create(new StringReader(s))); } bool parsed = CsdlReader.TryParse(readers, out model, out errors); Assert.IsTrue(parsed, "Model Parsed"); Assert.IsTrue(errors.Count() == 0, "No Errors"); if (visitModel != null) { visitModel(model); } StringWriter sw = new StringWriter(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.Encoding = System.Text.Encoding.UTF8; XmlWriter xw = XmlWriter.Create(sw, settings); EdmxWriter.TryWriteEdmx(model, xw, target, out errors); xw.Flush(); xw.Close(); string outputText = sw.ToString(); Assert.AreEqual(expectedResult, outputText, "Expected Result = Output"); }
public void DumpRoundTrippedEdmx(EdmxTarget edmxTarget) { IEnumerable <EdmError> writeErrors; var sb = new StringBuilder(2048); var xmlSettings = new XmlWriterSettings() { Encoding = Encoding.UTF8, Indent = true }; using (var db = new ScrumDb()) using (XmlWriter writer = XmlWriter.Create(sb, xmlSettings)) { var edmModel = db.GetEdmModel(); Microsoft.Data.Edm.Csdl.EdmxWriter.TryWriteEdmx(edmModel, writer, edmxTarget, out writeErrors); } Console.WriteLine(sb.ToString()); if (writeErrors.Any()) { Console.WriteLine(); Console.WriteLine("EDMX write errors:"); foreach (var error in writeErrors) { Console.WriteLine(error.ToString()); } } }
private EdmxWriter(IEdmModel model, IEnumerable<EdmSchema> schemas, XmlWriter writer, Version edmxVersion, EdmxTarget target) { this.model = model; this.schemas = schemas; this.writer = writer; this.edmxVersion = edmxVersion; this.target = target; this.edmxNamespace = CsdlConstants.SupportedEdmxVersions[edmxVersion]; }
private EdmxWriter(IEdmModel model, IEnumerable <EdmSchema> schemas, XmlWriter writer, Version edmxVersion, EdmxTarget target) { this.model = model; this.schemas = schemas; this.writer = writer; this.edmxVersion = edmxVersion; this.target = target; this.edmxNamespace = CsdlConstants.SupportedEdmxVersions[edmxVersion]; }
private void EdmxRoundTripCheck(string expectedEdmx, EdmxTarget target, IEdmModel model) { var errors = new EdmLibTestErrors(); this.VerifySemanticValidation(model, Microsoft.Test.OData.Utils.Metadata.EdmVersion.V40, errors); string actualEdmx = GetEdmx(model, target); var valid = XElement.DeepEquals(XElement.Parse(expectedEdmx), XElement.Parse(actualEdmx)); Assert.IsTrue(valid, "Invalid actual edmx."); }
public static bool TryWriteEdmx(IEdmModel model, XmlWriter writer, EdmxTarget target, out IEnumerable<EdmError> errors) { EdmUtil.CheckArgumentNull<IEdmModel>(model, "model"); EdmUtil.CheckArgumentNull<XmlWriter>(writer, "writer"); errors = model.GetSerializationErrors(); if (errors.FirstOrDefault<EdmError>() == null) { Version edmxVersion = model.GetEdmxVersion(); if (edmxVersion == null) { Dictionary<Version, Version> edmToEdmxVersions = CsdlConstants.EdmToEdmxVersions; Version edmVersion = model.GetEdmVersion(); Version edmVersionLatest = edmVersion; if (edmVersion == null) { edmVersionLatest = EdmConstants.EdmVersionLatest; } if (!edmToEdmxVersions.TryGetValue(edmVersionLatest, out edmxVersion)) { EdmError[] edmError = new EdmError[1]; edmError[0] = new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmVersion, Strings.Serializer_UnknownEdmVersion); errors = edmError; return false; } } else { if (!CsdlConstants.SupportedEdmxVersions.ContainsKey(edmxVersion)) { EdmError[] edmErrorArray = new EdmError[1]; edmErrorArray[0] = new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmxVersion, Strings.Serializer_UnknownEdmxVersion); errors = edmErrorArray; return false; } } IEnumerable<EdmSchema> schemas = (new EdmModelSchemaSeparationSerializationVisitor(model)).GetSchemas(); EdmxWriter edmxWriter = new EdmxWriter(model, schemas, writer, edmxVersion, target); edmxWriter.WriteEdmx(); errors = Enumerable.Empty<EdmError>(); return true; } else { return false; } }
public static bool TryWriteEdmx(IEdmModel model, XmlWriter writer, EdmxTarget target, out IEnumerable <EdmError> errors) { EdmUtil.CheckArgumentNull <IEdmModel>(model, "model"); EdmUtil.CheckArgumentNull <XmlWriter>(writer, "writer"); errors = model.GetSerializationErrors(); if (errors.FirstOrDefault <EdmError>() == null) { Version edmxVersion = model.GetEdmxVersion(); if (edmxVersion == null) { Dictionary <Version, Version> edmToEdmxVersions = CsdlConstants.EdmToEdmxVersions; Version edmVersion = model.GetEdmVersion(); Version edmVersionLatest = edmVersion; if (edmVersion == null) { edmVersionLatest = EdmConstants.EdmVersionLatest; } if (!edmToEdmxVersions.TryGetValue(edmVersionLatest, out edmxVersion)) { EdmError[] edmError = new EdmError[1]; edmError[0] = new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmVersion, Strings.Serializer_UnknownEdmVersion); errors = edmError; return(false); } } else { if (!CsdlConstants.SupportedEdmxVersions.ContainsKey(edmxVersion)) { EdmError[] edmErrorArray = new EdmError[1]; edmErrorArray[0] = new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmxVersion, Strings.Serializer_UnknownEdmxVersion); errors = edmErrorArray; return(false); } } IEnumerable <EdmSchema> schemas = (new EdmModelSchemaSeparationSerializationVisitor(model)).GetSchemas(); EdmxWriter edmxWriter = new EdmxWriter(model, schemas, writer, edmxVersion, target); edmxWriter.WriteEdmx(); errors = Enumerable.Empty <EdmError>(); return(true); } else { return(false); } }
private void WriteEdmx() { EdmxTarget edmxTarget = this.target; switch (edmxTarget) { case EdmxTarget.EntityFramework: { this.WriteEFEdmx(); return; } case EdmxTarget.OData: { this.WriteODataEdmx(); return; } } throw new InvalidOperationException(Strings.UnknownEnumVal_EdmxTarget(this.target.ToString())); }
private string GetEdmx(IEdmModel model, EdmxTarget target) { string edmx = string.Empty; using (StringWriter sw = new StringWriter()) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = System.Text.Encoding.UTF8; using (XmlWriter xw = XmlWriter.Create(sw, settings)) { IEnumerable <EdmError> errors; EdmxWriter.TryWriteEdmx(model, xw, target, out errors); xw.Flush(); } edmx = sw.ToString(); } return(edmx); }
private string GetEdmx(IEdmModel model, EdmxTarget target) { string edmx = string.Empty; using (StringWriter sw = new StringWriter()) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = System.Text.Encoding.UTF8; using (XmlWriter xw = XmlWriter.Create(sw, settings)) { IEnumerable<EdmError> errors; EdmxWriter.TryWriteEdmx(model, xw, target, out errors); xw.Flush(); } edmx = sw.ToString(); } return edmx; }
void VerifyResult(string inputText, string expectedResult, EdmxTarget target) { IEdmModel model; IEnumerable <EdmError> errors; bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(inputText)) }, out model, out errors); Assert.IsTrue(parsed, "Model Parsed"); Assert.IsTrue(errors.Count() == 0, "No Errors"); StringWriter sw = new StringWriter(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.Encoding = System.Text.Encoding.UTF8; XmlWriter xw = XmlWriter.Create(sw, settings); EdmxWriter.TryWriteEdmx(model, xw, target, out errors); xw.Flush(); xw.Close(); string outputText = sw.ToString(); Assert.AreEqual(expectedResult, outputText, "Expected Result = Output"); }
/// <summary> /// Outputs an EDMX artifact to the provided XmlWriter. /// </summary> /// <param name="model">Model to be written.</param> /// <param name="writer">XmlWriter the generated EDMX will be written to.</param> /// <param name="target">Target implementation of the EDMX being generated.</param> /// <param name="errors">Errors that prevented successful serialization, or no errors if serialization was successfull. </param> /// <returns>A value indicating whether serialization was successful.</returns> public static bool TryWriteEdmx(IEdmModel model, XmlWriter writer, EdmxTarget target, out IEnumerable <EdmError> errors) { EdmUtil.CheckArgumentNull(model, "model"); EdmUtil.CheckArgumentNull(writer, "writer"); errors = model.GetSerializationErrors(); if (errors.FirstOrDefault() != null) { return(false); } Version edmxVersion = model.GetEdmxVersion(); if (edmxVersion != null) { if (!CsdlConstants.SupportedEdmxVersions.ContainsKey(edmxVersion)) { errors = new EdmError[] { new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmxVersion, Edm.Strings.Serializer_UnknownEdmxVersion) }; return(false); } } else if (!CsdlConstants.EdmToEdmxVersions.TryGetValue(model.GetEdmVersion() ?? EdmConstants.EdmVersionLatest, out edmxVersion)) { errors = new EdmError[] { new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmVersion, Edm.Strings.Serializer_UnknownEdmVersion) }; return(false); } IEnumerable <EdmSchema> schemas = new EdmModelSchemaSeparationSerializationVisitor(model).GetSchemas(); EdmxWriter edmxWriter = new EdmxWriter(model, schemas, writer, edmxVersion, target); edmxWriter.WriteEdmx(); errors = Enumerable.Empty <EdmError>(); return(true); }
public void DumpRoundTrippedEdmx(EdmxTarget edmxTarget) { IEnumerable<EdmError> writeErrors; var sb = new StringBuilder(2048); var xmlSettings = new XmlWriterSettings() { Encoding = Encoding.UTF8, Indent = true }; using (var db = new ScrumDb()) using (XmlWriter writer = XmlWriter.Create(sb, xmlSettings)) { var edmModel = db.GetEdmModel(); Microsoft.Data.Edm.Csdl.EdmxWriter.TryWriteEdmx(edmModel, writer, edmxTarget, out writeErrors); } Console.WriteLine(sb.ToString()); if (writeErrors.Any()) { Console.WriteLine(); Console.WriteLine("EDMX write errors:"); foreach (var error in writeErrors) { Console.WriteLine(error.ToString()); } } }
void VerifyResult(string[] inputText, string expectedResult, EdmxTarget target) { VerifyResult(inputText, expectedResult, target, null); }
private void EdmxRoundTripCheck(string edmx, EdmxTarget target) { IEdmModel model = this.GetEdmxParserResult(edmx); this.EdmxRoundTripCheck(edmx, target, model); }
void VerifyResult(string inputText, string expectedResult, EdmxTarget target) { IEdmModel model; IEnumerable<EdmError> errors; bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(inputText)) }, out model, out errors); Assert.IsTrue(parsed, "Model Parsed"); Assert.IsTrue(errors.Count() == 0, "No Errors"); StringWriter sw = new StringWriter(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.Encoding = System.Text.Encoding.UTF8; XmlWriter xw = XmlWriter.Create(sw, settings); EdmxWriter.TryWriteEdmx(model, xw, target, out errors); xw.Flush(); xw.Close(); string outputText = sw.ToString(); Assert.AreEqual(expectedResult, outputText, "Expected Result = Output"); }
void VerifyResult(string[] inputText, string expectedResult, EdmxTarget target, Action<IEdmModel> visitModel) { IEdmModel model; IEnumerable<EdmError> errors; List<XmlReader> readers = new List<XmlReader>(); foreach (string s in inputText) { readers.Add(XmlReader.Create(new StringReader(s))); } bool parsed = CsdlReader.TryParse(readers, out model, out errors); Assert.IsTrue(parsed, "Model Parsed"); Assert.IsTrue(errors.Count() == 0, "No Errors"); if (visitModel != null) { visitModel(model); } StringWriter sw = new StringWriter(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.Encoding = System.Text.Encoding.UTF8; XmlWriter xw = XmlWriter.Create(sw, settings); EdmxWriter.TryWriteEdmx(model, xw, target, out errors); xw.Flush(); xw.Close(); string outputText = sw.ToString(); Assert.AreEqual(expectedResult, outputText, "Expected Result = Output"); }