Port to MonoMobile (MonoTouch MT and MonoForAndroid MA)

Topics: feature request (I want ...), patch (something to share)
Aug 4, 2012 at 7:24 AM

Hi everyone

I'm about to finish port to MM. There are still few issues with MonoDevelop. We have used version 6.1.1. on one of our project, so in order not to break our code I have ported 6.1.1.
I have tried with 7.x but ran into some problems and did not have neough time to fix 'em.

I will push my code to github next week and I'm willing to share my experience, knowledge
with You and tips how could we make porting easier next time.

Very short:

  1. I would separate csproj files like VS does single csproj per folder
  2. make all classes partial
    we are linking files with project linker and platform specific stuff goes to partial classes in
    separate files (#if defs are  nogo)
  3. windows phone is long way to go (Cryptography, UdpClient,)
    I have shut the compiler up with ifdefs but it is ugly!
    Do not use WP projects. It may explode into Your face.

I'm waiting for some answers from Xamarin/mono guys to fix those issues I believe they are not biggies and will push to

https://github.com/moljac

Howtos will be on: http://holisticware.net/HolisticWare/Know-How/development.aspx

Next few weeks I have to finish app that relies on sharpsnmp. This appwill be presented as proof of concept to one conference, so I won't have enough time to do serious job

thanks a lot for Your lib and attention

regards

mel 

Coordinator
Aug 5, 2012 at 12:51 AM

Hi mel,

Thanks for this exciting news.

I was about to start a Mono for Android port before my desktop PC broke last week, so I rather wait till seeing your port first. I don't have a Mac, so I personally could not work on the port to MonoTouch. I don't think Microsoft ever does good jobs on mobile platforms. .NET CF was a failure, and Silverlight for Windows Phone 7 was another. Not sure what might happen for Windows Phone 8 and Windows 8 RT.

Anyway, cannot thank you more on your working and look forward to seeing your fork.

Regards,

Lex

Aug 5, 2012 at 8:56 AM

Hi Lex

No problems - we are thankful for Your work and this library.

So You have problems with bare metal too.... My box is almot 5 years old and I'm scared it may die any second....

Regarding Microsoft I think Windows Phone is not bad platform for games, social media and reading mail (I cannot browse on small screen), but
guys from Microsoft have forgotten word-noun Phone in the name of the product. Our team does VoIP too and unless MS allows ASAP
native SIP (VoIP protocol, not Software Input Panel = Keyboard in MS linguistics) they will be doomed...
Xamarin (mono) guys have made tremendous job (I just cannot find words of thanks and admiration for their work), so that .net developers can
enter other platforms. In my opinion, .net through mono has better position than java - just to note: iOS (but that's my opinion).
Regarding WP8 - I had pretty tough discussion with MS MVPs on one conference where I have presented MT and MA and they said
I should wait and see. It looked like either MS is gonna allow better networking stack (with UDP) and/or native apps for all dev, but no
real info. 

I have borrowed Mac too, it is 4 yrs old MacBook Pro, but I'm working 90% in VS. These 10% are just to see, how projects/solutions copy
with MonoDevelop first on Windows and then on Mac. 

First I took 6.1.1, cos we worked with it on our desktop project and when I tried to use 7.x it was too much to take care of backward compatibility
with desktop project and push forward to mobile. I have lost 2-3 days trying, but due to the fact that this mobile app is going to be shown on
one quite big and important conference I have decided to go with 6.1.1 and will do it again for 7.x if You want.

Following my instructions friend of mine made "port" from desktop WPF to MA in 2 days and one day was work to cut out Microsoft.Unity stuff 
for configurations. He resorted to dirty trick: took some desktop assemblies (dlls) and referenced them in MA. This can be done (sometimes),
but suddenly it can break (as it did). I'm portability freak and I have always tried to target more platforms I can rember I tried to reuse Silverlight
on desktop it was doable, but with heavy tricksery.

So our team does

  • project pro platform
    try to follow VS and MonoDevelop art of creating projects each project goes in the directory with the same name
    (this was basically the most difficult issue for me during SharpSNMP port - You have several projects in one folder) 
    • each dll/assembly (BusinessLogic BL, data access, service layer) has basically N dlls
      (class library for desktop, MA, MT, WP)
    • create assemblies for each platform
      BL.MA, BL.MT, BL.WP, BL.RIA, BL.WF
      for UI it is necessary anyway - because of platform diffs (MonoTouch Dialog and 
      • change project properties: assembly name (optional) and default namespace (recommended)
         sometimes I had problems that Intellisense finds the class, but compiler screams that class does not exist
        (something with code linking) 
    • starting point is most restrictive platform - smallest common denominator
      currently WP (and I expect it will remain)
      If You want to port fast, forget WP... Make strating point either MT or MA (they are basically supersets of
      silverlight (WP, RIA)
      Sync methods can be used for proof of concept (but rewrite those ASAP).
      MA and MT allow synchronous methods on WebClient and other netowrking classes.
      They allow, but this does not mean it is good to use 'em - it is mobile and after all it is good coding
      it is good programming practice not to allow user to wait. 
    •  put all of the code in starting point (BL.WP)
    • compile
      see what must be 
      • excluded (Cryptography, UDP, etc..)
      • rewritten (async methods)
    • make all classes partial - this does not hurt, but it helps a lot when You need to refactor/extract
      I dunno why Microsoft has no project items (class) with partial keyword!
    • offending code
      • rewrite for current platform
      • and extract/refactor offending code to platforms that support it
        usually I put it in MA or MT or even desktop and then copy/paste link in other   
  • source code linking across projects 
    You have it in VS, but with extensions like 

here it is: https://github.com/moljac/MonoMobile.SharpSNMP

cheers

 

mel

 

Aug 27, 2012 at 7:22 AM

Hi Lex

Did You take a look? Would You like me/us to port newest version?

I'm asking cos we'd like to hit some other projects (commercial and non-commercial == open-source), so we would like to know to plan our resources.

thanks + regards

mel

Coordinator
Aug 27, 2012 at 9:02 AM

Hi mel,

If you like, your team can attempt to port 7.5. But there are too many significant changes between 6.1.1 and 7.5, I am not sure whether there is still possibly to port most of the bits.

Regards,

Lex

Aug 30, 2012 at 7:48 AM

Hi Lex

OK. We'll start porting 7.5. I believe it should not take more than a month.
Rough plan we (I)'ll:

  • reorganize (and rename) project/solution structure to make porting easier
  • split the code across the platforms to be compile clean
    (WP) comes in play, but I'm not sure if this is going to work
  • commit all to github, then You can fork/pull out and decide whatever You want to do with it (make it v.8.x) or so.

Is this OK?

BTW I was querying Transmitter through SNMP from my iPad, iPhone and Samsung Galaxy S II whole night. Each device
more than 300k+ queries and no errors. 

regards

 

mel

Coordinator
Aug 31, 2012 at 12:56 PM

Hi mel,

Just curious about how do you attempt to start porting 7.5?

Ideally I suggest you fork from http://github.com/lextm/sharpsnmplib and then start changing the structure of the code base and make it mobile friendly as you stated. In that way, I can easily accept your changes back to the main repository.

If it is impossible to fork from the main repository for this port, please let me know. I might review your changes and re-apply them to the main repository.

Regards,

Lex

Sep 6, 2012 at 10:18 AM

Hi lextm

Sorry for not answering, but had several projects that we had to finish and was thinking about the best way how to proceed and to be least intrusive.

Basically we have 2 options

  1. portable libs
    We have worked a bit with those, so not too much experience! And - our experience showed us 2nd approach better
    (We are currently porting 2 apps from CF/SmartDevice => MonoTouch (and this is basically MA) 
  2. source code reusing through linking (add links to files)
    1. team has several solutions (sets of x-platform projects) on github that help us porting (and few more to come)
    2. it is easier to add diffs (platform specific stuff) to [partial] classes in different projects

So I forked sharpsnmplib and my suggestion is

  • some defs (math ++ pseudocode)
    • List<string>Platforms = new List<string>(){ "WP", "MT", "MA", "WF"}
      WP is just to be ready something big happens in WP8
      WF is Std Windows class lib for WPF and WinForms
    • n = Platforms.Length  // set theory : |Platforms| 
      so for starter 4,
      After You say "go" -  give us green light we can add "CF" (some one can add new CF projects or I'll try to copy yours and adjust those)
      Namely we have only VS2010 and are preparing to switch to 2012 soon.
  • to go side-by-side along Your project only with different project naming
    • MonoVersal for prefix
      hope this does not bother You - it is not Uni-versal, Mono-versal 
    • different suffixes for platform designation like MA for MonoForAndroid, MT for MonoTouch, etc...
  • starting with N=4 in this order:
    1. SharpSnmpLib.csproj
      1. make for starter
        MonoVersal.SharpSNMP.WP
        MonoVersal.SharpSNMP.MT
        MonoVersal.SharpSNMP.MA
        MonoVersal.SharpSNMP.WF
        MonoVersal.SharpSNMP.CF (probably no intervention is needed) 
    2. SharpSnmpLib.Engine.csproj
      if it makes sense to have mobile api we'll port that too. 
    3. SharpSnmpLib.AST.csproj
      if it makes sense to have mobile api we'll port that too.  
    •  
      • this will have to wait so we can port log4net! 

So If You want me to start #1 and You can agree/disagree. I'll need couple of days!

Later on we can restructure projects into "Solution Folders" in VS and physical folders if necessary to maintain order

Oh yes - all projects will be MonoDevelop (mono) friendly from the begining!

regards

 

mel

Coordinator
Sep 15, 2012 at 1:05 PM

Hi mel,

It is really hard for me to comment further on which approach to go.

I will try my best to finish reviewing your previous port at https://github.com/moljac/MonoMobile.SharpSNMP to see if I can identify something "not easy to understand". Before I finish I think we might be caution and slow down the process.

Regards,

Lex

Coordinator
Oct 14, 2012 at 12:55 PM
Edited Oct 14, 2012 at 12:56 PM

Hi mel,

I started to test out Mono for Android and I finished the initial work today,

http://www.lextm.com/2012/10/tritonmate-words-official-port-to-mono.html

I still prefer the CF port approach I used, to create .ma.sln/.ma.csproj files in the same folder. There seems to be less API breaking in Mono for Android profile, so I did not see any need right now to use partial classes.

I will also test out Windows Phone 7.1, but it is not promising yet. I don't have a Mac yet, but plan to get one in the coming months so as to test out MonoTouch.

Regards,

Lex

Oct 14, 2012 at 9:51 PM

Hi Lex

Sorry for delay, but my PoC got cancelled because of some political reasons for IBC beginning of Sept, so I had to reorganize
and rethink how to proceed further.

So:

Our app runs perfectly on 6.1.1 and I hoped I would persuade our managers to allow me to port to 7.5. They said No - for time being.
So  I have started to prepare lof4net and others for porting.

Regarding making csproj files in the sam dir or not... If this is policy... OK - I have seen quite a lot generated confusion and conflicts
with that approach on projects mentioned above. one approach was to put all projects files in one dir and they include files from dir/subdirs
below.  Other approach was to put them in parallel - OK this project was simpler, but in general produced a lot less problems.

CF is generally subset of MonoMobile (MA and MT) so You can add it in the same folder. There sholud not be a lot differences. I have
split those mostly for WP, but w/o UDP this is doomed. I have not too much info about WP8...

I had pretty rough weekend chasing some stuff in iOS (MT), so I'll get back in few days

 

regards

 

mel