private void UploadPhotoInternal(IList <TLMessage> messages) { for (var i = 0; i < messages.Count; i++) { var message = messages[i]; var fileId = TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; UploadFileManager.UploadFile(fileId, message, message.Media.File); } }
private void SendPhotoInternal(IList <TLMessage> messages) { //if (messages.Count == 3) //{ // SendPhotoInternal((TLMessage25)messages[1]); // SendPhotoInternal((TLMessage25)messages[0]); // SendPhotoInternal((TLMessage25)messages[2]); //} //else { for (var i = 0; i < messages.Count; i++) { var message = messages[i]; //var photo = ((TLMessageMediaPhoto)message.Media).Photo as TLPhoto; //if (photo == null) return; //var photoSize = photo.Sizes[0] as TLPhotoSize; //if (photoSize == null) return; //var fileLocation = photoSize.Location; //if (fileLocation == null) return; //byte[] bytes = null; //var fileName = String.Format("{0}_{1}_{2}.jpg", // fileLocation.VolumeId, // fileLocation.LocalId, // fileLocation.Secret); //using (var store = IsolatedStorageFile.GetUserStoreForApplication()) //{ // using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read)) // { // if (fileStream.Length > 0) // { // bytes = new byte[fileStream.Length]; // fileStream.Read(bytes, 0, bytes.Length); // } // } //} //if (bytes == null) return; var fileId = TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; UploadFileManager.UploadFile(fileId, message, message.Media.File); //SendPhotoInternal((TLMessage25)messages[i]); } } }
private void SendAudioInternal(TLObject obj) { var message = GetDecryptedMessage(obj); if (message == null) { return; } var media = message.Media as TLDecryptedMessageMediaAudio; if (media == null) { return; } var fileLocation = media.File as TLEncryptedFile; if (fileLocation == null) { return; } var fileName = String.Format("audio{0}_{1}.mp3", fileLocation.Id, fileLocation.AccessHash); byte[] data; using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read)) { data = new byte[fileStream.Length]; fileStream.Read(data, 0, data.Length); } } var encryptedBytes = Telegram.Api.Helpers.Utils.AesIge(data, media.Key.Data, media.IV.Data, true); using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var file = storage.OpenFile("encrypted." + fileName, FileMode.Create, FileAccess.Write)) { file.Write(encryptedBytes, 0, encryptedBytes.Length); } } UploadFileManager.UploadFile(fileLocation.Id, obj, encryptedBytes); }
private void UploadPhotoInternal(byte[] data, TLObject obj) { var message = GetDecryptedMessage(obj); if (message == null) { return; } var media = message.Media as TLDecryptedMessageMediaPhoto; if (media == null) { return; } var file = media.File as TLEncryptedFile; if (file == null) { return; } if (data == null) { var fileName = String.Format("{0}_{1}_{2}.jpg", file.Id, file.DCId, file.AccessHash); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read)) { data = new byte[fileStream.Length]; fileStream.Read(data, 0, data.Length); } } } var encryptedBytes = Telegram.Api.Helpers.Utils.AesIge(data, media.Key.Data, media.IV.Data, true); UploadFileManager.UploadFile(file.Id, obj, encryptedBytes); }
private void SendDocumentInternal(TLMessage25 message, object o) #endif { var document = ((TLMessageMediaDocument)message.Media).Document as TLDocument; if (document == null) { return; } byte[] thumbBytes = null; var thumb = document.Thumb as TLPhotoSize; if (thumb != null) { var thumbLocation = thumb.Location as TLFileLocation; if (thumbLocation != null) { var fileName = String.Format("{0}_{1}_{2}.jpg", thumbLocation.VolumeId, thumbLocation.LocalId, thumbLocation.Secret); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read)) { thumbBytes = new byte[fileStream.Length]; fileStream.Read(thumbBytes, 0, thumbBytes.Length); } } } } var bytes = document.Buffer; var md5Bytes = Telegram.Api.Helpers.Utils.ComputeMD5(bytes ?? new byte[0]); var md5Checksum = BitConverter.ToInt64(md5Bytes, 0); StateService.GetServerFilesAsync( results => { var serverFile = results.FirstOrDefault(result => result.MD5Checksum.Value == md5Checksum); if (serverFile != null) { message.InputMedia = serverFile.Media; ShellViewModel.SendMediaInternal(message, MTProtoService, StateService, CacheService); } else { if (thumbBytes != null) { var thumbFileId = TLLong.Random(); UploadFileManager.UploadFile(thumbFileId, message.Media, thumbBytes); Thread.Sleep(100); //NOTE: без этой строки не работает. Почему??? } var fileId = TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; #if WP81 if (file == null) { UploadDocumentFileManager.UploadFile(fileId, message, bytes); } else { UploadDocumentFileManager.UploadFile(fileId, message, file); } #else UploadDocumentFileManager.UploadFile(fileId, message, bytes); #endif } }); }
private void UploadPhotoInternal(TLMessage34 message) { var photo = ((TLMessageMediaPhoto)message.Media).Photo as TLPhoto; if (photo == null) { return; } var photoSize = photo.Sizes[0] as TLPhotoSize; if (photoSize == null) { return; } var fileLocation = photoSize.Location; if (fileLocation == null) { return; } byte[] bytes = null; var fileName = String.Format("{0}_{1}_{2}.jpg", fileLocation.VolumeId, fileLocation.LocalId, fileLocation.Secret); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read)) { if (fileStream.Length > 0) { bytes = new byte[fileStream.Length]; fileStream.Read(bytes, 0, bytes.Length); } } } if (bytes == null) { return; } var md5Bytes = Telegram.Api.Helpers.Utils.ComputeMD5(bytes); var md5Checksum = BitConverter.ToInt64(md5Bytes, 0); StateService.GetServerFilesAsync( results => { var serverFile = results.FirstOrDefault(result => result.MD5Checksum.Value == md5Checksum); #if MULTIPLE_PHOTOS serverFile = null; #endif if (serverFile != null) { var media = serverFile.Media; var captionMedia = media as IInputMediaCaption; if (captionMedia == null) { var inputMediaPhoto = serverFile.Media as TLInputMediaPhoto; if (inputMediaPhoto != null) { var inputMediaPhoto75 = new TLInputMediaPhoto75(inputMediaPhoto); captionMedia = inputMediaPhoto75; media = inputMediaPhoto75; serverFile.Media = inputMediaPhoto75; StateService.SaveServerFilesAsync(results); } var inputMediaUploadedPhoto = serverFile.Media as TLInputMediaUploadedPhoto; if (inputMediaUploadedPhoto != null) { var inputMediaUploadedPhoto75 = new TLInputMediaUploadedPhoto75(inputMediaUploadedPhoto, null); captionMedia = inputMediaUploadedPhoto75; media = inputMediaUploadedPhoto75; serverFile.Media = inputMediaUploadedPhoto75; StateService.SaveServerFilesAsync(results); } } if (captionMedia != null) { captionMedia.Caption = message.Message ?? TLString.Empty; } var ttlMedia = media as IInputTTLMedia; if (ttlMedia != null) { ttlMedia.TTLSeconds = ((TLMessageMediaPhoto70)message.Media).TTLSeconds; } message.InputMedia = media; UploadService.SendMediaInternal(message, MTProtoService, StateService, CacheService); } else { var fileId = TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; UploadFileManager.UploadFile(fileId, message, bytes); } }); }
private void SendCompressedVideoInternal(TLMessage message, object o) #endif { var documentMedia = message.Media as TLMessageMediaDocument45; if (documentMedia != null) { var fileName = documentMedia.IsoFileName; if (string.IsNullOrEmpty(fileName)) { return; } var video = documentMedia.Document as TLDocument22; if (video == null) { return; } byte[] thumbBytes = null; var photoThumb = video.Thumb as TLPhotoSize; if (photoThumb != null) { var location = photoThumb.Location as TLFileLocation; if (location == null) { return; } var thumbFileName = String.Format("{0}_{1}_{2}.jpg", location.VolumeId, location.LocalId, location.Secret); using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var thumbFile = storage.OpenFile(thumbFileName, FileMode.Open, FileAccess.Read)) { thumbBytes = new byte[thumbFile.Length]; thumbFile.Read(thumbBytes, 0, thumbBytes.Length); } } } var fileId = message.Media.FileId ?? TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; //return; #if WP81 if (file != null) { UploadVideoFileManager.UploadFile(fileId, message.IsGif(), message, file); } else if (!string.IsNullOrEmpty(fileName)) { UploadVideoFileManager.UploadFile(fileId, message, fileName); } else { return; } #else UploadVideoFileManager.UploadFile(fileId, message, fileName); #endif if (thumbBytes != null) { var fileId2 = TLLong.Random(); UploadFileManager.UploadFile(fileId2, message.Media, thumbBytes); } return; } var videoMedia = message.Media as TLMessageMediaVideo; if (videoMedia != null) { var fileName = videoMedia.IsoFileName; if (string.IsNullOrEmpty(fileName)) { return; } var video = videoMedia.Video as TLVideo; if (video == null) { return; } byte[] thumbBytes = null; var photoThumb = video.Thumb as TLPhotoSize; if (photoThumb != null) { var location = photoThumb.Location as TLFileLocation; if (location == null) { return; } var thumbFileName = String.Format("{0}_{1}_{2}.jpg", location.VolumeId, location.LocalId, location.Secret); using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var thumbFile = storage.OpenFile(thumbFileName, FileMode.Open, FileAccess.Read)) { thumbBytes = new byte[thumbFile.Length]; thumbFile.Read(thumbBytes, 0, thumbBytes.Length); } } } var fileId = message.Media.FileId ?? TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; #if WP81 if (file != null) { UploadVideoFileManager.UploadFile(fileId, message.IsGif(), message, file); } else if (!string.IsNullOrEmpty(fileName)) { UploadVideoFileManager.UploadFile(fileId, message, fileName); } else { return; } #else UploadVideoFileManager.UploadFile(fileId, message, fileName); #endif if (thumbBytes != null) { var fileId2 = TLLong.Random(); UploadFileManager.UploadFile(fileId2, message.Media, thumbBytes); } return; } }