Пример #1
0
        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 };
            }
        }
Пример #2
0
        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();
            }
        }
Пример #3
0
        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);
                    }
                }
            }
        }
Пример #4
0
 protected override async Task<Stream> DownloadStreamedAsync(StorjApiClient client, string hash, string key)
 {
     return await client.DownloadStreamedAsync(hash, key);
 }
Пример #5
0
 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);
 }
Пример #6
0
 protected abstract Task<Stream> DownloadStreamedAsync(StorjApiClient client, string hash, string key);
Пример #7
0
        private void EnsureDownloadStarted()
        {
            lock (lockTask)
            {
                if (downloadTask == null)
                {
                    StorjApiClient client = new StorjApiClient(apiUrl);

                    downloadTask = DownloadStreamedAsync(client, hash, key);
                }
            }
        }