// upload.getFile#e3a6cfb5 location:InputFileLocation offset:int limit:int = upload.File; public async Task <UploadFileConstructor> GetFile(FileLocationConstructor fileLocation, int offset, int limit) { var request = new GetFileRequest(new InputFileLocationConstructor(fileLocation.volumeId, fileLocation.localId, fileLocation.secret), offset, limit); await SendRpcRequestInSeparateSession(fileLocation.dcId, request); // only single implementation available return((UploadFileConstructor)request.file); }
static TgLocation MapLocation(FileLocationConstructor location) { if (location == null) { return(null); } return(new TgLocation { VolumeId = location.volume_id, LocalId = location.local_id, Secret = location.secret, InputType = typeof(InputFileLocationConstructor) }); }
public async Task <string> GetFile(FileLocation fileLocation) { logger.debug("Getting file {0}", fileLocation); if (fileLocation.Constructor == Constructor.fileLocation) { FileLocationConstructor location = (FileLocationConstructor)fileLocation; string filePath = FileLocationToCachePath(location); using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { if (!storage.DirectoryExists("cache")) { storage.CreateDirectory("cache"); } if (storage.FileExists(filePath)) { logger.debug("Getting file {0} from cache", filePath); return(filePath); } TLApi api = await session.GetFileSession(location.dc_id); logger.debug("Got file session for dc {0}", location.dc_id); Upload_fileConstructor file = (Upload_fileConstructor)await api.upload_getFile(TL.inputFileLocation(location.volume_id, location.local_id, location.secret), 0, int.MaxValue); logger.debug("File constructor found"); using (Stream fileStream = new IsolatedStorageFileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, storage)) { await fileStream.WriteAsync(file.bytes, 0, file.bytes.Length); } logger.debug("File saved successfully"); return(filePath); } } else { throw new MTProtoFileUnavailableException(); } }
private string FileLocationToCachePath(FileLocationConstructor fileLocation) { return(String.Format("cache/{0}.{1}.{2}.jpg", fileLocation.volume_id, fileLocation.local_id, fileLocation.secret)); }
private string FileLocationToCachePath(FileLocationConstructor fileLocation) { return String.Format("cache/{0}.{1}.{2}.jpg", fileLocation.volume_id, fileLocation.local_id, fileLocation.secret); }