Page 4 of 5

Re: Plugin Scheduler Service. File stays in pending

PostPosted: Wed Mar 04, 2020 11:04 am
by Mike.Sheen
SBarnes wrote:your suggested work around was create the form and it worked.


That must have been when I was much younger and more reckless.

Re: Plugin Scheduler Service. File stays in pending

PostPosted: Wed Mar 04, 2020 11:06 am
by SBarnes
:lol:

The code is still in use at the client's today.

Re: Plugin Scheduler Service. File stays in pending

PostPosted: Wed Mar 04, 2020 11:19 am
by DannyC
Changed the encoding to utf-8.
Still got the error during import. But it does work fine when doing XML Import via the GUI. Encoding doesn't seem to make a difference - even the utf-16 version imported OK via the GUI.

I am generating the XML file.
The client has a couple of different Jiwa databases. A purchase order from one database creates an XML file (via a plugin I've written) and is saved to disk. The user drops it into the watch folder and is imported as a sales order in a second database.
They generate the XML via a button on the ribbon and basically just does this:
Code: Select all
      string TextOut = "";
      TextOut = "<?xml  and so on.......  just trying to get around the forum software detection of XML
      foreach (JiwaFinancials.Jiwa.JiwaPurchaseOrders.Line poLine in purchOrder.Lines)
      {
         TextOut += "<Line>";
         TextOut += "<PartNo>" + poLine.SupplierPartNo + "</PartNo>";
         TextOut += "<QuantityOrdered>" + poLine.Quantity + "</QuantityOrdered>";
         TextOut += "</Line>";
      }
      TextOut += "</Lines></JiwaDocument>";
      
      return TextOut;


I guess there's a better way to generate the XML file?

And to answer Stuart's suggestion of changing the service logon account. Just tried & tested. Still the same error.

Re: Plugin Scheduler Service. File stays in pending

PostPosted: Wed Mar 04, 2020 11:35 am
by SBarnes
Why could you not either

A. Use the Rest API and do it live.

or

B. Again do it live by log on to the other Jiwa and create the sales order

In other words why use a file at all?

Re: Plugin Scheduler Service. File stays in pending

PostPosted: Wed Mar 04, 2020 11:50 am
by Mike.Sheen
DannyC wrote:I am generating the XML file.


The error you get - "There is an error in XML document (1, 1)" means the XML deserializer is upset with the very first character of your xml file.

You should specify the encoding of the file to be UTF-16 when you write it - some good examples of that can be seen here.

That'll put the BOM (byte order mark) in the first few bytes of the file, and then fussy XML deserializers shouldn't complain.

Joel Spolsky has a nice and oft cited article on this topic, which is worth a read in case you're bewildered how something which should be so simple isn't: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

Re: Plugin Scheduler Service. File stays in pending

PostPosted: Wed Mar 04, 2020 12:54 pm
by DannyC
You should specify the encoding of the file to be UTF-16 when you write it

Tried that via
Code: Select all
System.IO.File.WriteAllText(purchOrderForm.DialogSave.FileName,XMLFileContents,System.Text.Encoding.Unicode)


The file opens cleanly in IE (it didn't previously) and also XMLPad, Notepad++ etc.

I thought we were on a winner, until I tried importing it & it still generated that log error. So I tried saving the file encoded as utf-8, with the XML tag also specifying same.
Code: Select all
System.IO.File.WriteAllText(purchOrderForm.DialogSave.FileName,XMLFileContents,System.Text.Encoding.UTF8)


Copied the file to the Watch folder. Still no go. The error still appears in the log
There is an error in XML document (1, 1).

As far as I can tell, there's some kind of corruption with Windows on this server.
a different version of some .NET component or something
I think I'll just ditch running the plugin scheduler service on this server & try on a different server. Fortunately this client has a TS server and a SQL server. The service is running on their TS server. I'll get it running on the SQL server and see what transpires.

Re: Plugin Scheduler Service. File stays in pending

PostPosted: Wed Mar 04, 2020 1:05 pm
by Mike.Sheen
DannyC wrote:As far as I can tell, there's some kind of corruption with Windows on this server.


When you earlier said you could import the file from the sales order form ok - was that running on the same machine as the one the Plugin Scheduler service that was having the problem?

Re: Plugin Scheduler Service. File stays in pending

PostPosted: Wed Mar 04, 2020 1:16 pm
by DannyC
Yep, service & Jiwa client running on same machine.

I think this issue may remain a mystery. Stuart has come up with a much better solution.
Based on viewtopic.php?f=27&t=491 I will just create a sales order in the other database. No need for a file.

Give me a few hours to knock up that code & we'll see how it goes.

Danny

Re: Plugin Scheduler Service. File stays in pending

PostPosted: Wed Mar 04, 2020 3:53 pm
by DannyC
Give me a few hours to knock up that code & we'll see how it goes.

Bingo!

Works in test, so I will deploy to their live database & get the users to test it.

EDIT: 1 day later, users have tested & we're good!
So now, instead of exporting a XML file, dropping it into Watch & hoping the service hasn't hung/stopped/or this weird mystery with the encoding or whatever, I'm just hooking into the second database & creating the sales order.

So the original issue remains but this workaround is actually a better solution.

Re: Plugin Scheduler Service. File stays in pending

PostPosted: Thu Mar 26, 2020 5:16 pm
by DannyC
This issue has reared its ugly head again.
Different client, different problem I'm trying to solve.

Once again, I am trying to use the salesOrder.deserialise method to import an XML file but am stuck on this error again.

Encoding is fine. I can open the file successfully in Notepad, Notepad++, HxD, XMLPad.

Maybe it's a .Net thing on my laptop?