Пример #1
0
        /// <summary>
        /// Save options.
        /// </summary>
        /// <param name="filePath">File name to save options to.</param>
        public void Serialize(string filePath)
        {
            System.Text.Encoding           encoding       = System.Text.Encoding.GetEncoding("ISO-8859-1");
            global::System.IO.MemoryStream newFileContent = null;
            try
            {
                newFileContent = new global::System.IO.MemoryStream();
                global::System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(newFileContent, encoding);
                xmlWriter.Formatting = System.Xml.Formatting.Indented;
                xmlWriter.WriteStartDocument();
                xmlWriter.WriteStartElement("ViewModelOptions");

                // write attributes
                xmlWriter.WriteAttributeString("errorCategoryVisible", this.ErrorCategoryVisible.ToString());
                xmlWriter.WriteAttributeString("warningCategoryVisible", this.WarningCategoryVisible.ToString());
                xmlWriter.WriteAttributeString("infoCategoryVisible", this.InfoCategoryVisible.ToString());
                xmlWriter.WriteAttributeString("filteredCategoryVisible", this.FilteredCategoryVisible.ToString());

                SerializeElements(xmlWriter);
                xmlWriter.WriteEndElement();

                xmlWriter.Flush();
                if (newFileContent != null)
                {
                    // Only write the content if there's no error encountered during serialization.
                    global::System.IO.FileStream fileStream = null;
                    try
                    {
                        fileStream = new global::System.IO.FileStream(filePath, 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))
                        {
                            try
                            {
                                writer.Write(newFileContent.ToArray());
                            }
                            finally
                            {
                                fileStream = null;
                            }
                        }
                    }
                    finally
                    {
                        if (fileStream != null)
                        {
                            fileStream.Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (newFileContent != null)
                {
                    newFileContent.Dispose();
                }
            }
        }
        public virtual void TemporarlySaveModelVModell(DslModeling::SerializationResult serializationResult, global::Tum.VModellXT.VModell modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
        {
            #region Check Parameters
            if (serializationResult == null)
                throw new global::System.ArgumentNullException("serializationResult");
            if (modelRoot == null)
                throw new global::System.ArgumentNullException("modelRoot");
            if (string.IsNullOrEmpty(fileName))
                throw new global::System.ArgumentNullException("fileName");
            #endregion

            if (serializationResult.Failed)
                return;

            //DslEditorModeling::DomainModelStore dStore = (DslEditorModeling::DomainModelStore)modelRoot.Store;
            //if( dStore == null)
            //    throw new global::System.ArgumentNullException("dStore");
				
			//dStore.WaitForWritingLockRelease();

			global::System.IO.MemoryStream newFileContent = null;
            try 
            {
				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);
                serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
                global::System.Xml.XmlWriterSettings settings = VModellXTSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
                
				global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings);
               	DslEditorModeling::SerializationOptions options = new DslEditorModeling.SerializationOptions();
              	options.SerializationMode = DslEditorModeling.SerializationMode.Temporarly;
              	this.WriteRootElementVModell(serializationContext, modelRoot, writer, options);
				
				writer.Flush();

                if (!serializationResult.Failed && newFileContent != null)
                {	// Only write the content if there's no error encountered during serialization.
					global::System.IO.FileStream fileStream = null;
                    try
                    {
						fileStream = new global::System.IO.FileStream(fileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None);
                        using (global::System.IO.BinaryWriter writerBin = new global::System.IO.BinaryWriter(fileStream, encoding))
                        {
							try
							{
                            	writerBin.Write(newFileContent.ToArray());
								fileStream.Dispose();
							}
							finally
							{
								fileStream = null;
							}							
                        }
                    }
					finally
					{
						if( fileStream != null )
							fileStream.Dispose();
					}
                }
            }
			finally
			{
				if( newFileContent != null )
					newFileContent.Dispose();
			}
        }
Пример #3
0
        /// <summary>
        /// Load options.
        /// </summary>
        /// <param name="filePath">File name to load options from.</param>
        private void DoDeserialize(string filePath)
        {
            if (System.IO.File.Exists(filePath))
            {
                global::System.IO.FileStream fileStream = null;
                try
                {
                    fileStream = global::System.IO.File.OpenRead(filePath);
                    if (fileStream.Length > 5)
                    {
                        using (global::System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(fileStream))
                        {
                            try
                            {
                                reader.MoveToContent();

                                // read attributes
                                string valueE = reader.GetAttribute("errorCategoryVisible");
                                if (valueE != null)
                                {
                                    this.ErrorCategoryVisible = Boolean.Parse(valueE);
                                }

                                string valueW = reader.GetAttribute("warningCategoryVisible");
                                if (valueW != null)
                                {
                                    this.WarningCategoryVisible = Boolean.Parse(valueW);
                                }

                                string valueI = reader.GetAttribute("infoCategoryVisible");
                                if (valueI != null)
                                {
                                    this.InfoCategoryVisible = Boolean.Parse(valueI);
                                }

                                string valueF = reader.GetAttribute("filteredCategoryVisible");
                                if (valueF != null)
                                {
                                    this.FilteredCategoryVisible = Boolean.Parse(valueF);
                                }

                                while (reader.Read())
                                {
                                    switch (reader.NodeType)
                                    {
                                    case System.Xml.XmlNodeType.Element:
                                    {
                                        DeserializeElement(reader, reader.Name);
                                        break;
                                    }
                                    }
                                }
                            }
                            finally
                            {
                                fileStream = null;
                            }
                        }
                    }
                }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Dispose();
                    }
                }
            }
        }
        /// <summary>
        /// Save options.
        /// </summary>
        /// <param name="filePath">File name to save options to.</param>
        public void Serialize(string filePath)
        {
            System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
            global::System.IO.MemoryStream newFileContent = null;
            try
            {
                newFileContent = new global::System.IO.MemoryStream();
                global::System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(newFileContent, encoding);
                xmlWriter.Formatting = System.Xml.Formatting.Indented;
                xmlWriter.WriteStartDocument();
                xmlWriter.WriteStartElement("ViewModelOptions");

                // write attributes
                xmlWriter.WriteAttributeString("errorCategoryVisible", this.ErrorCategoryVisible.ToString());
                xmlWriter.WriteAttributeString("warningCategoryVisible", this.WarningCategoryVisible.ToString());
                xmlWriter.WriteAttributeString("infoCategoryVisible", this.InfoCategoryVisible.ToString());
                xmlWriter.WriteAttributeString("filteredCategoryVisible", this.FilteredCategoryVisible.ToString());

                SerializeElements(xmlWriter);
                xmlWriter.WriteEndElement();

                xmlWriter.Flush();
                if (newFileContent != null)
                {
                    // Only write the content if there's no error encountered during serialization.
                    global::System.IO.FileStream fileStream = null;
                    try
                    {
                        fileStream = new global::System.IO.FileStream(filePath, 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))
                        {
                            try
                            {
                                writer.Write(newFileContent.ToArray());
                            }
                            finally
                            {
                                fileStream = null;
                            }
                        }
                    }
                    finally
                    {
                        if (fileStream != null)
                            fileStream.Dispose();
                    }
                }
            }
            finally
            {
                if (newFileContent != null)
                    newFileContent.Dispose();
            }
        }