public override Result Dispense(string TicketNo, string BarPosNo, int Amount)
        {
            Result res = new Result();

            //Implement glory dispenser interface
            try
            {
                _RequestAmount = Amount;
                _TicketNo      = TicketNo;
                DateTime PrintDate = DateTime.Now;

                _ValidationNo         = "#" + BarPosNo + DateTime.Now.ToString("ddMMyyyyHHmmss");
                _cOut                 = new CGDBSCCashoutDetail();
                _cOut.ValidationNo    = _ValidationNo; //ticket no
                _cOut.Amount          = Amount;        //in Cents
                _cOut.AssetNo         = BarPosNo;
                res.IsSuccess         = true;
                res.error             = new Error();
                res.error.MessageType = MessageType.Information.ToString();

                LogManager.WriteLog("Copying Glory Server Details from Registry" + UserInformation.User, LogManager.enumLogLevel.Info);
                IDictionary <string, string> dicGloryCDDetails = CommonDataAccess.GetGloryServerDetails();
                if (dicGloryCDDetails == null || dicGloryCDDetails.Count == 0)
                {
                    LogManager.WriteLog("Unable to find Glory Server Details from Registry" + UserInformation.User, LogManager.enumLogLevel.Info);
                    res.IsSuccess         = false;
                    res.error.Message     = "Unable to find Glory Server Details";
                    res.error.MessageType = MessageType.Error.ToString();
                    this.OnFinished(res);
                }
                else
                {
                    GloryDeviceHelper._ServerName = dicGloryCDDetails["ServerName"];
                    GloryDeviceHelper._ServerPort = Convert.ToInt32(dicGloryCDDetails["PortNo"]);

                    UserInformation.User   = dicGloryCDDetails["UserName"];
                    UserInformation.Device = dicGloryCDDetails["DeviceName"];

                    UserInformation.Password = CommonDataAccess.GetGloryServerPassword();

                    UserInformation.ID     = "BMC";
                    GloryDeviceHelper._SSL = dicGloryCDDetails["SSL"].ToUpper().Equals("TRUE") ? true : false;


                    //Finding Mode Of Glory CashDispenser is Duplex or Non Duplex
                    string strDispenserType = "";
                    try
                    {
                        strDispenserType = ConfigManager.GetConfigurationObject().Read("CD_Duplex");
                    }
                    catch (Exception ex)
                    {
                        LogManager.WriteLog(DispenserType + " Mode not found. Choosing default type-'DUPLEX MODE'", LogManager.enumLogLevel.Info);
                        strDispenserType = "TRUE";
                    }

                    bool IsNotDuplex = strDispenserType.ToUpper().Equals("TRUE") ? false : true;
                    //Finding SSL Mode Of Glory CashDispenser
                    //try
                    //{
                    //    GloryDeviceHelper._SSL = ConfigManager.GetConfigurationObject().Read("GLORYCD_SSL").ToUpper().Equals("TRUE") ? true : false;
                    //    // GloryDeviceHelper._SSL = dicGloryCDDetails["SSL"].ToUpper().Equals("TRUE") ? true : false;
                    //}
                    //catch (Exception ex)
                    //{
                    //    LogManager.WriteLog(DispenserType + " SSL configuration not found. Choosing default type SSL-'false'", LogManager.enumLogLevel.Info);
                    //    GloryDeviceHelper._SSL = false;
                    //}

                    GloryDeviceHelper._CertificateThumbprint = String.Empty;

                    //Open Session
                    OnStatusChanged("Opening Session...");
                    _SYS_CODE sOpen = doOpenSession();
                    if (sOpen == _SYS_CODE.SYS_SUCCESS)
                    {
                        AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                        {
                            AuditModuleName    = _cType,
                            Audit_Screen_Name  = _cType + "|Open Session",
                            Audit_Desc         = "Open Session Succeed ; Session ID:" + UserInformation.SessionID + "; StartTime:" + DateTime.Now.GetUniversalDateTimeFormat(),
                            AuditOperationType = OperationType.ADD,
                            Audit_Field        = "Session ID"
                        });
                        OnStatusChanged("Session Opened Successfully");
                        AuditOpenSessionGloryDetails();
                        LogManager.WriteLog(DispenserType + "User:"******"Occupying Device...");
                        _SYS_CODE sOcc = doOccupy();
                        if (sOcc == _SYS_CODE.SYS_SUCCESS)
                        {
                            AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                            {
                                AuditModuleName    = _cType,
                                Audit_Screen_Name  = _cType + "|Occupy",
                                Audit_Desc         = "Occupy Succeed ; Device Name:" + UserInformation.Device,
                                AuditOperationType = OperationType.ADD,
                                Audit_Field        = "Device Name"
                            });
                            OnStatusChanged("Device: " + UserInformation.Device + " Occupied");

                            //Cashout
                            List <CGDBSCCashoutDetail> listCashoutDetail = new List <CGDBSCCashoutDetail>();
                            listCashoutDetail.Add(_cOut);
                            LogManager.WriteLog(DispenserType + "Cashout :- TicketNo: " + TicketNo + "; Bar Position No: " + BarPosNo + "; Amount: " + Amount, LogManager.enumLogLevel.Info);

                            OnStatusChanged(" Dispensing Cash [" + Amount + "] in Cents...");
                            _TRANS_TYPE _type = _TRANS_TYPE.TICKET_REDEMPTION;
                            if (_cType != null)
                            {
                                switch (_cType)
                                {
                                case ModuleName.AttendantPay:
                                    _type = _TRANS_TYPE.VOUCHER_REDEMPTION;
                                    break;

                                case ModuleName.ManualAttendantPay:
                                    _type = _TRANS_TYPE.JACKPOT;
                                    break;
                                }
                            }

                            _SYS_CODE sRes = doCashout(listCashoutDetail, IsNotDuplex, _type);
                            if (sRes != _SYS_CODE.SYS_SUCCESS)
                            {
                                res.IsSuccess         = false;
                                res.error.Message     = sRes.ToString();
                                res.error.Code        = (int)sRes;
                                res.error.MessageType = MessageType.Error.ToString();
                                AuditCloseSessionGloryDetails(res.IsSuccess, res.error.Message);
                                GloryDeviceHelper.Instance.HeartbeatStop();
                                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                {
                                    AuditModuleName    = _cType,
                                    Audit_Screen_Name  = _cType + "|Cashout",
                                    Audit_Desc         = "Cashout Failed ; Session ID:" + UserInformation.SessionID,
                                    AuditOperationType = OperationType.ADD,
                                    Audit_Field        = "Session ID"
                                });
                                res.error.Message = Application.Current.FindResource("MessageID442") as string;
                                this.OnFinished(res);
                            }
                            //Non Duplex Mode
                            if (IsNotDuplex)
                            {
                                #region Release
                                _SYS_CODE syRel = doRelease();
                                if (syRel != _SYS_CODE.SYS_SUCCESS)
                                {
                                    LogManager.WriteLog(DispenserType + "Releasing Device Failed: Msg:-" + syRel.ToString() + "Error Code:-" + (int)syRel, LogManager.enumLogLevel.Info);
                                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                    {
                                        AuditModuleName    = _cType,
                                        Audit_Screen_Name  = _cType + "|Release Session",
                                        Audit_Desc         = "Failed to Release ; Device Name:" + UserInformation.Device,
                                        AuditOperationType = OperationType.ADD,
                                        Audit_Field        = "Device"
                                    });
                                    OnStatusChanged("Failed to Release ; Device Name:" + UserInformation.Device);
                                }
                                else
                                {
                                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                    {
                                        AuditModuleName    = _cType,
                                        Audit_Screen_Name  = _cType + "|Release Session",
                                        Audit_Desc         = "Release Succeed ; Device Name:" + UserInformation.Device,
                                        AuditOperationType = OperationType.ADD,
                                        Audit_Field        = "Device"
                                    });
                                    OnStatusChanged("Device Name:" + UserInformation.Device + " released succeesfully");
                                    LogManager.WriteLog(DispenserType + "Device Name:" + UserInformation.Device + " released succeesfully", LogManager.enumLogLevel.Info);
                                }
                                #endregion

                                #region Close Session
                                _SYS_CODE syObj = doCloseSession();
                                if (syObj != _SYS_CODE.SYS_SUCCESS)
                                {
                                    LogManager.WriteLog(DispenserType + "CloseSession Failed: Msg:-" + syObj.ToString() + "Error Code:-" + (int)syObj, LogManager.enumLogLevel.Info);
                                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                    {
                                        AuditModuleName    = _cType,
                                        Audit_Screen_Name  = _cType + "|Close Session",
                                        Audit_Desc         = "Close Session Failed ; Session ID:" + UserInformation.SessionID + "; EndTime:" + DateTime.Now.GetUniversalDateTimeFormat(),
                                        AuditOperationType = OperationType.ADD,
                                        Audit_Field        = "Session ID"
                                    });
                                    OnStatusChanged("Close Session Failed");
                                    res.error.Message = Application.Current.FindResource("MessageID441") as string;
                                }
                                else
                                {
                                    AuditCloseSessionGloryDetails(true, string.Empty);
                                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                    {
                                        AuditModuleName    = _cType,
                                        Audit_Screen_Name  = _cType + "|Close Session",
                                        Audit_Desc         = "Close Session Succeed ; Session ID:" + UserInformation.SessionID + "; EndTime:" + DateTime.Now.GetUniversalDateTimeFormat(),
                                        AuditOperationType = OperationType.ADD,
                                        Audit_Field        = "Session ID"
                                    });
                                    OnStatusChanged("Close Session Succeed");
                                    res.error.Message = Application.Current.FindResource("MessageID441") as string;
                                    LogManager.WriteLog(DispenserType + "Close Session Succeed", LogManager.enumLogLevel.Info);
                                }

                                #endregion

                                this.OnFinished(res);
                            }
                        }
                        else
                        {
                            res.IsSuccess         = false;
                            res.error.Message     = sOcc.ToString();
                            res.error.Code        = (int)sOcc;
                            res.error.MessageType = MessageType.Error.ToString();
                            AuditCloseSessionGloryDetails(res.IsSuccess, res.error.Message);
                            GloryDeviceHelper.Instance.HeartbeatStop();
                            AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                            {
                                AuditModuleName    = _cType,
                                Audit_Screen_Name  = _cType + "|Occupy",
                                Audit_Desc         = "Occupy Failed ; Device Name:" + UserInformation.Device,
                                AuditOperationType = OperationType.ADD,
                                Audit_Field        = "Device Name"
                            });
                            res.error.Message = Application.Current.FindResource("MessageID442") as string;
                            this.OnFinished(res);
                        }
                    }
                    else
                    {
                        res.IsSuccess         = false;
                        res.error.Message     = sOpen.ToString();
                        res.error.Code        = (int)sOpen;
                        res.error.MessageType = MessageType.Error.ToString();
                        AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                        {
                            AuditModuleName    = _cType,
                            Audit_Screen_Name  = _cType + "|Open Session",
                            Audit_Desc         = "Open Session Failed; StartTime:" + DateTime.Now.GetUniversalDateTimeFormat(),
                            AuditOperationType = OperationType.ADD,
                            Audit_Field        = "Session ID"
                        });
                        res.error.Message = Application.Current.FindResource("MessageID443") as string;
                        this.OnFinished(res);
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(DispenserType + "Dispense" + ex.Message, LogManager.enumLogLevel.Error);
                res.error.Message     = ex.Message;
                res.IsSuccess         = false;
                res.error.MessageType = MessageType.Error.ToString();
                this.OnFinished(res);
            }

            return(res);
        }