Skip to content
This repository was archived by the owner on Sep 2, 2019. It is now read-only.

Commit 1410e89

Browse files
committed
Upgrade to java-libstorj 0.8.1 - First fully working version!
1 parent 9d3d572 commit 1410e89

File tree

12 files changed

+116
-63
lines changed

12 files changed

+116
-63
lines changed

LibStorj.Wrapper.Contracts/Interfaces/IStorj.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public interface IStorj
3636
DownloadJob DownloadFile(File file, string localPath);
3737
DownloadJob DownloadFile(Bucket bucket, string fileId, string localPath);
3838
DownloadJob DownloadFile(string bucketId, string fileId, string localPath);
39-
Task<File> UploadFile(Bucket bucket, string fileName, string localPath, IProgress<ProgressStatusUpload> progress = null);
40-
Task<File> UploadFile(string bucketId, string fileName, string localPath, IProgress<ProgressStatusUpload> progress = null);
39+
UploadJob UploadFile(Bucket bucket, string fileName, string localPath);
40+
UploadJob UploadFile(string bucketId, string fileName, string localPath);
4141
}
4242
}

LibStorj.Wrapper.Contracts/Models/DownloadJob.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66

77
namespace LibStorj.Wrapper.Contracts.Models
88
{
9-
public class DownloadJob
9+
public class DownloadJob : JobBase
1010
{
11-
public long Id { get; set; }
12-
public bool IsFinished { get; set; }
13-
public bool IsOnError { get; set; }
1411
public ProgressStatusDownload CurrentProgress { get; set; }
12+
public string FileId { get; set; }
1513

1614
public DownloadJob(string fileId)
1715
{
16+
FileId = fileId;
1817
CurrentProgress = new ProgressStatusDownload(fileId, 0, 0, 0);
1918
}
2019
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace LibStorj.Wrapper.Contracts.Models
6+
{
7+
public delegate void ProgressChanged(JobBase job);
8+
public delegate void JobFinished(JobBase job);
9+
public delegate void JobFailed(JobBase job);
10+
11+
public abstract class JobBase
12+
{
13+
public long Id { get; set; }
14+
public bool IsFinished { get; set; }
15+
public bool IsOnError { get; set; }
16+
public int ErrorCode { get; set; }
17+
public string ErrorMessage { get; set; }
18+
19+
public event ProgressChanged ProgressChanged;
20+
public event JobFinished JobFinished;
21+
public event JobFailed JobFailed;
22+
23+
public void RaiseProgressChanged()
24+
{
25+
if (ProgressChanged != null)
26+
ProgressChanged(this);
27+
}
28+
29+
public void RaiseJobFinished()
30+
{
31+
if (JobFinished != null)
32+
JobFinished(this);
33+
}
34+
35+
public void RaiseJobFailed()
36+
{
37+
if (JobFailed != null)
38+
JobFailed(this);
39+
}
40+
}
41+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace LibStorj.Wrapper.Contracts.Models
8+
{
9+
public class UploadJob : JobBase
10+
{
11+
public ProgressStatusUpload CurrentProgress { get; set; }
12+
public string FileName { get; set; }
13+
14+
public UploadJob(string fileName)
15+
{
16+
FileName = fileName;
17+
CurrentProgress = new ProgressStatusUpload(fileName, 0, 0, 0);
18+
}
19+
}
20+
}
Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
using LibStorj.Wrapper.Contracts.Interfaces;
2-
using LibStorj.Wrapper.Contracts.Models;
32
using LibStorj.Wrapper.x64;
43
using Nito.AsyncEx;
5-
using System;
6-
using System.Collections.Generic;
7-
using System.Linq;
8-
using System.Text;
9-
using System.Threading.Tasks;
104

115
namespace LibStorj.Wrapper.Test.Console.x64
126
{
@@ -24,39 +18,19 @@ static async void MainAsync(string[] args)
2418
//First test - if this fails, the system could not load the DLLs correctly.
2519
var timestamp = utils.GetTimestamp();
2620

27-
IStorj storj = new Storj();
28-
//Set your keys and Mnemonics here or provide a keyfile vie the overloads.
29-
storj.ImportKeys(new Contracts.Models.Keys("USER","PASSWORD","MNEMONIC"),"PASSPHRASE");
30-
var keyExist = storj.KeysExist; //This is not really working - it always returns "true"
31-
32-
var buckets = await storj.GetBucketsAsync(); //Load all buckets - if that works your credentials did work
33-
var files = await storj.ListFilesAsync(buckets[0]); //Load the files of the first bucket
34-
3521
//Get the versions of the dependencies to see if they work
3622
var v1 = (new VersionInfo()).GetCurlVersion();
3723
var v2 = (new VersionInfo()).GetLibuvCVersion();
3824
var v3 = (new VersionInfo()).GetJsonCVersion();
3925
var v4 = (new VersionInfo()).GetNettleVersion();
4026

41-
storj.UploadFile(buckets[0].Id, "Uploadfile.txt", @"YOURPATH\YOURFILE.txt"); //Test-upload a file - provide a path to a small file here
42-
43-
//At this point, the upload does not work.
44-
//After the next line the upload works but blocks GetInfoAsync. If the file is uploaded, the GetInfo is executed and returns
45-
var info = await storj.GetInfoAsync();
46-
47-
//The same with download
48-
var job = storj.DownloadFile(files.Item2.First(), @"YOURPATH\YOURFILE.txt");
49-
while(!job.IsFinished)
50-
{
51-
System.Console.Clear();
52-
System.Console.WriteLine("Status: " + job.CurrentProgress.DoneBytes + "/" + job.CurrentProgress.TotalBytes + " - " + job.CurrentProgress.Progress + "%");
53-
//The same like above
54-
var infoDownload = await storj.GetInfoAsync();
55-
}
56-
}
57-
static void OnDownloadProgress(ProgressStatusDownload progress)
58-
{
59-
System.Console.WriteLine("DownloadProgress: " + progress.Progress);
27+
IStorj storj = new Storj();
28+
//Set your keys and Mnemonics here or provide a keyfile via the overloads.
29+
storj.ImportKeys(new Contracts.Models.Keys("USER","PASSWORD","MNEMONIC"),"PASSPHRASE");
30+
31+
var buckets = await storj.GetBucketsAsync(); //Load all buckets - if that works your credentials did work
32+
33+
//Now do whatever you like - storj is working for you! :)
6034
}
6135
}
6236
}

LibStorj.Wrapper.x64/AsyncCallbackWrapper/DownloadFileCallbackAsync.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,30 @@ public static DownloadJob DownloadFile(string bucketId, string fileId, string lo
2929
return job;
3030
}
3131

32-
public DownloadFileCallbackAsync(DownloadJob job)
32+
private DownloadFileCallbackAsync(DownloadJob job)
3333
{
3434
_job = job;
3535
}
3636

3737
public void onProgress(string fileId, double progress, long downloadedBytes, long totalBytes)
3838
{
3939
_job.CurrentProgress = new ProgressStatusDownload(fileId, progress, downloadedBytes, totalBytes);
40+
_job.RaiseProgressChanged();
4041
}
4142

4243
public void onComplete(string fileId, string localPath)
4344
{
4445
_job.CurrentProgress = new ProgressStatusDownload(fileId, 100, 0, 0);
4546
_job.IsFinished = true;
47+
_job.RaiseJobFinished();
4648
}
4749

4850
public void onError(string fileId, int errorCode, string message)
4951
{
5052
_job.IsOnError = true;
51-
//Todo: fehlermeldung übernehmen
53+
_job.ErrorCode = errorCode;
54+
_job.ErrorMessage = message;
55+
_job.RaiseJobFailed();
5256
}
5357
}
5458
}

LibStorj.Wrapper.x64/AsyncCallbackWrapper/UploadFileCallbackAsync.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,51 @@
88

99
namespace LibStorj.Wrapper.AsyncCallbackWrapper
1010
{
11-
class UploadFileCallbackAsync : TaskCompletionSource<File>, io.storj.libstorj.UploadFileCallback
11+
class UploadFileCallbackAsync : io.storj.libstorj.UploadFileCallback
1212
{
13-
private IProgress<ProgressStatusUpload> _progress;
13+
private UploadJob _job;
1414

15-
public UploadFileCallbackAsync(string bucketId, string fileName, string localPath, IProgress<ProgressStatusUpload> progress, io.storj.libstorj.Storj storj)
15+
public static UploadJob UploadFile(string bucketId, string fileName, string localPath, io.storj.libstorj.Storj storj)
1616
{
17-
_progress = progress;
17+
UploadJob job = new UploadJob(fileName);
18+
UploadFileCallbackAsync callback = new UploadFileCallbackAsync(job);
1819
try
1920
{
20-
storj.uploadFile(bucketId, fileName, localPath, this); //ToDo: CancelHandle
21+
22+
var handle = storj.uploadFile(bucketId, fileName, localPath, callback);
23+
job.Id = handle;
2124
}
2225
catch (io.storj.libstorj.KeysNotFoundException)
2326
{
2427
throw new KeysNotFoundException();
2528
}
29+
return job;
30+
}
31+
32+
private UploadFileCallbackAsync(UploadJob job)
33+
{
34+
_job = job;
2635
}
2736

28-
public void onProgress(string filePath, double progress, long downloadedBytes, long totalBytes)
37+
public void onProgress(string filePath, double progress, long uploadedBytes, long totalBytes)
2938
{
30-
if (_progress != null)
31-
_progress.Report(new ProgressStatusUpload(filePath, progress, downloadedBytes, totalBytes));
39+
_job.CurrentProgress = new ProgressStatusUpload(filePath, progress, uploadedBytes, totalBytes);
40+
_job.RaiseProgressChanged();
3241
}
3342

34-
public void onComplete(string str, io.storj.libstorj.File f)
43+
public void onComplete(string filePath, io.storj.libstorj.File f)
3544
{
36-
File file = new File(f.getId(), f.getBucketId(), f.getName(), f.getCreated(), f.isDecrypted(), f.getSize(), f.getMimeType(), f.getErasure(), f.getIndex(), f.getHMAC());
37-
SetResult(file);
45+
_job.CurrentProgress = new ProgressStatusUpload(filePath, 100, f.getSize(), f.getSize());
46+
_job.IsFinished = true;
47+
_job.RaiseJobFinished();
3848
}
3949

4050
public void onError(string filePath, int errorCode, string message)
4151
{
42-
SetException(new UploadFileFailedException(filePath, errorCode, message));
52+
_job.IsOnError = true;
53+
_job.ErrorCode = errorCode;
54+
_job.ErrorMessage = message;
55+
_job.RaiseJobFailed();
4356
}
4457
}
4558
}

LibStorj.Wrapper.x64/LibStorj.Wrapper.x64.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
<Reference Include="IKVM.Runtime.JNI">
3131
<HintPath>IKVM.Runtime.JNI.dll</HintPath>
3232
</Reference>
33-
<Reference Include="libstorj-java-0.7.3">
34-
<HintPath>libstorj-java-0.7.3.dll</HintPath>
35-
</Reference>
3633
<Reference Include="libstorj-java-0.8">
3734
<HintPath>libstorj-java-0.8.dll</HintPath>
3835
</Reference>
36+
<Reference Include="libstorj-java-0.8.1">
37+
<HintPath>libstorj-java-0.8.1.dll</HintPath>
38+
</Reference>
3939
</ItemGroup>
4040

4141
<ItemGroup>
@@ -88,6 +88,9 @@
8888
<None Update="libstorj-2.dll">
8989
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9090
</None>
91+
<None Update="libstorj-java-0.8.1.dll">
92+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
93+
</None>
9194
<None Update="libstorj-java-0.8.dll">
9295
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9396
</None>

LibStorj.Wrapper.x64/Storj.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ public DownloadJob DownloadFile(string bucketId, string fileId, string localPath
133133
return DownloadFileCallbackAsync.DownloadFile(bucketId, fileId, localPath, _storjJava);
134134
}
135135

136-
public Task<File> UploadFile(Bucket bucket, string fileName, string localPath, IProgress<ProgressStatusUpload> progress = null)
136+
public UploadJob UploadFile(Bucket bucket, string fileName, string localPath)
137137
{
138-
return UploadFile(bucket.Id, fileName, localPath, progress);
138+
return UploadFile(bucket.Id, fileName, localPath);
139139
}
140140

141-
public Task<File> UploadFile(string bucketId, string fileName, string localPath, IProgress<ProgressStatusUpload> progress = null)
141+
public UploadJob UploadFile(string bucketId, string fileName, string localPath)
142142
{
143-
return new UploadFileCallbackAsync(bucketId, fileName, localPath, progress, _storjJava).Task;
143+
return UploadFileCallbackAsync.UploadFile(bucketId, fileName, localPath, _storjJava);
144144
}
145145

146146

36 KB
Binary file not shown.

0 commit comments

Comments
 (0)