コード例 #1
0
ファイル: EdmxWriter.cs プロジェクト: rossjempson/odata.net
        /// <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;
        }
コード例 #2
0
        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");
        }
コード例 #3
0
ファイル: EdmTests.cs プロジェクト: skush/ODataServer
        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());
                }
            }
        }
コード例 #4
0
ファイル: EdmxWriter.cs プロジェクト: nickchal/pash
		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];
		}
コード例 #5
0
ファイル: EdmxWriter.cs プロジェクト: modulexcite/pash-1
 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];
 }
コード例 #6
0
        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.");
        }
コード例 #7
0
ファイル: EdmxWriter.cs プロジェクト: nickchal/pash
		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;
			}
		}
コード例 #8
0
ファイル: EdmxWriter.cs プロジェクト: modulexcite/pash-1
 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);
     }
 }
コード例 #9
0
ファイル: EdmxWriter.cs プロジェクト: modulexcite/pash-1
        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()));
        }
コード例 #10
0
ファイル: EdmxWriterTests.cs プロジェクト: sivethe/odata.net
        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);
        }
コード例 #11
0
        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;
        }
コード例 #12
0
        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");
        }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
ファイル: EdmTests.cs プロジェクト: mdabbagh88/ODataServer
		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());
				}
			}
		}
コード例 #15
0
 void VerifyResult(string[] inputText, string expectedResult, EdmxTarget target)
 {
     VerifyResult(inputText, expectedResult, target, null);
 }
コード例 #16
0
        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.");
        }
コード例 #17
0
        private void EdmxRoundTripCheck(string edmx, EdmxTarget target)
        {
            IEdmModel model = this.GetEdmxParserResult(edmx);

            this.EdmxRoundTripCheck(edmx, target, model);
        }
コード例 #18
0
        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");
        }
コード例 #19
0
 void VerifyResult(string[] inputText, string expectedResult, EdmxTarget target)
 {
     VerifyResult(inputText, expectedResult, target, null);
 }
コード例 #20
0
        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");
        }
コード例 #21
0
        private void EdmxRoundTripCheck(string edmx, EdmxTarget target)
        {
            IEdmModel model = this.GetEdmxParserResult(edmx);

            this.EdmxRoundTripCheck(edmx, target, model);
        }