Exemplo n.º 1
0
        public static OutboundPhotoAttachment CreateForUploadNewPhoto(Stream stream, long userOrGroupId = 0, bool isGroup = false, Stream previewStream = null, PostType postType = PostType.WallPost)
        {
            OutboundPhotoAttachment outboundPhotoAttachment = new OutboundPhotoAttachment();

            outboundPhotoAttachment._userOrGroupId = userOrGroupId;
            outboundPhotoAttachment._isGroup       = isGroup;
            outboundPhotoAttachment.UploadState    = OutboundAttachmentUploadState.NotStarted;
            outboundPhotoAttachment._postType      = postType;
            outboundPhotoAttachment._isForUpload   = true;
            Guid guid = Guid.NewGuid();

            outboundPhotoAttachment._localUri = string.Concat("/", guid.ToString());
            if (!ImageCache.Current.TrySetImageForUri(outboundPhotoAttachment.LocalUrlBig, stream))
            {
                stream.Close();
                previewStream.Close();
                throw new Exception("Failed to save local attachment");
            }
            if (previewStream != null)
            {
                if (!ImageCache.Current.TrySetImageForUri(outboundPhotoAttachment._localUri, previewStream))
                {
                    previewStream.Close();
                    throw new Exception("Failed to save local attachment");
                }
                previewStream.Close();
            }
            else
            {
                stream.Position = 0L;
                ImageCache.Current.TrySetImageForUri(outboundPhotoAttachment._localUri, stream);
            }
            stream.Close();
            return(outboundPhotoAttachment);
        }
Exemplo n.º 2
0
 private void UploadToImpl(Action <byte[], Action <BackendResult <Photo, ResultCode> >, Action <double>, Cancellation> uploadAction, byte[] bytes, Action completionCallback, Action <double> progressCallback)
 {
     this._c             = new Cancellation();
     this.UploadProgress = 0.0;
     uploadAction.Invoke(bytes, (Action <BackendResult <Photo, ResultCode> >)(res =>
     {
         if (res.ResultCode == ResultCode.Succeeded)
         {
             Photo resultData          = res.ResultData;
             this._attachmentId        = OutboundPhotoAttachment.ComposeAttachmentId(resultData.owner_id, resultData.pid, resultData.access_key);
             this._photo               = res.ResultData;
             MemoryStream memoryStream = new MemoryStream(bytes);
             ImageCache.Current.TrySetImageForUri(this._localUri, (Stream)memoryStream);
             memoryStream.Close();
             this.UploadState = OutboundAttachmentUploadState.Completed;
             completionCallback.Invoke();
         }
         else
         {
             Logger.Instance.Info("!!!!!!!!!!!!FAILED TO UPLOAD", new object[0]);
             this.UploadState = OutboundAttachmentUploadState.Failed;
             if (this._retryFlag)
             {
                 this._retryFlag = false;
                 this.Upload(completionCallback, null);
             }
             else
             {
                 completionCallback.Invoke();
             }
         }
     }), (Action <double>)(progress =>
     {
         this.UploadProgress = progress;
         if (progressCallback == null)
         {
             return;
         }
         progressCallback(progress);
     }), this._c);
 }
Exemplo n.º 3
0
        public static OutboundPhotoAttachment CreateForChoosingExistingPhoto(Photo photo, long userOrGroupId = 0, bool isGroup = false, PostType postType = PostType.WallPost)
        {
            OutboundPhotoAttachment outboundPhotoAttachment = new OutboundPhotoAttachment();

            outboundPhotoAttachment._userOrGroupId = userOrGroupId;
            outboundPhotoAttachment._isGroup       = isGroup;
            string str = OutboundPhotoAttachment.ComposeAttachmentId(photo.owner_id, photo.pid, photo.access_key);

            outboundPhotoAttachment._attachmentId = str;
            string srcBig = photo.src_big;

            outboundPhotoAttachment._localUri = srcBig;
            int num1 = 3;

            outboundPhotoAttachment.UploadState = (OutboundAttachmentUploadState)num1;
            int num2 = (int)postType;

            outboundPhotoAttachment._postType = (PostType)num2;
            Photo photo1 = photo;

            outboundPhotoAttachment._photo = photo1;
            return(outboundPhotoAttachment);
        }
Exemplo n.º 4
0
 public OutboundAttachmentContainer(IOutboundAttachment outboundAttachment)
 {
     this._outboundAttachment = outboundAttachment;
     if (outboundAttachment is OutboundPhotoAttachment)
     {
         this._photoAttachment = outboundAttachment as OutboundPhotoAttachment;
     }
     else if (outboundAttachment is OutboundGeoAttachment)
     {
         this._geoAttachment = outboundAttachment as OutboundGeoAttachment;
     }
     else if (outboundAttachment is OutboundVideoAttachment)
     {
         this._videoAttachment = outboundAttachment as OutboundVideoAttachment;
     }
     else if (outboundAttachment is OutboundAudioAttachment)
     {
         this._audioAttachment = outboundAttachment as OutboundAudioAttachment;
     }
     else if (outboundAttachment is OutboundDocumentAttachment)
     {
         this._documentAttachment = outboundAttachment as OutboundDocumentAttachment;
     }
     else if (outboundAttachment is OutboundUploadVideoAttachment)
     {
         this._uploadVideoAttachment = outboundAttachment as OutboundUploadVideoAttachment;
     }
     else if (outboundAttachment is OutboundWallPostAttachment)
     {
         this._wallPostAttachment = outboundAttachment as OutboundWallPostAttachment;
     }
     else if (outboundAttachment is OutboundForwardedMessages)
     {
         this._forwardedMessages = outboundAttachment as OutboundForwardedMessages;
     }
     else if (outboundAttachment is OutboundUploadDocumentAttachment)
     {
         this._uploadDocumentAttachment = outboundAttachment as OutboundUploadDocumentAttachment;
     }
     else if (outboundAttachment is OutboundPollAttachment)
     {
         this._pollAttachment = outboundAttachment as OutboundPollAttachment;
     }
     else if (outboundAttachment is OutboundTimerAttachment)
     {
         this._timerAttachment = outboundAttachment as OutboundTimerAttachment;
     }
     else if (outboundAttachment is OutboundLinkAttachment)
     {
         this._linkAttachment = outboundAttachment as OutboundLinkAttachment;
     }
     else if (outboundAttachment is OutboundProductAttachment)
     {
         this._productAttachment = outboundAttachment as OutboundProductAttachment;
     }
     else if (outboundAttachment is OutboundNoteAttachment)
     {
         this._noteAttachment = outboundAttachment as OutboundNoteAttachment;
     }
     else if (outboundAttachment is OutboundMarketAlbumAttachment)
     {
         this._marketAlbumAttachment = outboundAttachment as OutboundMarketAlbumAttachment;
     }
     else
     {
         if (!(outboundAttachment is OutboundAlbumAttachment))
         {
             throw new Exception("Unknown attachment type");
         }
         this._albumAttachment = outboundAttachment as OutboundAlbumAttachment;
     }
 }
Exemplo n.º 5
0
        public void Read(BinaryReader reader)
        {
            int num1 = reader.ReadInt32();

            this._photoAttachment = reader.ReadGeneric <OutboundPhotoAttachment>();
            if (this._photoAttachment != null)
            {
                this._outboundAttachment = (IOutboundAttachment)this._photoAttachment;
            }
            this._geoAttachment = reader.ReadGeneric <OutboundGeoAttachment>();
            if (this._geoAttachment != null)
            {
                this._outboundAttachment = (IOutboundAttachment)this._geoAttachment;
            }
            this._videoAttachment = reader.ReadGeneric <OutboundVideoAttachment>();
            if (this._videoAttachment != null)
            {
                this._outboundAttachment = (IOutboundAttachment)this._videoAttachment;
            }
            this._audioAttachment = reader.ReadGeneric <OutboundAudioAttachment>();
            if (this._audioAttachment != null)
            {
                this._outboundAttachment = (IOutboundAttachment)this._audioAttachment;
            }
            this._documentAttachment = reader.ReadGeneric <OutboundDocumentAttachment>();
            if (this._documentAttachment != null)
            {
                this._outboundAttachment = (IOutboundAttachment)this._documentAttachment;
            }
            int num2 = 2;

            if (num1 >= num2)
            {
                this._uploadVideoAttachment = reader.ReadGeneric <OutboundUploadVideoAttachment>();
                if (this._uploadVideoAttachment != null)
                {
                    this._outboundAttachment = (IOutboundAttachment)this._uploadVideoAttachment;
                }
            }
            int num3 = 3;

            if (num1 >= num3)
            {
                this._wallPostAttachment = reader.ReadGeneric <OutboundWallPostAttachment>();
                if (this._wallPostAttachment != null)
                {
                    this._outboundAttachment = (IOutboundAttachment)this._wallPostAttachment;
                }
                this._forwardedMessages = reader.ReadGeneric <OutboundForwardedMessages>();
                if (this._forwardedMessages != null)
                {
                    this._outboundAttachment = (IOutboundAttachment)this._forwardedMessages;
                }
            }
            int num4 = 4;

            if (num1 >= num4)
            {
                this._uploadDocumentAttachment = reader.ReadGeneric <OutboundUploadDocumentAttachment>();
                if (this._uploadDocumentAttachment != null)
                {
                    this._outboundAttachment = (IOutboundAttachment)this._uploadDocumentAttachment;
                }
                this._pollAttachment = reader.ReadGeneric <OutboundPollAttachment>();
                if (this._pollAttachment != null)
                {
                    this._outboundAttachment = (IOutboundAttachment)this._pollAttachment;
                }
                this._timerAttachment = reader.ReadGeneric <OutboundTimerAttachment>();
                if (this._timerAttachment != null)
                {
                    this._outboundAttachment = (IOutboundAttachment)this._timerAttachment;
                }
            }
            int num5 = 5;

            if (num1 >= num5)
            {
                this._linkAttachment = reader.ReadGeneric <OutboundLinkAttachment>();
                if (this._linkAttachment != null)
                {
                    this._outboundAttachment = (IOutboundAttachment)this._linkAttachment;
                }
            }
            int num6 = 6;

            if (num1 >= num6)
            {
                this._productAttachment = reader.ReadGeneric <OutboundProductAttachment>();
                if (this._productAttachment != null)
                {
                    this._outboundAttachment = (IOutboundAttachment)this._productAttachment;
                }
            }
            int num7 = 7;

            if (num1 >= num7)
            {
                this._noteAttachment = reader.ReadGeneric <OutboundNoteAttachment>();
                if (this._noteAttachment != null)
                {
                    this._outboundAttachment = (IOutboundAttachment)this._noteAttachment;
                }
            }
            int num8 = 8;

            if (num1 >= num8)
            {
                this._marketAlbumAttachment = reader.ReadGeneric <OutboundMarketAlbumAttachment>();
                if (this._marketAlbumAttachment != null)
                {
                    this._outboundAttachment = (IOutboundAttachment)this._marketAlbumAttachment;
                }
                this._albumAttachment = reader.ReadGeneric <OutboundAlbumAttachment>();
                if (this._albumAttachment != null)
                {
                    this._outboundAttachment = (IOutboundAttachment)this._albumAttachment;
                }
            }
            if (this._outboundAttachment == null)
            {
                throw new Exception("Outbound Attachment is NULL");
            }
        }