Пример #1
0
 public ApplicationDataAdapter(ApplicationData applicationDataObject)
 {
     ApplicationDataAdapter.AssertNotNull(applicationDataObject, "applicationDataObject");
     this._applicationData      = applicationDataObject;
     this._typedApplicationData = null;
     this._isTyped = false;
 }
Пример #2
0
 public ApplicationDataAdapter(string applicationId, object typedApplicationData)
 {
     ApplicationDataAdapter.AssertNotNull(applicationId, "applicationId");
     this._applicationData = new ApplicationData
     {
         ApplicationId = applicationId
     };
     this._typedApplicationData = typedApplicationData;
     this._isTyped = true;
 }
Пример #3
0
 private void Serialize()
 {
     if (this._typedApplicationData == null)
     {
         this._applicationData.Data   = new byte[0];
         this._applicationData.TypeId = string.Empty;
         return;
     }
     if (ApplicationDataAdapter.HasAttribute(this._typedApplicationData, typeof(DataContractAttribute)))
     {
         DataContractSerializer dataContractSerializer = new DataContractSerializer(this._typedApplicationData.GetType());
         using (MemoryStream memoryStream = new MemoryStream())
         {
             using (XmlDictionaryWriter xmlDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(memoryStream))
             {
                 dataContractSerializer.WriteObject(xmlDictionaryWriter, this._typedApplicationData);
             }
             this._applicationData.Data = memoryStream.ToArray();
         }
         this._applicationData.TypeId = ApplicationDataAdapter.BuildTypeIdForDataContract(this._typedApplicationData);
         return;
     }
     if (ApplicationDataAdapter.HasAttribute(this._typedApplicationData, typeof(SerializableAttribute)))
     {
         using (MemoryStream memoryStream2 = new MemoryStream())
         {
             ((IFormatter) new BinaryFormatter()).Serialize(memoryStream2, this._typedApplicationData);
             this._applicationData.Data = memoryStream2.ToArray();
         }
         this._applicationData.TypeId = ApplicationDataAdapter.BuildTypeIdForSerializable(this._typedApplicationData);
         return;
     }
     if (this._typedApplicationData is XmlElement)
     {
         XmlElement xmlElement = (XmlElement)this._typedApplicationData;
         this._applicationData.Data   = Encoding.UTF8.GetBytes(xmlElement.OuterXml);
         this._applicationData.TypeId = ApplicationDataAdapter.BuildTypeIdForXmlElement(xmlElement);
         return;
     }
     throw new NotSupportedException(string.Format("The conversion of '{0}' type is not supported. The type must be one of: WCF data contract, XmlElement, serializable", this._typedApplicationData.GetType().Name));
 }