C#->X# for dummies

This forum is meant for anything you would like to share with other visitors
FFF
Posts: 1582
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

C#->X# for dummies

Post by FFF »

Guys,
got me from https://github.com/andyturtles/Tess4Windows/releases (-> Assets)
a C# WPF app. Would like to see what it does, but C# source makes me cringe. So, is there a howto for noobs like me, how to proceed to move this to X#? If possible to Xide ;)
TIA
 
Tess4Windows-001.zip
(715.92 KiB) Downloaded 91 times
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
wriedmann
Posts: 3759
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

C#->X# for dummies

Post by wriedmann »

Hi Karl,
comeon: you are not a dummy!
The problem is not C# as you could build that application with Visual Studio and then use ILSpy to translate the code to X#. Another possibility would be to build that application and use the debugger to look into it.
But it seems to not be complete - you need the entire solution to build it.
And after all: C# may be much harder to read than X#, but the language itself should not be a problem.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

C#->X# for dummies

Post by ic2 »

Hello Wolfgang, Karl,
wriedmann wrote:Hi Karl,
But it seems to not be complete - you need the entire solution to build it.
Wolfgang
That is half true. Indeed the .sln file is missing but as there is a Tess4Windows.csproj file you can open the solution in VS by doubleclicking on that project file (and save a .sln file afterwards).
But there should be a Tessapi somewhere, not in the zip. There's an unresolved reference to it in the project. E.g. a reference to TessApiResult is one of the failing lines .
If you can retrieve that somewhere it may work although I also see errors like Error CS1501 No overload for method 'NotifyPropertyChanged' takes 1 arguments Tess4Windows D:ccodeSamplesKarlPrgUserControlsChooseUiController.cs 24 Active

So maybe there's more work to do before it compiles.

Finally it's not so clear what the program should do. It looks like a user control (grid). In general you can easily add a X# project to it and simply use the control (or whatever C# methods and classes) from within the X# program as tough it was an X# class. I would prefer that to trying to make a downloaded C# sample X# code
first.

Dick
User avatar
wriedmann
Posts: 3759
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

C#->X# for dummies

Post by wriedmann »

Hi Dick,
on he page there is another zip that contains only binaries and there are also the referenced libraries.
I would use ILSpy on that executable to see the code.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1582
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

C#->X# for dummies

Post by FFF »

Dick, Wolfgang,
thx for your assistance. The app provides a UI to access one's Tesla vehicle, using an API by Tesla. Since the first thing it requests are my credentials to "log in" to the car, i.e. the "general key" to it, i wanted to see in code, what it really does - i don't expect something nasty, but better safe than sorry ;)
I got me the zip and had a look with ILSpy, but somehow didn't manage to make ILSpy emit the transformed code. (You see, Wolfgang, dummy is correct...). Yes i can read C#, but as i'm also not very familiar with WPF, i hoped to make my life easier.

As for "not compile", i don't understand what's happening, as the exe indeed runs without any installation - i simply unpacked. But then i should login, and here i stopped...
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

C#->X# for dummies

Post by ic2 »

Hello Karl,

I unpacked the zip you attached. It is probably incomplete compared to the GitHub link.

Basically the WPF starts in MainWindow.xaml where a user control is defined and from TessUiController.cs the control is filled with a login control. In the Style folder, they also define their own layout of controls like the Textbox, Slider, etc in terms of color, border etc.

I think WPF leaves much to be desired, especially in terms of how the design view interacts with the code. For example, I have a WPF ribbon (you can see how it looks like in the -yet to be finished- website photorganize.eu) and it is not possible to see the 2nd and 3rd tab in design view, as far as I know. Also, placing a control somewhere in the designer often doesn't turn out to show where you placed/expect it. In the meantime I have a bag of tricks to try solving that kind of issues but WPF can't be called programmers friendly. On the other hand, having the screens as Xaml code means, at least in theory, that you should be able to influence anything.

I am not sure what you read in ILSpy, but it should be either an .exe or a dll (not the zip). Unless it it obfuscated, which is not to be expected for a program with the sources on Github, you should see the code pretty much as it is in the original. But maybe they obfuscated one of the DLL's to prevent you from finding out how the access to a Tesla is done exactly.

If you have more (specific) questions, feel free to ask and I will reinstall from Github (if I don't need to login to get the full solution).

If you mail me your Tesla login credentials I could check if assigning 0 to the public int ChargeLimit (get/set) means you are unable to recharge your Tesla from then :lol:

Dick
FFF
Posts: 1582
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

C#->X# for dummies

Post by FFF »

Hi Dick,
maybe i have a fundamental misunderstanding here: i CAN see the code in ILSpy in "X#" syntax. And the only option vaguely pointing to "output" is "Save code" - so, i'd expect, as doing so writes a tess4windows.xsproj file, that i could load that in VS and see a x# project - but in reality the code presented is c#. ??
EDIT: now found, when i change in the save dlg to "*.prg" the result IS X#.
Is that as intended?
(FTR, using ILSpy version 6.2.1.6137)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
TerryB1
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

C#->X# for dummies

Post by TerryB1 »

Hi Karl

I can't help thinking this is all a bit complex.

I have attached a short PDF which gives my warped take on it all, and which I hope will help.

Terry
Attachments
Operation of .Net.pdf
(277.14 KiB) Downloaded 95 times
FFF
Posts: 1582
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

C#->X# for dummies

Post by FFF »

Sorry, Terry,
the question was more or less, if there's a little bug in IlSpy integration, causing the emittance of c# syntax to a *.xsproj file.
No need for planets ;)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

C#->X# for dummies

Post by ic2 »

Hello Karl,

FFF wrote: EDIT: now found, when i change in the save dlg to "*.prg" the result IS X#.
Is that as intended?
(FTR, using ILSpy version 6.2.1.6137)
Try opening your own written X# exe for better understanding. You will see References, Resources and your program divided as the different classes used in your product. All methods within that class appear as code in the right pane.

However, that is not necessarily how it was organized in your project. You may have put the code of e.g. 4 different classes in 1 .cs or .prg file. You could however save all code, class by class, using the suggested name (like MainWindow.cs /,prg). Then you create solution like in VS of the right kind of project, and you just select Add/ Existing item and select all the .prg/.cs files (where you can overwrite the default created code like MainWindow).

That should give you the solution which may compile, although I think you will have to add the references and resources yourself as the export in References is a prg/cs with comments telling what you references/added as resource.

Most likely you will have to do some (or a lot, that will depend) finishing before it actually runs.

I hope this helps.

Dick
Post Reply