private static System.Data.DataTable QueryOnBase() { var extractCustomQueryName = System.Configuration.ConfigurationManager.AppSettings["extractCustomQueryName"]; if (!Int32.TryParse(System.Configuration.ConfigurationManager.AppSettings["numberOfDaysExtracted"], out Int32 numberOfDaysExtracted)) { Log.Logger.Warning("numberOfDaysExtracted in Config is invalid! Defaulting to 30 days!"); numberOfDaysExtracted = 30; } if (!Int32.TryParse(System.Configuration.ConfigurationManager.AppSettings["maxQueryDocuments"], out Int32 maxQueryDocuments)) { Log.Logger.Warning("maxQueryDocuments in Config is invalid! Defaulting to 10,000 documents!"); maxQueryDocuments = 10000; } System.Data.DataTable table = SetupTable(); using (Application obApp = OnBaseConnect()) { DocumentQuery docQuery = obApp.Core.CreateDocumentQuery(); CustomQuery extractCQ = obApp.Core.CustomQueries.Find(extractCustomQueryName); if (extractCQ != null) { Log.Logger.Debug(String.Format("Custom Query Found: {0}", extractCustomQueryName)); docQuery.AddCustomQuery(extractCQ); DateTime endTime = DateTime.Now; DateTime startTime = endTime.AddDays(-1 * numberOfDaysExtracted); docQuery.AddDateRange(startTime, endTime); DocumentList docList = docQuery.Execute(maxQueryDocuments); foreach (Document doc in docList) { Log.Logger.Debug("Doc: {docId} - {docName}", doc.ID, doc.Name); Form form = obApp.Core.GetDocumentByID(doc.ID).UnityForm; if (form != null) { HomeEquityApplication heApplication = new HomeEquityApplication(doc, form); table.Rows.Add(heApplication.RowDataArray()); } } } else { Log.Logger.Error("Custom Query NOT Found: {extractCustomQueryName}", extractCustomQueryName); } } return(table); }
private static System.Data.DataTable QueryOnBase() { System.Data.DataTable table = SetupTable(); int transactionSub = -1; using (Application obApp = OnBaseConnect()) { DocumentQuery docQuery = obApp.Core.CreateDocumentQuery(); String docTypeName = System.Configuration.ConfigurationManager.AppSettings["inputDocumentType"]; var documentType = obApp.Core.DocumentTypes.Find(docTypeName); DateTime endTime = DateTime.Now; DateTime startTime = new DateTime(endTime.Year, endTime.Month, endTime.Day - (endTime.DayOfWeek.Equals(DayOfWeek.Monday) ? 3 : 1), 0, 0, 0); docQuery.AddDocumentType(documentType); docQuery.AddDateRange(startTime, endTime); long maxDocuments = 10; using (QueryResult queryResults = docQuery.ExecuteQueryResults(maxDocuments)) { Document doc = null; foreach (QueryResultItem queryResultItem in queryResults.QueryResultItems) { doc = queryResultItem.Document; break; } if (doc == null) { Log.Logger.Information("Document Not Found! Date Range: {startTime} - {endTime}", startTime, endTime); } else { docDate = doc.DocumentDate; using (PageData pd = obApp.Core.Retrieval.Text.GetDocument(doc.DefaultRenditionOfLatestRevision)) { using (StreamReader streamReader = new StreamReader(pd.Stream)) { String line = null; Transaction trans = new Transaction(); while ((line = streamReader.ReadLine()) != null) { if (transactionSub == -1 && line.StartsWith("153")) { transactionSub++; trans.TransLine1(line); } else if (transactionSub == 0) { transactionSub++; trans.TransLine2(line); } else if (transactionSub == 1) { transactionSub++; trans.TransLine3(line); } else if (transactionSub == 2) { transactionSub++; trans.TransLine4(line); // Reset Transaction Sub Counter transactionSub = -1; // Add Data to Table table.Rows.Add(trans.RowDataArray()); } } } } } } } return(table); }