.NET wrapper for safe_app


#1

Hi everyone :slight_smile:

I have been translating @Kumar’s java library into c#.

Now, I am not a systems level programmer so I needed reading up a bit on stuff, but I do work as tech lead + architect on a small company developing a few financial products, and do a lot of coding and architecting in c#, so once I’m more familiar with interoping with system lvl languages this should be going quite well :slight_smile:
But programming is such a vast subject and it’s amazing how little you can now about some areas even though you are quite good at others. Luckily, it’s really good fun to learn :smile:
So, thing is I really want to be creative with the network, and I’d love to use the tool I’m best with. So, I just thought I’ll have to get myself this c# client. It would probably be a lot smoother for someone used to both c# and system level coding, so if you are out there just say hello, but I really don’t mind digging into this myself. :smile:

The trick at first was that I haven’t found any examples of JNA => C# equivalences. DllImport is quite easy to use etc, but there were some “magical” things done by JNA that I still have to investigate/experiment a bit to find out what is actually done there.

Currently I have been able to run the first of the tests (from the java version) in it’s c# version and almost having the second finishing successfully. I left off investigating how to correctly represent
*const ffi::ContainerPermissions that goes into test_create_app_with_access, as I haven’t fully grasped it’s java implementation yet.

So, just wanted to inform all that this is going on :slight_smile: and that I’d really like to have some input from you @Kumar on some things along the way, but I noticed you are maybe a bit busy now (congratulations and my best wishes!).

I’m a bit busy myself, but MaidSafe etc. is a long term interest (and has been since I learned about it early 2016). So, I’ll be doing this a small bit at a time.

So, this is the topic where I’ll be asking questions and report on progress, and there’ll be GitHub code.


#2

OK, small update.

So, I haven’t actually had time to do anything more since I last wrote here, (which was basically a straight off translation from the Java code).

But, I’ll put what I have up anyway so that someone a bit more experienced with pointers and memory could have a look maybe :slight_smile:

So, a couple of large caveats here:

The java CompletableFuture has just been mocked, and what should really be done here is to implement async/await pattern, just haven’t got to it.

Also, the CallBackHelper doesn’t have a proper implementation of GetStringArrayCallback.

FfiContainerPermission class is completely broken. I was totally lost here. And current code in FfiContainerPermission ctor is just guessing, and of course not working :slight_smile:

And… probably something more.

So bear with the ugliness and untidiness at places of mocks, guesses and similar :slight_smile:

Anyway: https://github.com/oetyng/safe_app_dotnet


#3

@Krishna, didn’t want to disturb earlier, but, is it possible that you might have a look at some of the parts where I have not got it right?

The most obvious one would be FfiContainerPermission. Next one would be GetStringArrayCallback in CallbackHelper.

Would be much appreciated as I haven’t gotten any further with it, but I understand if there is not time for it. I’ll have to give it another go this weekend.


#4

@oetyng, I will try doing the best to help you. The xamarin code for the mobile can be a good reference for C# implementation. Am linking the module here in case if that helps. In the same repository there is reference for consuming safe_app also. Let me know if you need more help. I don’t have any experience working with C#, if these links are not helpful please let me know.


#5

Great news, thanks alot! :slight_smile:

I will look into it later this week and see if I can make progress with it.


#6

Couldn’t refrain from downloading and starting to fiddle with it :smile:

This is absolutely perfect. I can toss my translation, and this weekend will be epic :smiley:


#7

Here is the new .NET wrapper https://github.com/oetyng/safe_dotnet

It’s still missing relevant FFI binaries. So these would have be compiled and included.

You can include this in a .NET Core2 solution to build cross platform apps running on Win, Linux, iOS and even ARM.
(Although to do this, the NativeBindings.cs file would have to be adjusted to detect current platform, and select proper binary based on it.)


#8

So, I will describe an architecture I think could be used successfully if you for example want a service or a more complex app running on your device, with a management UI let’s say.

I will give an example:

This weekend I coded on an app, it is a data manager of sorts. It will run as a server on localhost, and it has a management interface which can be accessed in the browser.

So, this is how I have built it now, (except that I have not published a SAFE website to access it yet, but I would consider it better than accessing the site on localhost through the browser, which I am doing currently).


#9