示例#1
0
        /// <summary>
        /// Implementation of <see cref="IWorkflowScript.OnWorkflowScriptExecute" />.
        /// <seealso cref="IWorkflowScript" />
        /// </summary>
        /// <param name="app"></param>
        /// <param name="args"></param>
        public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
            app.Diagnostics.Level = Diagnostics.DiagnosticsLevel.Verbose;

            try
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "Begin Script - 274 - Convert Supporting Document to TIFF");

                // Get the active document
                Document objCurrentDocument = args.Document;
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("Processing document: {0}", objCurrentDocument.ID.ToString()));

                // Get the default rendition and verify it is an e-form
                Rendition objFormRendition = objCurrentDocument.DefaultRenditionOfLatestRevision;
                if (objFormRendition.FileType.ID != EFORM_FILE_TYPE && objFormRendition.FileType.ID != VFORM_FILE_TYPE)
                {
                    throw new InvalidProgramException(string.Format("File format ({0}) is invalid!", objFormRendition.FileType.Name));
                }


                // Obtain the Image page data
                ImageDataProvider objImageProvider = app.Core.Retrieval.Image;
                PageData          objImageData     = objImageProvider.GetDocument(objFormRendition);
                string            fullPath         = String.Format("{0}.{1}", @"c:\Temp", objImageData.Extension);

                Stream stream = objImageData.Stream;
                Utility.WriteStreamToFile(stream, fullPath);

                DocumentType objNewDocType = app.Core.DocumentTypes.Find(CRD_DOCUMENT_TYPE);

                // Prepare to import the new document
                StoreNewDocumentProperties objDocProps = app.Core.Storage.CreateStoreNewDocumentProperties(objNewDocType, app.Core.FileTypes.Find(IMAGE_FILE_TYPE));

                //Add all keywords
                foreach (KeywordRecord objKeyRecord in objCurrentDocument.KeywordRecords)
                {
                    if (objKeyRecord.KeywordRecordType.RecordType == RecordType.StandAlone || objKeyRecord.KeywordRecordType.RecordType == RecordType.SingleInstance)
                    {
                        foreach (Keyword objKeyword in objKeyRecord.Keywords)
                        {
                            if (objNewDocType.KeywordRecordTypes.FindKeywordType(objKeyword.KeywordType.ID) != null)
                            {
                                objDocProps.AddKeyword(objKeyword);
                            }
                        }
                    }
                    else
                    {
                        EditableKeywordRecord objEditRecord = objKeyRecord.CreateEditableKeywordRecord();
                        objDocProps.AddKeywordRecord(objEditRecord);
                    }
                }

                List <string> lstImportFiles = new List <string>();
                lstImportFiles.Add(fullPath);

                // Store the new document
                Document objNewDoc = null;
                objNewDoc = app.Core.Storage.StoreNewDocument(lstImportFiles, objDocProps);
                if (objNewDoc == null)
                {
                    throw new InvalidProgramException("Failed to store new document");
                }

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("Stored new document: {0}", objNewDoc.ID.ToString()));

                // Clean up
                objImageData.Dispose();

                // If we got here, the script was successful
                args.ScriptResult = true;
            }
            catch (InvalidProgramException ex)
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Invalid Program Exception: {0}", ex.Message));
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
                args.ScriptResult = false;
            }
            catch (UnityAPIException ex)
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Unity API Exception: {0}", ex.Message));
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
                args.ScriptResult = false;
            }
            catch (Exception ex)
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("General Exception: {0}", ex.Message));
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
                args.ScriptResult = false;
            }
            finally
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "End Script - 274 - Convert HTML to TIFF");
            }
        }
        /// <summary>
        /// Implementation of <see cref="IWorkflowScript.OnWorkflowScriptExecute" />.
        /// <seealso cref="IWorkflowScript" />
        /// </summary>
        /// <param name="app"></param>
        /// <param name="args"></param>
        public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
            app.Diagnostics.Level = Diagnostics.DiagnosticsLevel.Verbose;

            try
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "Begin Script - Convert HTML to TIFF");

                // Get the active document
                Document objCurrentDocument = args.Document;
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("Processing document: {0}", objCurrentDocument.ID.ToString()));

                // Get the default rendition and verify it is an e-form
                Rendition objFormRendition = objCurrentDocument.DefaultRenditionOfLatestRevision;
                if (objFormRendition.FileType.ID != EFORM_FILE_TYPE && objFormRendition.FileType.ID != VFORM_FILE_TYPE)
                {
                    throw new InvalidProgramException(string.Format("File format ({0}) is invalid!", objFormRendition.FileType.Name));
                }

                // Validate the document type
                DocumentType objCrdDocType = app.Core.DocumentTypes.Find(CRD_DOCUMENT_TYPE);
                if (objCrdDocType == null)
                {
                    throw new InvalidProgramException(string.Format("Document type \"{0}\" does not exist!", CRD_DOCUMENT_TYPE));
                }

                // Obtain the Image page data
                ImageDataProvider objImageProvider = app.Core.Retrieval.Image;
                PageData          objImageData     = objImageProvider.GetDocument(objFormRendition);

                // Convert to Multi-Page TIFF
                using (ImageModifier imageMod = new ImageModifier(TEMP_DIRECTORY, PAGE_RATIO))
                {
                    strFilePath = imageMod.MakeMultiPage(objImageData, app);
                    if (strFilePath.StartsWith("ERROR:"))
                    {
                        throw new InvalidProgramException(string.Format("Error converting to multipage: ({0})", strFilePath.Replace("ERROR: ", "")));
                    }
                }

                // Prepare to import the new document
                StoreNewDocumentProperties objDocProps = app.Core.Storage.CreateStoreNewDocumentProperties(objCrdDocType, app.Core.FileTypes.Find(IMAGE_FILE_TYPE));

                // Add all keywords
                foreach (KeywordRecord objKeyRecord in objCurrentDocument.KeywordRecords)
                {
                    if (objKeyRecord.KeywordRecordType.RecordType == RecordType.StandAlone || objKeyRecord.KeywordRecordType.RecordType == RecordType.SingleInstance)
                    {
                        foreach (Keyword objKeyword in objKeyRecord.Keywords)
                        {
                            if (objCrdDocType.KeywordRecordTypes.FindKeywordType(objKeyword.KeywordType.ID) != null)
                            {
                                objDocProps.AddKeyword(objKeyword);
                            }
                        }
                    }
                    else
                    {
                        EditableKeywordRecord objEditRecord = objKeyRecord.CreateEditableKeywordRecord();
                        objDocProps.AddKeywordRecord(objEditRecord);
                    }
                }

                List <string> lstImportFiles = new List <string>();
                lstImportFiles.Add(strFilePath);

                // Store the new document
                Document objNewDoc = null;
                objNewDoc = app.Core.Storage.StoreNewDocument(lstImportFiles, objDocProps);
                if (objNewDoc == null)
                {
                    throw new InvalidProgramException("Failed to store new document");
                }
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("Stored new document: {0}", objNewDoc.ID.ToString()));

                // Clean up
                objImageData.Dispose();

                // If we got here, the script was successful
                args.ScriptResult = true;
            }
            catch (InvalidProgramException ex)
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Invalid Program Exception: {0}", ex.Message));
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
                args.ScriptResult = false;
            }
            catch (UnityAPIException ex)
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Unity API Exception: {0}", ex.Message));
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
                args.ScriptResult = false;
            }
            catch (Exception ex)
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("General Exception: {0}", ex.Message));
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
                args.ScriptResult = false;
            }
            finally
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "End Script - Convert HTML to TIFF");
            }
        }
        /***********************************************
        * USER/SE: PLEASE DO NOT EDIT BELOW THIS LINE *
        ***********************************************/

        #region IWorkflowScript

        /// <summary>
        /// Implementation of <see cref="IWorkflowScript.OnWorkflowScriptExecute" />.
        /// <seealso cref="IWorkflowScript" />
        /// </summary>
        /// <param name="app">Unity Application object</param>
        /// <param name="args">Workflow event arguments</param>
        public void OnWorkflowScriptExecute(Application app, WorkflowEventArgs args)
        // public void OnWorkflowScriptExecute(Application app, WorkflowEventArgs args = null)
        {
            try
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("{0} - Start Script - [{1}]", DateTime.Now.ToString(DateTimeFormat), ScriptName));

                // Get the active document
                Document objCurrentDocument = args.Document;
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("Processing document: {0}", objCurrentDocument.ID.ToString()));

                // Get the default rendition
                Rendition objFormRendition = objCurrentDocument.DefaultRenditionOfLatestRevision;

                DocumentType objCrdDocType = app.Core.DocumentTypes.Find(CRD_DOCUMENT_TYPE);

                // Validate the document type
                //DocumentType objCrdDocType = app.Core.DocumentTypes.Find(CRD_DOCUMENT_TYPE);
                if (objCrdDocType == null)
                {
                    throw new InvalidProgramException(string.Format("Document type \"{0}\" does not exist!", CRD_DOCUMENT_TYPE));
                }

                //If the doc is already an image, pull it in its default format and save the new copy
                if (objFormRendition.FileType.ID == IMAGE_FILE_TYPE)
                {
                    app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "Document is an image, save copy to new Doc Type");

                    DefaultDataProvider objDefaultProvider  = app.Core.Retrieval.Default;
                    PageData            objDefaultImageData = objDefaultProvider.GetDocument(objFormRendition);

                    StoreNewDocumentProperties objDocProps = app.Core.Storage.CreateStoreNewDocumentProperties(objCrdDocType, app.Core.FileTypes.Find(IMAGE_FILE_TYPE));

                    foreach (KeywordRecord objKeyRecord in objCurrentDocument.KeywordRecords)
                    {
                        if (objKeyRecord.KeywordRecordType.RecordType == RecordType.StandAlone || objKeyRecord.KeywordRecordType.RecordType == RecordType.SingleInstance)
                        {
                            foreach (Keyword objKeyword in objKeyRecord.Keywords)
                            {
                                if (objCrdDocType.KeywordRecordTypes.FindKeywordType(objKeyword.KeywordType.ID) != null)
                                {
                                    objDocProps.AddKeyword(objKeyword);
                                }
                            }
                        }
                        else
                        {
                            EditableKeywordRecord objEditRecord = objKeyRecord.CreateEditableKeywordRecord();
                            objDocProps.AddKeywordRecord(objEditRecord);
                        }
                    }

                    // Store the new document
                    Document objNewDoc = null;
                    objNewDoc = app.Core.Storage.StoreNewDocument(objDefaultImageData, objDocProps);
                    if (objNewDoc == null)
                    {
                        throw new InvalidProgramException("Failed to store new document");
                    }
                    app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("Stored new document: {0}", objNewDoc.ID.ToString()));

                    // Clean up
                    objDefaultImageData.Dispose();

                    // If we got here, the script was successful
                    args.ScriptResult = true;
                }
                //If the Doc is Word or Excel, convert it with the conversion utility and save it
                else if (objFormRendition.FileType.ID == WORD_FILE_TYPE || objFormRendition.FileType.ID == PDF_FILE_TYPE)
                {
                    ConversionUtilities unityConverter = new ConversionUtilities(app, TEMP_DIRECTORY, CONVERTER_DIRECTORY);
                    app.Diagnostics.Write("Word/PDF file conversion");

                    List <FileDefinition> files = unityConverter.Convert(args.Document, UnityFileConversions.ImxFileType.Image, UnityFileConversions.ImportType.Document, app.Core.DocumentTypes.Find(CRD_DOCUMENT_TYPE));

                    unityConverter.CleanupFiles();

                    args.ScriptResult = true;
                }
                else
                {
                    app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "Document is not image/Word/PDF, convert to new Doc Type");

                    ImageDataProvider objImageProvider = app.Core.Retrieval.Image;
                    PageData          objImageData     = objImageProvider.GetDocument(objFormRendition);

                    StoreNewDocumentProperties objDocProps = app.Core.Storage.CreateStoreNewDocumentProperties(objCrdDocType, app.Core.FileTypes.Find(IMAGE_FILE_TYPE));

                    foreach (KeywordRecord objKeyRecord in objCurrentDocument.KeywordRecords)
                    {
                        if (objKeyRecord.KeywordRecordType.RecordType == RecordType.StandAlone || objKeyRecord.KeywordRecordType.RecordType == RecordType.SingleInstance)
                        {
                            foreach (Keyword objKeyword in objKeyRecord.Keywords)
                            {
                                if (objCrdDocType.KeywordRecordTypes.FindKeywordType(objKeyword.KeywordType.ID) != null)
                                {
                                    objDocProps.AddKeyword(objKeyword);
                                }
                            }
                        }
                        else
                        {
                            EditableKeywordRecord objEditRecord = objKeyRecord.CreateEditableKeywordRecord();
                            objDocProps.AddKeywordRecord(objEditRecord);
                        }
                    }

                    // Store the new document
                    Document objNewDoc = null;
                    objNewDoc = app.Core.Storage.StoreNewDocument(objImageData, objDocProps);
                    if (objNewDoc == null)
                    {
                        throw new InvalidProgramException("Failed to store new document");
                    }
                    app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("Stored new document: {0}", objNewDoc.ID.ToString()));

                    // Clean up
                    objImageData.Dispose();

                    // If we got here, the script was successful
                    args.ScriptResult = true;
                }
            }
            catch (InvalidProgramException ex)
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Invalid Program Exception: {0}", ex.Message));
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
                args.ScriptResult = false;
            }
            catch (UnityAPIException ex)
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Unity API Exception: {0}", ex.Message));
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
                args.ScriptResult = false;
            }
            catch (Exception ex)
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("General Exception: {0}", ex.Message));
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, string.Format("Stack Trace: {0}", ex.StackTrace));
                args.ScriptResult = false;
            }
            finally
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("End Script - [{0}]", ScriptName));
            }
        }
示例#4
0
        /*
         * AppendToDocument() is the function that performs the operations designated for this script.
         * This sub will retrieve all of the pages from the source document and
         * append them to the destination document.
         * NOTE: This script uses IOBXDocumentArchiver and the IOBXFileManager.
         * Both objects are required to store a document in this fashion.
         * DocumentArchiver is used to retireve and append pages
         * FileManager is used to commit changes to document already stored in OnBase
         */

        private bool AppendToDocument(Application app, WorkflowEventArgs args, Int64 sourceDocHandle, Int64 destinationDocHandle)
        {
            try
            {
                Document destDocument = app.Core.GetDocumentByID(destinationDocHandle);
                if (destDocument == null)
                {
                    WriteLog(app, string.Format("No Destination document found with handle ( {0} ).", destinationDocHandle.ToString()));
                    strProcessingErrors = string.Format("{0}{1}{2}   No Destination document found with handle ( {4} ).", strProcessingErrors, Environment.NewLine, DateTime.Now, destinationDocHandle.ToString());
                    return(false);
                }
                Rendition         destRendition         = destDocument.DefaultRenditionOfLatestRevision;
                ImageDataProvider destImageDataProvider = app.Core.Retrieval.Image;
                PageData          destPageData          = destImageDataProvider.GetDocument(destRendition);

                Document sourceDocument = app.Core.GetDocumentByID(sourceDocHandle);
                if (sourceDocument == null)
                {
                    WriteLog(app, string.Format("No Source document found with handle ( {0}.", sourceDocHandle.ToString()));
                    strProcessingErrors = String.Format("{0}{1}{2}    No Source document found with handle ({3}).", strProcessingErrors, Environment.NewLine, DateTime.Now, sourceDocHandle.ToString());
                    return(false);
                }

                Rendition         sourceRendition         = sourceDocument.DefaultRenditionOfLatestRevision;
                ImageDataProvider sourceImageDataProvider = app.Core.Retrieval.Image;
                PageData          sourcePageData          = sourceImageDataProvider.GetDocument(sourceRendition);
                PageRangeSet      sourcePageRangeSet      = sourceImageDataProvider.CreatePageRangeSet();
                sourcePageRangeSet.AddRange(1, sourceRendition.NumberOfPages);
                PageDataList sourcePageDataList = sourceImageDataProvider.GetPages(sourceRendition, sourcePageRangeSet);

                if (sourcePageDataList == null)
                {
                    WriteLog(app, string.Format("No pages found in Source document  (ID: {0}.", sourceDocHandle.ToString()));
                    return(false);
                }
                else
                {
                    app.Diagnostics.Write(string.Format("Source Document Handle {0} has {1} pages.", sourceDocHandle.ToString()), sourcePageDataList.Count);
                    // Create a page range object

                    using (DocumentLock documentLock = destDocument.LockDocument())
                    {
                        // Ensure lock was obtained
                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                        {
                            throw new Exception("Document lock not obtained");
                        }

                        long lngPageCount = destDocument.DefaultRenditionOfLatestRevision.NumberOfPages;
                        int  intPageLoc   = Convert.ToInt32(lngPageCount) + 1;

                        destDocument.DefaultRenditionOfLatestRevision.Imaging.AddPages(sourcePageDataList, intPageLoc);
                    }

                    app.Diagnostics.Write(string.Format("Pages added to document {0}", destinationDocHandle.ToString()));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error in AppendDocument: {0}", ex.Message));
            }
            return(true);
        }