public static string makeGET(PostSubmitter post, string strSessionKey, HttpSessionState session, ref BFConfiguration configuration )
        {
            string result = "";
            post.Type = PostSubmitter.PostTypeEnum.Get;
            post.strSessionKey = strSessionKey;
            post.cookieContainer = configuration.cookieContainer;
            result = post.Post();

            return result;

        }
        // ********
        // This is the active Login method for this application
        // ********
        public static CurrentSession login(string strSessionKey, HttpSessionState session, BFConfiguration configuration)
        {
            string XForwardedFor = configuration.currentUser.ipAddress;

            if (string.IsNullOrEmpty(XForwardedFor)) return null;

            PostSubmitter post = new PostSubmitter();
            //post.Url = ServiceCaller.serviceUrlRoot(configuration) + "bms/auth/trusted.xml?devicePlatform=SPWebPart&X-Forwarded-For=" + System.Web.HttpUtility.UrlEncode(XForwardedFor);
            post.Url = ServiceCaller.serviceUrlRoot() + "bms/auth/trusted.xml?devicePlatform=SPWebPart&X-Forwarded-For=" + XForwardedFor;

            post.PostItems.Add("token", configuration.currentUser.sid);

            post.PostItems.Add("X-Forwarded-For", XForwardedFor);

            post.PostItems.Add("User-Agent", configuration.currentUser.userAgent);

            post.strSessionKey = strSessionKey;
            string BFLoginResponse = CommonFunctions.unLTGT(ServiceCaller.makePOST(post));

            string BFSessionKey = "";
            BFSessionKey = xmlReader.getValueBySimpleQuery(BFLoginResponse, "sessionKey", "", false);


            string BFPasscode = "";
            BFPasscode = xmlReader.getValueBySimpleQuery(BFLoginResponse, "passcode", "", false);

            CurrentSession _currentSession = new CurrentSession();
            _currentSession.sessionKey = BFSessionKey;
            _currentSession.passCode = BFPasscode;

            // bug27992: SharePoint portal authentication issue 
            // Modified - 09/18/2012
            // Serialized Session Information
            //session[CommonVariables.c_CookieContainer] = post.cookieContainer;
            configuration.currentSession = _currentSession;
            configuration.cookieContainer = post.cookieContainer;

            return _currentSession;

        }
 private static XmlDocument CreateSoapEnvelope(BFConfiguration configuration, string soapXml)
 {
     XmlDocument soapEnvelop = new XmlDocument();
     soapEnvelop.LoadXml(soapXml);
     return soapEnvelop;
 }
        public static bool completeActivity(BFConfiguration configuration)
        {
            var _url = ServiceCaller.serviceUrlRoot() + "webservice/HWActivity.hws";
            var _action = "complete"; // ServiceCaller.serviceUrlRoot() + "webservice/HWActivity";

            XmlDocument soapEnvelopeXml = CreateSoapEnvelope(configuration, completeActSoapMessage(configuration));
            HttpWebRequest webRequest = CreateWebRequest(_url, _action);
            InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

            IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
            asyncResult.AsyncWaitHandle.WaitOne();
            string soapResult;
            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
            {
                using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                {
                    soapResult = rd.ReadToEnd();
                }
            }

            return true;

        }
        public static bool completeWorkitem(BFConfiguration configuration, int processID)
        {
            configuration.currentProcessID = processID;

            if (configuration.processInfo.wiseq == 0)
            {
                throw new Exception("Workitem doesn't belong to the current user!");
            }

            var _url = ServiceCaller.serviceUrlRoot() + "webservice/HWWorkitem.hws";
            var _action = "BizCompleteWorkitem"; // ServiceCaller.serviceUrlRoot() + "webservice/HWActivity";

            XmlDocument soapEnvelopeXml = CreateSoapEnvelope(configuration, completeWorkitemSoapMessage(configuration));
            HttpWebRequest webRequest = CreateWebRequest(_url, _action);
            InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

            IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
            asyncResult.AsyncWaitHandle.WaitOne();
            string soapResult;
            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
            {
                using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                {
                    soapResult = rd.ReadToEnd();
                }
            }

            return true;
        }
        public static DataTable getBizCoveIDs(string strBizCoveType, HttpSessionState session, ref BFConfiguration configuration)
        {
            PostSubmitter post = new PostSubmitter();
            post.Url = ServiceCaller.serviceUrlRoot() + "bms/bizcove/" + strBizCoveType + ".xml";
            //post.strSessionKey = strSessionKey;
            post.strSessionKey = session.SessionID;

            // bug27992: SharePoint portal authentication issue 
            // Modified - 09/18/2012
            // Serialized Session Information
            //post.cookieContainer = (CookieContainer)session[CommonVariables.c_CookieContainer];
            post.cookieContainer = configuration.cookieContainer;

            string bizCoveType;

            bizCoveType = xmlReader.getValueBySimpleQuery(ServiceCaller.makeGET(post, session.SessionID, session, ref configuration), "HWRECBODY", "", true).Trim();

            DataSet dts = new DataSet();
            XmlDocument xDoc = new XmlDocument();

            try
            {
                dts = xmlReader.getDataSetFromXmlDocument(bizCoveType, "HWCOVELIST");
            }
            catch (Exception)
            {
            }

            if (dts.Tables.Count == 0) return null;

            return dts.Tables[0];


        }
        private static string LoginSoapMessage_117(BFConfiguration configuration)
        {
            StringBuilder soapMessage = new StringBuilder(4096);
            soapMessage.Append("<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.je.wf.bf.hs.com\">");
            soapMessage.Append("<soapenv:Header/>");
            soapMessage.Append("<soapenv:Body>");
            soapMessage.Append("<ser:login soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
            soapMessage.Append("<category xsi:type=\"xsd:int\">1</category>");
            soapMessage.Append("<SID xsi:type=\"xsd:string\">");
            soapMessage.Append(configuration.currentUser.sid);
            soapMessage.Append("</SID>");
            soapMessage.Append("<browserIP xsi:type=\"xsd:string\">");
            soapMessage.Append(configuration.currentUser.ipAddress);
            soapMessage.Append("</browserIP>");
            soapMessage.Append("<forceLogin xsi:type=\"xsd:boolean\">T</forceLogin>");
            soapMessage.Append("</ser:login>");
            soapMessage.Append("</soapenv:Body>");
            soapMessage.Append("</soapenv:Envelope>");

            return soapMessage.ToString();

        }
        public static bool login_117(BFConfiguration configuration)
        {
            var _url = ServiceCaller.serviceUrlRoot() + "webservice/HWSession.hws";
            var _action = "login"; // ServiceCaller.serviceUrlRoot() + "webservice/HWActivity";

            XmlDocument soapEnvelopeXml = CreateSoapEnvelope(configuration, LoginSoapMessage_117(configuration));
            HttpWebRequest webRequest = CreateWebRequest(_url, _action);
            InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

            IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
            asyncResult.AsyncWaitHandle.WaitOne();
            string soapResult;
            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
            {
                using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                {
                    soapResult = rd.ReadToEnd();
                }
            }


            if (!string.IsNullOrEmpty(soapResult))
            {
                StringBuilder sessionKey = new StringBuilder(1024);
                sessionKey.Append(CommonFunctions.between(soapResult, "<loginReturn xsi:type=\"xsd:string\">", "</loginReturn>"));
                sessionKey.Replace("&lt;", "<");
                sessionKey.Replace("&gt;", ">");
                sessionKey.Replace("&quot;", "\"");
                configuration.currentSession.sessionKey = sessionKey.ToString();
            }
            if (!string.IsNullOrEmpty(configuration.currentSession.sessionKey))
            {
                string memberId = CommonFunctions.between(configuration.currentSession.sessionKey, "USERID=\"", "\"");
                configuration.currentUser.memberId = memberId;
            }


            return true;

        }
 private static string completeActSoapMessage(BFConfiguration configuration)
 {
     StringBuilder soapMessage = new StringBuilder(4096);
     soapMessage.Append("<?xml version=\"1.0\"?>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<SOAP-ENV:Header>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<Version>1.0</Version>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<WfTransport/>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<Request ResponseRequired=\"Yes\"/>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("</SOAP-ENV:Header>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<SOAP-ENV:Body>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<BizCompleteActivity>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<SessionInfoXML>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<![CDATA[");
     soapMessage.Append(configuration.currentSession.sessionKey);
     soapMessage.Append("]]>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("</SessionInfoXML>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<ServerID>");
     soapMessage.Append(configuration.processInfo.serverId);
     soapMessage.Append("</ServerID>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<ProcessID>");
     soapMessage.Append(configuration.processInfo.processId.ToString());
     soapMessage.Append("</ProcessID>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("<ActivitySequence>");
     soapMessage.Append(configuration.processInfo.actSeq.ToString());
     soapMessage.Append("</ActivitySequence>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("</BizCompleteActivity>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("</SOAP-ENV:Body>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     soapMessage.Append("</SOAP-ENV:Envelope>");
     soapMessage.Append(CommonFunctions.xmlNewLine);
     return soapMessage.ToString();
 }
        public static string getBizCoveData_Delete(HttpSessionState session, ref BFConfiguration configuration)
        {
            if (configuration.currentPage <= 0) configuration.currentPage = 1;
            configuration.ItemLimit = 1000;

            PostSubmitter post = new PostSubmitter();
            StringBuilder postUrl = new StringBuilder(1024);

            postUrl.Append(ServiceCaller.serviceUrlRoot());
            postUrl.Append("bms/list/");
            postUrl.Append(BizCoveTypes.Worklist.ToString());
            postUrl.Append("/");
            postUrl.Append(configuration.BizCove.ToString());
            postUrl.Append(".xml?page=");
            if (configuration.currentPage > 0)
                postUrl.Append(configuration.currentPage.ToString());
            else
                postUrl.Append("1");

            postUrl.Append("&limit=");
            postUrl.Append(configuration.ItemLimit.ToString());

            #region discarded  // 04/30/2014

            //   04/30/2014
            /*
            if (configuration.bfFilter != null)
            {
                if (configuration.bfFilter.filterType == BFFilter.FilterType.QSFilterBy)
                {
                    postUrl.Append("&witemCategory=");
                    //postUrl.Append(CommonFunctions.getWorkItemStatusID(configuration.bfFilter.FilterValue));
                    postUrl.Append(CommonFunctions.mapFilterBy(configuration.bfFilter.FilterValue));
                }
                if (configuration.bfFilter.filterType == BFFilter.FilterType.QSText)
                {
                    postUrl.Append("&search=");
                    postUrl.Append(configuration.bfFilter.FilterValue);
                }
                if (configuration.bfFilter.filterType == BFFilter.FilterType.KeySearch)
                {
                    postUrl.Append("&");
                    postUrl.Append(configuration.bfFilter.FilterValue);
                }
                if (configuration.bfFilter.filterType == BFFilter.FilterType.AdvSearch)
                {
                    postUrl.Append("&advSearchKey=");
                    postUrl.Append(configuration.bfFilter.FilterValue);

                    // Deleting old Advance Search Session
                    configuration.bfFilter.filterType = BFFilter.FilterType.None;
                    configuration.bfFilter.FilterValue = "";
                }
            }
            */
            /*   04/30/2014
            if (configuration.bfSort != null)
            {
                string sortType = "";

                if (configuration.bfSort.sortType != BFSort.SortType.None)
                {
                    if (configuration.bfSort.sortType == BFSort.SortType.Asc)
                    {
                        sortType = "a";
                    }
                    else
                    {
                        sortType = "d";
                    }
                    postUrl.Append("&sort=");
                    postUrl.Append(configuration.bfSort.sortColumn);
                    postUrl.Append("|");
                    postUrl.Append(configuration.bfSort.dataType);
                    postUrl.Append("|");
                    postUrl.Append(sortType);
                    postUrl.Append("|");
                    postUrl.Append("column");

                }


            }
            */

#endregion

            post.Url = postUrl.ToString();
            post.strSessionKey = session.SessionID;

            post.cookieContainer = configuration.cookieContainer;

            string bizCoveDataString;

            bizCoveDataString = ServiceCaller.makeGET(post, session.SessionID, session, ref configuration);

            configuration.totalItems = Convert.ToInt16(xmlReader.getValueBySimpleQuery(bizCoveDataString, "total", "", false));

            if (configuration.totalItems == 0)
            {
                configuration.totalPages = 0;
            }

            if (!string.IsNullOrEmpty(bizCoveDataString))
            {
                configuration.sourceData = CommonFunctions.getAllData(bizCoveDataString);
                configuration.gridData = configuration.sourceData;
            }
            return bizCoveDataString;

        }
        private static void getBizCoveConfigSection(ref BFConfiguration configuration, string bizCoveConfig, bool isActionSecion)
        {
            DataSet dts = new DataSet();
            XmlDocument xDoc = new XmlDocument();

            string configSection = "";
            string dataTableName = "";
            string keyName = "";
            //string actionType = "";



            if (isActionSecion)
            {
                configSection = "actions";
                dataTableName = "actionDefs";
                //if (configuration.BizCoveType == BFConfiguration.BizCoveTypes.Worklist)
                //    actionType = "button";
                //else
                //    actionType = "image";

                keyName = CommonFunctions.between(bizCoveConfig, "<actions ", ">");

                //keyName = "showcheckbox=\"yes\" type=\"" + actionType + "\"";
            }
            else
            {
                configSection = "columns";
                dataTableName = "columnDefs";
                keyName = "";
            }

            try
            {
                xDoc.LoadXml(CommonFunctions.unEscape(xmlReader.getValueBySimpleQuery(bizCoveConfig, configSection, keyName, true, isActionSecion).Trim()));

                XmlNode childNode = xDoc.FirstChild;
                XmlNodeList childNodes = childNode.ChildNodes;

                DataTable dtColumnDef = new DataTable(dataTableName); //= xmlReader.xmlNodeListToTable(childNodes, "columnDefs", true);
                DataColumn dCol = new DataColumn();

                string columnName = "";
                string columnValue = "";

                foreach (XmlNode currentNode in childNodes)
                {

                    DataRow dRow = dtColumnDef.NewRow();

                    foreach (XmlAttribute attribute in currentNode.Attributes)
                    {

                        columnName = attribute.Name;
                        columnValue = attribute.Value;
                        if (!dtColumnDef.Columns.Contains(columnName))
                        {
                            dtColumnDef.Columns.Add(columnName);
                        }

                        dRow[columnName] = columnValue;
                    }

                    dtColumnDef.Rows.Add(dRow);
                }


                
                if (isActionSecion)
                    configuration.actionConfiguration = dtColumnDef;
                else
                    configuration.columnConfiguration = dtColumnDef;
                
            }
            catch (Exception)
            {

            }

        }
        private static void getBizCoveFilterSection(ref BFConfiguration configuration, string bizCoveConfig)
        {
            BFFilter bfFilter = configuration.bfFilter;
            if (configuration.bfFilter == null)
                bfFilter = new BFFilter();

            bfFilter.filterType = BFFilter.FilterType.None;
            bfFilter.TaskType = false;


            // Suspect: 04/30/2014
            //if (configuration.BizCoveType != BizCoveTypes.Worklist && configuration.BizCoveType != BizCoveTypes.Monitor)
            //{
            //    configuration.bfFilter = bfFilter;
            //    return;
            //}

            DataSet dts = new DataSet();
            XmlDocument xDoc = new XmlDocument();

            string configSection = "";
            //string dataTableName = "";
            string keyName = "";
            keyName = CommonFunctions.between(bizCoveConfig, "<filter ", ">");
            configSection = "filter";
            //dataTableName = "items";

            XmlNodeList filterList;


            if (keyName == "")
            {
                xDoc.LoadXml(CommonFunctions.unEscape(xmlReader.getValueBySimpleQuery(bizCoveConfig, configSection, keyName, true, false).Trim()));
                try
                {
                    filterList = xDoc.GetElementsByTagName("KEY");
                }
                catch (Exception)
                {
                    return;
                }
            }
            else
            {
                xDoc.LoadXml(CommonFunctions.unEscape(xmlReader.getValueBySimpleQuery(bizCoveConfig, configSection, keyName, true, true).Trim()));
                try
                {
                    filterList = xDoc.GetElementsByTagName("items")[0].ChildNodes;
                }
                catch (Exception)
                {
                    return;
                }
            }



            int countFilterItems = 0;


            try
            {
                countFilterItems = filterList.Count;
            }
            catch (Exception)
            {
                // do nothing.
            }

            bfFilter.TaskType = countFilterItems > 2;
            configuration.bfFilter = bfFilter;


            // Now retrieving Filter KEY information

            /*
            <item id="U"/>
            <item id="S"/>
            <item id="G"/>
            <item id="D"/>
            <item id="C"/>
            <item id="T"/>
            */

            string nodeIdValue = "";
            List<string> FilterByList = new List<string>();

            foreach (XmlNode currentNode in filterList)
            {
                try
                {
                    nodeIdValue = currentNode.Attributes["id"].Value;
                    FilterByList.Add(nodeIdValue);
                }
                catch (Exception)
                {

                }
            }

            configuration.filterBy = FilterByList;

            // Now Create a KEY section under BFConfiguration and set KEYS

        }
        public static void getBizCoveConfig(HttpSessionState session, ref BFConfiguration configuration)
        {

            PostSubmitter post = new PostSubmitter();
            post.Url = ServiceCaller.serviceUrlRoot() + "bms/bizcove/" + BizCoveTypes.Worklist + "/" + configuration.BizCove + ".xml";
            post.strSessionKey = session.SessionID;
            post.cookieContainer = configuration.cookieContainer;

            string bizCoveConfig;

            bizCoveConfig = ServiceCaller.makeGET(post, session.SessionID, session, ref configuration);

            getBizCoveConfigSection(ref configuration, bizCoveConfig, true);   // For fetching actionConfiguration         
            getBizCoveConfigSection(ref configuration, bizCoveConfig, false);  // For fetching columnConfiguration
            getBizCoveFilterSection(ref configuration, bizCoveConfig);         // For filter criteria  
        }
        private static string completeWorkitemSoapMessage_Discarded(BFConfiguration configuration)  // Discarded
        {
            StringBuilder soapMessage = new StringBuilder(4096);
            soapMessage.Append("<?xml version=\"1.0\"?>");
            soapMessage.Append("<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">");
            soapMessage.Append("<SOAP-ENV:Header>");
            soapMessage.Append("<Version>1.0</Version>");
            soapMessage.Append("<WfTransport/>");
            soapMessage.Append("<Request ResponseRequired=\"Yes\"/>");
            soapMessage.Append("</SOAP-ENV:Header>");
            soapMessage.Append("<SOAP-ENV:Body>");
            soapMessage.Append("<BizCompleteWorkitem>");
            soapMessage.Append("<SessionInfoXML>");
            soapMessage.Append("<![CDATA[");
            soapMessage.Append(CommonFunctions.removeBackslashes(configuration.currentSession.sessionKey));
            soapMessage.Append("]]>");
            soapMessage.Append("</SessionInfoXML>");
            soapMessage.Append("<ServerID>");
            soapMessage.Append(configuration.processInfo.serverId);
            soapMessage.Append("</ServerID>");
            soapMessage.Append("<ProcessID>");
            soapMessage.Append(configuration.processInfo.processId.ToString());
            soapMessage.Append("</ProcessID>");
            soapMessage.Append("<ActivitySequence>");
            soapMessage.Append(configuration.processInfo.actSeq.ToString());
            soapMessage.Append("</ActivitySequence>");
            soapMessage.Append("<WorkitemSequence>");
            soapMessage.Append(configuration.processInfo.wiseq.ToString());
            soapMessage.Append("</WorkitemSequence>");
            soapMessage.Append("<ResponseID/>");
            soapMessage.Append("<Completed>1</Completed>");
            soapMessage.Append("<Priority>100</Priority>");
            soapMessage.Append("<ApplicationXML/>");
            soapMessage.Append("<ApplicationFiles/>");
            soapMessage.Append("<AttachXML/>");
            soapMessage.Append("<AttachFiles/>");
            soapMessage.Append("<XMLSubProcInfoFile/>");
            soapMessage.Append("<SignFilePath/>");
            soapMessage.Append("<CommentXML/>");
            soapMessage.Append("<VariablesXML/>");
            //soapMessage.Append("<VariablesXML>");
            //soapMessage.Append("<![CDATA[<?xml version='1.0' encoding='utf-8'?> <HWRECORDSET NAME=\"HWRelDataDefinitions\" RECORD=\"HWRELDATADEFINITION\" RECORDCOUNT=\"1\"> <HWRECBODY> <HWRELDATADEFINITION DIRTY=\"A\"> <SERVERID>0000001001</SERVERID> <PROCESSID>");
            //soapMessage.Append(configuration.processInfo.processId.ToString());
            //soapMessage.Append("</PROCESSID> <SEQUENCE>");
            //soapMessage.Append(configuration.processInfo.seqid.ToString()); 
            //soapMessage.Append("</SEQUENCE> <VALUETYPE>S</VALUETYPE> <NAME>ProcVar</NAME> <DISPLAYVALUE/> <DESCRIPTION/> <VALUE DIRTY=\"T\">Updated</VALUE> <EXISTDATAFILE>F</EXISTDATAFILE> </HWRELDATADEFINITION> </HWRECBODY> </HWRECORDSET> ]]>");
            //soapMessage.Append("</VariablesXML>");
            soapMessage.Append("<SQLParameters/>");
            soapMessage.Append("</BizCompleteWorkitem>");
            soapMessage.Append("</SOAP-ENV:Body>");
            soapMessage.Append("</SOAP-ENV:Envelope>");
            return soapMessage.ToString();

        }
        public static string getMyCompletedWorkitems(HttpSessionState session, ref BFConfiguration configuration)
        {
            if (configuration.currentPage <= 0) configuration.currentPage = 1;
            configuration.ItemLimit = 1000;

            PostSubmitter post = new PostSubmitter();
            StringBuilder postUrl = new StringBuilder(1024);

            postUrl.Append(ServiceCaller.serviceUrlRoot());
            postUrl.Append("bms/list/");
            postUrl.Append(BizCoveTypes.Monitor.ToString());
            postUrl.Append("/");
            postUrl.Append("1000043");   // Completed Processes 
            postUrl.Append(".xml?page=");
            if (configuration.currentPage > 0)
                postUrl.Append(configuration.currentPage.ToString());
            else
                postUrl.Append("1");

            postUrl.Append("&limit=");
            postUrl.Append(configuration.ItemLimit.ToString());


            post.Url = postUrl.ToString();
            post.strSessionKey = session.SessionID;

            post.cookieContainer = configuration.cookieContainer;

            string bizCoveDataString;

            bizCoveDataString = ServiceCaller.makeGET(post, session.SessionID, session, ref configuration);

            configuration.totalItems = Convert.ToInt16(xmlReader.getValueBySimpleQuery(bizCoveDataString, "total", "", false));

            if (configuration.totalItems == 0)
            {
                configuration.totalPages = 0;
            }

            if (!string.IsNullOrEmpty(bizCoveDataString))
            {
                configuration.completedData = CommonFunctions.getAllData(bizCoveDataString);
                
            }
            return bizCoveDataString;

        }
        private static string getWorkitemSoapMessage(BFConfiguration configuration)
        {
            StringBuilder soapMessage = new StringBuilder(4096);
            soapMessage.Append("<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.je.wf.bf.hs.com\">");
            soapMessage.Append("<soapenv:Header>");
            soapMessage.Append("<serviceConstructor xsi:type=\"ser:HWWorkitemServiceConstructor\" xmlns:ser=\"http://handysoft.com/webservice/ServiceConstructor\">");
            soapMessage.Append("<sessionInfoXML xsi:type=\"xsd:string\"><![CDATA[");
            soapMessage.Append(CommonFunctions.removeBackslashes(configuration.currentSession.sessionKey));
            soapMessage.Append("]]></sessionInfoXML>");
            soapMessage.Append("<serverId xsi:type=\"xsd:string\">");
            soapMessage.Append(configuration.processInfo.serverId);
            soapMessage.Append("</serverId>");
            soapMessage.Append("<processId xsi:type=\"xsd:int\">");
            soapMessage.Append(configuration.processInfo.processId.ToString());
            soapMessage.Append("</processId>");
            soapMessage.Append("<workitemSequence xsi:type=\"xsd:int\">");
            soapMessage.Append(configuration.processInfo.wiseq.ToString());
            soapMessage.Append("</workitemSequence>");
            soapMessage.Append("<archive xsi:type=\"xsd:boolean\">F</archive>");
            soapMessage.Append("</serviceConstructor>");
            soapMessage.Append("</soapenv:Header>");
            soapMessage.Append("<soapenv:Body>");
            soapMessage.Append("<ser:getWorkitem soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"/>");
            soapMessage.Append("</soapenv:Body>");
            soapMessage.Append("</soapenv:Envelope>");
            return soapMessage.ToString();

        }
        public static string getBizCoveHTMLData(HttpSessionState session, ref BFConfiguration configuration)
        {
            PostSubmitter post = new PostSubmitter();

            StringBuilder postUrl = new StringBuilder(4096);

            /*  Discarded 04/30/2014
            switch (configuration.BizCoveType)
            {
                case BFConfiguration.BizCoveTypes.Report:
                    postUrl.Append(BFActions_Report.getActionLink((int)configuration.BizCove, ref configuration));
                    break;
                case BFConfiguration.BizCoveTypes.ReportList:
                    postUrl.Append(BFActions_ReportList.getActionLink((int)configuration.BizCove, ref configuration));
                    break;
                case BFConfiguration.BizCoveTypes.ExternalReport:
                    postUrl.Append(BFActions_ExternalReport.getActionLink((int)configuration.BizCove, ref configuration));
                    break;
                case BFConfiguration.BizCoveTypes.UrlViewer:
                    postUrl.Append(BFActions_UrlViewer.getActionLink((int)configuration.BizCove, ref configuration));
                    break;
                default: return "";
            }

            */
            // On Test:

            return postUrl.ToString();

        }
        private static string completeWorkitemSoapMessage(BFConfiguration configuration)
        {

            StringBuilder soapMessage = new StringBuilder(4096);

            //JIRA NIE-226
            //soapMessage.Append("<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.je.wf.bf.hs.com\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">");
            soapMessage.Append("<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.je.wf.bf.hs.com\">");
            //JIRA
            
            soapMessage.Append("<soapenv:Header>");
            soapMessage.Append("<serviceConstructor xsi:type=\"ser:HWWorkitemServiceConstructor\" xmlns:ser=\"http://handysoft.com/webservice/ServiceConstructor\">");
            soapMessage.Append("<sessionInfoXML xsi:type=\"xsd:string\"><![CDATA[");
            soapMessage.Append(CommonFunctions.removeBackslashes(configuration.currentSession.sessionKey));
            soapMessage.Append("]]></sessionInfoXML>");
            soapMessage.Append("<serverId xsi:type=\"xsd:string\">");
            soapMessage.Append(configuration.processInfo.serverId);
            soapMessage.Append("</serverId>");
            soapMessage.Append("<processId xsi:type=\"xsd:int\">");
            soapMessage.Append(configuration.processInfo.processId.ToString());
            soapMessage.Append("</processId>");
            soapMessage.Append("<workitemSequence xsi:type=\"xsd:int\">");
            soapMessage.Append(configuration.processInfo.wiseq.ToString());
            soapMessage.Append("</workitemSequence>");

            //JIRA NIE-226
            //soapMessage.Append("<archive xsi:type=\"xsd:boolean\">T</archive>");
            soapMessage.Append("<archive xsi:type=\"xsd:boolean\">F</archive>");
            //JIRA 
            soapMessage.Append("</serviceConstructor>");
            soapMessage.Append("</soapenv:Header>");
            soapMessage.Append("<soapenv:Body>");
            soapMessage.Append("<ser:complete soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
            soapMessage.Append("<workitem xsi:type=\"elem:HWWorkitem\" xmlns:elem=\"http://element.je.wf.bf.hs.com\">");
            soapMessage.Append("<dirtyFlag xsi:type=\"xsd:string\">F</dirtyFlag>");

            // get from workitemdetails webservice call for the body of the message

            string response = ServiceCaller.getWorkitemDetails(configuration);

            string filtered_response = CommonFunctions.between(response, "<getWorkitemReturn", "</getWorkitemReturn>");
            soapMessage.Append(filtered_response);

            // end of gettting and appending workitem soap body

            soapMessage.Append("</workitem>");
            soapMessage.Append("<completeOption xsi:type=\"xsd:string\">C</completeOption>");
            //JIRA NIE-226
            //soapMessage.Append("<attachments xsi:type=\"biz:ArrayOf_HWAttachmentFile\" soapenc:arrayType=\"elem:HWAttachmentFile[]\" xmlns:biz=\"http://handysoft.com/webservice/BizFlowSchema\" xmlns:elem=\"http://element.service.je.wf.bf.hs.com\"/>");
            soapMessage.Append("<attachments xsi:type=\"hww:ArrayOf_tns3_HWAttachmentFile\" xmlns:hww=\"http://hwworkitem\" xmlns:elem=\"http://element.service.je.wf.bf.hs.com\"/>");
            soapMessage.Append("<applications xsi:type=\"hww:ArrayOf_tns3_HWApplicationFile\" xmlns:hww=\"http://hwworkitem\" xmlns:elem=\"http://element.service.je.wf.bf.hs.com\"/>");
            soapMessage.Append("<comments xsi:type=\"hww:ArrayOf_tns1_HWComment\" xmlns:hww=\"http://hwworkitem\" xmlns:elem=\"http://element.je.wf.bf.hs.com\"/>");
            ////JIRA 
            
            soapMessage.Append("</ser:complete>");
            soapMessage.Append("</soapenv:Body>");
            soapMessage.Append("</soapenv:Envelope>");
            return soapMessage.ToString();
        }
        //Qais Overload function
        public static int initiateWorkitem(BFConfiguration configuration, BFWorkFlowTypes workflowType, string param1, string param2, string param3, string param4, string param5, string param6)
        {

            return initiateWorkitem(configuration, 
                workflowType,
                param1, // fundingPlan.FPGMOMemberId,      
                param2, // fpUrl,
                null, 
                null,
                param3, // fundingPlan.FundingPlanName,
                param4, // fundingPlan.FPPlNotifyMemberId
                param5, 
                param6);
        }
        private static string SpecialsApplicationSoapMessage(BFConfiguration configuration, string param1, string param2, BFWorkFlowTypes workflowType, string param3, string param4, string param5, string param6, string param7, string param8)
        {
            StringBuilder soapMessage = new StringBuilder(4096);
            soapMessage.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:def=\"http://DefaultNamespace\">");
            soapMessage.Append("<soapenv:Header/>");
            soapMessage.Append("<soapenv:Body>");
            soapMessage.Append("<def:Start>");
            soapMessage.Append("<def:ExtLink>");
            soapMessage.Append(param2);
            soapMessage.Append("</def:ExtLink>");

            if (workflowType == BFWorkFlowTypes.FundingPlan)
            {
                soapMessage.Append("<def:GMOUser>");
                soapMessage.Append(param1);
                soapMessage.Append("</def:GMOUser>");
                soapMessage.Append("<def:Title>");
                soapMessage.Append(param5); // param3 to param5 
                soapMessage.Append("</def:Title>");
                soapMessage.Append("<def:PlNotifyUser>");
                soapMessage.Append(param6); // param4 to param6
                soapMessage.Append("</def:PlNotifyUser>");
            }
            else
            {
                soapMessage.Append("<def:ProgramOfficers>");
                soapMessage.Append(param1);
                soapMessage.Append("</def:ProgramOfficers>");
                soapMessage.Append("<def:ProjectNumber>");
                soapMessage.Append(param5);
                soapMessage.Append("</def:ProjectNumber>");
                if (!string.IsNullOrEmpty(param6))
                {
                    soapMessage.Append("<def:SpecialType>");
                    soapMessage.Append(param6);
                    soapMessage.Append("</def:SpecialType>");
                }
                soapMessage.Append("<def:PIName>");
                soapMessage.Append(param7.TrimEnd());
                soapMessage.Append("</def:PIName>");
                soapMessage.Append("<def:Council>");
                soapMessage.Append(param8);
                soapMessage.Append("</def:Council>");

            }
            soapMessage.Append("</def:Start>");
            soapMessage.Append("</soapenv:Body>");
            soapMessage.Append("</soapenv:Envelope>");
            return soapMessage.ToString();

        }
        public static int initiateWorkitem(BFConfiguration configuration, BFWorkFlowTypes workflowType, string param1, string param2, string param3, string param4,string param5, string param6, string param7, string param8)
        {

            var _url = ""; 
            var _action = "" ;  // ServiceCaller.serviceUrlRoot() + "webservice/HWActivity";

            switch (workflowType)
            {
                case BFWorkFlowTypes.SpecialsApplication:
                    _url = ServiceCaller.serviceUrlRoot() + "data/webservice/SpecialsApplication.hws";
                    _action = "SpecialsApplicationService";
                    break;
                case BFWorkFlowTypes.AddedApplication:
                    _url = ServiceCaller.serviceUrlRoot() + "data/webservice/AddedApplication.hws";
                    _action = "AddedApplicationService";
                    break;
                case BFWorkFlowTypes.FundingPlan:
                    _url = ServiceCaller.serviceUrlRoot() + "data/webservice/FundingPlan.hws";
                    _action = "FundingPlansService";
                    break;
            }

            // DEBUG - Check that for Funding Plan Creation these are correct
            var message = String.Format("GMOUser: {0}, Title: {1}, PlNotifyUser: {2}", param1, param5, param6);

            string soapXml = SpecialsApplicationSoapMessage(configuration, param1, param2, workflowType, param3, param4, param5, param6, param7, param8);

            XmlDocument soapEnvelopeXml = CreateSoapEnvelope(configuration, soapXml);
            HttpWebRequest webRequest = CreateWebRequest(_url, _action);
            InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

            IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
            asyncResult.AsyncWaitHandle.WaitOne();
            string soapResult;
            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
            {
                using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                {
                    soapResult = rd.ReadToEnd();
                }
            }

            return Convert.ToInt32(CommonFunctions.between(soapResult, "<StartReturn xsi:type=\"xsd:int\">", "</StartReturn>"));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            
            
            var serverRoot = BFServiceConfiguration.ServiceRoot;

            BFConfiguration configuration = new BFConfiguration();
            CurrentUser user = new CurrentUser();
            user.ipAddress = "192.168.1.165"; //CommonFunctions.getIP(this.Request);
            //user.id = ;
            //user.sid = "S-1-5-21-981513146-3610399622-1152084407-1010";
            user.sid = "S-1-5-21-3062783291-1561283076-1759620232-3763";
            user.loginName = "ranwar";
            user.userAgent = this.Request.UserAgent;

            configuration.currentUser = user;

            CurrentSession session = new CurrentSession();
            session.sessionKey = "";
            configuration.currentSession = session;
            configuration.ItemLimit = 1000;

            Response.Write("<h1 style='bottom:5px'>BizFlow Web Service Tester</h1>");
            Response.Write(string.Format("<h2 style='bottom:10px'>Result: <Label ID='lbResult'>{0}</Label></h2>", serverRoot));

            try
            {
                CurrentSession result = ServiceCaller.login(session.sessionKey, this.Session, configuration);
                Response.Write(string.Format("<br/><h2 style='color:blue; bottom:100px;'>Session Information Success</h2>"));
            }
            catch (Exception ex)
            {
                Response.Write(string.Format("<br/><h2 style='color:red; bottom:100px;'>There was an error {0} and inner exception {1} </h2>", ex.Message, ex.InnerException));
                throw ex;
            }
            finally
            {
                Response.Write("<br/><h3 style='bottom:50px;'>Test Complete</h3>");

            }
                
                


            //ServiceCaller.login_117(configuration);
            //int retVal = ServiceCaller.initiateWorkitem(configuration, BFWorkFlowTypes.SpecialsApplication, "[U]0000000102", "http://www.microsoft.com");
            //ServiceCaller.getBizCoveData(this.Session, ref configuration);

            //configuration.currentProcessID = 304;

            //ServiceCaller.completeWorkitem(configuration, 299);
            //ServiceCaller.getMyCompletedWorkitems(this.Session, ref configuration);

            //string procDetails = ServiceCaller.getWorkitemDetails(configuration);


            // In order to get all completed processes from all users
            //  SELECT [procid],[name] FROM [workflow].[dbo].[PROCS] WHERE [State]='C'
            //  AND [procid] in (SELECT [ProcessId] from [DERTFundingDecisions].[dbo].[SpecialRequestWorkflow]) 


        }
        public static bool loginWithSessionKey(string strSessionKey, BFConfiguration configuration)
        {
            PostSubmitter post = new PostSubmitter();
            post.Url = ServiceCaller.serviceUrlRoot() + "bms/auth/sessionkey.xml";
            post.PostItems.Add("sessionKey", strSessionKey);
            post.strSessionKey = strSessionKey;

            string BFSessionKey;

            //BFSessionKey = xmlReader.getScalarValue(ServiceCaller.makeCall(post), "/");

            BFSessionKey = ServiceCaller.makePOST(post);

            return true;
        }