Esempio n. 1
0
        public List <PageData> GetAllPages(DataProvider aProvider, Rendition rendition)
        {
            if (aProvider == null)
            {
                throw new ArgumentNullException("provider", "No DataProvider specified");
            }
            if (rendition == null)
            {
                throw new ArgumentNullException("rendition", "No document rendition specified");
            }
            List <PageData> pagesResults = new List <PageData>();

            PageRangeSet lRangeSet = aProvider.CreatePageRangeSet();

            lRangeSet.AddRange(1, rendition.NumberOfPages);
            MethodInfo GetPagesMethod = aProvider.GetType().GetMethod("GetPages", new Type[] { typeof(Rendition), typeof(PageRangeSet) });

            if (GetPagesMethod == null)
            {
                throw new Exception("Specified DataProvider does not define file access");
            }
            try
            {
                pagesResults.AddRange(GetPagesMethod.Invoke(aProvider, new object[] { rendition, lRangeSet }) as PageDataList);
            }
            catch (TargetInvocationException ex)
            {
                throw ex.InnerException;
            }

            return(pagesResults);
        }
Esempio n. 2
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);
        }