ATMLModelLibrary.model.uut.UUTDescription.Serialize C# (CSharp) Méthode

Serialize() public méthode

Serializes current UUTDescription object into an XML string
public Serialize ( ) : string
Résultat 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 Save(UUTDescription uut)
 {
     string uuid;
     if (uut != null)
     {
         string model = uut.Item.Identification.ModelName;
         string documentName = BuildAtmlFileName(model);
         uuid = uut.uuid;
         Document document = DocumentManager.GetDocument(uuid);
         if (document != null)
         {
             document.DocumentContent = Encoding.UTF8.GetBytes(uut.Serialize());
             document.DataState = BASEBean.eDataState.DS_EDIT;
             document.name = documentName;
             DocumentManager.SaveDocument(document);
         }
         else
         {
             AssetIdentificationBean bean = new AssetIdentificationBean();
             document = new Document();
             document.name = documentName;
             document.DocumentContent = Encoding.UTF8.GetBytes(uut.Serialize());
             document.DocumentType = dbDocument.DocumentType.UUT_DESCRIPTION;
             document.ContentType = "text/xml";
             DocumentManager.SaveDocument(document);
             bean.assetNumber = model;
             bean.assetType = "Part";
             bean.uuid = Guid.Parse(uuid);
             bean.DataState = BASEBean.eDataState.DS_ADD;
             bean.save();
         }
     }
 }