internal static SharingMessage GetSharingMessage(MessageItem item)
        {
            StreamAttachment sharingMessageAttachment = SharingMessageAttachment.GetSharingMessageAttachment(item);

            if (sharingMessageAttachment != null)
            {
                using (sharingMessageAttachment)
                {
                    using (Stream stream = sharingMessageAttachment.TryGetContentStream(PropertyOpenMode.ReadOnly))
                    {
                        SharingMessage sharingMessage = null;
                        try
                        {
                            sharingMessage = SharingMessage.DeserializeFromStream(stream);
                        }
                        catch (InvalidOperationException)
                        {
                        }
                        if (sharingMessage != null)
                        {
                            ValidationResults validationResults = sharingMessage.Validate();
                            if (validationResults.Result == ValidationResult.Success)
                            {
                                return(sharingMessage);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
 public Stream GetPhotoStream()
 {
     foreach (AttachmentHandle handle in base.AttachmentCollection)
     {
         using (Attachment attachment = base.AttachmentCollection.Open(handle, null))
         {
             if (attachment.IsContactPhoto)
             {
                 StreamAttachment streamAttachment = attachment as StreamAttachment;
                 if (streamAttachment != null)
                 {
                     return(streamAttachment.TryGetContentStream(PropertyOpenMode.ReadOnly));
                 }
             }
         }
     }
     return(null);
 }
Exemplo n.º 3
0
 public override void Export(ContactWriter writer, Contact contact, OutboundVCardConverter.PropertyExporter.Context context)
 {
     foreach (AttachmentHandle handle in contact.AttachmentCollection)
     {
         using (Attachment attachment = contact.AttachmentCollection.Open(handle, null))
         {
             if (attachment.IsContactPhoto)
             {
                 StreamAttachment streamAttachment = attachment as StreamAttachment;
                 if (streamAttachment != null)
                 {
                     string text = streamAttachment.ContentType;
                     if (string.IsNullOrEmpty(text))
                     {
                         text = streamAttachment.CalculatedContentType;
                     }
                     string value = null;
                     if (!string.IsNullOrEmpty(text) && OutboundVCardConverter.PhotoExporter.contentTypeToType.TryGetValue(text, out value))
                     {
                         using (Stream stream = streamAttachment.TryGetContentStream(PropertyOpenMode.ReadOnly))
                         {
                             if (stream != null)
                             {
                                 writer.StartProperty(PropertyId.Photo);
                                 writer.WriteParameter(ParameterId.Type, value);
                                 writer.WriteParameter(ParameterId.Encoding, "B");
                                 using (Stream stream2 = new EncoderStream(stream, new Base64Encoder(0), EncoderStreamAccess.Read))
                                 {
                                     writer.WritePropertyValue(stream2);
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }