Does anyone know of a way to tell if a XML generation is complet

Try this
protected virtual bool IsFileLocked(FileInfo file)
        {
            FileStream stream = null;


            try
            {

                stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
            }
            catch (IOException ex)
            {

                //the file is unavailable because it is:

                //still being written to

                //or being processed by another thread
                //or does not exist (has already been processed)
                
                this.Invoke((ThreadStart)delegate()
                   {
                       lblpacket.Text = ex.Message;
                   }
               );

                return true;

            }
            finally

            {
                if (stream != null)

                    stream.Close();

            }

            //file is not locked
            return false;

        }


Jose C Gomez
Software Engineer


T: 904.469.1524 mobile


Quis custodiet ipsos custodes?


On Fri, Mar 7, 2014 at 4:50 PM, <livingstonmh@...> wrote:

 
<div>
  
  
  <p></p><p>Well the file we need to check is the actual XML file created by Epicor from the Sales Order Pick List. We have code set up that uses that XML file to build a separate XML file with picking quantities with custom logic. The first step that is performed is a button click that tells SOPick to generate the data. The next Button is print that goes through this generated file. If the user clicks it too soon, then a End of file Expected error pops up, or URL cannot be Null Error. The users requested that the Print Button not even be enabled until the XML is done, but I guess the developer dropped that idea.</p>

 

This is the code that is in use that reads that XML file:

 private void generateHelperXML()
 {
  Epicor.Mfg.Core.Session epiSession = default(Epicor.Mfg.Core.Session);
  epiSession = (Epicor.Mfg.Core.Session)SOPickListForm.Session;

  string lastfile = "";
  DateTime lastmod = DateTime.MinValue;

  string[] files = Directory.GetFiles(@"\\\\server\\EpicorData\\Reports\\" + epiSession.UserID , "SO Pick list*.xml");

  if(files.Length>0)
  {
   for(int i = 0; i<files.Length; i++)
   {
    if(lastfile == "")
    {
     lastfile = files[i].ToString();
     lastmod = File.GetLastWriteTime(files[i]);

    }
    else
    {
     if(File.GetLastWriteTime(files[i]) > lastmod)
     {
      lastfile = files[i].ToString();
      lastmod = File.GetLastWriteTime(files[i]);
     }
    }
   }
  }

</div>
 


<div style="color:#fff;min-height:0;"></div>


We have some custom code on a report to add information to an XML file to use in a crystal report.

 

What happens is the user generates the file, and the prints with another button.

 

We are experiencing errors when the user clicks Print before the XML finishes generating.

 

Does anyone know of a way to tell if a XML generation is complete or not? Would there be a way to tie into the system monitor to find this out?

<!-- #ygrps-yiv-1654679048 _filtered #ygrps-yiv-1654679048 {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0;} _filtered #ygrps-yiv-1654679048 {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0;} _filtered #ygrps-yiv-1654679048 {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} _filtered #ygrps-yiv-1654679048 {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4;} _filtered #ygrps-yiv-1654679048 {font-family:Consolas; panose-1:2 11 6 9 2 2 4 3 2 4;} _filtered #ygrps-yiv-1654679048 {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4;} #ygrps-yiv-1654679048 #ygrps-yiv-1654679048 p.ygrps-yiv-1654679048MsoNormal, #ygrps-yiv-1654679048 li.ygrps-yiv-1654679048MsoNormal, #ygrps-yiv-1654679048 div.ygrps-yiv-1654679048MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman", "serif";} #ygrps-yiv-1654679048 a:link, #ygrps-yiv-1654679048 span.ygrps-yiv-1654679048MsoHyperlink { color:blue; text-decoration:underline;} #ygrps-yiv-1654679048 a:visited, #ygrps-yiv-1654679048 span.ygrps-yiv-1654679048MsoHyperlinkFollowed { color:purple; text-decoration:underline;} #ygrps-yiv-1654679048 p {

margin-right:0in;

margin-left:0in;
font-size:12.0pt;
font-family:“Times New Roman”, “serif”;}
#ygrps-yiv-1654679048 code
{
font-family:“Courier New”;}
#ygrps-yiv-1654679048 pre
{

margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:“Courier New”;}
#ygrps-yiv-1654679048 tt
{
font-family:“Courier New”;}
#ygrps-yiv-1654679048 span.ygrps-yiv-1654679048HTMLPreformattedChar
{

font-family:“Consolas”, “serif”;}
#ygrps-yiv-1654679048 p.ygrps-yiv-1654679048attach, #ygrps-yiv-1654679048 li.ygrps-yiv-1654679048attach, #ygrps-yiv-1654679048 div.ygrps-yiv-1654679048attach
{

margin-right:0in;

margin-left:0in;
font-size:9.0pt;
font-family:“Arial”, “sans-serif”;}
#ygrps-yiv-1654679048 p.ygrps-yiv-1654679048bold, #ygrps-yiv-1654679048 li.ygrps-yiv-1654679048bold, #ygrps-yiv-1654679048 div.ygrps-yiv-1654679048bold
{

margin-right:0in;

margin-left:0in;
font-size:10.0pt;
font-family:“Arial”, “sans-serif”;
font-weight:bold;}
#ygrps-yiv-1654679048 p.ygrps-yiv-1654679048green, #ygrps-yiv-1654679048 li.ygrps-yiv-1654679048green, #ygrps-yiv-1654679048 div.ygrps-yiv-1654679048green
{

margin-right:0in;

margin-left:0in;
font-size:12.0pt;
font-family:“Times New Roman”, “serif”;
color:#628C2A;}
#ygrps-yiv-1654679048 p.ygrps-yiv-1654679048replbq, #ygrps-yiv-1654679048 li.ygrps-yiv-1654679048replbq, #ygrps-yiv-1654679048 div.ygrps-yiv-1654679048replbq
{
margin:3.0pt;
font-size:12.0pt;
font-family:“Times New Roman”, “serif”;}
#ygrps-yiv-1654679048 p.ygrps-yiv-1654679048ad, #ygrps-yiv-1654679048 li.ygrps-yiv-1654679048ad, #ygrps-yiv-1654679048 div.ygrps-yiv-1654679048ad
{

margin-right:0in;

margin-left:0in;
font-size:12.0pt;
font-family:“Times New Roman”, “serif”;}
#ygrps-yiv-1654679048 p.ygrps-yiv-1654679048underline, #ygrps-yiv-1654679048 li.ygrps-yiv-1654679048underline, #ygrps-yiv-1654679048 div.ygrps-yiv-1654679048underline
{

margin-right:0in;

margin-left:0in;
font-size:12.0pt;
font-family:“Times New Roman”, “serif”;}
#ygrps-yiv-1654679048 span.ygrps-yiv-1654679048yshortcuts
{}
#ygrps-yiv-1654679048 p.ygrps-yiv-1654679048ad1, #ygrps-yiv-1654679048 li.ygrps-yiv-1654679048ad1, #ygrps-yiv-1654679048 div.ygrps-yiv-1654679048ad1
{

margin-right:0in;

margin-left:0in;
font-size:12.0pt;
font-family:“Times New Roman”, “serif”;}
#ygrps-yiv-1654679048 p.ygrps-yiv-1654679048ad2, #ygrps-yiv-1654679048 li.ygrps-yiv-1654679048ad2, #ygrps-yiv-1654679048 div.ygrps-yiv-1654679048ad2
{

margin-right:0in;
margin-bottom:7.5pt;
margin-left:0in;
font-size:12.0pt;
font-family:“Times New Roman”, “serif”;}
#ygrps-yiv-1654679048 p.ygrps-yiv-1654679048underline1, #ygrps-yiv-1654679048 li.ygrps-yiv-1654679048underline1, #ygrps-yiv-1654679048 div.ygrps-yiv-1654679048underline1
{

margin-right:0in;

margin-left:0in;
font-size:12.0pt;
font-family:“Times New Roman”, “serif”;
text-decoration:underline;}
#ygrps-yiv-1654679048 span.ygrps-yiv-1654679048yshortcuts1
{
font-family:“Verdana”, “sans-serif”;
font-weight:bold;}
#ygrps-yiv-1654679048 span.ygrps-yiv-1654679048yshortcuts2
{
font-family:“Verdana”, “sans-serif”;
font-weight:normal;}
#ygrps-yiv-1654679048 span.ygrps-yiv-1654679048EmailStyle34
{
font-family:“Calibri”, “sans-serif”;
color:#1F497D;}
#ygrps-yiv-1654679048 .ygrps-yiv-1654679048MsoChpDefault
{
font-size:10.0pt;}
_filtered #ygrps-yiv-1654679048 {
margin:1.0in 1.0in 1.0in 1.0in;}
#ygrps-yiv-1654679048 div.ygrps-yiv-1654679048WordSection1
{}
#ygrps-yiv-1654679048
_filtered #ygrps-yiv-1654679048 {
}
_filtered #ygrps-yiv-1654679048 {

font-family:Symbol;}
_filtered #ygrps-yiv-1654679048 {

font-family:“Courier New”;
}
_filtered #ygrps-yiv-1654679048 {

font-family:Wingdings;}
_filtered #ygrps-yiv-1654679048 {

font-family:Wingdings;}
_filtered #ygrps-yiv-1654679048 {

font-family:Wingdings;}
_filtered #ygrps-yiv-1654679048 {

font-family:Wingdings;}
_filtered #ygrps-yiv-1654679048 {

font-family:Wingdings;}
_filtered #ygrps-yiv-1654679048 {

font-family:Wingdings;}
_filtered #ygrps-yiv-1654679048 {

font-family:Wingdings;}
#ygrps-yiv-1654679048 ol
{margin-bottom:0in;}
#ygrps-yiv-1654679048 ul
{margin-bottom:0in;}
–>

Can’t answer your direct question, but I can make a suggestion that MIGHT help…Can you put code for a timer to not enable the button for printing until after x seconds from generation? Do you know about how long it takes for the XML to generate?

 

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of livingstonmh@…
Sent: Friday, March 07, 2014 11:34 AM
To: vantage@yahoogroups.com
Subject: [Vantage] Does anyone know of a way to tell if a XML generation is complete or not with C#?

 

 


We have some custom code on a report to add information to an XML file to use in a crystal report.

 

What happens is the user generates the file, and the prints with another button.

 

We are experiencing errors when the user clicks Print before the XML finishes generating.

 

Does anyone know of a way to tell if a XML generation is complete or not? Would there be a way to tie into the system monitor to find this out?

How are you adding the data to the xml file?  Depending on on how you are adding it you might be able to run it synchronously so that it doesn't give control back until it is done.

Again not knowing how you are building the XML you can put a file-watcher on the file (standard .net event) to trap when the file is complete.

If you are using the report/task agent to run the report there are ways to submit the item and track its completion.  I'd have to dig up the code.

Jim Kinneman
Encompass Solutions, Inc
You can check to see if the file is locked using code and if it is, sleep for a second then check again.



Jose C Gomez
Software Engineer



T: 904.469.1524 mobile


Quis custodiet ipsos custodes?


On Fri, Mar 7, 2014 at 2:24 PM, <jckinneman@...> wrote:

 
<div>
  
  
  <p>How are you adding the data to the xml file?&nbsp; Depending on on how you are adding it you might be able to run it synchronously so that it doesn&#39;t give control back until it is done.<br><br>Again not knowing how you are building the XML you can put a file-watcher on the file (standard .net event) to trap when the file is complete.<br>


If you are using the report/task agent to run the report there are ways to submit the item and track its completion.  I'd have to dig up the code.

Jim Kinneman
Encompass Solutions, Inc

</div>
 


<div style="color:#fff;min-height:0;"></div>

Well the file we need to check is the actual XML file created by Epicor from the Sales Order Pick List. We have code set up that uses that XML file to build a separate XML file with picking quantities with custom logic. The first step that is performed is a button click that tells SOPick to generate the data. The next Button is print that goes through this generated file. If the user clicks it too soon, then a End of file Expected error pops up, or URL cannot be Null Error. The users requested that the Print Button not even be enabled until the XML is done, but I guess the developer dropped that idea.

 

This is the code that is in use that reads that XML file:

 private void generateHelperXML()
 {
  Epicor.Mfg.Core.Session epiSession = default(Epicor.Mfg.Core.Session);
  epiSession = (Epicor.Mfg.Core.Session)SOPickListForm.Session;
  string lastfile = "";
  DateTime lastmod = DateTime.MinValue;

  string[] files = Directory.GetFiles(@"\\\\server\\EpicorData\\Reports\\" + epiSession.UserID , "SO Pick list*.xml");
  if(files.Length>0)
  {
   for(int i = 0; i<files.Length; i++)
   {
    if(lastfile == "")
    {
     lastfile = files[i].ToString();
     lastmod = File.GetLastWriteTime(files[i]);
    }
    else
    {
     if(File.GetLastWriteTime(files[i]) > lastmod)
     {
      lastfile = files[i].ToString();
      lastmod = File.GetLastWriteTime(files[i]);
     }
    }
   }
  }