/// <summary>
 /// 通过密钥对文本进行加密
 /// </summary>
 /// <param name="str"></param>
 /// <param name="SecretKey">密钥</param>
 /// <param name="SingleLine">True:单行;False:所有</param>
 /// <param name="Standard">是否使用标准方式</param>
 /// <returns>加密后的文本</returns>
 public static string Encrypt(this string str, string SecretKey, bool SingleLine = true, bool Standard = false)
 {
     DESCryptoServiceProvider des = new DESCryptoServiceProvider();
     if (Standard)
     {
         des.Mode = CipherMode.ECB;
         des.Padding = PaddingMode.Zeros;
     }
     des.Key = SecretKey.ToMD5().Substring(0, 0x08).ToBytes();
     des.IV = SecretKey.ToMD5().Substring(0, 0x08).ToBytes();
     global::System.IO.MemoryStream ms = new global::System.IO.MemoryStream();
     CryptoStream encStream = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
     global::System.IO.StreamWriter sw = new global::System.IO.StreamWriter(encStream);
     if (SingleLine)
         sw.WriteLine(str);
     else
         sw.Write(str);
     sw.Close();
     encStream.Close();
     byte[] buffer = ms.ToArray();
     ms.Close();
     StringBuilder hash = new StringBuilder();
     foreach (byte b in buffer.ToArray())
     {
         hash.AppendFormat("{0:X2}", b);
     }
     return hash.ToString();
 }
        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());
                        }
                    }
                }
            }
        }
Beispiel #3
0
 private void method_2(string string_0, global::System.IO.MemoryStream memoryStream_0, global::System.IO.MemoryStream memoryStream_1)
 {
     using (global::System.IO.BinaryWriter binaryWriter = new global::System.IO.BinaryWriter(global::System.IO.File.Open(string_0, global::System.IO.FileMode.Create)))
     {
         binaryWriter.Write(memoryStream_0.ToArray());
         binaryWriter.Write(memoryStream_1.ToArray());
     }
 }
Beispiel #4
0
 public static void WriteFile(global::System.IO.MemoryStream stream, string filename)
 {
     using (global::System.IO.BinaryWriter binaryWriter = new global::System.IO.BinaryWriter(global::System.IO.File.Open(filename, global::System.IO.FileMode.Create)))
     {
         byte[] buffer = stream.ToArray();
         binaryWriter.Write(buffer);
     }
 }
Beispiel #5
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();
                }
            }
        }
        static public string ParameterToString <T>(T trg)
        {
            global::System.IO.MemoryStream ms = new global::System.IO.MemoryStream();

            WriteToStream(trg, new global::System.IO.StreamWriter(ms));

            byte[] buf       = ms.ToArray();
            string paramsstr = global::System.Text.Encoding.UTF8.GetString(buf);

            return(paramsstr);
        }
        /// <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());
                            }
                        }
                    }
                }
            }
        }
Beispiel #8
0
        // Token: 0x060004F0 RID: 1264 RVA: 0x00019538 File Offset: 0x00017738
        public string SaveToBase64()
        {
            string result;

            using (global::System.IO.MemoryStream memoryStream = new global::System.IO.MemoryStream())
            {
                this.SaveToStream(memoryStream);
                memoryStream.Position = 0L;
                result = global::System.Convert.ToBase64String(memoryStream.ToArray());
            }
            return(result);
        }
Beispiel #9
0
 private byte[] method_1(LanguageEntry languageEntry_0)
 {
     global::System.IO.MemoryStream memoryStream = new global::System.IO.MemoryStream();
     memoryStream.WriteByte(0);
     this.class47_0.method_10(513, memoryStream);
     this.class47_0.method_12(languageEntry_0.Name, memoryStream);
     this.class47_0.method_10(languageEntry_0.Messages.Count, memoryStream);
     foreach (MessageEntry messageEntry in languageEntry_0.Messages)
     {
         this.class47_0.method_12(messageEntry.Message, memoryStream);
     }
     return(memoryStream.ToArray());
 }
Beispiel #10
0
 private byte[] method_0(LanguagesContainer languagesContainer_0)
 {
     global::System.IO.MemoryStream memoryStream  = new global::System.IO.MemoryStream();
     global::System.IO.MemoryStream memoryStream2 = new global::System.IO.MemoryStream();
     foreach (LanguageEntry languageEntry in languagesContainer_0.Languages.Values)
     {
         byte[] array = this.method_1(languageEntry);
         this.class47_0.method_12(languageEntry.Name, memoryStream);
         this.class47_0.method_10(array.Length, memoryStream);
         memoryStream2.Write(array, 0, array.Length);
     }
     global::System.IO.MemoryStream memoryStream3 = new global::System.IO.MemoryStream();
     byte[] array2 = memoryStream.ToArray();
     memoryStream3.Write(array2, 0, array2.Length);
     array2 = memoryStream2.ToArray();
     memoryStream3.Write(array2, 0, array2.Length);
     return(memoryStream3.ToArray());
 }
        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();
			}
        }
		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());
								}
							}
						}
					}
				}
			}
		}
		internal virtual void SaveModel(DslModeling::SerializationResult serializationResult, ProductState 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;
	
			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 = ProductStateStoreSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
				using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
				{
					this.WriteRootElement(serializationContext, modelRoot, 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(fileName, 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());
						}
					}
				}
			}
		}
        /// <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();
            }
        }