Language: VB.NET
test
1: ''' <summary> 2: ''' Generates the Batch XML from the passed connection. 3: ''' </summary> 4: ''' <param name="DBConn">KC Database Connection.</param> 5: ''' <param name="BatchXMLFileName">File Name to export Batch XML to.</param> 6: ''' <remarks>This is the kickoff point to generate the Batch XML file.</remarks> 7: Public Sub GenerateBatchXML(ByRef DBConn As Kofax.IKfxDb.IKfxConnection, ByVal BatchXMLFileName As String) 8: 9: My.Application.LogFuncEntry("GenerateBatchXML") 10: 11: 'Every time this is run, a new XML Document is created. 12: oXMLDoc = New XmlDocument 13: 14: 'These elements are required for all XML Import Connector files. 15: Dim xImportSession = oXMLDoc.CreateElement("ImportSession") 16: oXMLDoc.AppendChild(xImportSession) 17: 18: 'MP - 7/29/2008 - Added support for User ID/Password. 19: If bSpecifyCredentials Then 20: xImportSession.SetAttribute("UserID", sUserName) 21: xImportSession.SetAttribute("Password", sPassword) 22: End If 23: 24: Dim xBatches = oXMLDoc.CreateElement("Batches") 25: xImportSession.AppendChild(xBatches) 26: 27: Dim xBatch = oXMLDoc.CreateElement("Batch") 28: xBatches.AppendChild(xBatch) 29: 30: My.Application.Log.WriteEntry("Reading Batch Data (Name, Description, Priority).", TraceEventType.Verbose) 31: 32: 'Populate the Name, Description and Priority of the original batch. 33: Dim BatchDefID As Integer = Nothing 34: With DBConn.GetDataReader("SELECT Name, Description, Priority, BatchDefID FROM Batch WHERE BatchID=" & CurrentBatchID & ";") 35: 36: 'MP - 8/12/2008 - Wrap these settings in Try statements to deal with the fact that some items can be blank. 37: Try 38: xBatch.SetAttribute("Name", "" & .GetFieldValue(0)) 39: Catch 40: xBatch.SetAttribute("Name", Nothing) 41: End Try 42: Try 43: xBatch.SetAttribute("Description", .GetFieldValue(1)) 44: Catch 45: xBatch.SetAttribute("Description", Nothing) 46: End Try 47: Try 48: xBatch.SetAttribute("Priority", .GetFieldValue(2)) 49: Catch ex As Exception 50: xBatch.SetAttribute("Priority", Nothing) 51: End Try 52: 53: BatchDefID = Integer.Parse(.GetFieldValue(3).ToString) 54: .CloseReader() 55: End With 56: 57: My.Application.Log.WriteEntry("Reading Batch Definition Data (Batch Class Name).", TraceEventType.Verbose) 58: 59: 'Go to the BatchDef table for the Batch Class Name. 60: With DBConn.GetDataReader("SELECT Name FROM BatchDef WHERE BatchDefID=" & BatchDefID & ";") 61: xBatch.SetAttribute("BatchClassName", .GetFieldValue(0)) 62: .CloseReader() 63: End With 64: 65: 'It is debatable as to whether this should be set each time, but 95% of the time, it is set. 66: 'xBatch.SetAttribute("EnableAutomaticSeparationAndFormID", "1") 67: 68: My.Application.Log.WriteEntry("Generating Batch Fields XML.", TraceEventType.Verbose) 69: 'Get the Batch level Index Fields. At the top purely for neatness. 70: Dim xBatchFields = GetBatchIndexFields(DBConn) 71: If xBatchFields.ChildNodes.Count > 0 Then 72: xBatch.AppendChild(xBatchFields) 73: End If 74: 75: My.Application.Log.WriteEntry("Generating Batch Folders XML.", TraceEventType.Verbose) 76: 'Get the Folder structure. 77: Dim xFolders = GetFoldersElement(DBConn) 78: If xFolders.ChildNodes.Count > 0 Then 79: xBatch.AppendChild(xFolders) 80: End If 81: 82: My.Application.Log.WriteEntry("Generating Batch Documents XML.", TraceEventType.Verbose) 83: 'Generate the Documents element under the Batch. 84: Dim xDocuments = GetDocumentsElement(DBConn) 85: If xDocuments.ChildNodes.Count > 0 Then 86: xBatch.AppendChild(xDocuments) 87: End If 88: 89: My.Application.Log.WriteEntry("Generating Batch Loose Pages XML.", TraceEventType.Verbose) 90: 'Get the Pages within the Batch. 91: Dim xPages = GetPagesElement(DBConn) 92: If xPages.ChildNodes.Count > 0 Then 93: xBatch.AppendChild(xPages) 94: End If 95: 96: My.Application.Log.WriteEntry("Saving Batch XML.", TraceEventType.Verbose) 97: 98: 'Save the XML file to the passed file name and clean up. 99: oXMLDoc.Save(BatchXMLFileName) 100: oXMLDoc = Nothing 101: 102: My.Application.LogFuncExit("GenerateBatchXML") 103: End Sub
by
February 08, 2010 @ 2:47pm
February 08, 2010 @ 2:47pm
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

