Example #1
0
		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;
			}
		}
Example #2
0
 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);
     }
 }
Example #3
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);
        }
Example #4
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;
        }