public static string IFLToString(InputFileLocation ifl) { if (ifl is InputFileLocationConstructor) { // photo var i = (InputFileLocationConstructor)ifl; return(i.volume_id + ":" + i.local_id + ":" + i.secret); } if (ifl is InputVideoFileLocationConstructor) { // video var i = (InputVideoFileLocationConstructor)ifl; return(i.id + ":" + i.access_hash); } if (ifl is InputDocumentFileLocationConstructor) { // document var i = (InputDocumentFileLocationConstructor)ifl; return(i.id + ":" + i.access_hash); } if (ifl is InputAudioFileLocationConstructor) { // audio var i = (InputAudioFileLocationConstructor)ifl; return(i.id + ":" + i.access_hash); } return(string.Empty); }
public async Task <UploadFileConstructor> GetFile(int dcId, InputFileLocation inputFileLocation, int offset, int limit) { var request = new GetFileRequest(inputFileLocation, offset, limit); await SendRpcRequestInSeparateSession(dcId, request); // only single implementation available return((UploadFileConstructor)request.file); }
public async Task <string> DownloadVideo(Video arg, FileUploadProcessHandler handler) { if (arg.Constructor == Constructor.videoEmpty) { return(null); } VideoConstructor video = (VideoConstructor)arg; TLApi api = await session.GetFileSession(video.dc_id); InputFileLocation inputFile = TL.inputVideoFileLocation(video.id, video.access_hash); string videoPath = GetVideoPath(video); string tempVideoPath = videoPath + ".tmp"; int allSize = video.size; int chunkSize = 128 * 1024; int chunksCount = allSize / chunkSize; int lastChunkSize = allSize - chunkSize * chunksCount; int allChunksCount = chunksCount + (lastChunkSize != 0 ? 1 : 0); using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { if (storage.FileExists(videoPath)) { return(videoPath); } using (Stream stream = new IsolatedStorageFileStream(tempVideoPath, FileMode.OpenOrCreate, FileAccess.Write, storage)) { for (int i = 0; i < chunksCount; i++) { handler((float)i * (float)chunkSize / (float)allSize); Upload_fileConstructor chunk = (Upload_fileConstructor)await api.upload_getFile(inputFile, i *chunkSize, chunkSize); stream.Write(chunk.bytes, 0, chunk.bytes.Length); } if (lastChunkSize != 0) { handler((float)chunksCount * (float)chunkSize / (float)allSize); Upload_fileConstructor lastChunk = (Upload_fileConstructor)await api.upload_getFile(inputFile, chunksCount *chunkSize, lastChunkSize); stream.Write(lastChunk.bytes, 0, lastChunk.bytes.Length); } handler(1.0f); } if (storage.FileExists(videoPath)) { storage.DeleteFile(videoPath); } storage.MoveFile(tempVideoPath, videoPath); } return(videoPath); }
public async Task <Upload_fileConstructor> GetFile(InputFileLocation location) { var request = new GetFileRequest(location, 0, int.MaxValue); await _sender.Send(request); await _sender.Recieve(request); return(new Upload_fileConstructor(request.type, request.mtime, request.bytes)); }
void LoadIfl(ChatPhoto photo) { if (photo is ChatPhotoConstructor) { var flbig = (FileLocationConstructor)((ChatPhotoConstructor)photo).photo_big; var flsmall = (FileLocationConstructor)((ChatPhotoConstructor)photo).photo_small; ifl_large = new InputFileLocationConstructor(flbig.volume_id, flbig.local_id, flbig.secret); ifl_small = new InputFileLocationConstructor(flsmall.volume_id, flsmall.local_id, flsmall.secret); } }
public async Task <byte[]> Download(InputFileLocation ifl) { if (ifl == null) { return(new byte[0]); } var bytes = new List <byte>(); await Task.Factory.StartNew(() => { lock (dlLock) { const int kilobyte = 1024; const int chunkSize = 512; int i = 0; while (true) { var request = new Upload_GetFileRequest( ifl, i *kilobyte *chunkSize, kilobyte *chunkSize); var stask = _sender.Send(request); stask.Wait(); var rtask = _sender.Recieve(request); rtask.Wait(); var result = (Upload_fileConstructor)request.result; if (result == null) { bytes.Clear(); // file migrate probably break; } bytes.AddRange(result.bytes); if (result.bytes.Length < kilobyte *chunkSize) { break; } ++i; } } }); return(bytes.ToArray()); }
//Limit req: value % 1024 public async Task <Upload_fileConstructor> GetFile(InputFileLocation ifl, int size, int limit = 1024) { var result = new Upload_fileConstructor(); result.bytes = new byte[size]; GetFileRequest req; for (int recieved = 0; recieved < size; recieved += req.bytes.Length) { req = new GetFileRequest(ifl, recieved, limit); await _sender.Send(req); await _sender.Recieve(req); result.type = req.type; result.mtime = req.mtime; req.bytes.CopyTo(result.bytes, recieved); } return(result); }
public Msg(int id, string sender, string content, long date, bool self, string action = "", string forwarded = "", int replyTo = -1, string mediaType = "", string mediaName = "", InputFileLocation mediaIfl = null) { Empty = false; ID = id; Sender = sender; Content = content; UnixDate = date; Date = Utils.FromUnixTime(date); Self = self; Forwarded = forwarded; ReplyTo = replyTo; Action = ""; MediaType = mediaType; MediaLocation = mediaIfl; MediaName = mediaName; }
public static async Task <byte[]> Download(InputFileLocation ifl) { return(await client.Download(ifl)); }
public static async Task <BitmapImage> DownloadImage(InputFileLocation ifl) { return(Utils.LoadImage(await client.Download(ifl))); }
public GetFileRequest(InputFileLocation location, int offset, int limit) { _location = location; _offset = offset; _limit = limit; }
public static async Task <Msg> BuildMessage(MessageConstructor msg) { var id = msg.id; LC s = msg.from_id.HasValue ? await Telestat.GetContact(msg.from_id.Value) : null; var sender = s != null ? s.FullName : string.Empty; var content = msg.message; var forwarded = string.Empty; if (msg.fwd_from_id != null) { var contact = await Telestat.GetContact(msg.fwd_from_id); forwarded = contact == null ? "Unknown" : contact.FullName; } var replyTo = msg.reply_to_msg_id.HasValue ? msg.reply_to_msg_id.Value : -1; var date = msg.date; var mediaType = ""; var mediaName = ""; InputFileLocation mediaIfl = null; if (msg.media is MessageMediaEmptyConstructor) { var m = (MessageMediaEmptyConstructor)msg.media; } else if (msg.media is MessageMediaPhotoConstructor) { var m = (MessageMediaPhotoConstructor)msg.media; content = m.caption; if (m.photo is PhotoConstructor) { var p = (PhotoConstructor)m.photo; // Should be largest var loc = ((PhotoSizeConstructor)p.sizes[p.sizes.Count - 1]).location; if (loc is FileLocationConstructor) { var l = (FileLocationConstructor)loc; mediaType = "photo"; mediaName = l.local_id + ".jpg"; mediaIfl = new InputFileLocationConstructor(l.volume_id, l.local_id, l.secret); } } } else if (msg.media is MessageMediaVideoConstructor) { var m = (MessageMediaVideoConstructor)msg.media; content = m.caption; if (m.video is VideoConstructor) { var v = (VideoConstructor)m.video; mediaType = "video"; mediaName = v.id + ".mp4"; // i guess, may not be mp4 mediaIfl = new InputVideoFileLocationConstructor(v.id, v.access_hash); } } else if (msg.media is MessageMediaGeoConstructor) { var m = (MessageMediaGeoConstructor)msg.media; // TODO implement } else if (msg.media is MessageMediaContactConstructor) { var m = (MessageMediaContactConstructor)msg.media; // TODO implement } else if (msg.media is MessageMediaUnsupportedConstructor) { var m = (MessageMediaUnsupportedConstructor)msg.media; // TODO implement } else if (msg.media is MessageMediaDocumentConstructor) { var m = (MessageMediaDocumentConstructor)msg.media; if (m.document is DocumentConstructor) { var d = (DocumentConstructor)m.document; mediaType = "document"; foreach (var atr in d.attributes) { if (atr is DocumentAttributeFilenameConstructor) { var a = (DocumentAttributeFilenameConstructor)atr; mediaName = d.id.ToString() + "_" + a.file_name; break; } } if (string.IsNullOrEmpty(mediaName)) { mediaName = d.id.ToString(); } mediaIfl = new InputDocumentFileLocationConstructor(d.id, d.access_hash); } } else if (msg.media is MessageMediaAudioConstructor) { var m = (MessageMediaAudioConstructor)msg.media; if (m.audio is AudioConstructor) { var a = (AudioConstructor)m.audio; mediaType = "audio"; var spl = a.mime_type.Split('/'); if (spl.Length > 1) { mediaName = a.id.ToString() + "." + spl[1]; } else { mediaName = a.id.ToString() + ".mp3"; // TODO it probs isn't mp3, but well! } mediaIfl = new InputAudioFileLocationConstructor(a.id, a.access_hash); } } else if (msg.media is MessageMediaWebPageConstructor) { var m = (MessageMediaWebPageConstructor)msg.media; // TODO implement } else if (msg.media is MessageMediaVenueConstructor) { var m = (MessageMediaVenueConstructor)msg.media; // TODO implement } var self = s != null ? s.Self : false; return(new Msg( id, sender, content, date, self, string.Empty, forwarded, replyTo, mediaType, mediaName, mediaIfl)); }
public DownloadFileRequest(InputFileLocation loc, int offset = 0, int limit = 0) { args.location = loc; args.offset = offset; args.limit = limit; }
public GetFileRequest(InputFileLocation location, int offset, int limit) { this.location = location; this.offset = offset; this.limit = limit; }
public DownloadFileRequest(InputFileLocation loc,int offset=0,int limit=0) { args.location = loc; args.offset = offset; args.limit = limit; }