Galen.Ci.EntityFramework.Configuration.DeploymentConfigurationXmlStore.Save C# (CSharp) Method

Save() public method

public Save ( DeploymentConfiguration configuration ) : void
configuration DeploymentConfiguration
return void
        public void Save(DeploymentConfiguration configuration)
        {
            Stream stream = null;

            try
            {
                stream = m_Stream ?? new FileStream(m_FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
                var serializer = new System.Xml.Serialization.XmlSerializer(typeof (DeploymentConfiguration));
                serializer.Serialize(stream, configuration);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Unable to save deployment configuration XML to path {filePath}", m_FilePath);
                throw;
            }
            finally
            {
                if (m_Stream == null && stream != null) //We own the stream
                    stream.Dispose();
            }
        }
    }

Usage Example

		public void SerializationShouldGenerateCorrectXml()
		{
			string expectedXml =
				ResourceHelper.ReadString(
					"Galen.Ci.EntityFramework.Deployer.Tests.Data.SerializationShouldGenerateCorrectXml_Expected.xml");

			string actualXml;

			var config = new DeploymentConfiguration()
			{
				MigrationConfigurationInfo = new MigrationConfigurationInfo
				{
					Type = "Galen.Enterprise.Data.Migrations.SomeContext.Configuration"
				},

				InitializerConfigurationInfo=new InitializerConfigurationInfo
				{
					Type = "Galen.Enterprise.Data.Initializers.SomeContextCreateDatabaseIfNotExists",
					ServiceAccount = new ServiceAccountInfo()
					{
						Name = "SomeWindowsAccountName",
						Domain = "SomeDomainName",
						DatabaseUser = "******",
						AccountType = "Windows"
					}
				}
			};

			using (var memoryStream = new MemoryStream())
			{
				var sut = new DeploymentConfigurationXmlStore(memoryStream);
				sut.Save(config);

				memoryStream.Position=0;
				using (var sr = new StreamReader(memoryStream))
				{
					actualXml=sr.ReadToEnd();
				}
			}

			Assert.AreEqual(expectedXml, actualXml);
		}
DeploymentConfigurationXmlStore