Example #1
0
        /// <summary>
        /// Connect to Onbase App Server
        /// </summary>
        private void Connect()
        {
            var authProps = Hyland.Unity.Application.CreateOnBaseAuthenticationProperties(onbaseSettings.AppServerURL, onbaseSettings.Username, onbaseSettings.Password, onbaseSettings.DataSource);

            authProps.LicenseType = LicenseType.QueryMetering;

            try
            {
                unityApplication = Hyland.Unity.Application.Connect(authProps);
            }
            catch (MaxLicensesException)
            {
                throw new OnbaseConnectionException("Error: All available licenses have been consumed.");
            }
            catch (SystemLockedOutException)
            {
                throw new OnbaseConnectionException("Error: The system is currently in lockout mode.");
            }
            catch (InvalidLoginException)
            {
                throw new OnbaseConnectionException("Error: Invalid Login Credentials.");
            }
            catch (AuthenticationFailedException)
            {
                throw new OnbaseConnectionException("Error: NT Authentication Failed.");
            }
            catch (MaxConcurrentLicensesException)
            {
                throw new OnbaseConnectionException("Error: All concurrent licenses for this user group have been consumed.");
            }
            catch (InvalidLicensingException)
            {
                throw new OnbaseConnectionException("Error: Invalid Licensing.");
            }
        }
Example #2
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 = app;
            Document doc = args.Document;

            SetKeywordValues(doc);
            string sName      = accountName.Replace("'", "");
            string month      = dateOfBirth.Substring(0, 2);
            string day        = dateOfBirth.Substring(3, 2);
            string year       = dateOfBirth.Substring(6, 4);
            string sBirthDate = year + "-" + month + "-" + day;

            if (sName != string.Empty && sBirthDate != "" && accountNumber == "")
            {
                string    connectionString = "Server = WPEC5009onbsq01.cardinalhealth; Database = ONBASE; user=hsi; password=wstinol";
                string    queryString      = "select ks101,ks102 from hsi.keysetdata112 (NOLOCK) where ks109 = '" + sBirthDate + "' and left(ks102,len(ks102)- len(substring(ks102,charindex(',',ks102),len(ks102)))) = '" + sName + "'";
                DataTable dt = SelectDataRows(connectionString, queryString);
                foreach (DataRow dr in dt.Rows)
                {
                    string sAccount     = dr[0].ToString();
                    string sAccountName = dr[1].ToString();
                    if (sAccount != "" && sAccountName != "")
                    {
                        ModifyKeywordInCurrentDocument(doc, "AR - Account Number", sAccount);
                    }
                }
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            Hyland.Unity.SingleSignOnAuthenticationProperties props = Application.CreateSingleSignOnAuthenticationProperties("URL", "Datasource");
            Hyland.Unity.Application app = Application.Connect(props);
            if (app != null)
            {
                DocumentType docType = app.Core.DocumentTypes.Find("Test Doc Type");
                Document     doc     = app.Core.GetDocumentByID(12345);

                KeywordType kt = app.Core.KeywordTypes.Find("test");

                //DocumentType docType = app.Core.DocumentTypes.Find("test");


                using (PageData pd = app.Core.Retrieval.Default.GetDocument(doc.Revisions[0].DefaultRendition))
                {
                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                    {
                        byte[] buff = new byte[1024];
                        int    read;
                        while ((read = pd.Stream.Read(buff, 0, buff.Length)) > 0)
                        {
                            ms.Write(buff, 0, read);
                        }
                        //fileLength = ms.Length;
                    }
                }
            }
        }
Example #4
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)
        {
            try
            {
                // Script name for diagnostics logging
                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 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));
                }

                ConversionUtilities unityConverter = new ConversionUtilities(app, TEMP_DIRECTORY, CONVERTER_DIRECTORY);

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

                unityConverter.CleanupFiles();

                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, ScriptName);
            }
        }
Example #5
0
        /// <summary>
        /// Get the signer information from the property bags. Also add anchors, if any from the SaveAnchorsToProp function
        /// </summary>
        /// <param name="app"></param>
        /// <param name="args"></param>
        /// <returns>A single signer object</returns>
        private Signer GetSigner(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
            Signer signer = new Signer();

            try
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "Adding a single signer to the envelope...");

                string email = "", first = "", last = "", codeDesc = "", codeVal = "";
                bool   external = false;

                //Get all the signer info from prop bags
                if (!args.SessionPropertyBag.TryGetValue("TrueSignSignerEmail", out email))
                {
                    throw new Exception("An email must be provided for the signer.");
                }

                args.SessionPropertyBag.TryGetValue("TrueSignFirstName", out first);
                args.SessionPropertyBag.TryGetValue("TrueSignLastName", out last);
                args.SessionPropertyBag.TryGetValue("TrueSignExternal", out external);
                args.SessionPropertyBag.TryGetValue("TrueSignCodeDesc", out codeDesc);
                args.SessionPropertyBag.TryGetValue("TrueSignCodeVal", out codeVal);

                signer.Email      = email;
                signer.First_Name = first == null ? "" : first; //not needed for internal signer
                signer.Last_Name  = last == null ? "" : last;   //not needed for internal signer
                signer.Type       = external == true ? Signer_Type.External : Signer_Type.Internal;

                if (signer.Type == Signer_Type.External)
                {
                    if (!string.IsNullOrEmpty(codeDesc) && !string.IsNullOrEmpty(codeVal))
                    {
                        //If the signer is an external user, we are requiring them to enter a code they would know before being able to sign.
                        //Only the code description will be known to the signer (they will see it in the email notification).
                        //The value itself should be something that the signer already knows (like a date of birth, last 4 of SSN, or a case number) -- NOT REQUIRED
                        Access_Code code = new Access_Code();
                        code.Description = codeDesc;
                        code.Value       = codeVal;
                        signer.Code      = code;
                    }
                }

                string noteJson = "";
                if (args.SessionPropertyBag.TryGetValue("TrueSignAnchors", out noteJson))
                {
                    List <Anchor> anchors = string.IsNullOrEmpty(noteJson) ? new List <Anchor>() : JsonConvert.DeserializeObject <List <Anchor> >(noteJson);
                    signer.Anchors = anchors;
                }
            }
            catch
            {
                throw;
            }

            return(signer);
        }
Example #6
0
        private void SaveAnchorsToProp(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args, Guid docId)
        {
            try
            {
                string email = ""; string[] multipleEmails = new string[10]; long noteId = 0; bool singleSigner = false;

                if (args.SessionPropertyBag.TryGetValue("TrueSignSignerNoteId", out noteId))
                {
                    if (args.SessionPropertyBag.TryGetValue("TrueSignSignerEmail", out email))
                    {
                        singleSigner = true;
                    }
                    else if (args.SessionPropertyBag.TryGetValue("TrueSignSignerEmail", out multipleEmails))
                    {
                        singleSigner = SignerArrayOnlyOne(multipleEmails);
                    }

                    if (singleSigner)
                    {
                        if (args.Document.LatestRevision.Document.Notes.Count > 0 && noteId > 0)
                        {
                            string noteJson;
                            args.SessionPropertyBag.TryGetValue("TrueSignAnchors", out noteJson);

                            //Get all the document notes for the configured NoteTypeID. Make sure to only get notes of the latest revision
                            //and the notes that have Repeat On All Revisions set to True.
                            List <Anchor> anchors = string.IsNullOrEmpty(noteJson) ? new List <Anchor>() : JsonConvert.DeserializeObject <List <Anchor> >(noteJson);
                            foreach (Note note in args.Document.Notes.FindAll(x => x.NoteType.ID == noteId && (x.DocumentRevision.ID == args.Document.LatestRevision.ID || x.NoteType.DisplaySettings == NoteTypeDisplaySettings.RepeatOnAllRevisions)))
                            {
                                var anchor = new Anchor();
                                anchor.Id          = Guid.NewGuid();
                                anchor.Comment     = note.Text;
                                anchor.Page        = (int)note.PageNumber;
                                anchor.Required    = true;
                                anchor.Height      = note.Size.Height * 72 / 96;
                                anchor.Width       = note.Size.Width * 72 / 96;
                                anchor.X           = note.Position.X * 72 / 96;
                                anchor.Y           = note.Position.Y * 72 / 96;
                                anchor.Doc_Id      = docId;
                                anchor.Client_Data = note.ID.ToString();
                                anchor.Type        = Anchor_Type.SignHere;
                                anchors.Add(anchor);
                            }

                            args.SessionPropertyBag.Set("TrueSignAnchors", JsonConvert.SerializeObject(anchors));
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Example #7
0
 /// <summary>
 /// Connect to Onbase App Server
 /// </summary>
 protected void GetConector()
 {
     try
     {
         unityApplication = this._onbaseConector.GetApplication();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #8
0
        /// <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)
        public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
            try
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                // Create keyword modifier object to hold keyword changes
                KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                Keyword kwdKeyName1 = null;
                if (!args.SessionPropertyBag.TryGetValue(gPropName1, out string[] lstProp1))
Example #9
0
        /// <summary>
        /// Handle exceptions and log to Diagnostics Console and document history
        /// </summary>
        /// <param name="ex">Exception</param>
        /// <param name="app">Unity Application object</param>
        /// <param name="args">Workflow event arguments</param>
        /// <param name="otherDocument">Document on which to update history if not active workflow document</param>
        private void HandleException(Exception ex, ref Application app, ref WorkflowEventArgs args, Document otherDocument = null)
        {
            var  history = app.Core.LogManagement;
            bool isInner = false;

            // Cycle through all inner exceptions
            while (ex != null)
            {
                // Construct error text to store to workflow property
                string propertyError = string.Format("{0}{1}: {2}",
                                                     isInner ? "Inner " : "",
                                                     ex.GetType().Name,
                                                     ex.Message);

                // Construct error text to store to document history
                string historyError = propertyError.Replace(ex.GetType().Name, "Unity Script Error");

                // Construct error text to log to diagnostics console
                string diagnosticsError = string.Format("{0} - ***ERROR***{1}{2}{1}{1}Stack Trace:{1}{3}",
                                                        DateTime.Now.ToString(DateTimeFormat),
                                                        Environment.NewLine,
                                                        propertyError,
                                                        ex.StackTrace);

                // Add error message to document history (on current or specified document)
                var document = otherDocument ?? _currentDocument;
                if (document != null && WriteErrorsToHistory)
                {
                    history.CreateDocumentHistoryItem(document, historyError);
                }

                // Write error message to Diagnostcs Consonle
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, diagnosticsError);

                // Store the original (inner) exception message to error workflow property
                if (ex.InnerException == null)
                {
                    args.SessionPropertyBag.Set(ErrorMessageProperty, ex.Message);
                }

                // Move on to next inner exception
                ex      = ex.InnerException;
                isInner = true;
            }

            // Set ScriptResult = false for workflow rules
            args.ScriptResult = false;
        }
Example #10
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)
        {
            args.SessionPropertyBag.TryGetValue("propPriKey", out priKey);
            args.SessionPropertyBag.TryGetValue("propSecKey", out secKey);
            Document     doc     = args.Document;
            DocumentType docType = doc.DocumentType;

            SetKeywordValues(doc);
            DocumentQuery docQuery = app.Core.CreateDocumentQuery();

            docQuery.AddDocumentType(docType);

            KeywordType keyType    = app.Core.KeywordTypes.Find(priKey);
            Keyword     priKeyword = keyType.CreateKeyword(priVal);

            docQuery.AddKeyword(priKeyword);

            DocumentList docList = docQuery.Execute(10000);

            Keyword secKeyword = keyType.CreateKeyword(secVal);

            foreach (Document newDoc in docList)
            {
                foreach (KeywordRecord keywordRecord in newDoc.KeywordRecords)
                {
                    foreach (Keyword keyword in keywordRecord.Keywords)
                    {
                        if (keyword.KeywordType.Name == priKey)
                        {
                            string priGetValToCompare = keyword.IsBlank?string.Empty:keyword.Value.ToString();
                            if (priGetValToCompare.Trim() == priVal.Trim())
                            {
                                using (DocumentLock documentLock = newDoc.LockDocument())
                                {
                                    if (documentLock.Status == DocumentLockStatus.LockObtained)
                                    {
                                        KeywordModifier keymod = newDoc.CreateKeywordModifier();
                                        keymod.UpdateKeyword(priKeyword, secKeyword);
                                        keymod.ApplyChanges();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        /// Initialize global settings
        /// </summary>
        /// <param name="app">Unity Application object</param>
        /// <param name="args">Workflow event arguments</param>
        private void IntializeScript(ref Application app, ref WorkflowEventArgs args)
        {
            // Set the specified diagnostics level
            app.Diagnostics.Level = DiagLevel;

            // Log script execution start
            app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                string.Format("{0} - Start Script - [{1}]", DateTime.Now.ToString(DateTimeFormat), ScriptName));

            // Capture active document as global
            _currentDocument = args.Document;
            //  _currentDocument = app.Core.GetDocumentByID(TestDocId);
            // If an error was stored in the property bag from a previous execution, clear it
            if (args.SessionPropertyBag.ContainsKey(ErrorMessageProperty)) args.SessionPropertyBag.Remove(ErrorMessageProperty);

            // Set ScriptResult = true for workflow rules (will become false if an error is caught)
            args.ScriptResult = true;
        }
        /// <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)
        {
            try
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("{0} - Start Script - [{1}]", DateTime.Now.ToString(DateTimeFormat), ScriptName));

                ConversionUtilities unityConverter = new ConversionUtilities(app, TEMP_DIRECTORY, CONVERTER_DIRECTORY);

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

                unityConverter.CleanupFiles();

                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));
            }
        }
        /// <summary>
        /// Implementation of <see cref="IClientWorkflowScript.OnClientWorkflowScriptExecute" />.
        /// <seealso cref="IClientWorkflowScript" />
        /// </summary>
        /// <param name="app"></param>
        /// <param name="args"></param>
        public void OnClientWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.ClientWorkflowEventArgs args)
        {
            app.Diagnostics.Level = Diagnostics.DiagnosticsLevel.Verbose;

            try
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "Begin Script - Get File Type");

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

                //Get Current Rendition
                Rendition objDocRendition = objCurrentDocument.DefaultRenditionOfLatestRevision;

                if (objDocRendition.FileType.ID == PDF_FILE_TYPE)
                {
                    args.ScriptResult = true;
                    app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "PDF File Format");
                }
                else
                {
                    args.ScriptResult = false;
                    app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "Not PDF File Format");
                }
            }
            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;
            }
            finally
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "End Script - Get File Type");
            }
        }
Example #14
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)
        {
            try
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                //get and clean Inspection Visit ID keyword for passing to LicEase database - says license type, but is passing ID

                KeywordType kwtLicenseType = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gSaveToInspectionVisitID);
                string      strLicenseType = "";
                if (kwtLicenseType != null)
                {
                    KeywordRecord keyRecLicenseType = _currentDocument.KeywordRecords.Find(kwtLicenseType);
                    if (keyRecLicenseType != null)
                    {
                        Keyword kwdLicenseType = keyRecLicenseType.Keywords.Find(kwtLicenseType);
                        if (kwdLicenseType != null)
                        {
                            strLicenseType = CleanSeedKW(kwdLicenseType.ToString());
                        }
                    }
                }

                if (strLicenseType == "")
                {
                    throw new Exception(string.Format("Inspection Visit ID is blank!"));
                }

                //access Config Item for LicEase User
                string gUSER = "";
                if (app.Configuration.TryGetValue("LicEaseUser", out gUSER))
                {
                }

                //access Config Item for LicEase Password
                string gPASS = "";
                if (app.Configuration.TryGetValue("LicEasePassword", out gPASS))
                {
                }

                /* COMMENT THIS SECTION OUT WHEN MOVING TO PROD */
                //access Config Item for LicEase UAT ODBC
                string gODBC = "";
                if (app.Configuration.TryGetValue("LicEaseUAT", out gODBC))
                {
                }

                /* UNCOMMENT THIS SECTION WHEN MOVING TO PROD
                 *              //access Config Item for LicEase PROD ODBC
                 *              string gODBC = "";
                 *              if (app.Configuration.TryGetValue("LicEasePROD", out gODBC))
                 *              {
                 *              }
                 */

                string connectionString = string.Format("DSN={0};Uid={1};Pwd={2};", gODBC, gUSER, gPASS);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Connection string: {0}", connectionString));

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"select a.cmpln_nbr As COMPLAINTNUM from insp_vst iv, insp_hist ih, cmpln a ");
                strSql.Append(@"  where iv.insp_vst_id = '");
                strSql.Append(strLicenseType);
                strSql.Append(@"' and iv.insp_hist_id = ih.insp_hist_id and ih.cmpln_id = a.cmpln_id");

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Sql Query: {0}", strSql.ToString()));

                using (OdbcConnection con = new OdbcConnection(connectionString))
                {
                    try
                    {
                        con.Open();
                        using (OdbcCommand command = new OdbcCommand(strSql.ToString(), con))
                            using (OdbcDataReader reader = command.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    string strCaseNum = "";

                                    reader.Read();

                                    strCaseNum = reader["COMPLAINTNUM"].ToString();

                                    Keyword kwdLicNum = null;
                                    if (!String.IsNullOrEmpty(strCaseNum))
                                    {
                                        KeywordType kwtLicNum = app.Core.KeywordTypes.Find(gSaveToCaseNum);
                                        if (kwtLicNum != null)
                                        {
                                            kwdLicNum = CreateKeywordHelper(kwtLicNum, strCaseNum);
                                        }
                                    }

                                    using (DocumentLock documentLock = _currentDocument.LockDocument())
                                    {
                                        // Ensure lock was obtained
                                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                                        {
                                            throw new Exception("Document lock not obtained");
                                        }
                                        // Create keyword modifier object to hold keyword changes
                                        KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                                        // Add update keyword call to keyword modifier object
                                        //Note Overloads available for use
                                        //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                                        if (kwdLicNum != null)
                                        {
                                            keyModifier.AddKeyword(kwdLicNum);
                                        }

                                        // Apply keyword change to the document
                                        keyModifier.ApplyChanges();

                                        string output = String.Format("Keyword: '{0}' Value: '{1}' added to Document {2}.", gSaveToCaseNum, strCaseNum, _currentDocument.ID);
                                        //Output the results to the OnBase Diagnostics Console
                                        app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);

                                        documentLock.Release();
                                    }
                                }
                                else
                                {
                                    throw new Exception(string.Format("No records found in database for  {0}='{1}' and {4}{2}='{3}' ", gSaveToInspectionVisitID, strLicenseType, gParamAppNum, strCaseNum, Environment.NewLine));
                                }
                            }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Error during database operations!", ex);
                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open)
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                        string.Format("End Script - [{0}]", ScriptName));
            }
        }
        /// <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)
        {
            try
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                //get and clean LicenseType and Application # keywords for passing to LicEase database
                KeywordType kwtInspectorName = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gParamInspectorName);
                string      strInspectorName = "";
                if (kwtInspectorName != null)
                {
                    KeywordRecord keyRecFileNum = _currentDocument.KeywordRecords.Find(kwtInspectorName);
                    if (keyRecFileNum != null)
                    {
                        Keyword kwdFileNum = keyRecFileNum.Keywords.Find(kwtInspectorName);
                        if (kwdFileNum != null)
                        {
                            strInspectorName = CleanSeedKW(kwdFileNum.ToString());
                        }
                    }
                }
                KeywordType kwtInspVisitID = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gParamInspVisitID);
                string      strInspVisitID = "";
                if (kwtInspVisitID != null)
                {
                    KeywordRecord keyRecLicenseType = _currentDocument.KeywordRecords.Find(kwtInspVisitID);
                    if (keyRecLicenseType != null)
                    {
                        Keyword kwdLicenseType = keyRecLicenseType.Keywords.Find(kwtInspVisitID);
                        if (kwdLicenseType != null)
                        {
                            strInspVisitID = CleanSeedKW(kwdLicenseType.ToString());
                        }
                    }
                }

                if ((strInspectorName == "") || (strInspVisitID == ""))
                {
                    throw new Exception(string.Format("Either {0} or {1} is blank.", gParamInspectorName, gParamInspVisitID));
                }

                //access Config Item for LicEase User
                string gUSER = "";
                if (app.Configuration.TryGetValue("LicEaseUser", out gUSER))
                {
                }

                //access Config Item for LicEase Password
                string gPASS = "";
                if (app.Configuration.TryGetValue("LicEasePassword", out gPASS))
                {
                }

                //access Config Item for LicEase PROD ODBC
                string gODBC = "";
                if (app.Configuration.TryGetValue("LicEasePROD", out gODBC))
                {
                }

                string connectionString = string.Format("DSN={0};Uid={1};Pwd={2};", gODBC, gUSER, gPASS);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Connection string: {0}", connectionString));

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"SELECT a.insp_nbr, key_name, dba_name as dba_kw, a.insp_vst_id, a.lic_type AS lic_type, a.indorg_num, a.file_num, a.lic_num AS lic_num, a.visit_num, a.visit_date, ");
                strSql.Append(@" a.insp_typ_desc, a.disposition_kw, city_kw, county_kw, region_kw, a.inspector_name  FROM (SELECT DISTINCT TO_CHAR (insp_hist.insp_nbr) AS insp_nbr, ");
                strSql.Append(@" TO_CHAR (insp_vst.insp_vst_id) AS insp_vst_id, lic.clnt_cde AS lic_type, lic.xent_id AS indorg_num, lic.lic_nbr AS lic_num, lic.file_nbr as file_num,");
                strSql.Append(@" TO_CHAR (insp_vst.insp_vst_nbr) AS visit_num, TO_CHAR (insp_vst.insp_vst_strt_dte) AS visit_date, insp_typ_defn.insp_typ_desc, insp_disp_typ.insp_disp_typ_desc AS disposition_kw, ");
                strSql.Append(@" stff.frst_nme || '.' || stff.surnme AS inspector_name ,insp_hist.lic_id as insp_lic_id ,(select max(key_nme) from name n, link k where k.link_id = insp_hist.link_id and ");
                strSql.Append(@" k.nme_id = n.nme_id) as key_name,(SELECT MAX (key_nme) FROM NAME n, LINK k WHERE k.prnt_id = insp_hist.lic_id and k.link_prnt_cde = 'L' and k.curr_ind = 'Y' ");
                strSql.Append(@" and k.clnt_link_typ_id in (select clnt_link_typ_id from clnt_link_typ c, link_typ t where t.link_typ_id = c.link_typ_id and t.link_typ_cde = 'DBA') ");
                strSql.Append(@" AND k.nme_id = n.nme_id) AS dba_name,(select addr_cty from addr n, link k where k.link_id = insp_hist.link_id and k.addr_id = n.addr_id) as city_kw, ");
                strSql.Append(@" (select cnty_desc from cnty c, addr n, link k where k.link_id = insp_hist.link_id and k.addr_id = n.addr_id and c.cnty = n.cnty) as county_kw , ");
                strSql.Append(@" (select  insp_regn_cde from insp_regn r, link k where k.link_id = insp_hist.link_id and k.insp_regn_id = r.insp_regn_id) as region_kw FROM insp_vst, insp_hist,");
                strSql.Append(@" insp_typ_defn,  insp_disp_typ, inspr, stff, lic WHERE insp_hist.insp_hist_id = insp_vst.insp_hist_id AND insp_vst.insp_vst_id = (SELECT NVL(max(s.alt_insp_vst_id), ");
                strSql.Append(@" max(s.insp_vst_id)) FROM insp_vst_synch s WHERE s.insp_vst_id = '");
                strSql.Append(strInspVisitID);
                strSql.Append(@"') AND insp_typ_defn.insp_typ_defn_id = insp_hist.insp_typ_defn_id AND insp_vst.inspr_id = inspr.inspr_id AND stff.stff_oper_id = inspr.stff_oper_id AND");
                strSql.Append(@" lic.lic_id = insp_hist.lic_id AND insp_disp_typ.insp_disp_typ_id = insp_hist.insp_disp_typ_id) a");

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Sql Query: {0}", strSql.ToString()));

                using (OdbcConnection con = new OdbcConnection(connectionString))
                {
                    try
                    {
                        con.Open();
                        using (OdbcCommand command = new OdbcCommand(strSql.ToString(), con))
                            using (OdbcDataReader reader = command.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    string strMOD = "";

                                    reader.Read();

                                    strMOD = reader["inspector_name"].ToString();

                                    Keyword kwdMOD = null;
                                    if (!String.IsNullOrEmpty(strMOD))
                                    {
                                        KeywordType kwtMOD = app.Core.KeywordTypes.Find(gSaveToEnfInspector);
                                        if (kwtMOD != null)
                                        {
                                            kwdMOD = CreateKeywordHelper(kwtMOD, strMOD);
                                        }
                                    }

                                    using (DocumentLock documentLock = _currentDocument.LockDocument())
                                    {
                                        // Ensure lock was obtained
                                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                                        {
                                            throw new Exception("Document lock not obtained");
                                        }
                                        // Create keyword modifier object to hold keyword changes
                                        KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                                        // Add update keyword call to keyword modifier object
                                        //Note Overloads available for use
                                        //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                                        if (kwdMOD != null)
                                        {
                                            keyModifier.AddKeyword(kwdMOD);
                                        }

                                        // Apply keyword change to the document
                                        keyModifier.ApplyChanges();

                                        string output = String.Format("Keyword: '{0}' Value: '{1}', {3}added to Document {2}.",
                                                                      gSaveToEnfInspector, strMOD, _currentDocument.ID, Environment.NewLine);
                                        //Output the results to the OnBase Diagnostics Console
                                        app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);
                                    }
                                }
                                else
                                {
                                    throw new Exception(string.Format("No records found in database for  {0}='{1}' and {4}{2}='{3}' ", gParamInspVisitID, strInspVisitID, gParamInspectorName, strInspectorName, Environment.NewLine));
                                }
                            }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Error during database operations!", ex);
                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open)
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                        string.Format("End Script - [{0}]", ScriptName));
            }
        }
Example #17
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)
        {
            try
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                //get and clean LicenseType and Case # keywords for passing to LicEase database
                KeywordType kwtLicNum  = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gParamFileNum);
                string      strFileNum = "";
                if (kwtLicNum != null)
                {
                    KeywordRecord keyRecLicNum = _currentDocument.KeywordRecords.Find(kwtLicNum);
                    if (keyRecLicNum != null)
                    {
                        Keyword kwdLicNum = keyRecLicNum.Keywords.Find(kwtLicNum);
                        if (kwdLicNum != null)
                        {
                            strFileNum = CleanSeedKW(kwdLicNum.ToString());
                        }
                    }
                }
                KeywordType kwtLicenseType = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gParamLicType);
                string      strLicenseType = "";
                if (kwtLicenseType != null)
                {
                    KeywordRecord keyRecLicenseType = _currentDocument.KeywordRecords.Find(kwtLicenseType);
                    if (keyRecLicenseType != null)
                    {
                        Keyword kwdLicenseType = keyRecLicenseType.Keywords.Find(kwtLicenseType);
                        if (kwdLicenseType != null)
                        {
                            strLicenseType = CleanSeedKW(kwdLicenseType.ToString());
                        }
                    }
                }

                if (strFileNum == "")
                {
                    throw new Exception(string.Format("Search keyword {0} is blank.", gSaveToDBA));
                }

                if (strLicenseType == "")
                {
                    throw new Exception(string.Format("Search keyword {0} is blank.", gParamLicType));
                }

                //access Config Item for LicEase User
                string gUSER = "";
                if (app.Configuration.TryGetValue("LicEaseUser", out gUSER))
                {
                }

                //access Config Item for LicEase Password
                string gPASS = "";
                if (app.Configuration.TryGetValue("LicEasePassword", out gPASS))
                {
                }

                //access Config Item for LicEase PROD ODBC
                string gODBC = "";
                if (app.Configuration.TryGetValue("LicEasePROD", out gODBC))
                {
                }

                string connectionString = string.Format("DSN={0};Uid={1};Pwd={2};", gODBC, gUSER, gPASS);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Connection string: {0}", connectionString));

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"select (select n.key_nme from link l, clnt_link_typ clt, link_typ lt, name n where c.lic_id = l.prnt_id and l.link_prnt_cde = 'L' and l.curr_ind = 'Y' ");
                strSql.Append(@" and l.clnt_link_typ_id = clt.clnt_link_typ_id and clt.link_typ_id = lt.link_typ_id and lt.link_typ_cde = 'DBA' and l.nme_id = n.nme_id and n.ent_nme_typ = 'D' ");
                strSql.Append(@" and n.cur_nme_ind = 'Y') as DBA, (select trim(a.str_addr_nbr||' '||a.addr_line1||' '||a.addr_line2||' '||a.addr_line3||' '||a.addr_cty||', '||a.st_cde||' '||a.addr_zip) ");
                strSql.Append(@" from link l, clnt_link_typ clt, link_typ lt, addr a where c.lic_id = l.prnt_id and l.link_prnt_cde = 'L' and l.curr_ind = 'Y' and l.clnt_link_typ_id = clt.clnt_link_typ_id ");
                strSql.Append(@" and clt.link_typ_id = lt.link_typ_id and lt.link_typ_cde = 'LL' and l.addr_id = a.addr_id) as LocationAddress, (select y.cnty_desc from link l, clnt_link_typ clt, link_typ lt, addr a, cnty y ");
                strSql.Append(@" where c.lic_id = l.prnt_id and l.link_prnt_cde = 'L' and l.curr_ind = 'Y' and l.clnt_link_typ_id = clt.clnt_link_typ_id  ");
                strSql.Append(@" and clt.link_typ_id = lt.link_typ_id and lt.link_typ_cde = 'LL' and l.addr_id = a.addr_id and a.cnty = y.cnty) as LocationCounty from lic c");
                strSql.Append(@" where c.clnt_cde = '");
                strSql.Append(strLicenseType);
                strSql.Append(@"' and c.file_nbr = '");
                strSql.Append(strFileNum);
                strSql.Append(@"'");

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Sql Query: {0}", strSql.ToString()));

                using (OdbcConnection con = new OdbcConnection(connectionString))
                {
                    try
                    {
                        con.Open();
                        using (OdbcCommand command = new OdbcCommand(strSql.ToString(), con))
                            using (OdbcDataReader reader = command.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    string strDBA    = "";
                                    string strCounty = "";
                                    string strDesc   = "";

                                    reader.Read();

                                    strDesc   = reader["LocationAddress"].ToString();
                                    strDBA    = reader["DBA"].ToString();
                                    strCounty = reader["LocationCounty"].ToString();

                                    Keyword kwdDesc = null;
                                    if (!String.IsNullOrEmpty(strDesc))
                                    {
                                        KeywordType kwtDesc = app.Core.KeywordTypes.Find(gSaveToLocationAddress);
                                        if (kwtDesc != null)
                                        {
                                            kwdDesc = CreateKeywordHelper(kwtDesc, strDesc);
                                        }
                                    }

                                    Keyword kwdDBA = null;
                                    if (!String.IsNullOrEmpty(strDBA))
                                    {
                                        KeywordType kwtDBA = app.Core.KeywordTypes.Find(gSaveToDBA);
                                        if (kwtDBA != null)
                                        {
                                            kwdDBA = CreateKeywordHelper(kwtDBA, strDBA);
                                        }
                                    }

                                    Keyword kwdCounty = null;
                                    if (!String.IsNullOrEmpty(strCounty))
                                    {
                                        KeywordType kwtCounty = app.Core.KeywordTypes.Find(gSaveToCounty);
                                        if (kwtCounty != null)
                                        {
                                            kwdCounty = CreateKeywordHelper(kwtCounty, strCounty);
                                        }
                                    }

                                    using (DocumentLock documentLock = _currentDocument.LockDocument())
                                    {
                                        // Ensure lock was obtained
                                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                                        {
                                            throw new Exception("Document lock not obtained");
                                        }
                                        // Create keyword modifier object to hold keyword changes
                                        KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                                        // Add update keyword call to keyword modifier object
                                        //Note Overloads available for use
                                        //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                                        if (kwdDesc != null)
                                        {
                                            keyModifier.AddKeyword(kwdDesc);
                                        }
                                        if (kwdDBA != null)
                                        {
                                            keyModifier.AddKeyword(kwdDBA);
                                        }
                                        if (kwdCounty != null)
                                        {
                                            keyModifier.AddKeyword(kwdCounty);
                                        }

                                        // Apply keyword change to the document
                                        keyModifier.ApplyChanges();

                                        string output = String.Format("Keyword: '{0}' Value: '{1}', {7}Keyword: '{2}' Value: '{3}', {7}Keyword: '{4}' Value: '{5}', {7}added to Document {6}.",
                                                                      gSaveToDBA, strDBA, gSaveToLocationAddress, strDesc, gSaveToCounty, strCounty, _currentDocument.ID, Environment.NewLine);
                                        //Output the results to the OnBase Diagnostics Console
                                        app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);

                                        documentLock.Release();
                                    }
                                }
                                else
                                {
                                    throw new Exception(string.Format("No records found in database"));
                                }
                            }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Error during database operations!", ex);
                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open)
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                        string.Format("End Script - [{0}]", ScriptName));
            }
        }
Example #18
0
        /// <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)
        public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
            try
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                KeywordType kwtISN = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gParamISN);
                string      strISN = "";
                if (kwtISN != null)
                {
                    KeywordRecord keyISN = _currentDocument.KeywordRecords.Find(kwtISN);
                    if (keyISN != null)
                    {
                        Keyword kwdISN = keyISN.Keywords.Find(kwtISN);
                        if (kwdISN != null)
                        {
                            strISN = kwdISN.ToString();
                        }
                    }
                }

                if (strISN == "")
                {
                    throw new Exception(string.Format("Search keyword {0} is blank.", gSaveToISN));
                }

                string strCountry  = "";
                string strTheater  = "";
                string strPower    = "";
                string strSequence = "";
                string strDetainee = "";

                strCountry  = strISN.Substring(0, 2);
                strTheater  = strISN.Substring(2, 1);
                strPower    = strISN.Substring(3, 2);
                strSequence = strISN.Substring(5, 6);
                strDetainee = strISN.Substring(11, 2);

                string strTheaterResult = "";

                switch (strTheater)
                {
                case "A":
                    strTheaterResult = "TRANSCOM";
                    break;

                case "1":
                    strTheaterResult = "FORSCOM";
                    break;

                case "2":
                    strTheaterResult = "AFRICOM";
                    break;

                case "3":
                    strTheaterResult = "PACOM";
                    break;

                case "4":
                    strTheaterResult = "EUCOM";
                    break;

                case "5":
                    strTheaterResult = "PACOM";
                    break;

                case "6":
                    strTheaterResult = "SOUTHCOM";
                    break;

                case "7":
                    strTheaterResult = "SPACECOM";
                    break;

                case "8":
                    strTheaterResult = "STRATCOM";
                    break;

                case "9":
                    strTheaterResult = "CENTCOM";
                    break;

                default:
                    strTheaterResult = "UNDETERMINED";
                    break;
                }

                Keyword kwdCountry = null;
                if (!String.IsNullOrEmpty(strCountry))
                {
                    KeywordType kwtCountry = app.Core.KeywordTypes.Find(gSaveToCountry);
                    if (kwtCountry != null)
                    {
                        kwdCountry = CreateKeywordHelper(kwtCountry, strCountry);
                    }
                }

                Keyword kwdTheater = null;
                if (!String.IsNullOrEmpty(strTheaterResult))
                {
                    KeywordType kwtTheater = app.Core.KeywordTypes.Find(gSaveToTheater);
                    if (kwtTheater != null)
                    {
                        kwdTheater = CreateKeywordHelper(kwtTheater, strTheaterResult);
                    }
                }

                Keyword kwdPower = null;
                if (!String.IsNullOrEmpty(strPower))
                {
                    KeywordType kwtPower = app.Core.KeywordTypes.Find(gSaveToPower);
                    if (kwtPower != null)
                    {
                        kwdPower = CreateKeywordHelper(kwtPower, strPower);
                    }
                }

                Keyword kwdSequence = null;
                if (!String.IsNullOrEmpty(strSequence))
                {
                    KeywordType kwtSequence = app.Core.KeywordTypes.Find(gSaveToSequence);
                    if (kwtSequence != null)
                    {
                        kwdSequence = CreateKeywordHelper(kwtSequence, strSequence);
                    }
                }

                Keyword kwdDetainee = null;
                if (!String.IsNullOrEmpty(strDetainee))
                {
                    KeywordType kwtDetainee = app.Core.KeywordTypes.Find(gSaveToDetainee);
                    if (kwtDetainee != null)
                    {
                        kwdDetainee = CreateKeywordHelper(kwtDetainee, strDetainee);
                    }
                }

                using (DocumentLock documentLock = _currentDocument.LockDocument())
                {
                    // Ensure lock was obtained
                    if (documentLock.Status != DocumentLockStatus.LockObtained)
                    {
                        throw new Exception("Document lock not obtained");
                    }
                    // Create keyword modifier object to hold keyword changes
                    KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                    keyModifier.AddKeyword(kwdCountry);
                    keyModifier.AddKeyword(kwdTheater);
                    keyModifier.AddKeyword(kwdPower);
                    keyModifier.AddKeyword(kwdSequence);
                    keyModifier.AddKeyword(kwdDetainee);

                    // Apply keyword change to the document
                    keyModifier.ApplyChanges();

                    string output = String.Format("Keyword: '{0}' Value: '{1}', {11}Keyword: '{2}' Value: '{3}', {11}Keyword: '{4}' Value: '{5}', {11}Keyword: '{6}' Value: '{7}'," +
                                                  "{11}Keyword: '{8}' Value: '{9}', {11}added to Document {10}.",
                                                  gSaveToCountry, strCountry, gSaveToTheater, strTheater, gSaveToPower, strPower, gSaveToSequence, strSequence, gSaveToDetainee, strDetainee, _currentDocument.ID, Environment.NewLine);
                    //Output the results to the OnBase Diagnostics Console
                    app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);

                    documentLock.Release();
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                        string.Format("End Script - [{0}]", ScriptName));
            }
        }
Example #19
0
        /// <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
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                args.PropertyBag.TryGetValue("pbLicType", out propLicType);
                propLicType = propLicType.Substring(0, 2);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("LicType trimmed: {0}", propLicType));

                string strBoard = "";

                switch (propLicType)
                {
                case "01":
                    strBoard = "CPA";
                    break;

                case "02":
                    strBoard = "Architecture";
                    break;

                case "03":
                    strBoard = "Barbers";
                    break;

                case "04":
                    strBoard = "Home Inspectors";
                    break;

                case "05":
                    strBoard = "Cosmetology";
                    break;

                case "06":
                    strBoard = "CILB";
                    break;

                case "07":
                    strBoard = "Mold";
                    break;

                case "08":
                    strBoard = "Electrical";
                    break;

                case "09":
                    strBoard = "CPE";
                    break;

                case "10":
                    strBoard = "PMW";
                    break;

                case "11":
                    strBoard = "Funeral Directors and Embalmers";
                    break;

                case "12":
                    strBoard = "Surveyors & Mappers";
                    break;

                case "13":
                    strBoard = "Landscape Architecture";
                    break;

                case "20":
                    strBoard = "Hotels and Restaurants";
                    break;

                case "21":
                    strBoard = "Elevator Safety";
                    break;

                case "23":
                    strBoard = "Harbor Pilot";
                    break;

                case "25":
                    strBoard = "FREC";
                    break;

                case "26":
                    strBoard = "Veterinary Medicine";
                    break;

                case "33":
                    strBoard = "DDC";
                    break;

                case "38":
                    strBoard = "CAM";
                    break;

                case "40":
                    strBoard = "ABT";
                    break;

                case "48":
                    strBoard = "Auctioneers";
                    break;

                case "49":
                    strBoard = "Talent Agents";
                    break;

                case "50":
                    strBoard = "Building Code Administrators";
                    break;

                case "53":
                    strBoard = "Geologists";
                    break;

                case "59":
                    strBoard = "Asbestos";
                    break;

                case "60":
                    strBoard = "Athletic Agents";
                    break;

                case "63":
                    strBoard = "Employee Leasing";
                    break;

                case "64":
                    strBoard = "FREAB";
                    break;

                case "74":
                    strBoard = "Labor Organization";
                    break;

                case "75":
                    strBoard = "Farm Labor";
                    break;

                case "76":
                    strBoard = "Child Labor";
                    break;

                case "80":
                    strBoard = "Condos, Coops, Timeshares";
                    break;

                case "81":
                    strBoard = "Mobile Homes";
                    break;

                case "82":
                    strBoard = "Land Sales";
                    break;

                case "83":
                    strBoard = "Other Entities";
                    break;

                case "85":
                    strBoard = "Yacht and Ship Brokers";
                    break;

                case "90":
                    strBoard = "Office of the Secretary";
                    break;

                case "98":
                    strBoard = "OGC Miscellaneous";
                    break;

                case "99":
                    strBoard = "Regulation";
                    break;
                }

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Board KW to = {0}", strBoard));

                Keyword kwdBoard = null;
                if (!String.IsNullOrEmpty(strBoard))
                {
                    KeywordType kwtBoard = app.Core.KeywordTypes.Find(gSaveToBoard);
                    if (kwtBoard != null)
                    {
                        kwdBoard = CreateKeywordHelper(kwtBoard, strBoard);
                    }
                }

                args.PropertyBag.TryGetValue("pbRegion", out propRegion);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Region = {0}", propRegion));

                string strRegionFullName = "";

                switch (propRegion)
                {
                case "01":
                    strRegionFullName = "Fort Walton";
                    break;

                case "02":
                    strRegionFullName = "Tallahassee";
                    break;

                case "03":
                    strRegionFullName = "Jacksonville";
                    break;

                case "04":
                    strRegionFullName = "Gainesville";
                    break;

                case "05":
                    strRegionFullName = "Orlando";
                    break;

                case "06":
                    strRegionFullName = "Tampa";
                    break;

                case "07":
                    strRegionFullName = "Fort Myers";
                    break;

                case "08":
                    strRegionFullName = "West Palm Beach";
                    break;

                case "09":
                    strRegionFullName = "Margate";
                    break;

                case "10":
                    strRegionFullName = "Miami";
                    break;

                default:
                    strRegionFullName = "";
                    break;
                }

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Region Value = {0}", strRegionFullName));

                string strFullComplainant = "DBPR - " + strRegionFullName;

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Complainant KW to = {0}", strFullComplainant));


                Keyword kwdRegion = null;
                if (!String.IsNullOrEmpty(strRegionFullName))
                {
                    KeywordType kwtRegion = app.Core.KeywordTypes.Find(gSaveToComplainant);
                    if (kwtRegion != null)
                    {
                        kwdRegion = CreateKeywordHelper(kwtRegion, strRegionFullName);
                    }
                }

                using (DocumentLock documentLock = _currentDocument.LockDocument())
                {
                    // Ensure lock was obtained
                    if (documentLock.Status != DocumentLockStatus.LockObtained)
                    {
                        throw new Exception("Document lock not obtained");
                    }
                    // Create keyword modifier object to hold keyword changes
                    KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                    // Add update keyword call to keyword modifier object
                    //Note Overloads available for use
                    //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                    if (kwdBoard != null)
                    {
                        keyModifier.AddKeyword(kwdBoard);
                    }
                    if (kwdRegion != null)
                    {
                        keyModifier.AddKeyword(kwdRegion);
                    }

                    // Apply keyword change to the document
                    keyModifier.ApplyChanges();

                    string output = String.Format("Keyword: '{0}' Value: '{1}', {5}Keyword: '{2}' Value: '{3}', {5}added to Document {4}.",
                                                  gSaveToBoard, strBoard, gSaveToComplainant, strFullComplainant, _currentDocument.ID, Environment.NewLine);
                    //Output the results to the OnBase Diagnostics Console
                    app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                        string.Format("End Script - [{0}]", ScriptName));
            }
        }
Example #20
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)
        {
            try
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, string.Format("{0} - Start Script - [{1}]", DateTime.Now.ToString(DateTimeFormat), ScriptName));

                // Initialize global settings
                IntializeScript(ref app, ref args);

                //access Config Item for OnBase User
                string gUSER = "";
                if (app.Configuration.TryGetValue("OnBaseUser", out gUSER))
                {
                }

                //access Config Item for OnBase Password
                string gPASS = "";
                if (app.Configuration.TryGetValue("OnBasePassword", out gPASS))
                {
                }

                /* COMMENT THIS SECTION OUT WHEN MOVING TO PROD */
                //access Config Item for OnBase UAT ODBC
                string gUATODBC = "";
                if (app.Configuration.TryGetValue("OnBaseUAT", out gUATODBC))
                {
                }

                //access Config Item for OnBase PROD ODBC
                string gPRODODBC = "";
                if (app.Configuration.TryGetValue("OnBasePROD", out gPRODODBC))
                {
                }

                LCID = args.Queue.LifeCycle.ID;

                app.Diagnostics.Write(LCID.ToString());

                string connectionString = string.Format("DSN={0};Uid={1};Pwd={2};", gUATODBC, gUSER, gPASS);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Connection string: {0}", connectionString));

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"SELECT hsi.useraccount.username AS USERNAME");
                strSql.Append(@"  FROM hsi.useraccount inner join hsi.itemlcxuser ");
                strSql.Append(@"  ON hsi.useraccount.usernum = hsi.itemlcxuser.usernum ");
                strSql.Append(@"  WHERE hsi.itemlcxuser.itemnum = '");
                strSql.Append(_currentDocument.ID);
                strSql.Append(@"' AND hsi.itemlcxuser.lcnum = '");
                strSql.Append(LCID);
                strSql.Append(@"'");

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Sql Query: {0}", strSql.ToString()));

                using (OdbcConnection con = new OdbcConnection(connectionString))
                {
                    try
                    {
                        con.Open();
                        using (OdbcCommand command = new OdbcCommand(strSql.ToString(), con))
                            using (OdbcDataReader reader = command.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    string strUN = "";

                                    reader.Read();

                                    strUN = reader["USERNAME"].ToString();

                                    Keyword kwdUN = null;
                                    if (!String.IsNullOrEmpty(strUN))
                                    {
                                        KeywordType kwtUN = app.Core.KeywordTypes.Find(gSaveToUserName);
                                        if (kwtUN != null)
                                        {
                                            kwdUN = CreateKeywordHelper(kwtUN, strUN);
                                        }
                                    }

                                    using (DocumentLock documentLock = _currentDocument.LockDocument())
                                    {
                                        // Ensure lock was obtained
                                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                                        {
                                            throw new Exception("Document lock not obtained");
                                        }
                                        // Create keyword modifier object to hold keyword changes
                                        KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                                        // Add update keyword call to keyword modifier object
                                        //Note Overloads available for use
                                        //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                                        if (kwdUN != null)
                                        {
                                            keyModifier.AddKeyword(kwdUN);
                                        }

                                        // Apply keyword change to the document
                                        keyModifier.ApplyChanges();

                                        string output = String.Format("Keyword: '{0}' Value: '{1}', {3}added to Document {2}.",
                                                                      gSaveToUserName, strUN, _currentDocument.ID, Environment.NewLine);
                                        //Output the results to the OnBase Diagnostics Console
                                        app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);

                                        documentLock.Release();
                                    }
                                }
                                else
                                {
                                    throw new Exception(string.Format("No records found in database for  DH {0} and LCID ='{1}'", _currentDocument.ID, LCID));
                                }
                            }
                    }
                    catch (Exception ex)
                    {
                        // Handle exceptions and log to Diagnostics Console and document history
                        HandleException(ex, ref app, ref args);
                    }
                    finally
                    {
                        // Log script execution end
                        app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                                string.Format("End Script - [{0}]", ScriptName));
                    }
                }
            }
            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));
            }
        }
        /// <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)
        {
            try
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);


                //access Config Item for LicEase User
                string gUSER = "";
                if (app.Configuration.TryGetValue("OnBaseUser", out gUSER))
                {
                }

                //access Config Item for LicEase Password
                string gPASS = "";
                if (app.Configuration.TryGetValue("OnBasePassword", out gPASS))
                {
                }

                //access Config Item for LicEase PROD ODBC
                string gODBC = "";
                if (app.Configuration.TryGetValue("OnBaseDEV", out gODBC))
                {
                }

                string strBatch = "";

                if (!args.SessionPropertyBag.TryGetValue(gProp, out strBatch))
                {
                }

                string connectionString = string.Format("DSN={0};Uid={1};Pwd={2};", gODBC, gUSER, gPASS);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Connection string: {0}", connectionString));

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"select hsi.keyitem114.keyvaluecurr AS VAL from hsi.keyitem114 join hsi.keyitem143 on hsi.keyitem114.itemnum = hsi.keyitem143.itemnum ");
                strSql.Append(@" join hsi.itemdata on hsi.keyitem114.itemnum = hsi.itemdata.itemnum where hsi.itemdata.itemtypenum <> 146 and hsi.itemdata.status = 0 and hsi.keyitem143.keyvaluebig = ");
                strSql.Append(strBatch);
                strSql.Append(@"'");

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Sql Query: {0}", strSql.ToString()));

                using (OdbcConnection con = new OdbcConnection(connectionString))
                {
                    try
                    {
                        con.Open();
                        using (OdbcCommand command = new OdbcCommand(strSql.ToString(), con))
                            using (OdbcDataReader reader = command.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    while (reader.Read())
                                    {
                                        lstProp.Add(reader["VAL"].ToString());
                                    }

                                    double total = 0;

                                    foreach (string remit in lstProp)
                                    {
                                        total = total + double.Parse(remit);
                                    }

                                    Keyword kwdDesc = null;
                                    if (!String.IsNullOrEmpty(total.ToString()))
                                    {
                                        KeywordType kwtDesc = app.Core.KeywordTypes.Find("Remittance Total");
                                        if (kwtDesc != null)
                                        {
                                            kwdDesc = CreateKeywordHelper(kwtDesc, total.ToString());
                                        }
                                    }


                                    using (DocumentLock documentLock = _currentDocument.LockDocument())
                                    {
                                        // Ensure lock was obtained
                                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                                        {
                                            throw new Exception("Document lock not obtained");
                                        }
                                        // Create keyword modifier object to hold keyword changes
                                        KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                                        // Add update keyword call to keyword modifier object
                                        //Note Overloads available for use
                                        //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                                        if (kwdDesc != null)
                                        {
                                            keyModifier.AddKeyword(kwdDesc);
                                        }

                                        // Apply keyword change to the document
                                        keyModifier.ApplyChanges();

                                        string output = String.Format("Keyword: '{0}' Value: '{1}', added to Document {2}.", "Remittance Total", total.ToString(), _currentDocument.ID);
                                        //Output the results to the OnBase Diagnostics Console
                                        app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);

                                        documentLock.Release();
                                    }
                                }
                                else
                                {
                                    throw new Exception(string.Format("No records found in database"));
                                }
                            }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Error during database operations!", ex);
                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open)
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                        string.Format("End Script - [{0}]", ScriptName));
            }
        }
        /// <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
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                KeywordType kwtLicenseType = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gParamLicType);
                string strLicenseType = "";
                if (kwtLicenseType != null)
                {
                    KeywordRecord keyRecLicenseType = _currentDocument.KeywordRecords.Find(kwtLicenseType);
                    if (keyRecLicenseType != null)
                    {
                        Keyword kwdLicenseType = keyRecLicenseType.Keywords.Find(kwtLicenseType);
                        if (kwdLicenseType != null)
                            strLicenseType = CleanSeedKW(kwdLicenseType.ToString());
                    }
                }

                KeywordType kwtLicenseNum = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gParamLicNum);
                string strLicenseNum = "";
                if (kwtLicenseNum != null)
                {
                    KeywordRecord keyRecLicenseNum = _currentDocument.KeywordRecords.Find(kwtLicenseNum);
                    if (keyRecLicenseNum != null)
                    {
                        Keyword kwdLicenseNum = keyRecLicenseNum.Keywords.Find(kwtLicenseNum);
                        if (kwdLicenseNum != null)
                            strLicenseNum = CleanSeedKW(kwdLicenseNum.ToString());
                    }
                }

                if ((strLicenseNum == "") || (strLicenseType == ""))
                {
                    throw new Exception(string.Format("Either {0} or {1} is blank.", gParamLicNum, gParamLicType));
                }

                //access Config Item for LicEase User
                string gUSER = "";
                if (app.Configuration.TryGetValue("LicEaseUser", out gUSER))
                {
                }

                //access Config Item for LicEase Password
                string gPASS = "";
                if (app.Configuration.TryGetValue("LicEasePassword", out gPASS))
                {
                }

                /* COMMENT THIS SECTION OUT WHEN MOVING TO PROD */
                //access Config Item for LicEase UAT ODBC
                string gODBC = "";
                if (app.Configuration.TryGetValue("LicEaseUAT", out gODBC))
                {
                }

                /* UNCOMMENT THIS SECTION WHEN MOVING TO PROD
				//access Config Item for LicEase PROD ODBC
				string gODBC = "";
				if (app.Configuration.TryGetValue("LicEasePROD", out gODBC))
				{
				}
				*/

                string connectionString = string.Format("DSN={0};Uid={1};Pwd={2};", gODBC, gUSER, gPASS);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Connection string: {0}", connectionString));

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"SELECT l.file_nbr AS FILENUM, n.key_nme AS KEYNAME, l.xent_id AS INDNUM ");
                strSql.Append(@"  FROM Lic l ");
                strSql.Append(@"  left join name n on l.xent_id = n.xent_id  ");
                strSql.Append(@"  WHERE l.clnt_cde = '");
                strSql.Append(strLicenseType);
                strSql.Append(@"' CAST(l.lic_nbr AS number) = '");
                strSql.Append(strLicenseNum);
                strSql.Append(@"' AND n.ent_nme_typ = 'D' AND n.cur_nme_ind = 'Y' AND rownum = '1'");

                using (OdbcConnection con = new OdbcConnection(connectionString))
                {
                    try
                    {
                        con.Open();
                        using (OdbcCommand command = new OdbcCommand(strSql.ToString(), con))
                        using (OdbcDataReader reader = command.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                string strFileNum = "";
                                string strKeyName = "";
                                string strIndNum = "";

                                reader.Read();

                                strFileNum = reader["FILENUM"].ToString();
                                strKeyName = reader["KEYNAME"].ToString();
                                strIndNum = reader["INDNUM"].ToString();

                                Keyword kwdFileNum = null;
                                if (!String.IsNullOrEmpty(strFileNum))
                                {
                                    KeywordType kwtFileNum = app.Core.KeywordTypes.Find(gSaveToFileNum);
                                    if (kwtFileNum != null)
                                        kwdFileNum = CreateKeywordHelper(kwtFileNum, strFileNum);
                                }
                                Keyword kwdKeyName = null;
                                if (!String.IsNullOrEmpty(strKeyName))
                                {
                                    KeywordType kwtKeyName = app.Core.KeywordTypes.Find(gSaveToKeyName);
                                    if (kwtKeyName != null)
                                        kwdKeyName = CreateKeywordHelper(kwtKeyName, strKeyName);
                                }
                                Keyword kwdIndNum = null;
                                if (!String.IsNullOrEmpty(strIndNum))
                                {
                                    KeywordType kwtIndNum = app.Core.KeywordTypes.Find(gSaveToIndNum);
                                    if (kwtIndNum != null)
                                        kwdIndNum = CreateKeywordHelper(kwtIndNum, strIndNum);
                                }
                                using (DocumentLock documentLock = _currentDocument.LockDocument())
                                {
                                    // Ensure lock was obtained
                                    if (documentLock.Status != DocumentLockStatus.LockObtained)
                                    {
                                        throw new Exception("Document lock not obtained");
                                    }
                                    // Create keyword modifier object to hold keyword changes
                                    KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                                    // Add update keyword call to keyword modifier object
                                    //Note Overloads available for use
                                    //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                                    if (kwdFileNum != null) keyModifier.AddKeyword(kwdFileNum);
                                    if (kwdKeyName != null) keyModifier.AddKeyword(kwdKeyName);
                                    if (kwdIndNum != null) keyModifier.AddKeyword(kwdIndNum);

                                    // Apply keyword change to the document
                                    keyModifier.ApplyChanges();

                                    string output = String.Format("Keyword: '{0}' Value: '{1}', {7}Keyword: '{2}' Value: '{3}', {7}Keyword: '{4}' Value: '{5}', {7}added to Document {6}.",
                                        gSaveToFileNum, strFileNum, gSaveToKeyName, strKeyName, gSaveToIndNum, strIndNum, _currentDocument.ID, Environment.NewLine);
                                    //Output the results to the OnBase Diagnostics Console
                                    app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);
                                }
                            }
                            else
                            {
                                throw new Exception(string.Format("No records found in database for  {0}='{1}' and {4}{2}='{3}' ", gParamLicType, strLicenseType, gParamLicNum, strLicenseNum, Environment.NewLine));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Error during database operations!", ex);
                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open) con.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                    string.Format("End Script - [{0}]", ScriptName));
            }
        }
Example #23
0
        /// <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
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                string strRelatedCase = "";
                args.SessionPropertyBag.TryGetValue(gPropCase, out strRelatedCase);

                app.Diagnostics.Write(string.Format("property for related case # = {0}", strRelatedCase));

                if (string.IsNullOrEmpty(strRelatedCase))
                {
                    throw new Exception(String.Format("Property '{0}' not found", strRelatedCase));
                }

                //access Config Item for OnBase User
                string gUSER = "";
                if (app.Configuration.TryGetValue("OnBaseUser", out gUSER))
                {
                }

                //access Config Item for OnBase Password
                string gPASS = "";
                if (app.Configuration.TryGetValue("OnBasePassword", out gPASS))
                {
                }

                /* COMMENT THIS SECTION OUT WHEN MOVING TO PROD */
                //access Config Item for OnBase UAT ODBC
                string gODBC = "";
                if (app.Configuration.TryGetValue("OBUAT", out gODBC))
                {
                }

                /* UNCOMMENT THIS SECTION WHEN MOVING TO PROD
                 *              //access Config Item for OnBase PROD ODBC
                 *              string gODBC = "";
                 *              if (app.Configuration.TryGetValue("OnBasePROD", out gODBC))
                 *              {
                 *              }
                 */

                string connectionString = string.Format("DSN={0};Uid={1};Pwd={2};", gODBC, gUSER, gPASS);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Connection string: {0}", connectionString));

                StringBuilder strSql = new StringBuilder();
                strSql.Append("select distinct ua.username AS USER FROM hsi.itemlc ilc ");
                strSql.Append("join hsi.itemlcxuser ilcxu on ilc.itemnum = ilcxu.itemnum ");
                strSql.Append("join hsi.useraccount ua on ilcxu.usernum = ua.usernum ");
                strSql.Append("join hsi.keyxitem138 ki138 on ilc.itemnum = ki138.itemnum ");
                strSql.Append("join hsi.keytable138 kt138 on ki138.keywordnum = kt138.keywordnum ");
                strSql.Append("where ilc.lcnum = 177 and ilc.statenum = 568 and kt138.keyvaluechar = '");
                strSql.Append(strRelatedCase);
                strSql.Append("'");

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Sql Query: {0}", strSql.ToString()));

                using (OdbcConnection con = new OdbcConnection(connectionString))
                {
                    try
                    {
                        con.Open();
                        using (OdbcCommand command = new OdbcCommand(strSql.ToString(), con))
                            using (OdbcDataReader reader = command.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    string strProf = "";

                                    reader.Read();

                                    strProf = reader["USER"].ToString();

                                    Keyword kwdProf = null;
                                    if (!String.IsNullOrEmpty(strProf))
                                    {
                                        KeywordType kwtProf = app.Core.KeywordTypes.Find(gSaveToReassignedAnalyst);
                                        if (kwtProf != null)
                                        {
                                            kwdProf = CreateKeywordHelper(kwtProf, strProf);
                                        }
                                    }

                                    using (DocumentLock documentLock = _currentDocument.LockDocument())
                                    {
                                        // Ensure lock was obtained
                                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                                        {
                                            throw new Exception("Document lock not obtained");
                                        }
                                        // Create keyword modifier object to hold keyword changes
                                        KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                                        // Add update keyword call to keyword modifier object
                                        //Note Overloads available for use
                                        //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                                        if (kwdProf != null)
                                        {
                                            keyModifier.AddKeyword(kwdProf);
                                        }

                                        // Apply keyword change to the document
                                        keyModifier.ApplyChanges();

                                        string output = String.Format("Keyword: '{0}' Value: '{1}', {3}added to Document {2}.",
                                                                      gSaveToReassignedAnalyst, strProf, _currentDocument.ID, Environment.NewLine);
                                        //Output the results to the OnBase Diagnostics Console
                                        app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);

                                        documentLock.Release();
                                    }
                                }
                                else
                                {
                                    throw new Exception(string.Format("No records found in database for  {0}='{1}'", gPropCase, strRelatedCase));
                                }
                            }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Error during database operations!", ex);
                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open)
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                        string.Format("End Script - [{0}]", ScriptName));
            }
        }
Example #24
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)
        {
            bool result = true;

            try
            {
                Guid     Envelope_Id = Guid.Empty;
                string   propEnvId = "", title = "", notifySigner = "", overrideDeliveryMethod = "", singleEmail = "";
                string[] multipleEmails = new string[10], designers = new string[10];
                bool     notify = true, design = false, uploadStaples = false;

                //Initiate a new TrueSign object. The clint API creds must have been set
                //on Session Property bags before the script was called.
                //TrueSignClientID - holds the Guid for the API client ID
                //TrueSignClientSecret - holds a string for the API client secret
                TrueSignNext TrueSign = new TrueSignNext(app, args);

                //Check if the envelope was already created (in a batch situation)
                if (!args.SessionPropertyBag.TryGetValue("TrueSignEnvelopeId", out propEnvId))
                {
                    //You are here because this is a new envelope. Get the title set in a prop bag
                    args.SessionPropertyBag.TryGetValue("TrueSignEnvelopeTitle", out title);

                    args.SessionPropertyBag.TryGetValue("TrueSignOverrideDeliveryMethod", out overrideDeliveryMethod);

                    //If the title was empty, we will set a default one
                    if (string.IsNullOrEmpty(title))
                    {
                        title = "OnBase Envelope " + DateTime.Now.ToString("g");
                    }

                    //Create a contact object that will be on external envelopes.
                    //This info will appear on the email sent to the required signer. NOT REQUIRED
                    var contact = new Contact();
                    contact.First_Name = "";
                    contact.Last_Name  = "";
                    contact.Title      = "ImageSoft County Court";
                    contact.Email      = "*****@*****.**";
                    contact.Phone      = "(313) 555 - 5555";

                    //Create the actual envelope
                    var env = TrueSign.CreateEnvelope(title, null, null, contact, overrideDeliveryMethod);
                    if (env == null)
                    {
                        throw new Exception("Failed to create a new envelope");
                    }

                    //Set the envelope ID to a property bag.
                    Envelope_Id = env.Id;
                    args.SessionPropertyBag.Set("TrueSignEnvelopeId", Envelope_Id.ToString());
                }
                else
                {
                    //You are here because an envelope has already been created and this is the 1+ document in the batch.
                    //You could also be here because you forgot to clear the properties.
                    Envelope_Id = Guid.Parse(propEnvId);

                    app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "Envelope had already been created, adding files...");
                }

                //Upload the current document to the envelope
                var doc = TrueSign.AddToEnvelope(Envelope_Id, args.Document);
                if (doc == null)
                {
                    throw new Exception(string.Format("Failed to add document to envelope. Doc ID: {0}", args.Document.ID));
                }

                args.SessionPropertyBag.TryGetValue("TrueSignUploadStaples", out uploadStaples);
                if (uploadStaples)
                {
                    List <Hyland.Unity.Document> staples = new List <Hyland.Unity.Document>();
                    foreach (var note in args.Document.Notes.FindAll(x => x.NoteType.Flavor == NoteFlavor.Staple))
                    {
                        staples.Add(note.StapledDocument);
                    }

                    if (staples.Count > 0)
                    {
                        TrueSign.AddToEnvelope(Envelope_Id, staples, true);
                    }
                }

                //Call the function to save all notes in a prop bag.
                //This only works when the envelope has one signer and a TrueSignNoteId prop has been set.
                SaveAnchorsToProp(app, args, doc.Id);

                //If this is the last document in the batch
                if (args.BatchDocumentsRemaining == 0)
                {
                    List <Signer> signers = new List <Signer>();

                    //Check if envelope has multiple or single signer
                    //if (args.SessionPropertyBag.TryGetValue("TrueSignSignerEmail", out singleEmail))
                    //    signers.Add(GetSigner(app, args));
                    if (args.SessionPropertyBag.TryGetValue("TrueSignSignerEmail", out multipleEmails))
                    {
                        signers.AddRange(GetSigners(app, args));
                    }
                    else
                    {
                        app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "No property bag for signer email found...");
                    }

                    foreach (Signer signer in signers)
                    {
                        //Check if this envelope is meant for an external signer
                        if (signer.Type == Signer_Type.External)
                        {
                            //Add the signer to the envelope.
                            TrueSign.AddExternalSigner(Envelope_Id, signer);
                        }
                        else
                        {
                            args.SessionPropertyBag.TryGetValue("TrueSignNotifySigner", out notifySigner);

                            if (!string.IsNullOrEmpty(notifySigner))
                            {
                                signer.Notify = bool.Parse(notifySigner);
                            }

                            //This is an internal signer so all we need is their email address
                            TrueSign.AddInternalSigner(Envelope_Id, signer);
                        }
                    }

                    args.SessionPropertyBag.TryGetValue("TrueSignDesign", out design);
                    if (!design)
                    {
                        //Close the envelope and mark it ready for the signer to sign.
                        TrueSign.SendEnvelope(Envelope_Id);
                    }
                    else
                    {
                        args.SessionPropertyBag.TryGetValue("TrueSignDesigners", out designers);
                        var designerList = new List <string>();
                        for (int i = 0; i < designers.Length; i++)
                        {
                            if (!string.IsNullOrEmpty(designers[i]))
                            {
                                designerList.Add(designers[i]);
                            }
                        }

                        TrueSign.SetDesigners(Envelope_Id, designerList);
                    }
                }
            }
            catch (Exception ex)
            {
                app.Diagnostics.Write(ex);
                result = false;
                args.PropertyBag.Set("error", ex.Message);
            }
            args.ScriptResult = result;
        }
        /// <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)
        {
            try
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                //get and clean LicenseType and Case # keywords for passing to LicEase database
                KeywordType kwtLicNum = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gSaveToLicNum);
                string      strLicNum = "";
                if (kwtLicNum != null)
                {
                    KeywordRecord keyRecLicNum = _currentDocument.KeywordRecords.Find(kwtLicNum);
                    if (keyRecLicNum != null)
                    {
                        Keyword kwdLicNum = keyRecLicNum.Keywords.Find(kwtLicNum);
                        if (kwdLicNum != null)
                        {
                            strLicNum = CleanSeedKW(kwdLicNum.ToString());
                        }
                    }
                }
                KeywordType kwtLicenseType = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gSaveToLicType);
                string      strLicenseType = "";
                if (kwtLicenseType != null)
                {
                    KeywordRecord keyRecLicenseType = _currentDocument.KeywordRecords.Find(kwtLicenseType);
                    if (keyRecLicenseType != null)
                    {
                        Keyword kwdLicenseType = keyRecLicenseType.Keywords.Find(kwtLicenseType);
                        if (kwdLicenseType != null)
                        {
                            strLicenseType = CleanSeedKW(kwdLicenseType.ToString());
                        }
                    }
                }

                KeywordType kwtInspectionDate = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gSaveToInspectVisitDate);
                string      strInspectionDate = "";
                if (kwtInspectionDate != null)
                {
                    KeywordRecord keyRecInspectionDate = _currentDocument.KeywordRecords.Find(kwtInspectionDate);
                    if (keyRecInspectionDate != null)
                    {
                        Keyword kwdInspectionDate = keyRecInspectionDate.Keywords.Find(kwtInspectionDate);
                        if (kwdInspectionDate != null)
                        {
                            strInspectionDate = CleanSeedKW(kwdInspectionDate.ToString());
                        }
                    }
                }

                if (strInspectionDate == "")
                {
                    throw new Exception(string.Format("Search keyword {0} is blank.", gSaveToInspectVisitDate));
                }

                if (strLicNum == "")
                {
                    throw new Exception(string.Format("Search keyword {0} is blank.", gSaveToLicNum));
                }

                if (strLicenseType == "")
                {
                    throw new Exception(string.Format("Search keyword {0} is blank.", gSaveToLicType));
                }

                //access Config Item for LicEase User
                string gUSER = "";
                if (app.Configuration.TryGetValue("LicEaseUser", out gUSER))
                {
                }

                //access Config Item for LicEase Password
                string gPASS = "";
                if (app.Configuration.TryGetValue("LicEasePassword", out gPASS))
                {
                }

                /* COMMENT THIS SECTION OUT WHEN MOVING TO PROD */
                //access Config Item for LicEase UAT ODBC
                string gODBC = "";
                if (app.Configuration.TryGetValue("LicEaseUAT", out gODBC))
                {
                }

                /* UNCOMMENT THIS SECTION WHEN MOVING TO PROD
                 *              //access Config Item for LicEase PROD ODBC
                 *              string gODBC = "";
                 *              if (app.Configuration.TryGetValue("LicEasePROD", out gODBC))
                 *              {
                 *              }
                 */

                string connectionString = string.Format("DSN={0};Uid={1};Pwd={2};", gODBC, gUSER, gPASS);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Connection string: {0}", connectionString));

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"SELECT a.insp_nbr, a.key_name, a.insp_vst_id AS insp_vst_id,a.lic_type AS lic_type, a.indorg_num, a.file_num, ");
                strSql.Append(@" a.lic_num AS lic_num, a.visit_num, a.visit_date,a.insp_typ, a.disposition_kw, a.city_kw, a.county_kw, a.region_kw,a.inspector_name  ");
                strSql.Append(@" FROM (SELECT DISTINCT TO_CHAR (insp_hist.insp_nbr) AS insp_nbr,TO_CHAR(insp_vst.insp_vst_id) AS insp_vst_id,lic.clnt_cde AS lic_type,lic.lic_nbr AS lic_num, ");
                strSql.Append(@" pri_name.key_nme AS key_name,TO_CHAR (lic.xent_id) AS indorg_num,TO_CHAR (lic.file_nbr) AS file_num,TO_CHAR (insp_vst.insp_vst_nbr) AS visit_num,TO_CHAR (insp_vst.insp_vst_strt_dte) AS visit_date, ");
                strSql.Append(@" insp_typ_defn.insp_typ_desc AS insp_typ,addr.addr_cty AS city_kw,cnty.cnty_desc AS county_kw,insp_regn.insp_regn_cde AS region_kw, ");
                strSql.Append(@" insp_disp_typ.insp_disp_typ_desc AS disposition_kw,stff.frst_nme || '.' || stff.surnme AS inspector_name ");
                strSql.Append(@" FROM insp_vst,insp_hist,insp_typ_defn,insp_disp_typ,inspr,stff,lic,clnt,NAME pri_name,insp_regn,inspr_insp_regn,LINK,addr,cnty ");
                strSql.Append(@" WHERE lic.lic_nbr = '");
                strSql.Append(strLicNum);
                strSql.Append(@"' AND lic.clnt_cde = '");
                strSql.Append(strLicenseType);
                strSql.Append(@"' AND insp_hist.lic_id = lic.lic_id and insp_hist.link_id = link.link_id AND LINK.nme_id = pri_name.nme_id AND addr.addr_id = LINK.addr_id ");
                strSql.Append(@" AND LINK.insp_regn_id = inspr_insp_regn.insp_regn_id AND insp_regn.insp_regn_id = inspr_insp_regn.insp_regn_id AND addr.cnty = cnty.cnty ");
                strSql.Append(@" AND lic.clnt_cde = clnt.clnt_cde AND clnt.clnt_cde_prnt = '210' and insp_hist.insp_hist_id = insp_vst.insp_hist_id ");
                strSql.Append(@" AND insp_vst.insp_vst_end_dte = TO_DATE ('");
                strSql.Append(strLicenseType);
                strSql.Append(@"', 'MM/DD/YYYY') AND insp_typ_defn.insp_typ_defn_id = insp_hist.insp_typ_defn_id AND insp_vst.inspr_id = inspr.inspr_id AND stff.stff_oper_id = inspr.stff_oper_id AND insp_disp_typ.insp_disp_typ_id = insp_hist.insp_disp_typ_id) a ");


                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Sql Query: {0}", strSql.ToString()));

                using (OdbcConnection con = new OdbcConnection(connectionString))
                {
                    try
                    {
                        con.Open();
                        using (OdbcCommand command = new OdbcCommand(strSql.ToString(), con))
                            using (OdbcDataReader reader = command.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    string strLicType     = "";
                                    string strInspID      = "";
                                    string strLicenseNum  = "";
                                    string strFileNum     = "";
                                    string strKeyName     = "";
                                    string strDBAName     = "";
                                    string strInDorgNum   = "";
                                    string strVisitNum    = "";
                                    string strDisposition = "";
                                    //string strInspDate = "";
                                    string strCity      = "";
                                    string strCounty    = "";
                                    string strRegion    = "";
                                    string strInspector = "";
                                    //string strInspNum = "";
                                    string strSubject  = "";
                                    string strInspType = "";

                                    reader.Read();

                                    strLicType    = reader["lic_Type"].ToString();
                                    strInspID     = reader["insp_vst_id"].ToString();
                                    strLicenseNum = reader["lic_Num"].ToString();
                                    strFileNum    = reader["file_Num"].ToString();
                                    strKeyName    = reader["key_Name"].ToString();
                                    strDBAName    = reader["dba_kw"].ToString();
                                    strInDorgNum  = reader["indorg_num"].ToString();
                                    strVisitNum   = reader["visit_Num"].ToString();
                                    //strInspDate = reader["visit_date"].ToString();
                                    strDisposition = reader["disposition_kw"].ToString();
                                    strCity        = reader["city_kw"].ToString();
                                    strInspector   = reader["inspector_name"].ToString();
                                    //strInspNum = reader["insp_nbr"].ToString();
                                    strSubject  = reader["key_Name"].ToString();
                                    strInspType = reader["insp_typ"].ToString();

                                    if (reader["county_kw"] != DBNull.Value)
                                    {
                                        strCounty = reader["county_kw"].ToString();
                                    }
                                    else
                                    {
                                        strCounty = "Not Available";
                                    }

                                    if (reader["region_kw"] != DBNull.Value)
                                    {
                                        strRegion = reader["region_kw"].ToString();
                                    }
                                    else
                                    {
                                        strRegion = "Not Available";
                                    }

                                    Keyword kwdLicType = null;
                                    if (!String.IsNullOrEmpty(strLicType))
                                    {
                                        KeywordType kwtLicType = app.Core.KeywordTypes.Find(gSaveToLicType);
                                        if (kwtLicType != null)
                                        {
                                            kwdLicType = CreateKeywordHelper(kwtLicType, strLicType);
                                        }
                                    }

                                    Keyword kwdLicenseNum = null;
                                    if (!String.IsNullOrEmpty(strLicenseNum))
                                    {
                                        KeywordType kwtLicenseNum = app.Core.KeywordTypes.Find(gSaveToLicNum);
                                        if (kwtLicenseNum != null)
                                        {
                                            kwdLicenseNum = CreateKeywordHelper(kwtLicenseNum, strLicenseNum);
                                        }
                                    }

                                    Keyword kwdFileNum = null;
                                    if (!String.IsNullOrEmpty(strFileNum))
                                    {
                                        KeywordType kwtFileNum = app.Core.KeywordTypes.Find(gSaveToFileNum);
                                        if (kwtFileNum != null)
                                        {
                                            kwdFileNum = CreateKeywordHelper(kwtFileNum, strFileNum);
                                        }
                                    }

                                    Keyword kwdKeyName = null;
                                    if (!String.IsNullOrEmpty(strKeyName))
                                    {
                                        KeywordType kwtKeyName = app.Core.KeywordTypes.Find(gSaveToKeyName);
                                        if (kwtKeyName != null)
                                        {
                                            kwdKeyName = CreateKeywordHelper(kwtKeyName, strKeyName);
                                        }
                                    }

                                    Keyword kwdSubject = null;
                                    if (!String.IsNullOrEmpty(strSubject))
                                    {
                                        KeywordType kwtSubject = app.Core.KeywordTypes.Find(gSaveToSubject);
                                        if (kwtSubject != null)
                                        {
                                            kwdSubject = CreateKeywordHelper(kwtSubject, strSubject);
                                        }
                                    }

                                    Keyword kwdDBAName = null;
                                    if (!String.IsNullOrEmpty(strDBAName))
                                    {
                                        KeywordType kwtDBAName = app.Core.KeywordTypes.Find(gSaveToDBA);
                                        if (kwtDBAName != null)
                                        {
                                            kwdDBAName = CreateKeywordHelper(kwtDBAName, strDBAName);
                                        }
                                    }

                                    Keyword kwdInDorgNum = null;
                                    if (!String.IsNullOrEmpty(strInDorgNum))
                                    {
                                        KeywordType kwtInDorgNum = app.Core.KeywordTypes.Find(gSaveToIndOrgNum);
                                        if (kwtInDorgNum != null)
                                        {
                                            kwdInDorgNum = CreateKeywordHelper(kwtInDorgNum, strInDorgNum);
                                        }
                                    }

                                    Keyword kwdVisitNum = null;
                                    if (!String.IsNullOrEmpty(strVisitNum))
                                    {
                                        KeywordType kwtVisitNum = app.Core.KeywordTypes.Find(gSaveToVisitNum);
                                        if (kwtVisitNum != null)
                                        {
                                            kwdVisitNum = CreateKeywordHelper(kwtVisitNum, strVisitNum);
                                        }
                                    }

                                    Keyword kwdDisposition = null;
                                    if (!String.IsNullOrEmpty(strDisposition))
                                    {
                                        KeywordType kwtDisposition = app.Core.KeywordTypes.Find(gSaveToLicType);
                                        if (kwtDisposition != null)
                                        {
                                            kwdDisposition = CreateKeywordHelper(kwtDisposition, strDisposition);
                                        }
                                    }

                                    Keyword kwdCity = null;
                                    if (!String.IsNullOrEmpty(strCity))
                                    {
                                        KeywordType kwtCity = app.Core.KeywordTypes.Find(gSaveToCity);
                                        if (kwtCity != null)
                                        {
                                            kwdCity = CreateKeywordHelper(kwtCity, strCity);
                                        }
                                    }

                                    Keyword kwdCounty = null;
                                    if (!String.IsNullOrEmpty(strCounty))
                                    {
                                        KeywordType kwtCounty = app.Core.KeywordTypes.Find(gSaveToCounty);
                                        if (kwtCounty != null)
                                        {
                                            kwdCounty = CreateKeywordHelper(kwtCounty, strCounty);
                                        }
                                    }

                                    Keyword kwdRegion = null;
                                    if (!String.IsNullOrEmpty(strRegion))
                                    {
                                        KeywordType kwtRegion = app.Core.KeywordTypes.Find(gSaveToRegion);
                                        if (kwtRegion != null)
                                        {
                                            kwdRegion = CreateKeywordHelper(kwtRegion, strRegion);
                                        }
                                    }

                                    Keyword kwdInspector = null;
                                    if (!String.IsNullOrEmpty(strInspector))
                                    {
                                        KeywordType kwtInspector = app.Core.KeywordTypes.Find(gSaveToInspectorName);
                                        if (kwtInspector != null)
                                        {
                                            kwdInspector = CreateKeywordHelper(kwtInspector, strInspector);
                                        }
                                    }

                                    Keyword kwdInspectorID = null;
                                    if (!String.IsNullOrEmpty(strInspID))
                                    {
                                        KeywordType kwtInspNum = app.Core.KeywordTypes.Find(gSaveToInspectionID);
                                        if (kwtInspNum != null)
                                        {
                                            kwdInspectorID = CreateKeywordHelper(kwtInspNum, strInspID);
                                        }
                                    }

                                    Keyword kwdInspTypeDesc = null;
                                    if (!String.IsNullOrEmpty(strInspType))
                                    {
                                        KeywordType kwtInspTypeDesc = app.Core.KeywordTypes.Find(gSaveToInspTypeDesc);
                                        if (kwtInspTypeDesc != null)
                                        {
                                            kwdInspTypeDesc = CreateKeywordHelper(kwtInspTypeDesc, strInspType);
                                        }
                                    }

                                    using (DocumentLock documentLock = _currentDocument.LockDocument())
                                    {
                                        // Ensure lock was obtained
                                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                                        {
                                            throw new Exception("Document lock not obtained");
                                        }
                                        // Create keyword modifier object to hold keyword changes
                                        KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                                        // Add update keyword call to keyword modifier object
                                        //Note Overloads available for use
                                        //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                                        if (kwdLicType != null)
                                        {
                                            keyModifier.AddKeyword(kwdLicType);
                                        }
                                        if (kwdLicenseNum != null)
                                        {
                                            keyModifier.AddKeyword(kwdLicenseNum);
                                        }
                                        if (kwdInspectorID != null)
                                        {
                                            keyModifier.AddKeyword(kwdInspectorID);
                                        }
                                        if (kwdFileNum != null)
                                        {
                                            keyModifier.AddKeyword(kwdFileNum);
                                        }
                                        if (kwdKeyName != null)
                                        {
                                            keyModifier.AddKeyword(kwdKeyName);
                                        }
                                        if (kwdDBAName != null)
                                        {
                                            keyModifier.AddKeyword(kwdDBAName);
                                        }
                                        if (kwdInDorgNum != null)
                                        {
                                            keyModifier.AddKeyword(kwdInDorgNum);
                                        }
                                        if (kwdVisitNum != null)
                                        {
                                            keyModifier.AddKeyword(kwdVisitNum);
                                        }
                                        if (kwdDisposition != null)
                                        {
                                            keyModifier.AddKeyword(kwdDisposition);
                                        }
                                        if (kwdCity != null)
                                        {
                                            keyModifier.AddKeyword(kwdCity);
                                        }
                                        if (kwdCounty != null)
                                        {
                                            keyModifier.AddKeyword(kwdCounty);
                                        }
                                        if (kwdRegion != null)
                                        {
                                            keyModifier.AddKeyword(kwdRegion);
                                        }
                                        if (kwdInspector != null)
                                        {
                                            keyModifier.AddKeyword(kwdInspector);
                                        }
                                        if (kwdInspTypeDesc != null)
                                        {
                                            keyModifier.AddKeyword(kwdInspTypeDesc);
                                        }
                                        if (kwdSubject != null)
                                        {
                                            keyModifier.AddKeyword(kwdSubject);
                                        }

                                        // Apply keyword change to the document
                                        keyModifier.ApplyChanges();

                                        string output = String.Format("Keyword: '{0}' Value: '{1}', {33}Keyword: '{2}' Value: '{3}', {33}Keyword: '{4}' Value: '{5}', {33}Keyword: '{6}' Value: '{7}'," +
                                                                      "{33}Keyword: '{8}' Value: '{9}', {33}Keyword: '{10}' Value: '{11}', {33}Keyword: '{12}' Value: '{13}', {33}Keyword: '{14}' Value: '{15}', {33}Keyword: '{16}' Value: '{17}'," +
                                                                      "{33}Keyword: '{18}' Value: '{19}', {33}Keyword: '{20}' Value: '{21}', {33}Keyword: '{22}' Value: '{23}', {33}Keyword: '{24}' Value: '{25}', {33}Keyword: '{26}' Value: '{27}'," +
                                                                      "{33}Keyword: '{28}' Value: '{29}', {33}Keyword: '{30}' Value: '{31}', {33}added to Document {32}.",
                                                                      gSaveToLicNum, strLicNum, gSaveToLicType, strLicType, gSaveToInspectionID, strInspID, gSaveToFileNum, strFileNum, gSaveToKeyName, strKeyName, gSaveToSubject, strSubject,
                                                                      gSaveToDBA, strDBAName, gSaveToIndOrgNum, strInDorgNum, gSaveToVisitNum, strVisitNum, gSaveToDisposition, strDisposition, gSaveToCity, strCity, gSaveToCounty, strCounty,
                                                                      gSaveToRegion, strRegion, gSaveToInspectorName, strInspector, gSaveToInspTypeDesc, strInspType, gSaveToInspNum, "Not being returned", _currentDocument.ID, Environment.NewLine);
                                        //Output the results to the OnBase Diagnostics Console
                                        app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);

                                        documentLock.Release();
                                    }
                                }
                                else
                                {
                                    throw new Exception(string.Format("No records found in database"));
                                }
                            }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Error during database operations!", ex);
                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open)
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                        string.Format("End Script - [{0}]", ScriptName));
            }
        }
Example #26
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)
        {
            try
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                //get and clean LicenseType and Application # keywords for passing to LicEase database
                KeywordType kwtAppNum = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gParamAppNum);
                string      strAppNum = "";
                if (kwtAppNum != null)
                {
                    KeywordRecord keyRecFileNum = _currentDocument.KeywordRecords.Find(kwtAppNum);
                    if (keyRecFileNum != null)
                    {
                        Keyword kwdFileNum = keyRecFileNum.Keywords.Find(kwtAppNum);
                        if (kwdFileNum != null)
                        {
                            strAppNum = CleanSeedKW(kwdFileNum.ToString());
                        }
                    }
                }

                if (strAppNum == "")
                {
                    throw new Exception(string.Format("App Num is blank!"));
                }

                //access Config Item for LicEase User
                string gUSER = "";
                if (app.Configuration.TryGetValue("LicEaseUser", out gUSER))
                {
                }

                //access Config Item for LicEase Password
                string gPASS = "";
                if (app.Configuration.TryGetValue("LicEasePassword", out gPASS))
                {
                }

                /* COMMENT THIS SECTION OUT WHEN MOVING TO PROD */
                //access Config Item for LicEase UAT ODBC
                string gODBC = "";
                if (app.Configuration.TryGetValue("LicEaseUAT", out gODBC))
                {
                }

                /* UNCOMMENT THIS SECTION WHEN MOVING TO PROD
                 *              //access Config Item for LicEase PROD ODBC
                 *              string gODBC = "";
                 *              if (app.Configuration.TryGetValue("LicEasePROD", out gODBC))
                 *              {
                 *              }
                 */

                string connectionString = string.Format("DSN={0};Uid={1};Pwd={2};", gODBC, gUSER, gPASS);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Connection string: {0}", connectionString));

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"select c.lic_nbr as Brand_Lic_Number, (select n.org_nme from link l, clnt_link_typ clt, link_typ lt, name n ");
                strSql.Append(@"  where c.xent_id = l.xent_id and l.link_prnt_cde is Null and l.curr_ind = 'Y' and l.clnt_link_typ_id = clt.clnt_link_typ_id");
                strSql.Append(@"  and clt.link_typ_id = lt.link_typ_id and lt.link_typ_cde = 'MA' and l.nme_id = n.nme_id and n.ent_nme_typ = 'P' and n.cur_nme_ind = 'Y') as Key_Name, ");
                strSql.Append(@"  (select cr.vald_nbr from csh_pmt cp, csh_rcpt cr where cp.chrg_id = a.applc_id and cp.csh_rcpt_id = cr.csh_rcpt_id and cp.chrg_typ = 'A' ");
                strSql.Append(@"  and cr.csh_rcpt_id = (select max (cp2.csh_rcpt_id) from csh_pmt cp2 where cp2.chrg_id = cp.chrg_id and cp2.chrg_typ = 'A')) as Validation_Number, ");
                strSql.Append(@"  x.xact_cde as Tran_Code from lic c, appl a, xact_defn x where a.applc_nbr = ' ");
                strSql.Append(strAppNum);
                strSql.Append(@"' and c.clnt_cde = '4008' and c.lic_id = a.lic_id and a.xact_defn_id = x.xact_defn_id ");

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Sql Query: {0}", strSql.ToString()));

                using (OdbcConnection con = new OdbcConnection(connectionString))
                {
                    try
                    {
                        con.Open();
                        using (OdbcCommand command = new OdbcCommand(strSql.ToString(), con))
                            using (OdbcDataReader reader = command.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    string strTranCode = "";
                                    string strKeyName  = "";
                                    string strValNum   = "";
                                    string strBrandNum = "";


                                    reader.Read();

                                    strTranCode = reader["Tran_Code"].ToString();
                                    strKeyName  = reader["Key_Name"].ToString();
                                    strValNum   = reader["Validation_Number"].ToString();
                                    strBrandNum = reader["Brand_Lic_Number"].ToString();

                                    Keyword kwdTranCode = null;
                                    if (!String.IsNullOrEmpty(strTranCode))
                                    {
                                        KeywordType kwtTranCode = app.Core.KeywordTypes.Find(gSaveToTranNum);
                                        if (kwtTranCode != null)
                                        {
                                            kwdTranCode = CreateKeywordHelper(kwtTranCode, strTranCode);
                                        }
                                    }

                                    Keyword kwdKeyName = null;
                                    if (!String.IsNullOrEmpty(strKeyName))
                                    {
                                        KeywordType kwtKeyName = app.Core.KeywordTypes.Find(gSaveToKeyName);
                                        if (kwtKeyName != null)
                                        {
                                            kwdKeyName = CreateKeywordHelper(kwtKeyName, strKeyName);
                                        }
                                    }

                                    Keyword kwdValNum = null;
                                    if (!String.IsNullOrEmpty(strValNum))
                                    {
                                        KeywordType kwtValNum = app.Core.KeywordTypes.Find(gSaveToValNum);
                                        if (kwtValNum != null)
                                        {
                                            kwdValNum = CreateKeywordHelper(kwtValNum, strValNum);
                                        }
                                    }

                                    Keyword kwdBrandNum = null;
                                    if (!String.IsNullOrEmpty(strBrandNum))
                                    {
                                        KeywordType kwtBrandNum = app.Core.KeywordTypes.Find(gSaveToLicNum);
                                        if (kwtBrandNum != null)
                                        {
                                            kwdBrandNum = CreateKeywordHelper(kwtBrandNum, strBrandNum);
                                        }
                                    }


                                    using (DocumentLock documentLock = _currentDocument.LockDocument())
                                    {
                                        // Ensure lock was obtained
                                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                                        {
                                            throw new Exception("Document lock not obtained");
                                        }
                                        // Create keyword modifier object to hold keyword changes
                                        KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                                        // Add update keyword call to keyword modifier object
                                        //Note Overloads available for use
                                        //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                                        if (kwdTranCode != null)
                                        {
                                            keyModifier.AddKeyword(kwdTranCode);
                                        }
                                        if (kwdKeyName != null)
                                        {
                                            keyModifier.AddKeyword(kwdKeyName);
                                        }
                                        if (kwdValNum != null)
                                        {
                                            keyModifier.AddKeyword(kwdValNum);
                                        }
                                        if (kwdBrandNum != null)
                                        {
                                            keyModifier.AddKeyword(kwdBrandNum);
                                        }

                                        // Apply keyword change to the document
                                        keyModifier.ApplyChanges();

                                        string output = String.Format("Keyword: '{0}' Value: '{1}', {9}Keyword: '{2}' Value: '{3}', {9}Keyword: '{4}' Value: '{5}', {9}Keyword: '{6}' Value: '{7}', {9}added to Document {8}.",
                                                                      gSaveToTranNum, strTranCode, gSaveToKeyName, strKeyName, gSaveToLicNum, strBrandNum, gSaveToValNum, strValNum, _currentDocument.ID, Environment.NewLine);
                                        //Output the results to the OnBase Diagnostics Console
                                        app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);
                                    }
                                }
                                else
                                {
                                    throw new Exception(string.Format("No records found in database for  {0}='{1}' ", gParamAppNum, strAppNum));
                                }
                            }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Error during database operations!", ex);
                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open)
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                        string.Format("End Script - [{0}]", ScriptName));
            }
        }
Example #27
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)
        {
            var result = true;

            try
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, "Starting Download Envelope Script");

                //Check if this document is of type TrueSign Completed Envelope
                if (args.Document.DocumentType.Name.ToUpper() == "TRUESIGN COMPLETED ENVELOPE")
                {
                    //Initiate a new TrueSign object
                    TrueSignNext TrueSign = new TrueSignNext(app);

                    //Read the JSON of this document as a TrueSign envelope
                    var envelope = TrueSign.ReadEnvelope(args.Document);
                    if (envelope == null)
                    {
                        throw new Exception("Unable to read OnBase doc as a TrueSign Envelope");
                    }

                    //Add all doc ids to a property bag
                    AddDocsProperty(app, args, envelope);

                    //Check if the envelope was rejected
                    if (envelope.Status == Envelope_Status.Rejected)
                    {
                        AddRejectionProperty(app, args, envelope);
                    }
                    else
                    {
                        app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Downloading envelope with ID: {0}", envelope.Id));

                        //Download and create a new revision of the document
                        var success = TrueSign.DownloadEnvelopeDocs(envelope);
                        if (!success)
                        {
                            throw new Exception("Unable to download envelope docs from the TrueSign API");
                        }
                    }
                }
                else
                {
                    string Envelope_Id = "";
                    if (args.SessionPropertyBag.TryGetValue("TrueSignEnvelopeId", out Envelope_Id))
                    {
                        app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Downloading envelope with ID: {0}", Envelope_Id));

                        //Initialize a new TrueSign object. We will retrieve the API creds from the prop bags
                        //TrueSignClientId
                        //TrueSignClientSecret
                        TrueSignNext TrueSign = new TrueSignNext(app, args);

                        //Get the envelope from the API
                        var envelope = TrueSign.GetEnvelope(Guid.Parse(Envelope_Id));
                        if (envelope == null)
                        {
                            throw new Exception(string.Format("Unable to get envelope with ID {0} from TrueSign API", Envelope_Id));
                        }

                        //Add all doc ids to a property bag
                        AddDocsProperty(app, args, envelope);

                        //Check if the envelope was rejected
                        if (envelope.Status == Envelope_Status.Rejected)
                        {
                            AddRejectionProperty(app, args, envelope);
                        }
                        else
                        {
                            //Download and create a new revision of the document
                            var success = TrueSign.DownloadEnvelopeDocs(envelope);
                            if (!success)
                            {
                                throw new Exception("Unable to download envelope docs from the TrueSign API");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("TrueSignEnvelopeId property bag not found.");
                    }
                }
            }
            catch (Exception ex)
            {
                app.Diagnostics.Write(ex);
                result = false;
                args.PropertyBag.Set("error", ex.ToString());
            }

            args.ScriptResult = result;
        }
        /// <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
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                KeywordType ktwBatchType = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gParamBatchType);
                string      strBatchType = "";
                if (ktwBatchType != null)
                {
                    KeywordRecord keyRecFileNum = _currentDocument.KeywordRecords.Find(ktwBatchType);
                    if (keyRecFileNum != null)
                    {
                        Keyword kwdBatchType = keyRecFileNum.Keywords.Find(ktwBatchType);
                        if (kwdBatchType != null)
                        {
                            strBatchType = kwdBatchType.ToString();
                        }
                    }
                }

                if (strBatchType == "")
                {
                    throw new Exception(string.Format("{0} is blank.", gParamBatchType));
                }

                //access Config Item for OnBase User
                string gUSER = "";
                if (app.Configuration.TryGetValue("OnBaseUser", out gUSER))
                {
                }

                //access Config Item for OnBase Password
                string gPASS = "";
                if (app.Configuration.TryGetValue("OnBasePassword", out gPASS))
                {
                }

                /* COMMENT THIS SECTION OUT WHEN MOVING TO PROD */
                //access Config Item for OnBase UAT ODBC
                string gODBC = "";
                if (app.Configuration.TryGetValue("OnBaseUAT", out gODBC))
                {
                }

                /* UNCOMMENT THIS SECTION WHEN MOVING TO PROD
                 *              //access Config Item for OnBase PROD ODBC
                 *              string gODBC = "";
                 *              if (app.Configuration.TryGetValue("OnBasePROD", out gODBC))
                 *              {
                 *              }
                 */

                string connectionString = string.Format("DSN={0};Uid={1};Pwd={2};", gODBC, gUSER, gPASS);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Connection string: {0}", connectionString));

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"SELECT TOP 1 ua.username AS PROFILER ");
                strSql.Append(@"  FROM hsi.userxusergroup ux ");
                strSql.Append(@"  INNER JOIN hsi.useraccount ua on ua.usernum = ux.usernum ");
                strSql.Append(@"  INNER JOIN hsi.usergroup ug on ug.usergroupnum = ux.usergroupnum ");
                strSql.Append(@"  where ug.usergroupname = '");
                strSql.Append(strBatchType);
                strSql.Append(@"' ORDER BY NEWID()'");

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Sql Query: {0}", strSql.ToString()));

                using (OdbcConnection con = new OdbcConnection(connectionString))
                {
                    try
                    {
                        con.Open();
                        using (OdbcCommand command = new OdbcCommand(strSql.ToString(), con))
                            using (OdbcDataReader reader = command.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    string strProf = "";

                                    reader.Read();

                                    strProf = reader["PROFILER"].ToString();

                                    Keyword kwdProf = null;
                                    if (!String.IsNullOrEmpty(strProf))
                                    {
                                        KeywordType kwtProf = app.Core.KeywordTypes.Find(gSaveToAssignedProf);
                                        if (kwtProf != null)
                                        {
                                            kwdProf = CreateKeywordHelper(kwtProf, strProf);
                                        }
                                    }

                                    using (DocumentLock documentLock = _currentDocument.LockDocument())
                                    {
                                        // Ensure lock was obtained
                                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                                        {
                                            throw new Exception("Document lock not obtained");
                                        }
                                        // Create keyword modifier object to hold keyword changes
                                        KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                                        // Add update keyword call to keyword modifier object
                                        //Note Overloads available for use
                                        //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                                        if (kwdProf != null)
                                        {
                                            keyModifier.AddKeyword(kwdProf);
                                        }

                                        // Apply keyword change to the document
                                        keyModifier.ApplyChanges();

                                        string output = String.Format("Keyword: '{0}' Value: '{1}', {3}added to Document {2}.",
                                                                      gSaveToAssignedProf, strProf, _currentDocument.ID, Environment.NewLine);
                                        //Output the results to the OnBase Diagnostics Console
                                        app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);
                                    }
                                }
                                else
                                {
                                    throw new Exception(string.Format("No records found in database for  {0}='{1}'", gParamBatchType, strBatchType));
                                }
                            }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Error during database operations!", ex);
                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open)
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                        string.Format("End Script - [{0}]", ScriptName));
            }
        }
        /// <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)
        {
            try
            {
                // Initialize global settings
                IntializeScript(ref app, ref args);

                //get and clean LicenseType and Application # keywords for passing to LicEase database
                KeywordType kwtAppNum = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gParamAppNum);
                string      strAppNum = "";
                if (kwtAppNum != null)
                {
                    KeywordRecord keyRecFileNum = _currentDocument.KeywordRecords.Find(kwtAppNum);
                    if (keyRecFileNum != null)
                    {
                        Keyword kwdFileNum = keyRecFileNum.Keywords.Find(kwtAppNum);
                        if (kwdFileNum != null)
                        {
                            strAppNum = CleanSeedKW(kwdFileNum.ToString());
                        }
                    }
                }
                KeywordType kwtLicenseType = _currentDocument.DocumentType.KeywordRecordTypes.FindKeywordType(gParamLicType);
                string      strLicenseType = "";
                if (kwtLicenseType != null)
                {
                    KeywordRecord keyRecLicenseType = _currentDocument.KeywordRecords.Find(kwtLicenseType);
                    if (keyRecLicenseType != null)
                    {
                        Keyword kwdLicenseType = keyRecLicenseType.Keywords.Find(kwtLicenseType);
                        if (kwdLicenseType != null)
                        {
                            strLicenseType = CleanSeedKW(kwdLicenseType.ToString());
                        }
                    }
                }

                if ((strAppNum == "") || (strLicenseType == ""))
                {
                    throw new Exception(string.Format("Either {0} or {1} is blank.", gParamAppNum, gParamLicType));
                }

                //access Config Item for LicEase User
                string gUSER = "";
                if (app.Configuration.TryGetValue("LicEaseUser", out gUSER))
                {
                }

                //access Config Item for LicEase Password
                string gPASS = "";
                if (app.Configuration.TryGetValue("LicEasePassword", out gPASS))
                {
                }

                /* COMMENT THIS SECTION OUT WHEN MOVING TO PROD */
                //access Config Item for LicEase UAT ODBC
                string gODBC = "";
                if (app.Configuration.TryGetValue("LicEaseUAT", out gODBC))
                {
                }

                /* UNCOMMENT THIS SECTION WHEN MOVING TO PROD
                 *              //access Config Item for LicEase PROD ODBC
                 *              string gODBC = "";
                 *              if (app.Configuration.TryGetValue("LicEasePROD", out gODBC))
                 *              {
                 *              }
                 */

                string connectionString = string.Format("DSN={0};Uid={1};Pwd={2};", gODBC, gUSER, gPASS);
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Connection string: {0}", connectionString));

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"SELECT f.mod_desc AS PLANMOD FROM appl a, appl_mdf m, mdf f");
                strSql.Append(@"  WHERE a.applc_id = m.applc_id AND m.mod_id = f.mod_id AND");
                strSql.Append(@"  f.mod_typ = 'K' AND a.clnt_cde = '");
                strSql.Append(strLicenseType);
                strSql.Append(@"' AND a.applc_nbr = '");
                strSql.Append(strAppNum);
                strSql.Append(@"'");

                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, string.Format("Sql Query: {0}", strSql.ToString()));

                using (OdbcConnection con = new OdbcConnection(connectionString))
                {
                    try
                    {
                        con.Open();
                        using (OdbcCommand command = new OdbcCommand(strSql.ToString(), con))
                            using (OdbcDataReader reader = command.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    string strMOD = "";

                                    reader.Read();

                                    strMOD = reader["PLANMOD"].ToString();

                                    Keyword kwdMOD = null;
                                    if (!String.IsNullOrEmpty(strMOD))
                                    {
                                        KeywordType kwtMOD = app.Core.KeywordTypes.Find(gSaveToPlanMod);
                                        if (kwtMOD != null)
                                        {
                                            kwdMOD = CreateKeywordHelper(kwtMOD, strMOD);
                                        }
                                    }

                                    using (DocumentLock documentLock = _currentDocument.LockDocument())
                                    {
                                        // Ensure lock was obtained
                                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                                        {
                                            throw new Exception("Document lock not obtained");
                                        }
                                        // Create keyword modifier object to hold keyword changes
                                        KeywordModifier keyModifier = _currentDocument.CreateKeywordModifier();

                                        // Add update keyword call to keyword modifier object
                                        //Note Overloads available for use
                                        //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                                        if (kwdMOD != null)
                                        {
                                            keyModifier.AddKeyword(kwdMOD);
                                        }

                                        // Apply keyword change to the document
                                        keyModifier.ApplyChanges();

                                        string output = String.Format("Keyword: '{0}' Value: '{1}', {3}added to Document {2}.",
                                                                      gSaveToPlanMod, strMOD, _currentDocument.ID, Environment.NewLine);
                                        //Output the results to the OnBase Diagnostics Console
                                        app.Diagnostics.WriteIf(Hyland.Unity.Diagnostics.DiagnosticsLevel.Verbose, output);
                                    }
                                }
                                else
                                {
                                    throw new Exception(string.Format("No records found in database for  {0}='{1}' and {4}{2}='{3}' ", gParamLicType, strLicenseType, gParamAppNum, strAppNum, Environment.NewLine));
                                }
                            }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Error during database operations!", ex);
                    }
                    finally
                    {
                        if (con.State == ConnectionState.Open)
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log to Diagnostics Console and document history
                HandleException(ex, ref app, ref args);
            }
            finally
            {
                // Log script execution end
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info,
                                        string.Format("End Script - [{0}]", ScriptName));
            }
        }
Example #30
0
        /// <summary>
        /// Get all signers for this envelope from the propery bags. No anchors are possible.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="args"></param>
        /// <returns>A list of signer objects</returns>
        private List <Signer> GetSigners(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
            List <Signer> signers = new List <Signer>();

            try
            {
                app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "Adding multiple signers to the envelope...");
                string[] email = new string[10], first = new string[10], last = new string[10],
                codeDesc = new string[10], codeVal = new string[10];
                bool[] external     = new bool[10];
                bool   singleSigner = false;

                //Get all the signer info from prop bags
                if (!args.SessionPropertyBag.TryGetValue("TrueSignSignerEmail", out email))
                {
                    throw new Exception("An email must be provided for the signer.");
                }

                singleSigner = SignerArrayOnlyOne(email);

                args.SessionPropertyBag.TryGetValue("TrueSignFirstName", out first);
                args.SessionPropertyBag.TryGetValue("TrueSignLastName", out last);
                args.SessionPropertyBag.TryGetValue("TrueSignExternal", out external);
                args.SessionPropertyBag.TryGetValue("TrueSignCodeDesc", out codeDesc);
                args.SessionPropertyBag.TryGetValue("TrueSignCodeVal", out codeVal);

                if (singleSigner)
                {
                    app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Info, "This property bag has a single signer...");
                    //Create the signer data transfer object
                    Signer signer = new Signer();
                    signer.Email      = email[0];
                    signer.First_Name = first == null ? "" : first[0] ?? ""; //not needed for internal signer
                    signer.Last_Name  = last == null ? "" : last[0] ?? "";   //not needed for internal signer
                    signer.Type       = external == null ? Signer_Type.Internal : external[0] == true ? Signer_Type.External : Signer_Type.Internal;

                    if (signer.Type == Signer_Type.External)
                    {
                        if (!string.IsNullOrEmpty(codeDesc[0]) && !string.IsNullOrEmpty(codeVal[0]))
                        {
                            //If the signer is an external user, we are requiring them to enter a code they would know before being able to sign.
                            //Only the code description will be known to the signer (they will see it in the email notification).
                            //The value itself should be something that the signer already knows (like a date of birth, last 4 of SSN, or a case number) -- NOT REQUIRED
                            Access_Code code = new Access_Code();
                            code.Description = codeDesc[0];
                            code.Value       = codeVal[0];
                            signer.Code      = code;
                        }
                    }

                    string noteJson = "";
                    if (args.SessionPropertyBag.TryGetValue("TrueSignAnchors", out noteJson))
                    {
                        List <Anchor> anchors = string.IsNullOrEmpty(noteJson) ? new List <Anchor>() : JsonConvert.DeserializeObject <List <Anchor> >(noteJson);
                        signer.Anchors = anchors;
                    }

                    signers.Add(signer);
                }
                else
                {
                    for (int i = 0; i < email.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(email[i]))
                        {
                            //Create the signer data transfer object
                            Signer signer = new Signer();
                            signer.Email      = email[i];
                            signer.First_Name = first == null ? "" : first[i] ?? ""; //not needed for internal signer
                            signer.Last_Name  = last == null ? "" : last[i] ?? "";   //not needed for internal signer
                            signer.Type       = external == null ? Signer_Type.Internal : external[i] == true ? Signer_Type.External : Signer_Type.Internal;

                            if (signer.Type == Signer_Type.External)
                            {
                                if (!string.IsNullOrEmpty(codeDesc[i]) && !string.IsNullOrEmpty(codeVal[i]))
                                {
                                    //If the signer is an external user, we are requiring them to enter a code they would know before being able to sign.
                                    //Only the code description will be known to the signer (they will see it in the email notification).
                                    //The value itself should be something that the signer already knows (like a date of birth, last 4 of SSN, or a case number) -- NOT REQUIRED
                                    Access_Code code = new Access_Code();
                                    code.Description = codeDesc[i];
                                    code.Value       = codeVal[i];
                                    signer.Code      = code;
                                }
                            }

                            signers.Add(signer);
                        }
                    }
                }
            }
            catch
            {
                throw;
            }

            return(signers);
        }