private static FileReferences LoadFileReferences(string dataFile) { if (!File.Exists(dataFile)) { return(new FileReferences { Name = string.Empty }); } try { IList <string> data = File.ReadAllText(dataFile).Split('|'); StorjApiClient client = new StorjApiClient(apiUrl); byte[] fileListBytes = client.DownloadAsync(data.First(), data.Last()).Result; return(JsonConvert.DeserializeObject <FileReferences>(Encoding.ASCII.GetString(fileListBytes))); } catch (Exception e) { return(new FileReferences { Name = string.Empty }); } }
private void EnsureDownloadStarted() { lock (lockTask) { if (downloadTask == null) { StorjApiClient client = new StorjApiClient(apiUrl); downloadTask = DownloadStreamedAsync(client, hash, key); } } }
private void EnsureUploadStarted() { lock (lockTask) { if (uploadTask == null) { StorjApiClient client = new StorjApiClient(apiUrl); if (Size > 0) { uploadTask = client.UploadStreamedAsync(Upload, fileName, Size); } else { uploadTask = client.UploadAsync(UploadAsync, fileName); } } } }
private void PersistFileReferences() { StartCommunication(); string data = JsonConvert.SerializeObject(files.Value); StorjApiClient client = new StorjApiClient(apiUrl); try { UploadedFile cloudFile = client.UploadAsync(new MemoryStream(Encoding.ASCII.GetBytes(data)), "data.dat").Result; File.WriteAllText(dataFile.Value, string.Format("{0}|{1}", cloudFile.FileHash, cloudFile.Key)); } catch (Exception e) { } finally { EndCommunication(); } }
protected override async Task <Stream> DownloadStreamedAsync(StorjApiClient client, string hash, string key) { return(await client.DownloadStreamedAsync(hash, key)); }
protected override async Task <Stream> DownloadStreamedAsync(StorjApiClient client, string hash, string key) { // Do not provide the key to download the file encrypted return(await client.DownloadStreamedAsync(hash)); }
protected abstract Task <Stream> DownloadStreamedAsync(StorjApiClient client, string hash, string key);