private void btnTestKendoxConnection_Click(object sender, EventArgs e) { DocSafe.DocSafeHandler dsHandler = new DocSafe.DocSafeHandler(); try { MessageBox.Show(string.Format("Version information was successfully retrieved!\n {0}", dsHandler.GetVersion(txtBxClientURL.Text, txtBxCertificateFilePath.Text)), "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(string.Format("Sommething went wrong while trying to get the version info!\n {0} \n {1}", ex.Message, ex.StackTrace), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Process() { if (ready && !error) { try { log4.Info(string.Format("Processing Document. ObjectID:'{0}'", objectID)); string mailRecipient = null; string docSafeRecipient = null; #region Checkout all documents needed during processing. //Try to checkout document. try { WCFHandler.GetInstance.CheckOutDocument(this.objectID); } catch (Exception e) { throw new Exception(string.Format("Document could not be checked out. Msg:'{0}'", e.Message)); } if (Properties.Settings.Default.GroupingInheritMarkerProperties) { try { foreach (DocumentContract childDoc in childDocuments) { try { WCFHandler.GetInstance.CheckOutDocument(childDoc.Id); } catch (Exception e) { throw new Exception(string.Format("Child-ObjectID:'{0}'. Msg:'{1}'", childDoc.Id, e.Message)); } } } catch (Exception e) { throw new Exception(string.Format("Child-Document could not be checked out. Msg:'{0}'", e.Message)); } } #endregion #region Send E-Mail if (Properties.Settings.Default.SendMailActive) { string attachmentDirectory = ""; try { DateTime startOfDownload = DateTime.Now; if (Properties.Settings.Default.AttachDocument) { //Create temp-directory. string tempDirectory = Path.Combine(Path.GetTempPath(), Convert.ToString(Guid.NewGuid())); Directory.CreateDirectory(tempDirectory); //Prepare list of all documents to send. List <DocumentContract> documentsToSend = new List <DocumentContract>(); if (!Properties.Settings.Default.GroupingActive) { documentsToSend.Add(this.document); } else { documentsToSend.AddRange(childDocuments); if (Properties.Settings.Default.GroupingAddParent) { documentsToSend.Add(this.document); } } foreach (DocumentContract doc in documentsToSend) { byte[] docBytes = WCFHandler.GetInstance.GetDocumentFile(this.objectID); string fileName = Properties.Settings.Default.AttachmentRenameProperty; if (fileName != "") { fileName = ExpressionsEvaluator.GetInstance.Evaluate(fileName, doc); if (fileName == "") { fileName = doc.Name; } else { string fileExtension = Path.GetExtension(doc.Name); fileName = fileName + fileExtension; } } else { fileName = doc.Name; } fileName = FileHelper.CleanUpFileName(fileName); string path = Path.Combine(tempDirectory, fileName); path = FileHelper.GetUniqueFilePath(path); System.IO.File.WriteAllBytes(path, docBytes); } DateTime endOfDownload = DateTime.Now; log4.Debug(string.Format("Downloading documents took {0}ms. ObjectID:'{1}'", (endOfDownload - startOfDownload).TotalMilliseconds.ToString(), this.objectID)); if (Properties.Settings.Default.GroupingZipped) { //Create directory withing tempDirectory. string dirName = new DirectoryInfo(@tempDirectory).Name; //Create name of ZipFile string zipName = ""; if (Properties.Settings.Default.GroupingZipName != "") { zipName = Properties.Settings.Default.GroupingZipName + ".zip"; } else { zipName = "Documents.zip"; } //Create ZipFilePath string zipTempDirectory = Path.Combine(Path.GetTempPath(), Convert.ToString(Guid.NewGuid())); Directory.CreateDirectory(zipTempDirectory); string zipFilePath = Path.Combine(zipTempDirectory, zipName); //Create Zip-File. ZipFile.CreateFromDirectory(tempDirectory, zipFilePath); //Delete old Tempdirectory Directory.Delete(tempDirectory, true); //Set new tempdirectory where ZIP file is. tempDirectory = zipTempDirectory; DateTime endOfZipping = DateTime.Now; log4.Debug(string.Format("Zipping took {0}ms. ObjectID:'{1}'", (endOfZipping - endOfDownload).TotalMilliseconds.ToString(), this.objectID)); } attachmentDirectory = tempDirectory; } try { using (Task <string> AsyncTaskSendMail = MailHandler.GetInstance.SendDocumentMail(this.document, attachmentDirectory)) { mailRecipient = AsyncTaskSendMail.Result; } } catch (Exception e) { throw new Exception(string.Format(e.InnerException.Message)); } if (attachmentDirectory != "") { Directory.Delete(attachmentDirectory, true); } #region OldStuff ////If no grouping is active. //if (!Properties.Settings.Default.GroupingActive) //{ // document = WCFHandler.GetInstance.GetDocumentFile(this.objectID); // string fileName = Properties.Settings.Default.AttachmentRenameProperty; // if (fileName != "") // { // fileName = NEWExpressionsEvaluator.GetInstance.Evaluate(fileName, this.document); // if (fileName == "") // fileName = this.document.Name; // else // { // string fileExtension = Path.GetExtension(this.document.Name); // fileName = fileName + fileExtension; // } // } // else // fileName = this.document.Name; // fileName = FileHelper.CleanUpFileName(fileName); // //docinfo.fileName = fileName; //} ////If Grouping is active. //else //{ //} //11.02.2016 AEPH: Get UserList //if (lUsers == null) // lUsers = getAllUsers(); //using (Task<bool> AsyncTaskSendMail = MailHandler.GetInstance.SendDocumentMail(document, docinfo, row, lUsers, attachmentDirectory)) //{ // processed = AsyncTaskSendMail.Result; //} // using (Task<bool> AsyncTaskSendMail = MailHandler.GetInstance.SendDocumentMail(this.document, attachmentDirectory)) // { // bool processed = AsyncTaskSendMail.Result; // if (!processed) // throw new Exception(string.Format("Document E-Mail could not be sent.")); // } // //MailHandler.GetInstance.SendDocumentMail(this.document, attachmentDirectory); // if (attachmentDirectory != "") // Directory.Delete(attachmentDirectory, true); // } #endregion } catch (Exception e) { throw new Exception(string.Format("Document E-Mail could not be sent. Msg:'{0}'", e.Message)); } } #endregion #region Send to DocSafe if (Properties.Settings.Default.DocSafeActive) { try { DocSafe.DocSafeHandler dsHandler = new DocSafe.DocSafeHandler(); byte[] document = null; //document = WebService.GetDocumentFile(sSessionGuid, Properties.Settings.Default.Culture, Properties.Settings.Default.Culture, docGuid, null, null, KXWS.AccessTypesEnum.ContentExport, out docinfo); document = WCFHandler.GetInstance.GetDocumentFile(this.objectID); docSafeRecipient = dsHandler.SendDocumentToDocsafe(document, this.document); } catch (Exception e) { throw new Exception("Document E-Mail could not be sent."); } } #endregion #region Start Process if (Properties.Settings.Default.StartProcessActive) { try { WCFHandler.GetInstance.StartProcess(this.procTemplate, this.objectID, this.procUserIDS); } catch (Exception e) { throw new Exception(string.Format("Process could not be started. Msg{0}", e.Message)); } } #endregion #region Set Markerproperties try { if (markerProperties.Count > 0) { DateTime start = DateTime.Now; //Evaluate MarkerProperty-Values foreach (MarkerProperty mProp in markerProperties) { //Evaluate markerproperty for (int i = 0; i < mProp.values.Length; i++) { mProp.values[i] = ExpressionsEvaluator.GetInstance.Evaluate(mProp.values[i], this.document, false, true); } } DateTime end = DateTime.Now; log4.Debug(string.Format("Evaulation of markerproperties for document took {0}ms. ObjectID:'{1}'", (end - start).TotalMilliseconds.ToString(), this.objectID)); start = DateTime.Now; //Merge propertyupdates into all affected documents foreach (DocumentContract doc in allAffectedDocuments) { MergeMarkerPropertiesToDocument(doc); } end = DateTime.Now; log4.Debug(string.Format("Merging of markerproperties for document took {0}ms. ObjectID:'{1}'", (end - start).TotalMilliseconds.ToString(), this.objectID)); start = DateTime.Now; foreach (DocumentContract doc in allAffectedDocuments) { WCFHandler.GetInstance.UpdateDocument(doc); } end = DateTime.Now; log4.Debug(string.Format("Documentupdates for document took {0}ms. ObjectID:'{1}'", (end - start).TotalMilliseconds.ToString(), this.objectID)); } } catch (Exception e) { throw new Exception(string.Format("Markerproperties could not be set! Msg:'{0}'", e.Message)); } #endregion string message = string.Format("Document processed sucessfully. ObjectID:'{0}' {1} {2}", this.objectID, mailRecipient != null ? "E-Mail Recipient: '" + mailRecipient + "'" : "", docSafeRecipient != null ? "DocSafe Recipient: '" + docSafeRecipient + "'" : ""); log4.Info(message); info = message; finished = true; } //If an error happens during processing. catch (Exception e) { string message = string.Format("An error happened during documentprocessing! ObjectID:'{0}', Msg:'{1}'", this.objectID, e.Message); log4.Error(message); info = message; error = true; } //Documents are always checked back in in when finished. finally { try { foreach (DocumentContract doc in allAffectedDocuments) { WCFHandler.GetInstance.UndoCheckOutDocument(doc.Id); } } catch { } } } }