ATMLModelLibrary.model.common.TestConfiguration15.Serialize C# (CSharp) Method

Serialize() public method

Serializes current TestConfiguration15 object into an XML string
public Serialize ( ) : string
return string
        public virtual string Serialize()
        {
            System.IO.StreamReader streamReader = null;
            System.IO.MemoryStream memoryStream = null;
            try
            {
                memoryStream = new System.IO.MemoryStream();
                Serializer.Serialize(memoryStream, this);
                memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                streamReader = new System.IO.StreamReader(memoryStream);
                return streamReader.ReadToEnd();
            }
            finally
            {
                if ((streamReader != null))
                {
                    streamReader.Dispose();
                }
                if ((memoryStream != null))
                {
                    memoryStream.Dispose();
                }
            }
        }

Usage Example

        public static void CreateProject( ProjectInfo projectInfo )
        {
            //--- Prompt for a test set name ---//
            //--- Check if the name exisists ---//
            //--- If name exists then notify the user, ask if they want to open that test set ---//
            //--- Otherwise create the test set and open it ---//
            if (projectInfo != null)
            {
                TestProgramSet currentTestProgramSet = TestProgramSet.CreateTestSet( projectInfo.ProjectName );
                if (currentTestProgramSet != null)
                {
                    SaveProjectInfo( projectInfo, currentTestProgramSet );
                    OpenProject( projectInfo.ProjectName );
                    Document uutDescriptionDocument = DocumentManager.GetDocument( projectInfo.UutId );
                    if (uutDescriptionDocument != null)
                    {
                        SaveATMLDocument( UutManager.BuildAtmlFileName( projectInfo.UutName ),
                                          AtmlFileType.AtmlTypeUut,
                                          uutDescriptionDocument.DocumentContent );
                    }

                    //--- Create a Test Description ---//
                    if (uutDescriptionDocument != null)
                    {
                        var uutDoc = new DocumentReference();
                        uutDoc.ID = "UUT1";
                        uutDoc.uuid = uutDescriptionDocument.uuid;
                        var uutRef = new ItemDescriptionReference();
                        uutRef.Item = uutDoc;
                        var testConfiguration = new TestConfiguration15();
                        testConfiguration.uuid = Guid.NewGuid().ToString();
                        testConfiguration.TestedUUTs.Add( uutRef );
                        SaveATMLDocument( projectInfo.ProjectName + ATMLContext.ATML_CONFIG_FILENAME_SUFFIX,
                                          AtmlFileType.AtmlTypeTestConfiguration,
                                          Encoding.UTF8.GetBytes( testConfiguration.Serialize() ) );
                    }
                }
            }
        }