diff --git a/LibStorj.Wrapper.Contracts/Interfaces/IStorj.cs b/LibStorj.Wrapper.Contracts/Interfaces/IStorj.cs index bad3587..be35742 100644 --- a/LibStorj.Wrapper.Contracts/Interfaces/IStorj.cs +++ b/LibStorj.Wrapper.Contracts/Interfaces/IStorj.cs @@ -36,7 +36,7 @@ public interface IStorj DownloadJob DownloadFile(File file, string localPath); DownloadJob DownloadFile(Bucket bucket, string fileId, string localPath); DownloadJob DownloadFile(string bucketId, string fileId, string localPath); - Task UploadFile(Bucket bucket, string fileName, string localPath, IProgress progress = null); - Task UploadFile(string bucketId, string fileName, string localPath, IProgress progress = null); + UploadJob UploadFile(Bucket bucket, string fileName, string localPath); + UploadJob UploadFile(string bucketId, string fileName, string localPath); } } diff --git a/LibStorj.Wrapper.Contracts/Models/DownloadJob.cs b/LibStorj.Wrapper.Contracts/Models/DownloadJob.cs index 6ee7ffe..ded106c 100644 --- a/LibStorj.Wrapper.Contracts/Models/DownloadJob.cs +++ b/LibStorj.Wrapper.Contracts/Models/DownloadJob.cs @@ -6,15 +6,14 @@ namespace LibStorj.Wrapper.Contracts.Models { - public class DownloadJob + public class DownloadJob : JobBase { - public long Id { get; set; } - public bool IsFinished { get; set; } - public bool IsOnError { get; set; } public ProgressStatusDownload CurrentProgress { get; set; } + public string FileId { get; set; } public DownloadJob(string fileId) { + FileId = fileId; CurrentProgress = new ProgressStatusDownload(fileId, 0, 0, 0); } } diff --git a/LibStorj.Wrapper.Contracts/Models/JobBase.cs b/LibStorj.Wrapper.Contracts/Models/JobBase.cs new file mode 100644 index 0000000..2364e71 --- /dev/null +++ b/LibStorj.Wrapper.Contracts/Models/JobBase.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace LibStorj.Wrapper.Contracts.Models +{ + public delegate void ProgressChanged(JobBase job); + public delegate void JobFinished(JobBase job); + public delegate void JobFailed(JobBase job); + + public abstract class JobBase + { + public long Id { get; set; } + public bool IsFinished { get; set; } + public bool IsOnError { get; set; } + public int ErrorCode { get; set; } + public string ErrorMessage { get; set; } + + public event ProgressChanged ProgressChanged; + public event JobFinished JobFinished; + public event JobFailed JobFailed; + + public void RaiseProgressChanged() + { + if (ProgressChanged != null) + ProgressChanged(this); + } + + public void RaiseJobFinished() + { + if (JobFinished != null) + JobFinished(this); + } + + public void RaiseJobFailed() + { + if (JobFailed != null) + JobFailed(this); + } + } +} diff --git a/LibStorj.Wrapper.Contracts/Models/UploadJob.cs b/LibStorj.Wrapper.Contracts/Models/UploadJob.cs new file mode 100644 index 0000000..c80bf31 --- /dev/null +++ b/LibStorj.Wrapper.Contracts/Models/UploadJob.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibStorj.Wrapper.Contracts.Models +{ + public class UploadJob : JobBase + { + public ProgressStatusUpload CurrentProgress { get; set; } + public string FileName { get; set; } + + public UploadJob(string fileName) + { + FileName = fileName; + CurrentProgress = new ProgressStatusUpload(fileName, 0, 0, 0); + } + } +} diff --git a/LibStorj.Wrapper.Test.Console/Program.cs b/LibStorj.Wrapper.Test.Console/Program.cs index f85e11d..cb291d7 100644 --- a/LibStorj.Wrapper.Test.Console/Program.cs +++ b/LibStorj.Wrapper.Test.Console/Program.cs @@ -1,12 +1,6 @@ using LibStorj.Wrapper.Contracts.Interfaces; -using LibStorj.Wrapper.Contracts.Models; using LibStorj.Wrapper.x64; using Nito.AsyncEx; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LibStorj.Wrapper.Test.Console.x64 { @@ -24,39 +18,19 @@ static async void MainAsync(string[] args) //First test - if this fails, the system could not load the DLLs correctly. var timestamp = utils.GetTimestamp(); - IStorj storj = new Storj(); - //Set your keys and Mnemonics here or provide a keyfile vie the overloads. - storj.ImportKeys(new Contracts.Models.Keys("USER","PASSWORD","MNEMONIC"),"PASSPHRASE"); - var keyExist = storj.KeysExist; //This is not really working - it always returns "true" - - var buckets = await storj.GetBucketsAsync(); //Load all buckets - if that works your credentials did work - var files = await storj.ListFilesAsync(buckets[0]); //Load the files of the first bucket - //Get the versions of the dependencies to see if they work var v1 = (new VersionInfo()).GetCurlVersion(); var v2 = (new VersionInfo()).GetLibuvCVersion(); var v3 = (new VersionInfo()).GetJsonCVersion(); var v4 = (new VersionInfo()).GetNettleVersion(); - storj.UploadFile(buckets[0].Id, "Uploadfile.txt", @"YOURPATH\YOURFILE.txt"); //Test-upload a file - provide a path to a small file here - - //At this point, the upload does not work. - //After the next line the upload works but blocks GetInfoAsync. If the file is uploaded, the GetInfo is executed and returns - var info = await storj.GetInfoAsync(); - - //The same with download - var job = storj.DownloadFile(files.Item2.First(), @"YOURPATH\YOURFILE.txt"); - while(!job.IsFinished) - { - System.Console.Clear(); - System.Console.WriteLine("Status: " + job.CurrentProgress.DoneBytes + "/" + job.CurrentProgress.TotalBytes + " - " + job.CurrentProgress.Progress + "%"); - //The same like above - var infoDownload = await storj.GetInfoAsync(); - } - } - static void OnDownloadProgress(ProgressStatusDownload progress) - { - System.Console.WriteLine("DownloadProgress: " + progress.Progress); + IStorj storj = new Storj(); + //Set your keys and Mnemonics here or provide a keyfile via the overloads. + storj.ImportKeys(new Contracts.Models.Keys("USER","PASSWORD","MNEMONIC"),"PASSPHRASE"); + + var buckets = await storj.GetBucketsAsync(); //Load all buckets - if that works your credentials did work + + //Now do whatever you like - storj is working for you! :) } } } diff --git a/LibStorj.Wrapper.x64/AsyncCallbackWrapper/DownloadFileCallbackAsync.cs b/LibStorj.Wrapper.x64/AsyncCallbackWrapper/DownloadFileCallbackAsync.cs index 31f7817..116bdc7 100644 --- a/LibStorj.Wrapper.x64/AsyncCallbackWrapper/DownloadFileCallbackAsync.cs +++ b/LibStorj.Wrapper.x64/AsyncCallbackWrapper/DownloadFileCallbackAsync.cs @@ -29,7 +29,7 @@ public static DownloadJob DownloadFile(string bucketId, string fileId, string lo return job; } - public DownloadFileCallbackAsync(DownloadJob job) + private DownloadFileCallbackAsync(DownloadJob job) { _job = job; } @@ -37,18 +37,22 @@ public DownloadFileCallbackAsync(DownloadJob job) public void onProgress(string fileId, double progress, long downloadedBytes, long totalBytes) { _job.CurrentProgress = new ProgressStatusDownload(fileId, progress, downloadedBytes, totalBytes); + _job.RaiseProgressChanged(); } public void onComplete(string fileId, string localPath) { _job.CurrentProgress = new ProgressStatusDownload(fileId, 100, 0, 0); _job.IsFinished = true; + _job.RaiseJobFinished(); } public void onError(string fileId, int errorCode, string message) { _job.IsOnError = true; - //Todo: fehlermeldung übernehmen + _job.ErrorCode = errorCode; + _job.ErrorMessage = message; + _job.RaiseJobFailed(); } } } diff --git a/LibStorj.Wrapper.x64/AsyncCallbackWrapper/UploadFileCallbackAsync.cs b/LibStorj.Wrapper.x64/AsyncCallbackWrapper/UploadFileCallbackAsync.cs index b0c92bb..941af81 100644 --- a/LibStorj.Wrapper.x64/AsyncCallbackWrapper/UploadFileCallbackAsync.cs +++ b/LibStorj.Wrapper.x64/AsyncCallbackWrapper/UploadFileCallbackAsync.cs @@ -8,38 +8,51 @@ namespace LibStorj.Wrapper.AsyncCallbackWrapper { - class UploadFileCallbackAsync : TaskCompletionSource, io.storj.libstorj.UploadFileCallback + class UploadFileCallbackAsync : io.storj.libstorj.UploadFileCallback { - private IProgress _progress; + private UploadJob _job; - public UploadFileCallbackAsync(string bucketId, string fileName, string localPath, IProgress progress, io.storj.libstorj.Storj storj) + public static UploadJob UploadFile(string bucketId, string fileName, string localPath, io.storj.libstorj.Storj storj) { - _progress = progress; + UploadJob job = new UploadJob(fileName); + UploadFileCallbackAsync callback = new UploadFileCallbackAsync(job); try { - storj.uploadFile(bucketId, fileName, localPath, this); //ToDo: CancelHandle + + var handle = storj.uploadFile(bucketId, fileName, localPath, callback); + job.Id = handle; } catch (io.storj.libstorj.KeysNotFoundException) { throw new KeysNotFoundException(); } + return job; + } + + private UploadFileCallbackAsync(UploadJob job) + { + _job = job; } - public void onProgress(string filePath, double progress, long downloadedBytes, long totalBytes) + public void onProgress(string filePath, double progress, long uploadedBytes, long totalBytes) { - if (_progress != null) - _progress.Report(new ProgressStatusUpload(filePath, progress, downloadedBytes, totalBytes)); + _job.CurrentProgress = new ProgressStatusUpload(filePath, progress, uploadedBytes, totalBytes); + _job.RaiseProgressChanged(); } - public void onComplete(string str, io.storj.libstorj.File f) + public void onComplete(string filePath, io.storj.libstorj.File f) { - File file = new File(f.getId(), f.getBucketId(), f.getName(), f.getCreated(), f.isDecrypted(), f.getSize(), f.getMimeType(), f.getErasure(), f.getIndex(), f.getHMAC()); - SetResult(file); + _job.CurrentProgress = new ProgressStatusUpload(filePath, 100, f.getSize(), f.getSize()); + _job.IsFinished = true; + _job.RaiseJobFinished(); } public void onError(string filePath, int errorCode, string message) { - SetException(new UploadFileFailedException(filePath, errorCode, message)); + _job.IsOnError = true; + _job.ErrorCode = errorCode; + _job.ErrorMessage = message; + _job.RaiseJobFailed(); } } } diff --git a/LibStorj.Wrapper.x64/LibStorj.Wrapper.x64.csproj b/LibStorj.Wrapper.x64/LibStorj.Wrapper.x64.csproj index bcde584..8d8f0e1 100644 --- a/LibStorj.Wrapper.x64/LibStorj.Wrapper.x64.csproj +++ b/LibStorj.Wrapper.x64/LibStorj.Wrapper.x64.csproj @@ -30,12 +30,12 @@ IKVM.Runtime.JNI.dll - - libstorj-java-0.7.3.dll - libstorj-java-0.8.dll + + libstorj-java-0.8.1.dll + @@ -88,6 +88,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/LibStorj.Wrapper.x64/Storj.cs b/LibStorj.Wrapper.x64/Storj.cs index 45823b4..ed15f90 100644 --- a/LibStorj.Wrapper.x64/Storj.cs +++ b/LibStorj.Wrapper.x64/Storj.cs @@ -133,14 +133,14 @@ public DownloadJob DownloadFile(string bucketId, string fileId, string localPath return DownloadFileCallbackAsync.DownloadFile(bucketId, fileId, localPath, _storjJava); } - public Task UploadFile(Bucket bucket, string fileName, string localPath, IProgress progress = null) + public UploadJob UploadFile(Bucket bucket, string fileName, string localPath) { - return UploadFile(bucket.Id, fileName, localPath, progress); + return UploadFile(bucket.Id, fileName, localPath); } - public Task UploadFile(string bucketId, string fileName, string localPath, IProgress progress = null) + public UploadJob UploadFile(string bucketId, string fileName, string localPath) { - return new UploadFileCallbackAsync(bucketId, fileName, localPath, progress, _storjJava).Task; + return UploadFileCallbackAsync.UploadFile(bucketId, fileName, localPath, _storjJava); } diff --git a/LibStorj.Wrapper.x64/libstorj-java-0.8.1.dll b/LibStorj.Wrapper.x64/libstorj-java-0.8.1.dll new file mode 100644 index 0000000..5664f68 Binary files /dev/null and b/LibStorj.Wrapper.x64/libstorj-java-0.8.1.dll differ diff --git a/LibStorj.Wrapper.x64/libstorj-java-0.8.dll b/LibStorj.Wrapper.x64/libstorj-java-0.8.dll deleted file mode 100644 index baf3622..0000000 Binary files a/LibStorj.Wrapper.x64/libstorj-java-0.8.dll and /dev/null differ diff --git a/README.md b/README.md index e781f87..ed3f31f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ A .Net/C#-wrapper for Storj -This is the very first version - please excuse the missing documentation at this point. Just the short info: this library is based on the java-libstorj-binding and is done via IKVM. It works except the upload and download and there is still debug-code in it. Use at your own risk! +This is the very first version - please excuse the missing documentation at this point. Just the short info: this library is based on the java-libstorj-binding and is done via IKVM. -# Attention -Currently the library is not working due to threading issues. +Use at your own risk! \ No newline at end of file