fbpx
× Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET

New to X# and need some direction

More
6 months 3 weeks ago #1 by Tom Szabo
New to X# and need some direction was created by Tom Szabo
Hi Guys,

This is my second day with X# and learned a fair bit but still lost. I would need some help.

Basically I need to access an MS-SQL Database and extract data and upload it using the access provided through the .NET SDK.

This is the SDK: developer.myob.com/api/accountright/arlive-sdk/dotnet_sdk/
that I need to use to upload the data

I am an old VO programmer that stuck with VO and just about to move to X# with this small project. I have already downloaded XIDE and also Vs but I think I will go with XIDE for the time being as long as I can utilise the above SDK.

I do not have Vulcan so do I need anything additional to install or XIDE installation is sufficient on its own for Native X#?

Any help and pointers will be greatly appriciated

Thanks again

Tom

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

More
6 months 3 weeks ago #2 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic New to X# and need some direction
Hi Tom,

you don't need any special runtime or similar - you can work with X# right out of the box.

Maybe you should search some C# samples and move them over to X#.

Please don't forget: as VO programmers we were almost alone, but with X# we are a part of the really large .NET world.

Wolfgang

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

More
6 months 3 weeks ago #3 by Johan Nel
Replied by Johan Nel on topic New to X# and need some direction

tom@dieselworks.com.au wrote:
Basically I need to access an MS-SQL Database and extract data and upload it using the access provided through the .NET SDK.

This is the SDK: developer.myob.com/api/accountright/arlive-sdk/dotnet_sdk/
that I need to use to upload the data

Here is a quick and dirty translate from the above website. Remember it is C# which use ";" as end of statement, so we need to remove that. All "new" keywords basically mean creation of object, X# like VO uses {}, so we need to change () to {} except where it is a method call where () is used the same. C# also use "=" for assignments, X#/VO use ":="
using MYOB.AccountRight.SDK
using MYOB.AccountRight.SDK.Services
using MYOB.AccountRight.SDK.Contracts

var configuration := ApiConfiguration{"http://localhost:8080/accountright"}
var cfService := CompanyFileService{configuration}
var companyFiles := cfService.GetRange()

//Next step in the flow is to select a company file that supports v2 contracts
// for the AccountRight API - anything from 2013.3 and up will do here.
var companyFile := companyFiles.FirstOrDefault({x => Version{x.ProductVersion} >= Version{"2013.3"}})

//The company file credentials are an AccountRight requirement with the SDK providing the 
//CompanyFileCredentials class to encapsulate these. For our example the company file 
//login details in use are username: Administrator with no password on the admin account.
var credentials := CompanyFileCredentials{"Administrator",""}

//Now you are ready to start accessing resources directly from the API
var accountService := AccountService{configuration}
var accounts := accountService.GetRange(companyFile,null,credentials)

I do not have Vulcan so do I need anything additional to install or XIDE installation is sufficient on its own for Native X#?

No you need nothing extra, XIDE as it is can even be an editor for c# and Harbour. You just need to tell it the Application is of that type.
Only thing you have to do is in your MYOB interface application Add a reference to the MYOB Assembly. You will have to do this also in VS.

Hope this helps.

______________________
Johan Nel
George, South Africa

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

More
6 months 3 weeks ago #4 by Tom Szabo
Replied by Tom Szabo on topic New to X# and need some direction
Thanks VM Johan, Can you tell me when I install the XIDE, it also asks me if I like to install the Community Edition of the VS. Installing the VS which options do I need to select ? TIA Tom

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

More
6 months 3 weeks ago #5 by Johan Nel
Replied by Johan Nel on topic New to X# and need some direction

tom@dieselworks.com.au wrote:
Thanks VM Johan, Can you tell me when I install the XIDE, it also asks me if I like to install the Community Edition of the VS. Installing the VS which options do I need to select ?


If you already have VS, then you don't need to install it again. Just make sure you install XIDE. It wont' hurt to install the VS Community if you don't have VS installed yet.

Regards,

______________________
Johan Nel
George, South Africa

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

More
6 months 3 weeks ago #6 by Tom Szabo
Replied by Tom Szabo on topic New to X# and need some direction
Ok, getting close :-)One more question: "Add a reference to the MYOB Assembly" - how do I do this?

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

More
6 months 3 weeks ago #7 by Karl Faller
Replied by Karl Faller on topic New to X# and need some direction
Hi Tom,
in Xide, in the Projectpane, there's an entry References unter each app in the tree. Rightclick, "Add reference", point in the dialog to the assembly you need.

Karl

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

More
6 months 3 weeks ago #8 by Tom Szabo
Replied by Tom Szabo on topic New to X# and need some direction
Ah well, still a prob: I have installed the package in VS -> Install-package MYOB.AccountRight.API.SDK - and I can see it, it installed into the default app in VS - but I can't see it from XIDE

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

More
6 months 3 weeks ago #9 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic New to X# and need some direction
Hi Tom,

Visual Studio uses NuGet to retrieve the packages, XIDE cannot do that.

In these cases I use an VS project to download the references, copy the assemblies away and add them to the XIDE project.

Wolfgang

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

More
6 months 3 weeks ago #10 by Karl Faller
Replied by Karl Faller on topic New to X# and need some direction
Wolfgang,
i have no clue about Nuget, but it seems there's a commandline version available, maybe one could use this for a Xide-extension? Just a thought ;)

Karl

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

More
6 months 3 weeks ago #11 by Johan Nel
Replied by Johan Nel on topic New to X# and need some direction
Hi Tom,

tom@dieselworks.com.au wrote:
and I can see it, it installed into the default app in VS - but I can't see it from XIDE

Not sure if I miss the point, but look at the attached screenshot. The browse tab let you add a reference from any directory. Press the browse disk for dll files. Go to where VS installed it and voila.
Regards,

______________________
Johan Nel
George, South Africa
Attachments:

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

More
6 months 3 weeks ago #12 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic New to X# and need some direction
Hi Karl,

of course one could use this - but unfortunately I have no experience with this.

Until now I have created a C# project, added the libraries there and copied them over to my X# project.

Wolfgang

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

More
6 months 3 weeks ago #13 by Tom Szabo
Replied by Tom Szabo on topic New to X# and need some direction
Thanks for all the comments, I have progressed ore than I expected but have got stuck again and this time it is getting more interesting. So far I have got XIDE working in native , loaded the relevant sample form app and got it running. In VS have loaded the MYOM SDK and managed to get it working. Wow!
Through VS I am able to connect to MYOB, the C# sample app returns the datafile info so I know it works to some extent but fails to compile and run when I have these two lines:
var accountService = new AccountService(configuration);
var accounts = accountService.GetRange(companyFile, null, credentials);


Just for reference, this is the full code posted on the MYOB site:

using MYOB.AccountRight.SDK;
using MYOB.AccountRight.SDK.Services;
using MYOB.AccountRight.SDK.Contracts;

var configuration = new ApiConfiguration("http://localhost:8080/accountright");
var cfService = new CompanyFileService(configuration);
var companyFiles = cfService.GetRange();
var companyFile = companyFiles.FirstOrDefault(x => new Version(x.ProductVersion) >= new Version("2013.3"));
var credentials = new CompanyFileCredentials("Administrator", "muffin023H");
var accountService = new AccountService(configuration);
var accounts = accountService.GetRange(companyFile, null, credentials);


so if I comment out the last two lines of code it works, and no error, but if included I get this error :

Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'AccountService' could not be found (are you missing a using directive or an assembly reference?) WindowsFormsApp1 C:\Users\intersoft.SBS\source\repos\WindowsFormsApp1\WindowsFormsApp1\Program.cs 30 Active


In X# in XIDE I do not get this far unfortunately.
Using the same code if complains about JSON is missing, which is strange as with exact same inclusion C# in VS doesn't complain and goes a few lines further

Just puzzled a little :-(
Attachments:

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

More
6 months 3 weeks ago #14 by Tom Szabo
Replied by Tom Szabo on topic New to X# and need some direction
Here is the actual code and error message:

#using System.Windows.Forms
#using System.Drawing

#using MYOB.AccountRight.SDK
#using MYOB.AccountRight.SDK.Services
#using MYOB.AccountRight.SDK.Contracts

===================================================================

METHOD OKButtonClick2() AS VOID

VAR configuration := ApiConfiguration{"http://localhost:8080/accountright"}
VAR cfService := CompanyFileService{configuration}
VAR companyFiles := cfService.GetRange()

//Next step in the flow is to select a company file that supports v2 contracts
// for the AccountRight API - anything from 2013.3 and up will do here.
//VAR companyFile := companyFiles.FirstOrDefault({x => Version{x.ProductVersion} >= Version{"2013.3"}})

//The company file credentials are an AccountRight requirement with the SDK providing the
//CompanyFileCredentials class to encapsulate these. For our example the company file
//login details in use are username: Administrator with no password on the admin account.
//VAR credentials := CompanyFileCredentials{"Administrator",""}

//Now you are ready to start accessing resources directly from the API
//VAR accountService := AccountService{configuration}
//VAR accounts := accountService.GetRange(companyFile,NULL,credentials)

RETURN

END CLASS

=================================================
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
MYOB.AccountRight.SDK.ApiOperationException: Encountered an operation error (http://localhost:8080/accountright) ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at MYOB.AccountRight.SDK.Extensions.JsonExtensions.FromJson[T](String data)
at MYOB.AccountRight.SDK.Communication.BaseRequestHandler.ExtractDetails[T](HttpWebResponse response, String& location, HttpStatusCode& statusCode) in c:\projects\accountright-live-api-net-sdk\MYOB.API.SDK\SDK\Communication\BaseRequestHandler.cs:line 152
at MYOB.AccountRight.SDK.Communication.BaseRequestHandler.HandleResponseCallback[T,TResp](IAsyncResult asynchronousResult) in c:\projects\accountright-live-api-net-sdk\MYOB.API.SDK\SDK\Communication\BaseRequestHandler.cs:line 122
--- End of inner exception stack trace ---
at MYOB.AccountRight.SDK.Extensions.ExceptionExtensions.ProcessException(Exception ex, Uri requestUri) in c:\projects\accountright-live-api-net-sdk\MYOB.API.SDK\SDK\Extensions\ExceptionExtensions.cs:line 31
at MYOB.AccountRight.SDK.Services.ServiceBase.MakeApiGetRequestSync[T](Uri uri, ICompanyFileCredentials credentials, String eTag) in c:\projects\accountright-live-api-net-sdk\MYOB.API.SDK\SDK\Services\ServiceBase.cs:line 151
at MYOB.AccountRight.SDK.Services.CompanyFileService.GetRange() in c:\projects\accountright-live-api-net-sdk\MYOB.API.SDK\SDK\Services\CompanyFileService.cs:line 45
at BasicForm.OKButtonClick2() in C:\XIDE\Projects\Tom_Test1\Applications\MYOB_Test1\Prg\Form1.prg:line 67
at BasicForm.OKButtonClick(Object sender, EventArgs e) in C:\XIDE\Projects\Tom_Test1\Applications\MYOB_Test1\Prg\Form1.prg:line 56
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
MYOB_Test1
Assembly Version: 0.0.0.0
Win32 Version: 0.0.0.0
CodeBase: file:///C:/XIDE/Projects/Tom_Test1/Bin/Debug/MYOB_Test1.exe
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
System
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
MYOB.AccountRight.SDK
Assembly Version: 2016.2.99.0
Win32 Version: 2016.2.99.0
CodeBase: file:///C:/XIDE/Projects/Tom_Test1/Bin/Debug/MYOB.AccountRight.SDK.DLL

************** JIT Debugging **************

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

More
6 months 3 weeks ago #15 by Johan Nel
Replied by Johan Nel on topic New to X# and need some direction
Hi Tom,

tom@dieselworks.com.au wrote:
System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


In XIDE it seems you copied the MYOB assembly to the XIDE path. However NewtonJSON is an assembly that MYOB reference, so get it into the same folder as your MYOB assembly and it would work.

Regards,
Johan

______________________
Johan Nel
George, South Africa

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

More
6 months 3 weeks ago #16 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic New to X# and need some direction
Hi Tom,

to understand what is going on, maybe you should read this article:
docs.xsharp.it/doku.php?id=namespace_assembly_reference

If something is not clear, please let me know, so I can make it clearer

Wolfgang

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

More
6 months 3 weeks ago #17 by Karl Faller
Replied by Karl Faller on topic New to X# and need some direction
Tom,
var accountService = new AccountService(configuration);
var accounts = accountService.GetRange(companyFile, null, credentials);
This should be: var accountService := AccountService{configuration}
var accounts = accountService:GetRange(companyFile, null, credentials)

Note the colon vs fullstop. My personal way of thinking is:
A "dot" is NOTHING special, it's a character like any other.
So, tom.dieselworks is simply a name.
The colon is an operator, so tom:dieselworks asks the compiler for the value which the property dieselworks of object tom holds at this moment.
Never understood why MS made such a fuss with "namespace". There's no such thing, it is only a convention to name things coherently...
(FTR, i know there's a small glitch in my argumentation as VO and unfortunately X# treat "structures" special, in using the dot for accessing members of strucs. Again, i see no reason why this made it into core - you have to declare strucs like objects, so the compiler knows what it has at hand and could handle this correctly, but this is getting OT <g>)

Karl

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

More
6 months 3 weeks ago #18 by Johan Nel
Replied by Johan Nel on topic New to X# and need some direction
Hi Karl,

FFF wrote:

var accountService = new AccountService(configuration);
var accounts = accountService.GetRange(companyFile, null, credentials);
This should be: var accountService := AccountService{configuration}
var accounts = accountService:GetRange(companyFile, null, credentials)

Note the colon vs fullstop. My personal way of thinking is:

Be careful what you say. If you look at Tom's code it is the c# version. you read it as "X#", so yes .GetRange should change to :GetRange in X#, but stay .GetRange in c#.

As I read his problem, he did not copy the NewtonJSON assembly also into his XIDE bin\debug folder, hence the MYOB assembly cannot find it.
Regards,
Regards,

______________________
Johan Nel
George, South Africa

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

More
6 months 3 weeks ago #19 by Karl Faller
Replied by Karl Faller on topic New to X# and need some direction
Johan,
i stand corrected, re-reading i see you are right. Sorry for confusing...

Karl
The following user(s) said Thank You: Johan Nel

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

More
6 months 3 weeks ago #20 by Tom Szabo
Replied by Tom Szabo on topic New to X# and need some direction
Thanks Johan, You are most likely right, the only issue I have is that I have no idea what to copy where? I have located two folders in the project that I have set up in C# / Vs and copied them over into a new folder under the XIDE test project. Then I set up the references.

Both of these, the MYOB and JSON has a number of subfolders and to be honest I have no clue what to do here. I have copied the v4.0 folder of the JSon DLL into the v4.0 version of MYOB SDK but I still have the message

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