private string parseXML(string toParse, callType reason)
        {
            string parsedData = null;

            //Parse gateway reponse for OTK
            using (XmlTextReader xmlReader = new XmlTextReader(new StringReader(toParse)))
            {
                while (xmlReader.Read())
                {
                    while (xmlReader.ReadToFollowing("ResponseCode"))
                    {
                        string responseCode = xmlReader.ReadElementContentAsString();

                        if (reason == callType.otk)
                        {
                            if (responseCode == "100")
                            {
                                while (xmlReader.ReadToFollowing("OTK"))
                                {
                                    parsedData = xmlReader.ReadElementContentAsString();
                                }
                            }
                        }
                        else
                        {
                            parsedData = responseCode;
                        }
                    }
                }

                xmlReader.Close();

                return(parsedData);
            }
        }
        private string parseAlias(string toParse, callType reason)
        {
            string parsedData = null;

            //parse Gateway for Alias
            using (XmlTextReader xmlReader = new XmlTextReader(new StringReader(toParse)))
            {
                while (xmlReader.Read())
                {
                    while (xmlReader.ReadToFollowing("ResponseCode"))
                    {
                        string responseCode = xmlReader.ReadElementContentAsString();

                        if (reason == callType.result)
                        {
                            if (responseCode == "005")
                            {
                                while (xmlReader.ReadToFollowing("Alias"))
                                {
                                    parsedData = xmlReader.ReadElementContentAsString();
                                }
                            }
                        }
                        else
                        {
                            parsedData = responseCode;
                        }
                    }
                }
                xmlReader.Close();

                return(parsedData);
            }
        }
        private void fireEventInFireEventThread(callType ct, MulticastDelegate ev, params object[] parameter)
        {
            if (ev == null)
            {
                return;             //return if Multicast-delegate has no content
            }
            //if (Thread.CurrentThread != EvaluationThread) return; //Do not call while Initialization

            _internalMessage msg =
                new _internalMessage()
            {
                pleaseCall = ev,
                calltype   = ct,
                parameters = parameter
            };

            lock (_internalMessageQueue)
            {
                while (_internalMessageQueue.Count >= MaximumMessageInQueue)
                {
                    _internalMessageQueue.Dequeue();
                }
                _internalMessageQueue.Enqueue(msg);
            }

            fireEventsFlag.Set();
        }
Esempio n. 4
0
 public void RegistChangeCamera(string changeName, callType callback)
 {
     if (string.IsNullOrEmpty(isChanging))     // 没有在改变摄像机
     {
         if (changeName == currentCamera.name) // 现在就是要的摄像机
         {
             callback(currentCamera);          // 直接执行
         }
         else if (ChangeCamera(changeName))    // 如果成功执行切换摄像机
         {
             afterChangeCamera += callback;    // 进行注册
         }
     }
     else                                      // 正在改变摄像机
     {
         if (changeName == isChanging)         // 是改变成想要的摄像机
         {
             afterChangeCamera += callback;    // 追加注册
         }
         else                                  // 不是改变成想要的摄像机
         {
             return;                           // 拒绝这次注册
         }
     }
 }
Esempio n. 5
0
 public void UnRegistChangeCamera(callType callback)
 {
     if (afterChangeCamera != null)
     {
         afterChangeCamera -= callback;
     }
 }
Esempio n. 6
0
 internal void RunTask(object task, callType taskType)
 {
     this.domainUnload.Type = fastCSharp.domainUnload.unloadType.None;
     this.onErrorType       = errorType.None;
     this.task.Set(task, taskType);
     waitHandle.Set();
 }
Esempio n. 7
0
 internal void RunTask(object task, object onError, object domainUnload, callType taskType, errorType onErrorType, domainUnload.unloadType domainUnloadType)
 {
     this.domainUnload.Set(domainUnload, domainUnloadType);
     this.onError     = onError;
     this.onErrorType = onErrorType;
     this.task.Set(task, taskType);
     waitHandle.Set();
 }
Esempio n. 8
0
 /// <summary>
 /// 线程池线程
 /// </summary>
 /// <param name="threadPool">线程池</param>
 /// <param name="stackSize">堆栈大小</param>
 /// <param name="task">任务委托</param>
 /// <param name="taskType">任务委托调用类型</param>
 internal thread(threadPool threadPool, int stackSize, object task, callType taskType)
 {
     this.task.Set(task, taskType);
     this.domainUnload.Type    = fastCSharp.domainUnload.unloadType.None;
     this.onErrorType          = errorType.None;
     waitHandle                = new autoWaitHandle(false);
     this.threadPool           = threadPool;
     threadHandle              = new Thread(run, stackSize);
     threadHandle.IsBackground = true;
     threadIndex               = threads.Push(threadHandle);
     threadHandle.Start();
 }
        private string generateRequest(callType reason)
        {
            string request;

            //Create StringBuilder for OTK request to gateway
            StringBuilder sbRequest = new StringBuilder();

            //Create new instance of XML settings, set indent
            XmlWriterSettings ws = new XmlWriterSettings();

            ws.Indent = true;

            //Create OTK request, generates XML request
            using (XmlWriter xmlWriter = XmlWriter.Create(sbRequest, ws))
            {
                //Start XML writer
                xmlWriter.WriteStartDocument();
                //StartRoot element
                xmlWriter.WriteStartElement("GatewayRequest");

                //Start XWeb credentials
                xmlWriter.WriteStartElement("XWebID");
                xmlWriter.WriteString("800000001377");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("TerminalID");
                xmlWriter.WriteString("80021450");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("AuthKey");
                xmlWriter.WriteString("swUleKfQRuEm6VACYvYkyIuyXQC7jZDv");
                xmlWriter.WriteEndElement();
                //End XWeb credentials

                xmlWriter.WriteStartElement("Industry");
                xmlWriter.WriteString("RETAIL");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("SpecVersion");
                xmlWriter.WriteString("XWebSecure3.4");
                xmlWriter.WriteEndElement();

                if (reason == callType.otk)
                {
                    xmlWriter.WriteStartElement("TransactionType");
                    xmlWriter.WriteString("AliasCreateTransaction");
                    xmlWriter.WriteEndElement();
                }
                else
                {
                    xmlWriter.WriteStartElement("OTK");
                    xmlWriter.WriteString(otk);
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("ResponseMode");
                    xmlWriter.WriteString("POLL");
                    xmlWriter.WriteEndElement();
                }

                //End root element
                xmlWriter.WriteEndElement();
                //End XML writer
                xmlWriter.WriteEndDocument();
            }
            request = sbRequest.ToString();

            return(request);
        }
        /// <summary>
        /// Used to execute the search request
        /// </summary>
        /// <param name="method">HTTP method</param>
        /// <param name="requestUrl">URL to request</param>
        /// <param name="content">The content</param>
        /// <returns></returns>
        public async Task <JObject> ExecuteRequest(callType type, string method, string requestUrl, object content, CancellationToken token)
        {
            string[]   hosts  = null;
            HttpClient client = null;

            if (type == callType.Write)
            {
                hosts  = _writeHosts;
                client = _buildHttpClient;
            }
            else
            {
                hosts = _readHosts;
                if (type == callType.Read)
                {
                    client = _buildHttpClient;
                }
                else
                {
                    client = _searchHttpClient;
                }
            }

            Dictionary <string, string> errors = new Dictionary <string, string>();

            foreach (string host in hosts)
            {
                try
                {
                    try
                    {
                        string url = string.Format("https://{0}{1}", host, requestUrl);
                        HttpResponseMessage responseMsg = null;
                        switch (method)
                        {
                        case "GET":
                            responseMsg = await client.GetAsync(url, token).ConfigureAwait(_continueOnCapturedContext);

                            break;

                        case "POST":
                            HttpContent postcontent = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(content));
                            responseMsg = await client.PostAsync(url, postcontent, token).ConfigureAwait(_continueOnCapturedContext);

                            break;

                        case "PUT":
                            HttpContent putContent = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(content));
                            responseMsg = await client.PutAsync(url, putContent, token).ConfigureAwait(_continueOnCapturedContext);

                            break;

                        case "DELETE":
                            responseMsg = await client.DeleteAsync(url, token).ConfigureAwait(_continueOnCapturedContext);

                            break;
                        }
                        if (responseMsg.IsSuccessStatusCode)
                        {
                            string serializedJSON = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(_continueOnCapturedContext);

                            JObject obj = JObject.Parse(serializedJSON);
                            return(obj);
                        }
                        else
                        {
                            string serializedJSON = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(_continueOnCapturedContext);

                            string message = "Internal Error";
                            string status  = "0";
                            try
                            {
                                JObject obj = JObject.Parse(serializedJSON);
                                message = obj["message"].ToString();
                                status  = obj["status"].ToString();
                                if (obj["status"].ToObject <int>() / 100 == 4)
                                {
                                    throw new AlgoliaException(message);
                                }
                            }
                            catch (JsonReaderException)
                            {
                                message = responseMsg.ReasonPhrase;
                                status  = "0";
                            }

                            errors.Add(host + '(' + status + ')', message);
                        }
                    }
                    catch (AlgoliaException)
                    {
                        throw;
                    }
                    catch (TaskCanceledException e)
                    {
                        if (token.IsCancellationRequested)
                        {
                            throw e;
                        }
                        errors.Add(host, "Timeout expired");
                    }
                    catch (Exception ex)
                    {
                        errors.Add(host, ex.Message);
                    }
                }
                catch (AlgoliaException)
                {
                    throw;
                }
            }
            throw new AlgoliaException("Hosts unreachable: " + string.Join(", ", errors.Select(x => x.Key + "=" + x.Value).ToArray()));
        }
        private string generateRequest(callType reason)
        {
            string request;

            //Create StringBuilder for OTK request to gateway
            StringBuilder sbRequest = new StringBuilder();

            //Create new instance of XML settings, set indent
            XmlWriterSettings ws = new XmlWriterSettings();

            ws.Indent = true;

            //Create OTK request, generates XML request
            using (XmlWriter xmlWriter = XmlWriter.Create(sbRequest, ws))
            {
                //Start XML writer
                xmlWriter.WriteStartDocument();
                //StartRoot element
                xmlWriter.WriteStartElement("GatewayRequest");

                //Start XWeb credentials
                xmlWriter.WriteStartElement("XWebID");
                xmlWriter.WriteString("800000001828");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("TerminalID");
                xmlWriter.WriteString("80022604");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("AuthKey");
                xmlWriter.WriteString("OPSiIZQlZTiNulWIGyGbC6pphpEfKD8N");
                xmlWriter.WriteEndElement();
                //End XWeb credentials

                xmlWriter.WriteStartElement("Industry");
                xmlWriter.WriteString("RETAIL");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("SpecVersion");
                xmlWriter.WriteString("XWebSecure3.4");
                xmlWriter.WriteEndElement();

                if (reason == callType.otk)
                {
                    xmlWriter.WriteStartElement("TransactionType");
                    xmlWriter.WriteString("CreditSaleTransaction");
                    xmlWriter.WriteEndElement();

                    //Flags Transaction to return Alias.
                    xmlWriter.WriteStartElement("CreateAlias");
                    xmlWriter.WriteString("TRUE");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("DuplicateMode");
                    xmlWriter.WriteString("CHECKING_OFF");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("Amount");
                    xmlWriter.WriteString("1.00");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("AmountLocked");
                    xmlWriter.WriteString("TRUE");
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("ShowReceipt");
                    xmlWriter.WriteString("TRUE");
                    xmlWriter.WriteEndElement();
                }
                else
                {
                    xmlWriter.WriteStartElement("OTK");
                    xmlWriter.WriteString(otk);
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("ResponseMode");
                    xmlWriter.WriteString("POLL");
                    xmlWriter.WriteEndElement();
                }

                //End root element
                xmlWriter.WriteEndElement();
                //End XML writer
                xmlWriter.WriteEndDocument();
            }
            request = sbRequest.ToString();

            return(request);
        }
        /// <summary>
        /// Used to execute the search request
        /// </summary>
        /// <param name="method">HTTP method</param>
        /// <param name="requestUrl">URL to request</param>
        /// <param name="content">The content</param>
        /// <returns></returns>
        public async Task<JObject> ExecuteRequest(callType type, string method, string requestUrl, object content = null)
        {
            string[] hosts = null;
            HttpClient client = null;
            if (type == callType.Write)
            {
                hosts = _writeHosts;
                client = _buildHttpClient;
            }
            else
            {
                hosts = _readHosts;
                if (type == callType.Read)
                {
                    client = _buildHttpClient;
                }
                else
                {
                    client = _searchHttpClient;
                }
            }

            Dictionary<string, string> errors = new Dictionary<string, string>();
            foreach (string host in hosts)
            {
                try
                {
                    try
                    {
                        string url = string.Format("https://{0}{1}", host, requestUrl);
                        HttpResponseMessage responseMsg = null;
                        switch (method)
                        {
                            case "GET":
                                responseMsg = await client.GetAsync(url).ConfigureAwait(_continueOnCapturedContext);
                                break;
                            case "POST":
                                HttpContent postcontent = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(content));
                                responseMsg = await client.PostAsync(url, postcontent).ConfigureAwait(_continueOnCapturedContext);
                                break;
                            case "PUT":
                                HttpContent putContent = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(content));
                                responseMsg = await client.PutAsync(url, putContent).ConfigureAwait(_continueOnCapturedContext);
                                break;
                            case "DELETE":
                                responseMsg = await client.DeleteAsync(url).ConfigureAwait(_continueOnCapturedContext);
                                break;
                        }
                        if (responseMsg.IsSuccessStatusCode)
                        {
                            string serializedJSON = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(_continueOnCapturedContext);
                            JObject obj = JObject.Parse(serializedJSON);
                            return obj;
                        }
                        else
                        {
                            string serializedJSON = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(_continueOnCapturedContext);
                            string message = "Internal Error";
                            string status = "0";
                            try
                            {
                                JObject obj = JObject.Parse(serializedJSON);
                                message = obj["message"].ToString();
                                status = obj["status"].ToString();
                                if (obj["status"].ToObject<int>() / 100 == 4)
                                {
                                    throw new AlgoliaException(message);
                                }
                            }
                            catch (JsonReaderException)
                            {
                                message = responseMsg.ReasonPhrase;
                                status = "0";
                            }
                            
                            errors.Add(host + '(' + status + ')', message);
                        }
                    }
                    catch (AlgoliaException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        errors.Add(host, ex.Message);
                    }

                }
                catch (AlgoliaException)
                {
                    throw;
                }

            }
            throw new AlgoliaException("Hosts unreachable: " + string.Join(", ", errors.Select(x => x.Key + "=" + x.Value).ToArray()));
        }
Esempio n. 13
0
 /// <summary>
 /// 线程池线程
 /// </summary>
 /// <param name="threadPool">线程池</param>
 /// <param name="stackSize">堆栈大小</param>
 /// <param name="task">任务委托</param>
 /// <param name="domainUnload">应用程序退出处理</param>
 /// <param name="onError">应用程序退出处理</param>
 /// <param name="taskType">任务委托调用类型</param>
 /// <param name="domainUnloadType">应用程序退出处理调用类型</param>
 /// <param name="onErrorType">应用程序退出处理调用类型</param>
 internal thread(threadPool threadPool, int stackSize, object task, object onError, object domainUnload, callType taskType, errorType onErrorType, domainUnload.unloadType domainUnloadType)
 {
     this.task.Set(task, taskType);
     this.domainUnload.Set(domainUnload, domainUnloadType);
     this.onError              = onError;
     this.onErrorType          = onErrorType;
     waitHandle                = new autoWaitHandle(false);
     this.threadPool           = threadPool;
     threadHandle              = new Thread(run, stackSize);
     threadHandle.IsBackground = true;
     threadIndex               = threads.Push(threadHandle);
     threadHandle.Start();
 }
Esempio n. 14
0
 /// <summary>
 /// 调用信息
 /// </summary>
 /// <param name="value"></param>
 /// <param name="type"></param>
 public void Set(object value, callType type)
 {
     Value = value;
     Type  = type;
 }
Esempio n. 15
0
        private string generateRequest(callType reason)
        {
            string request;

            //Create StringBuilder for OTK request to gateway
            StringBuilder sbRequest = new StringBuilder();

            //Create new instance of XML settings, set indent
            XmlWriterSettings ws = new XmlWriterSettings();

            ws.Indent = true;

            //Create OTK request, generates XML request
            using (XmlWriter xmlWriter = XmlWriter.Create(sbRequest, ws))
            {
                //Start XML writer
                xmlWriter.WriteStartDocument();
                //StartRoot element
                xmlWriter.WriteStartElement("GatewayRequest");

                //Start XWeb credentials
                xmlWriter.WriteStartElement("XWebID");
                xmlWriter.WriteString("800000001844");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("TerminalID");
                xmlWriter.WriteString("80022690");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("AuthKey");
                xmlWriter.WriteString("XisLfXu2QVDYuBSt4k4r9go7ZELxRlie");
                xmlWriter.WriteEndElement();
                //End XWeb credentials



                xmlWriter.WriteStartElement("SpecVersion");
                xmlWriter.WriteString("XWebSecure3.5");
                xmlWriter.WriteEndElement();

                if (reason == callType.otk)
                {
                    xmlWriter.WriteStartElement("TransactionType");
                    xmlWriter.WriteString("CheckAliasCreateTransaction");
                    xmlWriter.WriteEndElement();
                }
                else
                {
                    xmlWriter.WriteStartElement("OTK");
                    xmlWriter.WriteString(otk);
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("ResponseMode");
                    xmlWriter.WriteString("POLL");
                    xmlWriter.WriteEndElement();
                }

                //End root element
                xmlWriter.WriteEndElement();
                //End XML writer
                xmlWriter.WriteEndDocument();
            }
            request = sbRequest.ToString();

            return(request);
        }
Esempio n. 16
0
        private string generateRequest(callType reason, TranType type)
        {
            string request;

            //Create StringBuilder for OTK request to gateway
            StringBuilder sbRequest = new StringBuilder();

            //Create new instance of XML settings, set indent
            XmlWriterSettings ws = new XmlWriterSettings();

            ws.Indent = true;

            //Create OTK request, generates XML request
            using (XmlWriter xmlWriter = XmlWriter.Create(sbRequest, ws))
            {
                //Start XML writer
                xmlWriter.WriteStartDocument();
                //StartRoot element
                xmlWriter.WriteStartElement("GatewayRequest");

                //Check for Custom Creds
                if (useCustomCreds == false)
                {
                    // Standard XWeb Creds
                    if (type == TranType.CreditSale || type == TranType.CreditReturn || type == TranType.AliasCreate)
                    {
                        //Start XWeb credentials
                        xmlWriter.WriteStartElement("XWebID");
                        xmlWriter.WriteString("800000001844");
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("TerminalID");
                        xmlWriter.WriteString("80023342");
                        xmlWriter.WriteEndElement();

                        //
                        xmlWriter.WriteStartElement("AuthKey");
                        xmlWriter.WriteString("Qqkg3Pv1F0hNzG0qfs7CZugoBBcUPgUV");
                        xmlWriter.WriteEndElement();
                        //End XWeb credentials

                        xmlWriter.WriteStartElement("Industry");
                        xmlWriter.WriteString("RETAIL");
                        xmlWriter.WriteEndElement();
                    }
                    //Credit EMV Creds (PG)
                    if (type == TranType.CreditEMV || type == TranType.CreditEMVReturn)
                    {
                        //Start XWeb credentials
                        xmlWriter.WriteStartElement("XWebID");
                        xmlWriter.WriteString("800000001694");
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("TerminalID");
                        xmlWriter.WriteString("80022125");
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("AuthKey");
                        xmlWriter.WriteString("t6Gr99v6eo8xfLFSzYieujuPLkkDfbHI");
                        xmlWriter.WriteEndElement();
                        //End XWeb credentials

                        xmlWriter.WriteStartElement("Industry");
                        xmlWriter.WriteString("RETAIL");
                        xmlWriter.WriteEndElement();
                    }
                    //Debit EMV Creds (PG)
                    if (type == TranType.DebitSale || type == TranType.DebitReturn)
                    {
                        //Start XWeb credentials
                        xmlWriter.WriteStartElement("XWebID");
                        xmlWriter.WriteString("800000001694");
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("TerminalID");
                        xmlWriter.WriteString("80022120");
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("AuthKey");
                        xmlWriter.WriteString("NAFV4pikCkOydaS2SXZbArEdcc2xXlkj");
                        xmlWriter.WriteEndElement();
                        //End XWeb credentials

                        xmlWriter.WriteStartElement("Industry");
                        xmlWriter.WriteString("RETAIL");
                        xmlWriter.WriteEndElement();
                    }
                    //Check Creds
                    if (type == TranType.CheckAlias || type == TranType.CheckSale || type == TranType.CheckCredit)
                    {
                        //Start XWeb credentials
                        xmlWriter.WriteStartElement("XWebID");
                        xmlWriter.WriteString("800000001844");
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("TerminalID");
                        xmlWriter.WriteString("80022690");
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("AuthKey");
                        xmlWriter.WriteString("XisLfXu2QVDYuBSt4k4r9go7ZELxRlie");
                        xmlWriter.WriteEndElement();
                        //End XWeb credentials
                    }
                }
                //Use Custom Creds
                if (useCustomCreds == true)
                {
                    xmlWriter.WriteStartElement("XWebID");
                    xmlWriter.WriteString(xWebIDCustom);
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("TerminalID");
                    xmlWriter.WriteString(terminalIDCustom);
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("AuthKey");
                    xmlWriter.WriteString(authKeyCustom);
                    xmlWriter.WriteEndElement();

                    if (industryCustom != null || industryCustom != "")
                    {
                        xmlWriter.WriteStartElement("Industry");
                        xmlWriter.WriteString(industryCustom);
                        xmlWriter.WriteEndElement();
                    }
                }

                xmlWriter.WriteStartElement("SpecVersion");
                xmlWriter.WriteString("XWebSecure3.5");
                xmlWriter.WriteEndElement();

                //Transaction Type Writer
                if (reason == callType.otk)
                {
                    if (type == TranType.CreditSale || type == TranType.CreditEMV)
                    {
                        xmlWriter.WriteStartElement("TransactionType");
                        xmlWriter.WriteString("CreditSaleTransaction");
                        xmlWriter.WriteEndElement();
                    }

                    if (type == TranType.CreditReturn || type == TranType.CreditEMVReturn)
                    {
                        xmlWriter.WriteStartElement("TransactionType");
                        xmlWriter.WriteString("CreditReturnTransaction");
                        xmlWriter.WriteEndElement();
                    }

                    if (type == TranType.DebitSale)
                    {
                        xmlWriter.WriteStartElement("TransactionType");
                        xmlWriter.WriteString("DebitSaleTransaction");
                        xmlWriter.WriteEndElement();
                    }

                    if (type == TranType.DebitReturn)
                    {
                        xmlWriter.WriteStartElement("TransactionType");
                        xmlWriter.WriteString("DebitReturnTransaction");
                        xmlWriter.WriteEndElement();
                    }
                    if (type == TranType.AliasCreate)
                    {
                        xmlWriter.WriteStartElement("TransactionType");
                        xmlWriter.WriteString("AliasCreateTransaction");
                        xmlWriter.WriteEndElement();
                    }
                    if (type == TranType.CheckSale)
                    {
                        xmlWriter.WriteStartElement("TransactionType");
                        xmlWriter.WriteString("CheckSaleTransaction");
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("EntryClass");
                        xmlWriter.WriteString("WEB");
                        xmlWriter.WriteEndElement();
                    }
                    if (type == TranType.CheckCredit)
                    {
                        xmlWriter.WriteStartElement("TransactionType");
                        xmlWriter.WriteString("CheckCreditTransaction");
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("EntryClass");
                        xmlWriter.WriteString("PPD");
                        xmlWriter.WriteEndElement();
                    }
                    if (type == TranType.CheckAlias)
                    {
                        xmlWriter.WriteStartElement("TransactionType");
                        xmlWriter.WriteString("CheckAliasCreateTransaction");
                        xmlWriter.WriteEndElement();
                    }

                    //Flag to Create Alias for Transactiosn that Support CreateAlias = TRUE
                    if (type != TranType.AliasCreate && type != TranType.DebitSale && type != TranType.DebitReturn && type != TranType.CheckAlias)
                    {
                        if (type != TranType.CheckCredit && type != TranType.CheckSale)
                        {
                            //Flags Transaction to return Alias.
                            xmlWriter.WriteStartElement("CreateAlias");
                            xmlWriter.WriteString("TRUE");
                            xmlWriter.WriteEndElement();

                            xmlWriter.WriteStartElement("DuplicateMode");
                            xmlWriter.WriteString("CHECKING_OFF");
                            xmlWriter.WriteEndElement();

                            /*
                             * xmlWriter.WriteStartElement("ShowReceipt");
                             * xmlWriter.WriteString("TRUE");
                             * xmlWriter.WriteEndElement();
                             */
                        }

                        xmlWriter.WriteStartElement("Amount");
                        xmlWriter.WriteString(".01");
                        xmlWriter.WriteEndElement();

                        xmlWriter.WriteStartElement("AmountLocked");
                        xmlWriter.WriteString("TRUE");
                        xmlWriter.WriteEndElement();
                    }
                }

                //Results call Writer
                if (type == TranType.ResultsCall)
                {
                    xmlWriter.WriteStartElement("XWebID");
                    xmlWriter.WriteString(currentXWebID);
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("TerminalID");
                    xmlWriter.WriteString(currentTerminalID);
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("AuthKey");
                    xmlWriter.WriteString(currentAuthKey);
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("OTK");
                    xmlWriter.WriteString(otk);
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("ResponseMode");
                    xmlWriter.WriteString("POLL");
                    xmlWriter.WriteEndElement();
                }

                // Else if for not
                else
                {
                }
                //End root element
                xmlWriter.WriteEndElement();
                //End XML writer
                xmlWriter.WriteEndDocument();
            }
            request = sbRequest.ToString();

            return(request);
        }