コード例 #1
0
        private MemoryStream InternalSaveModel2(DslModeling::SerializationResult serializationResult, PatternModelSchema modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
        {
            #region Check Parameters
            global::System.Diagnostics.Debug.Assert(serializationResult != null);
            global::System.Diagnostics.Debug.Assert(modelRoot != null);
            global::System.Diagnostics.Debug.Assert(!serializationResult.Failed);
            #endregion

            serializationResult.Encoding = encoding;

            DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(modelRoot.Store);


            global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream();

            DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileName, serializationResult);
            this.InitializeSerializationContext(modelRoot.Partition, serializationContext, false);
            // MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.
            serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
            global::System.Xml.XmlWriterSettings settings = PatternModelSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
            using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
            {
                this.WriteRootElement(serializationContext, modelRoot, writer);
            }

            return(newFileContent);
        }
コード例 #2
0
        private global::System.IO.MemoryStream InternalSaveDiagram(DslModeling::SerializationResult serializationResult, DslDiagrams::Diagram diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
        {
            #region Check Parameters
            global::System.Diagnostics.Debug.Assert(serializationResult != null);
            global::System.Diagnostics.Debug.Assert(diagram != null);
            global::System.Diagnostics.Debug.Assert(!serializationResult.Failed);
            #endregion

            global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream();
            var directory = this.GetDirectory(diagram.Store);
            DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, diagramFileName, serializationResult);
            this.InitializeSerializationContext(diagram.Partition, serializationContext, false);
            // MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.
            serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
            global::System.Xml.XmlWriterSettings settings = EFModelSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, true, encoding);
            var diagramSerializer = GetSerializer(diagram);

            using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
            {
                //this.WriteRootElement(serializationContext, diagram, writer);
                // Carry out the normal serialization.
                this.WriteRootElement(serializationContext, diagramSerializer, diagram, writer);
            }

            return(newFileContent);
        }
コード例 #3
0
        public override void SaveModel(DslModeling::SerializationResult serializationResult, MetaModel modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
        {
            base.SaveModel(serializationResult, modelRoot, fileName, encoding, writeOptionalPropertiesWithDefaultValue);

            System.IO.FileInfo info = new System.IO.FileInfo(fileName);
            string fileNameDiagram = info.DirectoryName + "\\" + info.Name.Remove(info.Name.Length - info.Extension.Length, info.Extension.Length) + DiagramExtension;

            // save view information
            using (global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream())
            {
                DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(modelRoot.Store);

                DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileName, serializationResult);
                this.InitializeSerializationContext(modelRoot.Partition, serializationContext, false);
                // MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.
                serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
                global::System.Xml.XmlWriterSettings settings = LanguageDSLSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
                using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
                {
                    ViewSerializer serializer = directory.GetSerializer(View.DomainClassId) as ViewSerializer;
                    serializer.Write(serializationContext, modelRoot.View, writer);
                }

                if (!serializationResult.Failed && newFileContent != null)
                {	// Only write the content if there's no error encountered during serialization.
                    using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(fileNameDiagram, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None))
                    {
                        using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding))
                        {
                            writer.Write(newFileContent.ToArray());
                        }
                    }
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates and returns the settings used when writing a file.
        /// </summary>
        /// <param name="serializationContext">The current serialization context instance.</param>
        /// <param name="isDiagram">Indicates whether a diagram or model file is currently being serialized.</param>
        /// <param name="encoding">The encoding to use when writing the file.</param>
        internal virtual global::System.Xml.XmlWriterSettings CreateXmlWriterSettings(DslModeling::SerializationContext serializationContext, bool isDiagram, global::System.Text.Encoding encoding)
        {
            global::System.Xml.XmlWriterSettings settings = new global::System.Xml.XmlWriterSettings();
            settings.Indent   = true;
            settings.Encoding = encoding;

            return(settings);
        }
コード例 #5
0
        /// <summary>
        /// Saves the diagram.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <param name="serializationResult">The serialization result.</param>
        /// <param name="modelRoot">The model root.</param>
        /// <param name="modelFileName">Name of the model file.</param>
        /// <param name="diagram">The diagram.</param>
        /// <param name="diagramFileName">Name of the diagram file.</param>
        /// <param name="encoding">The encoding.</param>
        /// <param name="writeOptionalPropertiesWithDefaultValue">if set to <c>true</c> [write optional properties with default value].</param>
        public void SaveDiagram <TModel>(DslModeling::SerializationResult serializationResult, TModel modelRoot, string modelFileName, ComponentModelDiagram diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
            where TModel : ModelElement
        {
            if (serializationResult.Failed)
            {
                return;
            }

            // MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.

            using (global::System.IO.MemoryStream diagramFileContent = new global::System.IO.MemoryStream())
            {
                DslModeling::DomainClassXmlSerializer diagramSerializer = this.Directory.GetSerializer(diagram.GetDomainClass().Id);
                global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for " + diagram.GetDomainClass().Name + "!");
                if (diagramSerializer != null)
                {
                    DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, diagramFileName, serializationResult);
                    serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
                    global::System.Xml.XmlWriterSettings settings = new global::System.Xml.XmlWriterSettings();
                    settings.Indent   = true;
                    settings.Encoding = encoding;
                    using (global::System.IO.StreamWriter streamWriter = new global::System.IO.StreamWriter(diagramFileContent, encoding))
                    {
                        using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(streamWriter, settings))
                        {
                            diagramSerializer.WriteRootElement(serializationContext, diagram, writer);
                        }
                    }
                }
                if (!serializationResult.Failed)
                {       // Only write the contents if there's no error encountered during serialization.
                    if (diagramFileContent != null)
                    {
                        IVsQueryEditQuerySave2 scc = ServiceLocator.Instance.GetService <IVsQueryEditQuerySave2>(typeof(SVsQueryEditQuerySave));
                        if (scc != null)
                        {
                            uint result;
                            if (scc.QuerySaveFile(diagramFileName, 0, null, out result) != (int)tagVSQuerySaveResult.QSR_SaveOK)
                            {
                                return;
                            }
                        }
                        using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(diagramFileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None))
                        {
                            using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding))
                            {
                                writer.Write(diagramFileContent.ToArray());
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
        public string ConvertLayoutInfoToString(LayoutInfo info)
        {
            string result = String.Empty;

            Microsoft.VisualStudio.Modeling.SerializationResult serializationResult = new Microsoft.VisualStudio.Modeling.SerializationResult();
            DomainXmlSerializerDirectory directory = this.GetDirectory(info.Store);

            System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
            Microsoft.VisualStudio.Modeling.SerializationContext serializationContext = new SerializationContext(directory, "", serializationResult);
            this.InitializeSerializationContext(info.Partition, serializationContext, false);

            global::System.IO.MemoryStream       newFileContent = new global::System.IO.MemoryStream();
            global::System.Xml.XmlWriterSettings settings       = DiagramsDSLSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
            using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
            {
                DomainClassXmlSerializer rootSerializer = directory.GetSerializer(LayoutInfo.DomainClassId);

                RootElementSettings rootElementSettings = new RootElementSettings();
                rootElementSettings.SchemaTargetNamespace = "http://schemas.microsoft.com/dsltools/DiagramsDSL";
                rootElementSettings.Version = new global::System.Version("1.0.0.0");

                // Carry out the normal serialization.
                rootSerializer.Write(serializationContext, info, writer, rootElementSettings);
            }

            char[] chars = encoding.GetChars(newFileContent.GetBuffer());

            // search the open angle bracket and trim off the Byte Of Mark.
            result = new string(chars);
            int indexPos = result.IndexOf('<');

            if (indexPos > 0)
            {
                // strip off the leading Byte Of Mark.
                result = result.Substring(indexPos);
            }

            // trim off trailing 0s.
            result = result.TrimEnd('\0');

            return(result);
        }
コード例 #7
0
		/// <summary>
		/// Creates and returns the settings used when writing a file.
		/// </summary>
		/// <param name="serializationContext">The current serialization context instance.</param>
		/// <param name="isDiagram">Indicates whether a diagram or model file is currently being serialized.</param>
		/// <param name="encoding">The encoding to use when writing the file.</param>
		internal virtual global::System.Xml.XmlWriterSettings CreateXmlWriterSettings(DslModeling::SerializationContext serializationContext, bool isDiagram, global::System.Text.Encoding encoding)
		{
			global::System.Xml.XmlWriterSettings settings = new global::System.Xml.XmlWriterSettings();
			settings.Indent = true;
			settings.Encoding = encoding;
	        settings.CheckCharacters = true;

			return settings;
		}
コード例 #8
0
		private global::System.IO.MemoryStream InternalSaveDiagram(DslModeling::SerializationResult serializationResult, AsyncDslDiagram diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			global::System.Diagnostics.Debug.Assert(serializationResult != null);
			global::System.Diagnostics.Debug.Assert(diagram != null);
			global::System.Diagnostics.Debug.Assert(!serializationResult.Failed);
			#endregion
			
			global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream();
			
			DslModeling::DomainClassXmlSerializer diagramSerializer = this.Directory.GetSerializer(diagram.GetDomainClass().Id);
			global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for " + diagram.GetDomainClass().Name + "!");
			if (diagramSerializer != null)
			{
				DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, diagramFileName, serializationResult);
				// MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.
				serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
				global::System.Xml.XmlWriterSettings settings = new global::System.Xml.XmlWriterSettings();
				settings.Indent = true;
				settings.Encoding = encoding;
				using (global::System.IO.StreamWriter streamWriter = new global::System.IO.StreamWriter(newFileContent, encoding))
				{
					using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(streamWriter, settings))
					{
						diagramSerializer.WriteRootElement(serializationContext, diagram, writer);
					}
				}
			}
			return newFileContent;
		}
コード例 #9
0
		public virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, Model modelRoot, string modelFileName, ActiveRecordMapping diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			if (serializationResult == null)
				throw new global::System.ArgumentNullException("serializationResult");
			if (string.IsNullOrEmpty(modelFileName))
				throw new global::System.ArgumentNullException("modelFileName");
			if (diagram == null)
				throw new global::System.ArgumentNullException("diagram");
			if (string.IsNullOrEmpty(diagramFileName))
				throw new global::System.ArgumentNullException("diagramFileName");
			#endregion
	
			if (serializationResult.Failed)
				return;
	
			// Save the model file first
			using (global::System.IO.MemoryStream modelFileContent = this.InternalSaveModel(serializationResult, modelRoot, modelFileName, encoding, writeOptionalPropertiesWithDefaultValue))
			{
				if (serializationResult.Failed)
					return;
	
				using (global::System.IO.MemoryStream diagramFileContent = new global::System.IO.MemoryStream())
				{
					DslModeling::DomainClassXmlSerializer diagramSerializer = this.Directory.GetSerializer(diagram.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for " + diagram.GetDomainClass().Name + "!");
					if (diagramSerializer != null)
					{
						DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, diagramFileName, serializationResult);
						// MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.
						serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
						global::System.Xml.XmlWriterSettings settings = new global::System.Xml.XmlWriterSettings();
						settings.Indent = true;
						settings.Encoding = encoding;
						using (global::System.IO.StreamWriter streamWriter = new global::System.IO.StreamWriter(diagramFileContent, encoding))
						{
							using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(streamWriter, settings))
							{
								diagramSerializer.WriteRootElement(serializationContext, diagram, writer);
							}
						}
					}
					if (!serializationResult.Failed)
					{	// Only write the contents if there's no error encountered during serialization.
						if (modelFileContent != null)
						{
							using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(modelFileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None))
							{
								using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding))
								{
									writer.Write(modelFileContent.ToArray());
								}
							}
						}
						if (diagramFileContent != null)
						{
							using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(diagramFileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None))
							{
								using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding))
								{
									writer.Write(diagramFileContent.ToArray());
								}
							}
						}
					}
				}
			}
		}