fbpx
Welcome, Guest
Username: Password: Remember me

TOPIC:

C#->X# for dummies 20 Jan 2021 21:21 #17244

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 1082
  • Guys,
    got me from 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
     

    File Attachment:

    File Name: Tess4Windows-001.zip
    File Size:716 KB
    Regards
    Karl (X# 2.7; Xide 1.27; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 21 Jan 2021 07:14 #17246

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2524
  • 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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 21 Jan 2021 18:18 #17254

  • ic2's Avatar

  • ic2


  • Posts: 855
  • 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:\ccodeSamples\KarlPrg\UserControls\ChooseUiController.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

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 21 Jan 2021 18:22 #17255

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2524
  • 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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 21 Jan 2021 18:41 #17256

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 1082
  • 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 (X# 2.7; Xide 1.27; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 21 Jan 2021 20:53 #17257

  • ic2's Avatar

  • ic2


  • Posts: 855
  • 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

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 21 Jan 2021 21:58 #17258

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 1082
  • 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 (X# 2.7; Xide 1.27; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    Last edit: by FFF.

    C#->X# for dummies 22 Jan 2021 16:45 #17263

  • Terry's Avatar

  • Terry


  • Posts: 216
  • 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

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 22 Jan 2021 16:55 #17264

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 1082
  • 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 (X# 2.7; Xide 1.27; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 25 Jan 2021 23:30 #17295

  • ic2's Avatar

  • ic2


  • Posts: 855
  • 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

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 26 Jan 2021 18:04 #17297

  • Fabrice's Avatar

  • Fabrice


  • Posts: 97
  • Hi Karl,
    thanks for your feedback.
    Unfortunately, this feature hasn't been implemented right now as it is indicated in the Readme.md in the GitHub repository.
    This is one of the numerous things I will need to complete :)

    Cheers,
    Fab

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 26 Jan 2021 20:02 #17298

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 1082
  • Hi Fabrice,
    thx for jumping in. Do you mean this: "WholeProject decompilation is currently not supported"?
    Didn't understand that as influencing export ;->
    Ok, glad to know it's not my usual stupidity...
    Regards
    Karl (X# 2.7; Xide 1.27; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 27 Jan 2021 15:23 #17319

  • Fabrice's Avatar

  • Fabrice


  • Posts: 97
  • Karl,

    yes, my "Documentation" is may be not really self-explanatory, sorry ! :)

    I'm currrently extracting all files, but recreating the xsproj is not fonctionnal right now.

    Regards
    Fab

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 03 Feb 2021 08:34 #17364

  • Horst's Avatar

  • Horst


  • Posts: 230
  • Hallo
    I try to compile this little C# Code and wanna later decompile it to X# with IlSpy
    The compiler dont find SwissQRCode,QRCode but i have the dll in the ref list and also the using, what i am doing wrong ?
    Horst

    using System;
    using QRCoder;

    public class Program
    {
    static void Main()
    {
    System.Console.WriteLine("Hello XIDE from c#!");

    //Anlegen der Kontaktdaten
    SwissQrCode.Contact contactGeneral = new SwissQrCode.Contact("John Doe", "3003", "Bern", "CH", "Parlamentsgebäude", "1");
    //Anlegen der IBAN
    SwissQrCode.Iban iban = new SwissQrCode.Iban("CH2609000000857666015", PayloadGenerator.SwissQrCode.Iban.IbanType.Iban);
    //Anlegen der Referenz
    SwissQrCode.Reference reference = new SwissQrCode.Reference(SwissQrCode.Reference.ReferenceType.QRR, "990005000000000320071012303", SwissQrCode.Reference.ReferenceTextType.QrReference);
    //Festlegen der Währung und Summe
    SwissQrCode.Currency currency = SwissQrCode.Currency.CHF;
    decimal amount = 100.25m;

    //Erstellung der Swiss QR Code Payload
    SwissQrCode generator = new SwissQrCode(iban, currency, contactGeneral, reference, null, amount, null, null);
    string payload = generator.ToString();

    //QR-Code Generator erzeugen
    QRCodeGenerator qrGenerator = new QRCodeGenerator();
    //Swiss QR Code payload in QR code format bringen
    QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.M);
    //Rohdaten-QR-Code erzeugen
    QRCode qrCode = new QRCode(qrCodeData);
    //Swiss-QR-Code-Bild aus Rohdaten erzeugen
    Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.Black, Color.White, (Bitmap)Bitmap.FromFile(Application.StartupPath + "\\CH-Kreuz_7mm.png"), 14, 1);
    }
    }

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 03 Feb 2021 09:18 #17365

  • Chris's Avatar

  • Chris


  • Posts: 2350
  • Hi Horst,

    What is the exact error message and for which line is it being reported?
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 03 Feb 2021 09:30 #17366

  • Horst's Avatar

  • Horst


  • Posts: 230
  • Hi Chris

    Message CS0246
    And starts -> SwissQrCode.Contact contactGeneral = new SwissQrCode.Contact("Jo......
    and every following line

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 03 Feb 2021 09:37 #17367

  • Horst's Avatar

  • Horst


  • Posts: 230
  • Hi Chris

    I made a viaef
    Attachments:

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 03 Feb 2021 11:14 #17370

  • Horst's Avatar

  • Horst


  • Posts: 230
  • Hi ChrisUpps was the wrong one zip :-)

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 03 Feb 2021 11:45 #17371

  • Chris's Avatar

  • Chris


  • Posts: 2350
  • Hi Horst,

    Unfortunately I cannot compile this, because I do not have the dll...
    What is the exact error message you are getting?
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    C#->X# for dummies 03 Feb 2021 12:21 #17372

  • Horst's Avatar

  • Horst


  • Posts: 230
  • Hi Chris

    I made a screenshot
    Attachments:

    Please Log in or Create an account to join the conversation.