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?

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]);
     }
    }
   }
  }