Skip to content

Instantly share code, notes, and snippets.

@dylanlangston
Last active February 24, 2021 16:36
Show Gist options
  • Save dylanlangston/f151621550d5b9d964d4cf392a5bf38a to your computer and use it in GitHub Desktop.
Save dylanlangston/f151621550d5b9d964d4cf392a5bf38a to your computer and use it in GitHub Desktop.
Code for PVE Workflow which searchs for and displays a document in the browser based viewer inside an embedded web browser control.
/*
* Version: 86.1
* Generated Date: 4/28/2020
* Modified Date: 5/14/2020
*/
using System;
using System.Xml;
using System.Xml.Linq;
using DSI.PVEInterop.Data;
using DSI.PVECommon.API;
using System.Data.OleDb;
using System.Data;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;
using DSI.DocumentViewer.Client.UI.Controls;
using System.Net;
namespace DSI.PVECommon.ScriptingLibrary
{
// Main
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public class ManualCode : ManualCodeBase, ICode
{
UCWorkstepInstances uc { get; set; }
UCViewerHost vh { get; set; }
System.Windows.Forms.Control olddoc { get; set; }
System.Guid olddocID {get; set;}
System.Windows.Forms.WebBrowser wb { get; set;}
public void CallHandler()
{
// Setup program variables
string[] indexFields = new string[] {"Company", "Contact", "Invoice Amount", "Doc Type", "ID"}; // Fields to search on.
string idField = "ID"; // Field which is should be blank as it will be populated with the ID later.
string doctypeFiled = "Doc Type"; // Field which should correspond to the doctype.
string doctype = "Receipt"; // Doctype to find.
// Used later
int newdocID = 0;
// Try and connect to Workflow UI to scrape information.
int formi = 0;
try {
while (formi < Application.OpenForms.Count)
{
if(Application.OpenForms[formi].GetType().ToString().ToUpper() == "DSI.DOCUMENTVIEWER.CLIENT.FORMMAIN")
{
if(Application.OpenForms[formi].Controls.Find("ucWorkstepInstances", true).Length != 0)
{
uc = (UCWorkstepInstances)Application.OpenForms[formi].Controls.Find("ucWorkstepInstances", true)[0];
break;
}
}
formi++;
}
} catch (Exception ex) {
throw new System.InvalidOperationException("Error connecting to Viewer - \n"+ex.Message);
}
// Get info for PVE connection
var URL = "";
var SESSIONID = "";
var ENTITYID = 0;
var ProjectID = "";
var DocumentID = 0;
try {
URL = uc.IUIContext.Parameter.ServerUrlWithoutHttpInterface;
SESSIONID = uc.IUIContext.Parameter.SESSIONID;
ENTITYID = uc.IUIContext.Parameter.ENTITYID;
ProjectID = uc.IUIContext.DocumentNavService.CurrentDocument.ProjectID;
DocumentID = uc.IUIContext.DocumentNavService.CurrentDocument.ID;
} catch (Exception ef) {
throw new System.InvalidOperationException("Error getting PVE connection information - \n"+ef.Message);
}
// Get the Viewer Host Control and save the current document control info.
vh = (UCViewerHost)Application.OpenForms[formi].Controls.Find("ucViewerHost1", true)[0];
olddoc = (System.Windows.Forms.Integration.ElementHost)vh.Controls.Find("elementHost1", true)[0];
olddocID = vh.IUIContext.DocumentNavService.CurrentDocument.InternalID;
// Search for corresponding doc
string formattedIndexes = "";
string formattedIndexesFrom = "";
string formattedIndexesTo = ""; // Not actually populated.
string result = "";
for (int i = 0; i < indexFields.Length; i++) {
formattedIndexes += indexFields[i];
string value = "";
if (idField == indexFields[i]) {
value = "[Blank]";
}
else if (doctypeFiled == indexFields[i]) {
value = doctype;
}
else {
uc.IUIContext.DocumentNavService.CurrentDocument.PVEDocumentIndexValues.TryGetValue(indexFields[i], out value);
}
formattedIndexesFrom += value;
if (i < (indexFields.Length-1)) {
formattedIndexes += "|";
formattedIndexesFrom += "|";
}
}
// Extract new docid from results
XmlDocument resultsdoc = new XmlDocument();
try {
bool search = submitSearchRequest(URL, ENTITYID, SESSIONID, ProjectID, formattedIndexes, formattedIndexesFrom, formattedIndexesTo);
if (search) {
result = executeSearchRequest(URL, ENTITYID, SESSIONID, ProjectID, DocumentID);
}
resultsdoc.LoadXml(result);
newdocID = Int32.Parse(resultsdoc.GetElementsByTagName("DOC")[0].Attributes[0].Value);
} catch {
throw new System.InvalidOperationException("No documents found. Please ensure document is uploaded with matching index information.\n(Fields:"+formattedIndexes+" Values:"+formattedIndexesFrom+")");
}
if (resultsdoc.GetElementsByTagName("DOC").Count > 1) {
uc.IUIContext.DialogService.ShowMessage("Found more than one document, displaying the first (DOCID: "+newdocID+"). If this is incorrect please ensure indexes (Fields:"+formattedIndexes+" Values:"+formattedIndexesFrom+") are unique and that older workflows are completed before newer ones.", "Multiple Documents Found", DSI.DocumentViewer.Data.ConstantsAndEnums.DialogButton.OK, DSI.DocumentViewer.Data.ConstantsAndEnums.DialogImage.Information);
}
// Create new web browser control.
wb = new System.Windows.Forms.WebBrowser();
wb.Name = "bbvControl";
wb.Width = vh.Width;
wb.Height = vh.Height;
wb.ObjectForScripting = this;
wb.ScriptErrorsSuppressed = true;
wb.AllowWebBrowserDrop = false;
wb.IsWebBrowserContextMenuEnabled = false;
wb.WebBrowserShortcutsEnabled = false;
// Web Browser Loaded event.
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_Loaded);
// Resize event.
vh.Resize += new EventHandler(HandleResize);
// Bring into Focus event aka refresh document.
var viewerControl = (DSI.DocumentViewer.WpfClientControls.ScrollingViewerHost.UCScrollingViewerHost)((System.Windows.Forms.Integration.ElementHost)olddoc).Child;
viewerControl.RequestBringIntoView -= new System.Windows.RequestBringIntoViewEventHandler(documentChanged);
viewerControl.RequestBringIntoView += new System.Windows.RequestBringIntoViewEventHandler(documentChanged);
// Loads Document in Browser Based Viewer.
wb.Navigate("https://login.imagesilo.com/Home/DocViewer?EntID="+ENTITYID+"&SessionID="+SESSIONID+"&ProjID="+ProjectID+"&DocID="+newdocID+"&Page=1");
// Add Web Browser control to Viewer Host.
vh.Controls.Add(wb);
wb.BringToFront();
}
// Soap Stuff
private static string CallHTTPInterface(string Url, string XML)
{
HttpWebRequest request = CreateWebRequest(Url);
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(XML);
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
//MessageBox.Show(soapResult); // For debugging.
return soapResult;
}
}
}
private static HttpWebRequest CreateWebRequest(string URL)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(URL + "httpinterface.aspx");
if (URL.ToLower().Contains("httpinterface.aspx")) {
webRequest = (HttpWebRequest)WebRequest.Create(URL);
}
webRequest.Headers.Add(@"SOAP:Action");
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
public bool submitSearchRequest(string URL, int ENT, string SESS, string PROJ, string fieldNames, string fromFields, string toFields)
{
string submitSearchRequest = "<SubmitSearchCriteria_Project_REQUEST>" +
"<FUNCTION>" +
"<NAME>SUBMITSEARCHCRITERIA_PROJECT</NAME>" +
"<PARAMETERS>" +
"<ENTITYID>"+ENT+"</ENTITYID>" +
"<SESSIONID>"+SESS+"</SESSIONID>" +
"<PARAMETERS></PARAMETERS>" +
"<SOURCEIP></SOURCEIP>" +
"<FIELDNAMES>"+fieldNames+"</FIELDNAMES>" +
"<FROMFIELDS>"+fromFields+"</FROMFIELDS>" +
"<TOFIELDS>"+toFields+"</TOFIELDS>" +
"<SORTBY></SORTBY>" +
"<SEARCHTYPE>AND</SEARCHTYPE>" +
"<FTQUERY></FTQUERY>" +
"<FTOPTIONS></FTOPTIONS>" +
"<PROJID>"+PROJ+"</PROJID>" +
"</PARAMETERS>" +
"</FUNCTION>" +
"</SubmitSearchCriteria_Project_REQUEST>";
// Send XML and get response
var result = CallHTTPInterface(URL, submitSearchRequest);
if (result != null) {
return true;
}
return false;
}
public string executeSearchRequest(string URL, int ENT, string SESS, string PROJ, int startDoc)
{
string executeSearchRequest = "<ExecuteQuery_Project_REQUEST>" +
"<FUNCTION>"+
"<NAME>EXECUTEQUERY_PROJECT</NAME>"+
"<PARAMETERS>"+
"<ENTITYID>"+ENT+"</ENTITYID>"+
"<SESSIONID>"+SESS+"</SESSIONID>"+
"<PARAMETERS></PARAMETERS>"+
"<SOURCEIP></SOURCEIP>"+
"<FORMATVALUES>1</FORMATVALUES>"+
"<PROJID>"+PROJ+"</PROJID>"+
"<STARTINGDOCID>"+startDoc+"</STARTINGDOCID>"+
"</PARAMETERS>"+
"</FUNCTION>"+
"</ExecuteQuery_Project_REQUEST>";
// Send XML and get response
var result = CallHTTPInterface(URL, executeSearchRequest);
if (result != null) {
return result;
}
return "failed";
}
// Web Browser Stuff
private void wb_Loaded(object sender, WebBrowserDocumentCompletedEventArgs e) {
if (e.Url.ToString() == "about:blank")
return;
if (wb.ReadyState != WebBrowserReadyState.Complete) {
return;
} else {
int c = 0;
while (c < 100) {
try {
// Define CSS to be injected into the page later. There are better ways to do this but they require mshtml which does not ship with DOTNET. This avoids having to ship a copy of that dll with this custom code.
string css = "body{overflow: hidden;}";
css += "#divViewer{margin: 0px .25% 0px !important; width:99.5% !important; background-color:#F0F1F2 !important; border-top: 2px solid #F0F1F2 !important;}";
css += "#emailHeader,#divViewer>div{background:#F0F1F2;}";
css += "#dsiFooterPlaceHolder_docViewer{display: none !important;}";
// Overwrite page javascript functions with a custom ones that fixes formatting and hides buttons.
HtmlElement scriptElement = wb.Document.CreateElement("script");
// Return modified page height.
scriptElement.InnerText = "function getFullPageHeight(){if (window.innerWidth > 992) { return window.innerHeight + 30} else { return window.innerHeight + 10}};";
// Polyfil for IU. Source: https://github.com/jserz/js_piece/blob/master/DOM/ParentNode/append()/append().md
scriptElement.InnerText += "(function(arr){arr.forEach(function(item){if(item.hasOwnProperty('append')){return}Object.defineProperty(item,'append',{configurable:true,enumerable:true,writable:true,value:function append(){var argArr=Array.prototype.slice.call(arguments),docFrag=document.createDocumentFragment();argArr.forEach(function(argItem){var isNode=argItem instanceof Node;docFrag.appendChild(isNode?argItem:document.createTextNode(String(argItem)))});this.appendChild(docFrag)}})})})([Element.prototype,Document.prototype,DocumentFragment.prototype]);";
// Function which takes a string and appends it to the page's style.
scriptElement.InnerText += "function addStyle(styleString) {const style = document.createElement('style');style.textContent = styleString;document.head.append(style);}";
// Add CSS to header.
scriptElement.InnerText += "addStyle(\""+css+"\");";
// Return modified buttons
scriptElement.InnerText += @"buildToolBarButtons=function(){var lt=Handlebars.compile($(""#docViewerNavSm-template"").html()),at=lt({}),a,g,b,it,c,s,ot,rt,ut,st,v,o,ht,ft,et,ct,f,h,r,y,p,w,l,k,u,d,nt,tt;$(""#dsiViewerNavbar"").replaceWith(at);a=[];g=[];u==""xs""&&(b=""home"",it=dsiCommon.getLocalStorageValue(""tabSetting|""+n),it!=null&&(b=it),g.push({type:""button"",id:""tabHomeDocLink"",imageUrl:""../Images/V/32x32/house.png"",attributes:{title:$.t(""strings.TITLE_HOME""),dsiLabel:$.t(""strings.TITLE_HOME"")},enable:b!=""home"",click:function(){stopEvent(event);dsiCommon.setLocalStorageValue(""tabSetting|""+n,""home"");setupPageSize(!0);updateNavBarButtons()}}),g.push({type:""button"",id:""tabEditDocLink"",imageUrl:""../Images/V/32x32/edit.png"",attributes:{title:$.t(""strings.LBL_EDIT""),dsiLabel:$.t(""strings.LBL_EDIT"")},enable:b==""home"",click:function(){stopEvent(event);dsiCommon.setLocalStorageValue(""tabSetting|""+n,""edit"");setupPageSize(!0);updateNavBarButtons()}}));c=[];c.push({type:""button"",id:""printDocLink"",imageUrl:""../Images/V/32x32/printer3.png"",attributes:{title:$.t(""strings.PRINT_DOCUMENT""),dsiLabel:$.t(""strings.LBL_PRINT"")},enable:!1,click:function(){dsiDocViewer.toggleSideNav(!0,function(){enhAudit(""Print|Fax"",""true"",""printDocument()"")})}});c.push({type:""button"",id:""openDocLink"",imageUrl:""../Images/V/32x32/folder_document.png"",attributes:{title:$.t(""strings.OPEN_FILE_NATIVE""),dsiLabel:$.t(""strings.OPEN"")},enable:!1,click:function(){dsiDocViewer.toggleSideNav(!0,function(){enhAudit(""Open File"",""true"",""openDocument()"")})}});s=[];v=[];v.push({type:""button"",id:""previousItemLink"",imageUrl:""../Images/V/32x32/PrevItem.png"",attributes:{title:$.t(""strings.PREV_ITEM""),dsiLabel:$.t(""strings.PREVIOUS"")},enable:!1,click:function(){getItem(""prevItem"")}});v.push({type:""button"",id:""nextItemLink"",imageUrl:""../Images/V/32x32/NextItem.png"",attributes:{title:$.t(""strings.NEXT_ITEM""),dsiLabel:$.t(""strings.NEXT"")},enable:!1,click:function(){getItem(""nextItem"")}});o=[];ht={type:""button"",id:""firstPageLink"",imageUrl:""../Images/V/32x32/FirstPage.png"",attributes:{title:$.t(""strings.FIRST_PAGE""),dsiLabel:$.t(""strings.FIRST"")},enable:!1,click:function(){getPage(""firstPage"")}};(u==""lg""||u==""xs"")&&o.push(ht);ft={type:""button"",id:""previousPageLink"",imageUrl:""../Images/V/32x32/PrevPage.png"",attributes:{title:$.t(""strings.PREV_PAGE""),dsiLabel:$.t(""strings.PREVIOUS"")},enable:!1,click:function(){getPage(""prevPage"")}};o.push(ft);a.push(ft);et={type:""button"",id:""nextPageLink"",imageUrl:""../Images/V/32x32/NextPage.png"",attributes:{title:$.t(""strings.NEXT_PAGE""),dsiLabel:$.t(""strings.NEXT"")},enable:!1,click:function(){getPage(""nextPage"")}};o.push(et);a.push(et);ct={type:""button"",id:""lastPageLink"",imageUrl:""../Images/V/32x32/LastPage.png"",attributes:{title:$.t(""strings.LAST_PAGE""),dsiLabel:$.t(""strings.LAST"")},enable:!1,click:function(){getPage(""lastPage"")}};(u==""lg""||u==""xs"")&&o.push(ct);o.push({type:""button"",id:""jumpPageLink"",imageUrl:""../Images/V/32x32/JumpPage.png"",attributes:{title:$.t(""strings.JUMP_TO_PAGE""),dsiLabel:$.t(""strings.JUMP"")},enable:!1,click:function(){dsiDocViewer.toggleSideNav(!0,function(){jumpToPage()})}});f=[];f.push({type:""button"",id:""rotatePageLink"",imageUrl:""../Images/V/32x32/rotate_right.png"",attributes:{title:$.t(""strings.ROTATE_IMAGE""),dsiLabel:$.t(""strings.ROTATE"")},enable:!1,click:function(){rotateImage()}});f.push({type:""button"",id:""resetPageLink"",imageUrl:""../Images/V/32x32/view_1_1.png"",attributes:{title:$.t(""strings.RESET_IMAGE""),dsiLabel:$.t(""strings.RESET"")},enable:!1,click:function(){resetImage()}});f.push({type:""button"",id:""scaleWidthLink"",imageUrl:""../Images/V/32x32/page_width.png"",attributes:{title:$.t(""strings.SCALE_TO_WIDTH""),dsiLabel:$.t(""strings.WIDTH"")},enable:!1,click:function(){scaleToWidth()}});f.push({type:""button"",id:""scaleHeightLink"",imageUrl:""../Images/V/32x32/page_height.png"",attributes:{title:$.t(""strings.SCALE_TO_HEIGHT""),dsiLabel:$.t(""strings.HEIGHT"")},enable:!1,click:function(){scaleToHeight()}});f.push({type:""button"",id:""scaleWindowLink"",imageUrl:""../Images/V/32x32/page_size.png"",attributes:{title:$.t(""strings.SCALE_TO_WINDOW""),dsiLabel:$.t(""strings.WINDOW"")},enable:!1,click:function(){scaleToWindow()}});h=[];r=[];y=[];y.push({type:""button"",id:""txtNotesDocLink"",imageUrl:""../Images/V/32x32/note.png"",attributes:{title:$.t(""strings.TEXTUAL_NOTE""),dsiLabel:$.t(""strings.NOTES"")},enable:!1,click:function(){dsiDocViewer.toggleSideNav(!0,function(){textualNote()})}});y.push({type:""button"",id:""showHideAnnotationsDocLink"",imageUrl:""../Images/V/32x32/text_rich.png"",attributes:{title:$.t(""strings.SHOW_HIDE_ANNOTATIONS""),dsiLabel:$.t(""strings.SHOW"")},enable:!1,click:function(){showHideAnnotations()}});p=[];w=[];l=[];var t=[],e=[],i=u==""xs"";$(""#sideNavBar"").empty();k=!i||i&&b==""home"";d=!i||i&&b!=""home"";i&&g.length>0&&addSideNavTabs(g);c.length>0&&k&&(i?addButtonsToSideNavBar(c):(t.length>0&&t.push({type:""separator"",overflow:""never""}),t.push({id:""generalActionsGroup"",type:""buttonGroup"",buttons:c,attributes:{""class"":""dsi-toolbar-split-expand"",dsiLabel:$.t(""strings.LBL_GENERAL"")}}),t.push({id:""generalActionsGroup_split"",type:""splitButton"",imageUrl:""../Images/V/32x32/folder_floppy_disk.png"",menuButtons:c,attributes:{""class"":""dsi-toolbar-split-collapse"",dsiLabel:$.t(""strings.LBL_GENERAL"")},overflow:""never""}),e.push(""generalActionsGroup_split"")));s.length>0&&k&&(i?addButtonsToSideNavBar(s):(t.length>0&&t.push({type:""separator"",overflow:""never""}),t.push({id:""docNavActionsGroup"",type:""buttonGroup"",buttons:s,attributes:{""class"":""dsi-toolbar-split-expand"",dsiLabel:$.t(""strings.DOCUMENT"")}}),t.push({id:""docNavActionsGroup_split"",type:""splitButton"",imageUrl:""../Images/V/32x32/folder.png"",menuButtons:s,attributes:{""class"":""dsi-toolbar-split-collapse"",dsiLabel:$.t(""strings.DOCUMENT"")},overflow:""never""}),e.push(""docNavActionsGroup_split"")));v.length>0&&k&&(i?addButtonsToSideNavBar(v):(t.length>0&&t.push({type:""separator"",overflow:""never"",id:""itemNavSeparator""}),t.push({id:""itemNavActionsGroup"",type:""buttonGroup"",buttons:v,attributes:{""class"":""dsi-toolbar-split-expand"",dsiLabel:$.t(""strings.ITEM"")}}),t.push({id:""itemNavActionsGroup_split"",type:""splitButton"",imageUrl:""../Images/V/32x32/documents.png"",menuButtons:v,attributes:{""class"":""dsi-toolbar-split-collapse"",dsiLabel:$.t(""strings.ITEM"")},overflow:""never""}),e.push(""itemNavActionsGroup_split"")));o.length>0&&k&&(i?addButtonsToSideNavBar(o):(t.length>0&&t.push({type:""separator"",overflow:""never""}),t.push({id:""pageNavActionsGroup"",type:""buttonGroup"",buttons:o,attributes:{""class"":""dsi-toolbar-split-expand"",dsiLabel:$.t(""strings.PAGE"")}}),t.push({id:""pageNavActionsGroup_split"",type:""splitButton"",imageUrl:""../Images/V/32x32/document.png"",menuButtons:o,attributes:{""class"":""dsi-toolbar-split-collapse"",dsiLabel:$.t(""strings.PAGE"")},overflow:""never""}),e.push(""pageNavActionsGroup_split"")));f.length>0&&k&&(i?addButtonsToSideNavBar(f):(t.length>0&&t.push({type:""separator"",overflow:""never""}),t.push({id:""formatNavActionsGroup"",type:""buttonGroup"",buttons:f,attributes:{""class"":""dsi-toolbar-split-expand"",dsiLabel:$.t(""strings.FORMAT"")}}),t.push({id:""formatNavActionsGroup_split"",type:""splitButton"",imageUrl:""../Images/V/32x32/document_plain_tool.png"",menuButtons:f,attributes:{""class"":""dsi-toolbar-split-collapse"",dsiLabel:$.t(""strings.FORMAT"")},overflow:""never""}),e.push(""formatNavActionsGroup_split"")));h.length>0&&d&&(i?addButtonsToSideNavBar(h):(t.length>0&&t.push({type:""separator"",overflow:""never""}),t.push({id:""versionNavActionsGroup"",type:""buttonGroup"",buttons:h,attributes:{""class"":""dsi-toolbar-split-expand"",dsiLabel:$.t(""strings.VERSION"")}}),t.push({id:""versionNavActionsGroup_split"",type:""splitButton"",imageUrl:""../Images/V/32x32/document_lock.png"",menuButtons:h,attributes:{""class"":""dsi-toolbar-split-collapse"",dsiLabel:$.t(""strings.VERSION"")},overflow:""never""}),e.push(""versionNavActionsGroup_split"")));r.length>0&&d&&(i?addButtonsToSideNavBar(r):(t.length>0&&t.push({type:""separator"",overflow:""never""}),t.push({id:""manageNavActionsGroup"",type:""buttonGroup"",buttons:r,attributes:{""class"":""dsi-toolbar-split-expand"",dsiLabel:$.t(""strings.MANAGE"")}}),t.push({id:""manageNavActionsGroup_split"",type:""splitButton"",imageUrl:""../Images/V/32x32/document_gear.png"",menuButtons:r,attributes:{""class"":""dsi-toolbar-split-collapse"",dsiLabel:$.t(""strings.MANAGE"")},overflow:""never""}),e.push(""manageNavActionsGroup_split"")));y.length>0&&d&&(i?addButtonsToSideNavBar(y):(t.length>0&&t.push({type:""separator"",overflow:""never""}),t.push({id:""annoteNavActionsGroup"",type:""buttonGroup"",buttons:y,attributes:{""class"":""dsi-toolbar-split-expand"",dsiLabel:$.t(""strings.ANNOTATE"")}}),t.push({id:""annoteNavActionsGroup_split"",type:""splitButton"",imageUrl:""../Images/V/32x32/document_attachment.png"",menuButtons:y,attributes:{""class"":""dsi-toolbar-split-collapse"",dsiLabel:$.t(""strings.ANNOTATE"")},overflow:""never""}),e.push(""annoteNavActionsGroup_split"")));p.length>0&&d&&(i?addButtonsToSideNavBar(p):(t.length>0&&t.push({type:""separator"",overflow:""never""}),t.push({id:""wfNavActionsGroup"",type:""buttonGroup"",buttons:p,attributes:{""class"":""dsi-toolbar-split-expand"",dsiLabel:$.t(""strings.WORKFLOW"")}}),t.push({id:""wfNavActionsGroup_split"",type:""splitButton"",imageUrl:""../Images/V/32x32/branch.png"",menuButtons:p,attributes:{""class"":""dsi-toolbar-split-collapse"",dsiLabel:$.t(""strings.WORKFLOW"")},overflow:""never""}),e.push(""wfNavActionsGroup_split"")));w.length>0&&d&&(i?addButtonsToSideNavBar(w):(t.length>0&&t.push({type:""separator"",overflow:""never""}),t.push({id:""signNavActionsGroup"",type:""buttonGroup"",buttons:w,attributes:{""class"":""dsi-toolbar-split-expand"",dsiLabel:$.t(""strings.SIGN"")}}),t.push({id:""signNavActionsGroup_split"",type:""splitButton"",imageUrl:""../Images/V/32x32/pencil.png"",menuButtons:w,attributes:{""class"":""dsi-toolbar-split-collapse"",dsiLabel:$.t(""strings.SIGN"")},overflow:""never""}),e.push(""signNavActionsGroup_split"")));l.length>0&&(i?addButtonsToSideNavBar(l):(t.length>0&&t.push({type:""separator"",overflow:""never""}),t.push({id:""optionNavActionsGroup"",type:""buttonGroup"",buttons:l,attributes:{""class"":""dsi-toolbar-split-expand"",dsiLabel:$.t(""strings.OPTIONS"")}}),t.push({id:""optionNavActionsGroup_split"",type:""splitButton"",imageUrl:""../Images/V/32x32/preferences_edit.png"",menuButtons:l,attributes:{""class"":""dsi-toolbar-split-collapse"",dsiLabel:$.t(""strings.LBL_OPTIONS"")},overflow:""never""}),e.push(""optionNavActionsGroup_split"")));a.push({type:""button"",id:""sideNavButton"",buttonHtml:""<span class='sr-only'>Toggle Navigation<\/span><span class='icon-bar><\/span><span class='icon-bar><\/span><span class='icon-bar><\/span>"",imageUrl:""../Images/O/blue/32x32/navicon.png"",attributes:{title:$.t(""strings.LBL_MENU""),dsiLabel:$.t(""strings.LBL_MENU"")},enable:!0,click:function(){var n=$(""#dsiViewerNavbar"").find(""#sideNavButton"");$(""#sideNavBar"").hasClass(""open"")?($(""#dsiViewerNavbar"").find(""#sideNavButton"").kendoButton({imageUrl:""../Images/O/blue/32x32/navicon.png""}),n.attr(""title"",$.t(""strings.LBL_MENU"")),$(""#dsiViewerNavbar"").find(""#sideNavButton"").parent().find("".dsi-label"").html($.t(""strings.LBL_MENU""))):($(""#dsiViewerNavbar"").find(""#sideNavButton"").kendoButton({imageUrl:""../Images/O/blue/32x32/delete.png""}),n.attr(""title"",$.t(""strings.LBL_CLOSE"")),$(""#dsiViewerNavbar"").find(""#sideNavButton"").parent().find("".dsi-label"").html($.t(""strings.LBL_CLOSE"")));dsiDocViewer.toggleSideNav()}});i?$.each(a,function(n,i){t.push(i)}):dsiDocViewer.toggleSideNav(!0);dsiKendo.initializeKendoToolbar(""#dsiViewerNavbar"",t,e);i&&(nt=$(""#tabHomeDocLink""),$(nt).wrap(""<div class='dsi-label-button'><\/div>""),$(nt).after(""<div class='dsi-label'>""+$(nt).attr(""dsiLabel"")+""<\/div>""),tt=$(""#tabEditDocLink""),$(tt).wrap(""<div class='dsi-label-button'><\/div>""),$(tt).after(""<div class='dsi-label'>""+$(tt).attr(""dsiLabel"")+""<\/div>""))},addSideNavTabs=function(n){var t='<ul class=""nav nav-tabs"">';$.each(n,function(n,i){t+=i.enable?'<li id=""'+i.id+'_nav""><a href=""#"">'+i.attributes.dsiLabel+""<\/a><\/li>"":'<li class=""active"" id=""'+i.id+'_nav""><a href=""#"">'+i.attributes.dsiLabel+""<\/a><\/li>""});t+=""<\/ul>"";$(""#sideNavBar"").append(t);$.each(n,function(n,t){$(""#sideNavBar"").on(""tap.sideNavEvent"",""#""+t.id+""_nav"",t.click)})},addButtonsToSideNavBar=function(n){var t=$(""#sideNavItem-template"").html(),i=Handlebars.compile(t),r=i({buttons:n});$(""#sideNavBar"").append(r);$.each(n,function(n,t){$(""#sideNavBar"").on(""tap.sideNavEvent"",""#""+t.id+""_nav:enabled"",t.click)})};";
// Resize doc on pageload.
scriptElement.InnerText += "{function defer(method) {if (document.getElementById('divLoading').getAttribute('style') == 'display: none;') {method} else {setTimeout(function() { defer(method) }, 50);}}defer(function () {resizeDoc();});}";
scriptElement.InnerText += "resizeDoc();";
// Add javascript to page.
wb.Document.GetElementById("dsiFooterPlaceHolder_docViewer").AppendChild(scriptElement);
break;
} catch {}
c++;
}
}
}
// Resize webbrowser control when window resizes.
private void HandleResize(object sender, System.EventArgs e)
{
wb.Width = vh.Width;
wb.Height = vh.Height;
}
// Remove Web Browser Control when document Changes.
private void documentChanged(object sender, System.Windows.RequestBringIntoViewEventArgs e)
{
var viewerControl = (DSI.DocumentViewer.WpfClientControls.ScrollingViewerHost.UCScrollingViewerHost)((System.Windows.Forms.Integration.ElementHost)olddoc).Child;
if (vh.IUIContext.DocumentNavService.CurrentDocument.InternalID != olddocID) {
vh.Controls.Remove(wb);
wb.Dispose();
viewerControl.RequestBringIntoView -= this.documentChanged;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment