Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Data.Common

Imports System.IO
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Imports System.Text

Imports System.Xml
Imports System.Xml.Serialization
Imports System.Web
Imports nsWS = G2BServicesProvider.WSG2B
Imports Microsoft.Practices.EnterpriseLibrary.Data

Imports CharterDotCom.CommonEntities.Library
Imports CharterDotCom.CommonEntities.Library.Enumerations

''' <summary> 
''' ProviderManager gathers data from the G2B call and packages 
''' that data into an object that is returned to the Web Server 
''' layer. 
''' </summary> 
Public Class ProviderManager
    Inherits IG2BServicesProvider

#Region "Member Variables"
    ' web service references:
    Private _wsSubmitOrder As nsWS.G2BV41
    Private _wsCancelOrder As nsWS.G2BV41
    Private _wsScheduleInstall As nsWS.G2BV41
    Private _wsAuthenticate As nsWS.G2BV41
    Private _wsG2BV41 As nsWS.G2BV41

    '############################ 
    'USED FOR ORDER LOG CURRENTLY 
    '############################ 
    Private _cmd As DbCommand
    Private _db As Database

    Private _blnLIVE As Boolean = False
    Private _strtelephoneFeatureID As String = String.Empty
    Private Const _cstrTelephoneFeature As String = "TelephoneFeatureID"
    Private Const _strNumOfComputers As String = "NumOfComputersID"

    Private _strnumOfComputersID As String = String.Empty
    Private _decnumOfComputersPrice As Decimal = 0

    Private _blnaffiliate_notcharter As Boolean = False

    Private _strContentParams As String
    Private _dctCatalogContent As Dictionary(Of String, String)
    Private _dctCatalogContentDetail As Dictionary(Of String, String)

    Private _intRegionID As Integer
    Private _intKMAId As Integer
    Private _intBillingStationID As Integer
    Private _strFTAID As String

    ''' <summary> 
    ''' Added 8/2007 for 4.1 changes 
    ''' </summary> 
    Private _strVersion As String = String.Empty

#End Region

#Region "Constructor / Destructor"
    ''' <summary> 
    ''' Default no-args constructor 
    ''' </summary> 
    Public Sub New()
        If System.Web.HttpContext.Current.Application("LIVE").Equals("true") Then
            _blnLIVE = True
        Else
            _blnLIVE = False
        End If

        If System.Web.HttpContext.Current.Application(_cstrTelephoneFeature) Is Nothing Then
            _strtelephoneFeatureID = String.Empty
        Else
            _strtelephoneFeatureID = TryCast(System.Web.HttpContext.Current.Application(_cstrTelephoneFeature), String)
        End If

        If System.Web.HttpContext.Current.Application(_strNumOfComputers) Is Nothing Then
            _strnumOfComputersID = String.Empty
        Else
            Dim str As String = TryCast(System.Web.HttpContext.Current.Application(_strNumOfComputers), String)
            Dim index As Integer = str.IndexOf(",")
            _strnumOfComputersID = str.Substring(0, index)
            Decimal.TryParse(str.Substring(index + 1, (str.Length - index) - 1), _decnumOfComputersPrice)
        End If
        Me.DB = DatabaseFactory.CreateDatabase(Constant.COMMERCEENGINE_CONNECTIONSTRING)

        '###################################################################################################### 
        'Feb 27, 2007 ROD COPELAND 
        'THIS CHANGE WAS ADDED BECAUSE THE MEMBERSERIVCE WEBSERVICE IS USING AN INTERNAL 
        'IP ON HTTPS AND THEY HAVE A PUBLIC CERTIFICATE THAT HAS A DIFFERENT NAME WHICH CAUSES 
        'AN INVALID CERT ERROR. WHY THE CERT IS INVALID ON THE MEMBERSERVICES SERVER IS A LIMITATION ON THEIR SIDE, SO IM TOLD. 
        'TO GET AROUND THIS, THIS CODE WAS ADDED TO MAKE THE WS REQUEST 
        'REGARDLESS IF THE CERT IS VALID OR NOT. AT THIS POINT, THIS SHOULD BE FINE SINCE 
        'THE WEBSERVICE IS INTERNAL. 
        '###################################################################################################### 
        Select Case Environment.MachineName.ToLower()
            Case "kstlmcc2p03", "kstlmcc2p04"
                '####### 
                ''PROD 
                ''####### 
                Exit Select
            Case "kstlmweb68", "kstlmweb69"
                ' '####### 
                ' 'UAT 
                ' '####### 
                Exit Select
            Case Else
                'KSTLMWEB65, LOCAL DEVELOPMENT BOXES, OR ANY OTHER UNKNOWN, IGNORE THE CERTIFICATE 
                ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
                Exit Select
        End Select
    End Sub

    ''' <summary>
    ''' Override Certificate Validation for debugging purposes
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="pCertificate"></param>
    ''' <param name="pChain"></param>
    ''' <param name="sslPolicyErrors"></param>
    ''' <returns>Boolean Success/Failure</returns>
    ''' <remarks>###################################################################################################### <BR/>
    ''' Feb 27, 2007 ROD COPELAND <BR/>
    ''' THIS CHANGE WAS ADDED BECAUSE THE MEMBERSERIVCE WEBSERVICE IS USING 
    ''' AN INTERNAL IP ON HTTPS AND THEY HAVE A PUBLIC CERTIFICATE THAT HAS 
    ''' A DIFFERENT NAME WHICH CAUSES AN INVALID CERT ERROR. <BR/>
    ''' TO GET AROUND THIS, THIS CODE WAS ADDED TO MAKE THE WS REQUEST 
    ''' REGARDLESS IF THE CERT IS VALID OR NOT. AT THIS POINT, THIS SHOULD 
    ''' BE FINE SINCE ALL THE WEBSERVICES ARE INTERNAL (ASIDE FROM G2B). 
    ''' ###################################################################################################### 
    ''' </remarks>
    Private Function ValidateCertificate(ByVal sender As Object, ByVal pCertificate As X509Certificate, ByVal pChain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
        Return True
    End Function

    ''' <summary> 
    ''' New constructor to request specific version of QueryOffers 
    ''' and other functions 
    ''' </summary> 
    ''' <param name="pstrVersion">Version Number (such as "4.1")</param> 
    Public Sub New(ByVal pstrVersion As String)
        Me.New()
        Me._strVersion = pstrVersion
    End Sub
    'public ProviderManager(string configData) 
    '{ 
    ' XmlNode args; 
    ' XmlDocument xDoc; 
    ' //############################ 
    ' //USED FOR ORDER LOG CURRENTLY 
    ' //############################ 
    ' this.DB = DatabaseFactory.CreateDatabase(Constant.COMMERCEENGINE_CONNECTIONSTRING); 

    ' if (System.Web.HttpContext.Current.Application["LIVE"].Equals("true")) 
    ' { LIVE = true; } 
    ' else 
    ' { LIVE = false; } 

    ' NetworkCredential netCredential; 
    ' Uri uri; 
    ' ICredentials credentials; 
    ' try 
    ' { 
    ' xDoc = new XmlDocument(); 
    ' xDoc.LoadXml(configData); 
    ' args = xDoc.DocumentElement; 
    ' if ((args != null) && (args.ChildNodes[0] != null) && (args.ChildNodes[0].LocalName == Constant.CONFIG_PROVIDERDATA)) 
    ' { 
    ' foreach (XmlNode providerData in args.ChildNodes[0].ChildNodes) 
    ' { 
    ' switch (providerData.LocalName.ToUpper()) 
    ' { 
    ' case Constant.CONFIG_SUBMITORDERWEBSERVICE: 
    ' wsSubmitOrder = new namespaceWSSubmit.SubmitOrderService(); 
    ' if ((providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED] != null) && 
    ' (providerData.Attributes[Constant.CONFIG_USER] != null) && 
    ' (providerData.Attributes[Constant.CONFIG_PASSWORD] != null)) 
    ' { 
    ' if (Convert.ToBoolean(providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED].Value)) 
    ' { 
    ' netCredential = new NetworkCredential(providerData.Attributes[Constant.CONFIG_USER].Value, providerData.Attributes[Constant.CONFIG_PASSWORD].Value); 
    ' uri = new Uri(providerData.Attributes["URL"].Value); 
    ' credentials = netCredential.GetCredential(uri, "Basic"); 
    ' wsSubmitOrder.Credentials = credentials; 
    ' wsSubmitOrder.Url = uri.ToString(); 
    ' } 
    ' } 
    ' else 
    ' { 
    ' throw new Exception(Constant.EXCEPTION_CONFIGURATION); 
    ' } 

    ' break; 
    ' case Constant.CONFIG_CANCELORDERWEBSERVICE: 
    ' wsCancelOrder = new namespaceWSCancel.CancelOrderService(); 
    ' if ((providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED] != null) && 
    ' (providerData.Attributes[Constant.CONFIG_USER] != null) && 
    ' (providerData.Attributes[Constant.CONFIG_PASSWORD] != null)) 
    ' { 
    ' if (Convert.ToBoolean(providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED].Value)) 
    ' { 
    ' netCredential = new NetworkCredential(providerData.Attributes[Constant.CONFIG_USER].Value, providerData.Attributes[Constant.CONFIG_PASSWORD].Value); 
    ' uri = new Uri(providerData.Attributes["URL"].Value); 
    ' credentials = netCredential.GetCredential(uri, "Basic"); 
    ' wsCancelOrder.Credentials = credentials; 
    ' wsCancelOrder.Url = uri.ToString(); 
    ' } 
    ' } 
    ' else 
    ' { 
    ' throw new Exception(Constant.EXCEPTION_CONFIGURATION); 
    ' } 

    ' break; 
    ' case Constant.CONFIG_QUERYOFFERSWEBSERVICE: 
    ' wsQueryOffers = new namespaceWSQueryOffers.QueryOffersService(); 
    ' if ((providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED] != null) && 
    ' (providerData.Attributes[Constant.CONFIG_USER] != null) && 
    ' (providerData.Attributes[Constant.CONFIG_PASSWORD] != null)) 
    ' { 
    ' if (Convert.ToBoolean(providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED].Value)) 
    ' { 
    ' netCredential = new NetworkCredential(providerData.Attributes[Constant.CONFIG_USER].Value, providerData.Attributes[Constant.CONFIG_PASSWORD].Value); 
    ' uri = new Uri(providerData.Attributes["URL"].Value); 
    ' credentials = netCredential.GetCredential(uri, "Basic"); 
    ' wsQueryOffers.Credentials = credentials; 
    ' wsQueryOffers.Url = uri.ToString(); 
    ' } 
    ' } 
    ' else 
    ' { 
    ' throw new Exception(Constant.EXCEPTION_CONFIGURATION); 
    ' } 

    ' break; 
    ' case Constant.CONFIG_SCHEDULEINSTALLWEBSERVICE: 
    ' wsScheduleInstall = new namespaceWSScheduleInstall.ScheduleInstallService(); 
    ' if ((providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED] != null) && 
    ' (providerData.Attributes[Constant.CONFIG_USER] != null) && 
    ' (providerData.Attributes[Constant.CONFIG_PASSWORD] != null)) 
    ' { 
    ' if (Convert.ToBoolean(providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED].Value)) 
    ' { 
    ' netCredential = new NetworkCredential(providerData.Attributes[Constant.CONFIG_USER].Value, providerData.Attributes[Constant.CONFIG_PASSWORD].Value); 
    ' uri = new Uri(providerData.Attributes["URL"].Value); 
    ' credentials = netCredential.GetCredential(uri, "Basic"); 
    ' wsScheduleInstall.Credentials = credentials; 
    ' wsScheduleInstall.Url = uri.ToString(); 
    ' } 
    ' } 
    ' else 
    ' { 
    ' throw new Exception(Constant.EXCEPTION_CONFIGURATION); 
    ' } 

    ' break; 
    ' default: 
    ' break; 
    ' } 
    ' } 

    ' } 
    ' else 
    ' { 
    ' throw new Exception(Constant.EXCEPTION_CONFIGURATION); 
    ' } 
    ' } 
    ' catch (Exception ex) 
    ' { 

    ' throw ; 
    ' } 
    '} 

    'public ProviderManager(XmlNode args) 
    '{ 
    '/ if (System.Web.HttpContext.Current.Application["LIVE"].Equals("true")) 
    '/ { LIVE = true; } 
    '/ else 
    '/ { LIVE = false; } 

    '/ if (System.Web.HttpContext.Current.Application[TelephoneFeature] == null) 
    '/ { telephoneFeatureID = string.Empty; } 
    '/ else 
    '/ { telephoneFeatureID = (string)System.Web.HttpContext.Current.Application[TelephoneFeature]; } 

    '/ if (System.Web.HttpContext.Current.Application[NumOfComputers] == null) 
    '/ { numOfComputersID = string.Empty; } 
    '/ else 
    '/ { 
    '/ string str = (string)System.Web.HttpContext.Current.Application[NumOfComputers]; 
    '/ int index = str.IndexOf(","); 
    '/ numOfComputersID = str.Substring(0, index); 
    '/ decimal.TryParse(str.Substring(index + 1, (str.Length - index)-1), out numOfComputersPrice); 
    '/ } 

    '/ this.DB = DatabaseFactory.CreateDatabase(Constant.COMMERCEENGINE_CONNECTIONSTRING); 
    '/ NetworkCredential netCredential; 
    '/ Uri uri; 
    '/ ICredentials credentials; 

    '/ if ((args != null) && (args.ChildNodes[0] != null) && (args.ChildNodes[0].LocalName == Constant.CONFIG_PROVIDERDATA)) 
    '/ { 
    '/ foreach (XmlNode providerData in args.ChildNodes[0].ChildNodes) 
    '/ { 
    '/ switch (providerData.LocalName.ToUpper()) 
    '/ { 
    '/ case Constant.CONFIG_SUBMITORDERWEBSERVICE: 
    '/ wsSubmitOrder = new namespaceWSSubmit.SubmitOrderService(); 
    '/ if ((providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED] != null) && 
    '/ (providerData.Attributes[Constant.CONFIG_USER] != null) && 
    '/ (providerData.Attributes[Constant.CONFIG_PASSWORD] != null)) 
    '/ { 
    '/ uri = new Uri(providerData.Attributes["URL"].Value); 
    '/ wsSubmitOrder.Url = uri.ToString(); 

    '/ if (Convert.ToBoolean(providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED].Value)) 
    '/ { 
    '/ netCredential = new NetworkCredential(providerData.Attributes[Constant.CONFIG_USER].Value, providerData.Attributes[Constant.CONFIG_PASSWORD].Value); 
    '/ credentials = netCredential.GetCredential(uri, "Basic"); 
    '/ wsSubmitOrder.Credentials = credentials; 
    '/ } 

    '/ } 
    '/ else 
    '/ { 
    '/ throw new Exception(Constant.EXCEPTION_CONFIGURATION); 
    '/ } 

    '/ break; 
    '/ case Constant.CONFIG_CANCELORDERWEBSERVICE: 
    '/ wsCancelOrder = new namespaceWSCancel.CancelOrderService(); 
    '/ if ((providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED] != null) && 
    '/ (providerData.Attributes[Constant.CONFIG_USER] != null) && 
    '/ (providerData.Attributes[Constant.CONFIG_PASSWORD] != null)) 
    '/ { 
    '/ uri = new Uri(providerData.Attributes["URL"].Value); 
    '/ wsCancelOrder.Url = uri.ToString(); 

    '/ if (Convert.ToBoolean(providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED].Value)) 
    '/ { 
    '/ netCredential = new NetworkCredential(providerData.Attributes[Constant.CONFIG_USER].Value, providerData.Attributes[Constant.CONFIG_PASSWORD].Value); 
    '/ credentials = netCredential.GetCredential(uri, "Basic"); 
    '/ wsCancelOrder.Credentials = credentials; 
    '/ } 

    '/ } 
    '/ else 
    '/ { 
    '/ throw new Exception(Constant.EXCEPTION_CONFIGURATION); 
    '/ } 

    '/ break; 
    '/ case Constant.CONFIG_QUERYOFFERSWEBSERVICE: 
    '/ wsQueryOffers = new namespaceWSQueryOffers.QueryOffersService(); 
    '/ if ((providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED] != null) && 
    '/ (providerData.Attributes[Constant.CONFIG_USER] != null) && 
    '/ (providerData.Attributes[Constant.CONFIG_PASSWORD] != null)) 
    '/ { 
    '/ uri = new Uri(providerData.Attributes["URL"].Value); 
    '/ wsQueryOffers.Url = uri.ToString(); 

    '/ if (Convert.ToBoolean(providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED].Value)) 
    '/ { 
    '/ netCredential = new NetworkCredential(providerData.Attributes[Constant.CONFIG_USER].Value, providerData.Attributes[Constant.CONFIG_PASSWORD].Value); 
    '/ credentials = netCredential.GetCredential(uri, "Basic"); 
    '/ wsQueryOffers.Credentials = credentials; 
    '/ } 

    '/ } 
    '/ else 
    '/ { 
    '/ throw new Exception(Constant.EXCEPTION_CONFIGURATION); 
    '/ } 

    '/ break; 
    '/ case Constant.CONFIG_SCHEDULEINSTALLWEBSERVICE: 
    '/ wsScheduleInstall = new namespaceWSScheduleInstall.ScheduleInstallService(); 
    '/ if ((providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED] != null) && 
    '/ (providerData.Attributes[Constant.CONFIG_USER] != null) && 
    '/ (providerData.Attributes[Constant.CONFIG_PASSWORD] != null)) 
    '/ { 
    '/ uri = new Uri(providerData.Attributes["URL"].Value); 
    '/ wsScheduleInstall.Url = uri.ToString(); 

    '/ if (Convert.ToBoolean(providerData.Attributes[Constant.CONFIG_AUTHENTICATIONREQUIRED].Value)) 
    '/ { 
    '/ netCredential = new NetworkCredential(providerData.Attributes[Constant.CONFIG_USER].Value, providerData.Attributes[Constant.CONFIG_PASSWORD].Value); 
    '/ credentials = netCredential.GetCredential(uri, "Basic"); 
    '/ wsScheduleInstall.Credentials = credentials; 
    '/ } 

    '/ } 
    '/ else 
    '/ { 
    '/ throw new Exception(Constant.EXCEPTION_CONFIGURATION); 
    '/ } 

    '/ break; 
    '/ default: 
    '/ break; 
    '/ } 
    '/ } 

    '/ } 
    '/ else 
    '/ { 
    '/ throw new Exception(Constant.EXCEPTION_CONFIGURATION); 
    '/ } 
    '} 
#End Region

#Region "Private Properties"
    '############################ 
    'USED FOR ORDER LOG CURRENTLY 
    '############################ 
    Private Property DB() As Database
        Get
            Return _db
        End Get
        Set(ByVal value As Database)
            _db = value
        End Set
    End Property
    '############################ 
    'USED FOR ORDER LOG CURRENTLY 
    '############################ 
    Private Property CMD() As DbCommand
        Get
            Return _cmd
        End Get
        Set(ByVal value As DbCommand)
            _cmd = value
        End Set
    End Property
#End Region

#Region "Interfaces to G2B Web Service Methods"
    ''' <summary> 
    ''' Submit an Order to G2B 
    ''' </summary> 
    ''' <param name="pobjRequest">Submit-Order input parameters, in the G2BSubmitOrderRequest format</param> 
    ''' <returns>G2BSubmitOrderResponse object</returns> 
    ''' <remarks>This method acts as a pass-through between the 
    ''' Web Server charter.com front end and the G2B Web Service. 
    ''' It re-formats data [provided by Charter.com for a 
    ''' SubmitOrder message] into the G2B Input request format, 
    ''' calls the G2B web service, and packages the G2B output into 
    ''' something the front-end can utilize.</remarks> 
    Public Overloads Overrides Function SubmitOrder(ByVal pobjRequest As IProviderParameters) As IProviderResults
        Dim lG2BSubmitOrderRequest As EntityG2BServices.G2BSubmitOrderRequest
        Dim objG2BSubmitOrderResponse As EntityG2BServices.G2BSubmitOrderResponse = Nothing

        Dim objSubmitOrder As nsWS.SubmitOrder = New G2BServicesProvider.WSG2B.SubmitOrder()
        Dim lWS_Confirmations As nsWS.ConfirmationType() = Nothing
        Dim lOfferOrder As nsWS.OfferOrderType() = Nothing
        Dim lDiscount As nsWS.DiscountOrderType() = Nothing
        Dim lWS_Customization As nsWS.CustomizationOrderType() = Nothing
        Dim lWS_ShippingAddress As nsWS.UnparsedUSAddressType = Nothing
        Dim lCreditCard As nsWS.CreditCardType = Nothing
        Dim lTrackingID As Integer
        Dim lMSOID As Integer
        Dim lAddressID As String
        Dim lResend As Integer

        Dim objTempResponse As New nsWS.SubmitOrderResponse()
        Dim objConfirmation As New List(Of EntityG2BServices.ConfirmationType)()
        Dim objInstallWindow As New List(Of EntityG2BServices.InstallWindowType)()
        Dim arrChoices As String()
        Dim lstChoice As List(Of String)
        Dim netCredential As NetworkCredential
        Dim lobjURI As Uri
        Dim objCredentials As ICredentials
        Dim objContext As HttpContext
        Dim counterI As Integer = 0
        Dim counterJ As Integer = 0
        'int counterK = 0; 
        Dim counterL As Integer = 0
        Try
            ' take the front-end supplied request object 
            '(entityG2BServices G2BSubmitOrderRequest object) 
            ' and convert it into the Web-service based SubmitOrderRequest object
            lG2BSubmitOrderRequest = TryCast(pobjRequest, EntityG2BServices.G2BSubmitOrderRequest)
            If lG2BSubmitOrderRequest IsNot Nothing Then
                LogOrder(pobjRequest)
                If lG2BSubmitOrderRequest.IsMoving Then
                    Return Nothing
                Else
                    If lG2BSubmitOrderRequest.OfferOrder IsNot Nothing Then
                        lOfferOrder = New nsWS.OfferOrderType(lG2BSubmitOrderRequest.OfferOrder.Count - 1) {}
                        counterI = 0
                        ' EACH OfferOrder is a different Service plan requested by the customer
                        For Each offerOrder As EntityG2BServices.OfferOrderTypeG2BOrder In lG2BSubmitOrderRequest.OfferOrder
                            lOfferOrder(counterI) = New nsWS.OfferOrderType()
                            lOfferOrder(counterI).AffiliateInstall = offerOrder.AffiliateInstall
                            lOfferOrder(counterI).AffiliateLineID = offerOrder.AffiliateLineID
                            lOfferOrder(counterI).AffiliateOrderID = offerOrder.AffiliateOrderID
                            ' convert customization items
                            If offerOrder.Customization IsNot Nothing Then
                                lWS_Customization = New nsWS.CustomizationOrderType(offerOrder.Customization.Count - 1) {}
                                counterJ = 0
                                For Each customization As EntityG2BServices.CustomizationTypeOrder In offerOrder.Customization
                                    lWS_Customization(counterJ) = New nsWS.CustomizationOrderType()
                                    lWS_Customization(counterJ).CustomizationID = customization.CustomizationID
                                    If customization.Items IsNot Nothing Then
                                        lWS_Customization(counterJ).Items = New Object(0) {}
                                        'counterK = 0; 
                                        Dim item As Object = customization.Items
                                        ' foreach (object item in customization.Items) 
                                        ' { 
                                        ' customizations can be
                                        ' int
                                        ' selection types
                                        ' inputTextType objects
                                        ' cast it to the correct one before passing on to the web service
                                        If (item.[GetType]().FullName = GetType(Integer).FullName) OrElse (item.[GetType]().FullName = GetType(String).FullName) Then
                                            lWS_Customization(counterJ).Items(0) = item
                                        ElseIf item.[GetType]().FullName = GetType(EntityG2BServices.SelectionTypeOrder).FullName Then
                                            counterL = 0
                                            Dim selections As EntityG2BServices.SelectionTypeOrder = TryCast(item, EntityG2BServices.SelectionTypeOrder)
                                            lstChoice = selections.ChoiceIDs
                                            arrChoices = New String(lstChoice.Count - 1) {}
                                            For Each selection As String In lstChoice
                                                arrChoices(counterL) = selection
                                                counterL += 1
                                            Next
                                            Dim selectionItem As New nsWS.SelectionOrderType()
                                            selectionItem.ChoiceID = arrChoices

                                            lWS_Customization(counterJ).Items(0) = selectionItem
                                        ElseIf item.[GetType]().FullName = GetType(EntityG2BServices.InputTextTypeOrder).FullName Then
                                            Dim objInpTextOrder As EntityG2BServices.InputTextTypeOrder = TryCast(item, EntityG2BServices.InputTextTypeOrder)
                                            Dim objInputTextG2B As New nsWS.InputTextOrderType()
                                            objInputTextG2B.TextID = objInpTextOrder.TextID
                                            objInputTextG2B.Value = objInpTextOrder.Value
                                            lWS_Customization(counterJ).Items(0) = objInputTextG2B
                                        Else
                                            If objG2BSubmitOrderResponse Is Nothing Then
                                                objG2BSubmitOrderResponse = New EntityG2BServices.G2BSubmitOrderResponse()
                                            End If
                                            ' Error 1
                                            ProviderManager.FormatG2BCommonResponse(objG2BSubmitOrderResponse, _
                                                Constant.EXCEPTION_INVALID_INPUT_SUBMITORDER_CODE, System.Reflection.MethodInfo.GetCurrentMethod().Name + " Item Collection in not of a valid type.")
                                            Return objG2BSubmitOrderResponse
                                            'Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " Item Collection in not of a valid type.")
                                            ' counterK++; 
                                            ' } 
                                        End If
                                    End If
                                    counterJ += 1
                                Next
                            End If

                            lOfferOrder(counterI).Customization = lWS_Customization
                            lOfferOrder(counterI).OfferID = offerOrder.OfferID
                            lOfferOrder(counterI).Version = offerOrder.Version
                            counterI += 1
                        Next
                    End If
                    ' TODO: take out this 
                    ' TextWriter tw ; 
                    ' tw = new StreamWriter("C:/InetPub/wwwroot/RR/rules22.xml"); 
                    ' XmlSerializer serializer ; 
                    ' serializer = new XmlSerializer(lOfferOrder.GetType()); 
                    ' serializer.Serialize(tw, lOfferOrder); 
                    'tw.Close(); 

                    If lG2BSubmitOrderRequest.Discount IsNot Nothing Then
                        lDiscount = New nsWS.DiscountOrderType(lG2BSubmitOrderRequest.Discount.Count - 1) {}
                        counterI = 0
                        For Each discount As EntityG2BServices.DiscountTypeOrder In lG2BSubmitOrderRequest.Discount
                            lDiscount(counterI).DiscountID = discount.DiscountID
                            counterI += 1
                        Next
                    End If
                    If lG2BSubmitOrderRequest.CreditCard IsNot Nothing Then
                        lCreditCard = New nsWS.CreditCardType()

                        lCreditCard.Number = lG2BSubmitOrderRequest.CreditCard.Number
                        lCreditCard.Expiration = lG2BSubmitOrderRequest.CreditCard.Expiration
                        lCreditCard.SecurityCode = lG2BSubmitOrderRequest.CreditCard.SecurityCode
                        lCreditCard.BillingFullName = lG2BSubmitOrderRequest.CreditCard.BillingFullName
                        lCreditCard.BillingPhone = lG2BSubmitOrderRequest.CreditCard.BillingPhone
                        If lG2BSubmitOrderRequest.CreditCard.BillingAddress IsNot Nothing Then
                            lCreditCard.BillingAddress = BuildAddress(lG2BSubmitOrderRequest.CreditCard.BillingAddress)
                        End If
                    End If
                    If lG2BSubmitOrderRequest.ShippingAddress IsNot Nothing Then
                        lWS_ShippingAddress = BuildAddress(lG2BSubmitOrderRequest.ShippingAddress)
                    End If
                    lTrackingID = lG2BSubmitOrderRequest.TrackingID
                    lMSOID = lG2BSubmitOrderRequest.MSOID
                    lAddressID = lG2BSubmitOrderRequest.AddressID
                    lResend = lG2BSubmitOrderRequest.Resend

                    'Configure settings for G2B Submit Order WebService 

                    objContext = HttpContext.Current
                    Dim objElig As EntityG2BServices.EligibilityType = Nothing

                    _wsSubmitOrder = New nsWS.G2BV41()

                    lobjURI = New Uri(TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_SUBMITORDERWEBSERVICE_URL), String))
                    _wsSubmitOrder.Url = lobjURI.ToString()

                    If Convert.ToBoolean(objContext.Application(Constant.G2BSERVICESPROVIDER_SUBMITORDERWEBSERVICE_AUTHENTICATIONREQUIRED)) Then
                        netCredential = New NetworkCredential(TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_SUBMITORDERWEBSERVICE_USER), String), TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_SUBMITORDERWEBSERVICE_PASSWORD), String))
                        objCredentials = netCredential.GetCredential(lobjURI, "Basic")
                        _wsSubmitOrder.Credentials = objCredentials
                    End If
                    If Not objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH") Is Nothing Then
                        If objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH").ToString().Trim() <> "" Then
                            _wsSubmitOrder.ClientCertificates.Add(X509Certificate.CreateFromCertFile(objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH")))
                        End If
                    End If






                    ' pass values from local "G2B" object to Web Service request object:
                    objSubmitOrder = New nsWS.SubmitOrder()
                    objSubmitOrder.OfferOrder = lOfferOrder
                    objSubmitOrder.Discount = lDiscount
                    objSubmitOrder.FirstName = lG2BSubmitOrderRequest.FirstName
                    objSubmitOrder.LastName = lG2BSubmitOrderRequest.LastName
                    objSubmitOrder.ServiceAddressPhone = lG2BSubmitOrderRequest.ServiceAddressPhone
                    objSubmitOrder.ContactPhone = lG2BSubmitOrderRequest.ContactPhone
                    objSubmitOrder.Email = lG2BSubmitOrderRequest.Email
                    objSubmitOrder.ContactInstructions = lG2BSubmitOrderRequest.ContactInstructions
                    objSubmitOrder.CreditCard = lCreditCard
                    objSubmitOrder.ShippingAddress = lWS_ShippingAddress
                    objSubmitOrder.AdditionalInfo = lG2BSubmitOrderRequest.AdditionalInfo
                    objSubmitOrder.TrackingID = lTrackingID
                    objSubmitOrder.MSOID = lMSOID
                    objSubmitOrder.AddressID = lAddressID
                    objSubmitOrder.Resend = lResend
                    ' 8/2007 jwg added for g2b 4.1 
                    objSubmitOrder.CustomerHardware = ConvertCustomerHardware(lG2BSubmitOrderRequest.CustomerHardware)


                    ' make the call to the submit order web service:
                    objTempResponse = _wsSubmitOrder.SubmitOrder(objSubmitOrder)

                    '############################ 
                    'USED FOR ORDER LOG CURRENTLY 
                    '############################ 
                    'LogOrder(obj); 

                    ' convert the web service SubmitOrderResponse into out
                    ' EntityG2BServices.G2BSubmitOrderResponse object, which
                    ' can be passed back to the calling front-end layer:

                    If objTempResponse Is Nothing Then
                        If objG2BSubmitOrderResponse Is Nothing Then
                            objG2BSubmitOrderResponse = New EntityG2BServices.G2BSubmitOrderResponse()
                        End If

                        ' Error 2
                        ProviderManager.FormatG2BCommonResponse(objG2BSubmitOrderResponse, _
                            Constant.EXCEPTION_INVALID_RESPONSE_SUBMITORDER_CODE, "No Response Received from SubmitOrder call")
                        Return objG2BSubmitOrderResponse
                        'Throw New Exception(Constant.EXCEPTION_NO_RESULT)
                    End If

                    ' formerly "out" parameters, now just part of 
                    ' the returned object response: 
                    If objTempResponse.Confirmation IsNot Nothing Then
                        lWS_Confirmations = objTempResponse.Confirmation
                    End If

                    lTrackingID = objTempResponse.TrackingID
                    lMSOID = objTempResponse.MSOID
                    If objTempResponse.AddressID IsNot Nothing Then
                        lAddressID = objTempResponse.AddressID
                    End If

                    If [String].Compare(objTempResponse.SubmitOrderResult.Value, Constant.RESPONSE_SUCCESS, StringComparison.OrdinalIgnoreCase) <> 0 Then
                        If objG2BSubmitOrderResponse Is Nothing Then
                            objG2BSubmitOrderResponse = New EntityG2BServices.G2BSubmitOrderResponse()
                        End If
                        ' Error 3
                        ProviderManager.FormatG2BCommonResponse(objG2BSubmitOrderResponse, _
                            objTempResponse.SubmitOrderResult.Code, objTempResponse.SubmitOrderResult.Value)
                        Return objG2BSubmitOrderResponse
                        'Throw New Exception(objTempResponse.SubmitOrderResult.Value)
                    End If

                    If lWS_Confirmations IsNot Nothing Then
                        For Each lConfirmation As nsWS.ConfirmationType In lWS_Confirmations
                            If lConfirmation.InstallWindow IsNot Nothing Then
                                '###############################################################################
                                'MODIFICATION   ROD COPELAND    JUNE 27, 2008
                                '##############################################################################
                                'IN SITUATIONS WERE THE WS CALL WOULD RETURN BACK TWO CONFIRMATIONS AND EACH 
                                'CONFIRMATION CONTAINING ITS OWN INSTALL WINDOW COLLECTION, A CHANGE TO THE 
                                '4.1 PROJECT CODE NEED TO BE UPDATED TO NOT ADD THE INSTALL WINDOWS FOR BOTH 
                                'CONFIRMATIONS TO THE SAME INSTALL WINDOW COLLECTION.  CHANGE WAS MADE TO 
                                'CREATE A NEW INSTANCE OF THE INSTALL WINDOW COLLECTION RATHER THAN CONTINUALLY 
                                'ADDING ALL THE INSTALL WINDOWS FOR BOTH CONFIRMATIONS TO THE SAME INSTANCE OF 
                                'THE INSTALL WINDOW COLLECTION. 
                                '###############################################################################
                                objInstallWindow = New List(Of EntityG2BServices.InstallWindowType)()
                                '###############################################################################

                                For Each installWindow As nsWS.InstallWindowType In lConfirmation.InstallWindow
                                    objInstallWindow.Add(New EntityG2BServices.InstallWindowType(installWindow.InstallWindowID, installWindow.[Date], installWindow.StartTime, installWindow.EndTime))
                                Next
                            End If
                            ' 8/2007 jwg changed for G2B 4.1 
                            objConfirmation.Add(New EntityG2BServices.ConfirmationType(objInstallWindow, lConfirmation.OfferID, lConfirmation.OrderConfirmationID, lConfirmation.FollowUpMessage, lConfirmation.ServiceLineID))
                        Next

                        If objTempResponse.Eligibility IsNot Nothing Then
                            objElig = ConvertEligibility(objTempResponse.Eligibility)
                        End If
                        ' #if DEBUG
                        ' For testing purposes, we set up a new application variable.
                        ' This is NOT to be used in UAT or Production.  It exists to
                        ' allow us to populate fields not yet updated in the Recom Message
                        ' Engine (since Recom does not pass any data for these fields yet,
                        ' it is hard to test changes to the Charter.Com Web Server front
                        ' end to validate the display of these new fields).
                        If (System.Web.HttpContext.Current.Application("G2BV41_DummyData") IsNot Nothing) _
                            AndAlso _
                            System.Web.HttpContext.Current.Application("G2BV41_DummyData").Equals("T") Then
                            If (objElig Is Nothing) Then
                                objElig = New EntityG2BServices.EligibilityType("TestAcct", _
                                     1, True, 10.0, True, "GoodCredit")
                            End If
                        End If

                        ' build the response object to be passed back to the front-end
                        objG2BSubmitOrderResponse = New EntityG2BServices.G2BSubmitOrderResponse(lTrackingID, _
                            lMSOID, _
                            lAddressID, _
                            objConfirmation)

                        ' additional properties not set in the constructor
                        objG2BSubmitOrderResponse.Results = New EntityG2BServices.Result(objTempResponse.SubmitOrderResult.Code, objTempResponse.SubmitOrderResult.Value)
                        objG2BSubmitOrderResponse.Eligibility = objElig


                        '################################################################ 
                        'ASSIGN THE WEB SERVICE RETURN CODE TO THE BL RESPONSE OBJECT 
                        '################################################################ 
                        objG2BSubmitOrderResponse.WS_ResponseCode = objTempResponse.SubmitOrderResult.Code
                    Else
                        If objG2BSubmitOrderResponse Is Nothing Then
                            objG2BSubmitOrderResponse = New EntityG2BServices.G2BSubmitOrderResponse()
                        End If
                        ' Error 4
                        ProviderManager.FormatG2BCommonResponse(objG2BSubmitOrderResponse, _
                            Constant.EXCEPTION_NO_RESULT_SUBMITORDER_CODE, "No Confirmation Received from SubmitOrder call")
                        Return objG2BSubmitOrderResponse
                        'Throw New Exception(Constant.EXCEPTION_NO_RESULT)
                    End If
                    Return objG2BSubmitOrderResponse
                    ' if not moving end 
                End If
            Else

                If objG2BSubmitOrderResponse Is Nothing Then
                    objG2BSubmitOrderResponse = New EntityG2BServices.G2BSubmitOrderResponse()
                End If
                ' Error 5
                ProviderManager.FormatG2BCommonResponse(objG2BSubmitOrderResponse, Constant.EXCEPTION_INVALID_Request_SUBMITORDER_CODE, "Submit Order received invalid Input Request object")
                Return objG2BSubmitOrderResponse
                'Throw New Exception(Constant.EXCEPTION_INVALID_INPUT)
            End If
        Catch ex As System.Web.Services.Protocols.SoapException
            If objG2BSubmitOrderResponse Is Nothing Then
                objG2BSubmitOrderResponse = New EntityG2BServices.G2BSubmitOrderResponse()
            End If
            objG2BSubmitOrderResponse.Exception = True
            objG2BSubmitOrderResponse.ExceptionMessage = ex.Detail.InnerText + " " + ex.Message
            objG2BSubmitOrderResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 6
            objG2BSubmitOrderResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_INVALID_RESPONSE_SUBMITORDER_CODE, ex.Detail.Name + " " + ex.Detail.InnerText)
            Return objG2BSubmitOrderResponse
        Catch ex As Exception
            If objG2BSubmitOrderResponse Is Nothing Then
                objG2BSubmitOrderResponse = New EntityG2BServices.G2BSubmitOrderResponse()
            End If
            objG2BSubmitOrderResponse.Exception = True
            objG2BSubmitOrderResponse.ExceptionMessage = ex.Message
            objG2BSubmitOrderResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 7
            objG2BSubmitOrderResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_NO_RESULT_SUBMITORDER_CODE, ex.Message)
            Return objG2BSubmitOrderResponse
        End Try
    End Function

    ''' <summary> 
    ''' Cancel an Order to G2B 
    ''' </summary> 
    ''' <param name="pobjRequest">Cancel-Order input parameters, in the G2BCancelOrderRequest format</param> 
    ''' <returns>G2BCancelOrderResponse object</returns> 
    ''' <remarks>8/2007 modified for G2B version 4.1<BR/> 
    ''' This method acts as a pass-through between the 
    ''' Web Server charter.com front end and the G2B Web Service. 
    ''' It re-formats data [provided by Charter.com for a 
    ''' CancelOrder message] into the G2B Input request format, 
    ''' calls the G2B web service, and packages the G2B output into 
    ''' something the front-end can utilize.</remarks> 
    Public Overloads Overrides Function CancelOrder(ByVal pobjRequest As IProviderParameters) As IProviderResults
        Dim lG2BCancelOrderRequest As EntityG2BServices.G2BCancelOrderRequest
        Dim objG2BCancelOrderResponse As EntityG2BServices.G2BCancelOrderResponse = Nothing
        Dim lTrackingID As Integer
        Dim lMSOID As Integer
        Dim lAddressID As String
        Dim lOrderConfirmationID As String
        Dim lReasonCode As nsWS.CancellationReasonEnum
        Dim lAffiliateOrderID As String
        Dim lCancelOrderConfirmation As nsWS.CancelOrderConfirmationType = Nothing
        Dim objRequest As New nsWS.CancelOrder()
        Dim objTempResponse As New nsWS.CancelOrderResponse()
        Dim objConfirmationCancel As EntityG2BServices.ConfirmationCancelType
        Dim netCredential As NetworkCredential
        Dim lobjURI As Uri
        Dim objCredentials As ICredentials
        Dim objContext As HttpContext

        Try
            lG2BCancelOrderRequest = TryCast(pobjRequest, EntityG2BServices.G2BCancelOrderRequest)
            If lG2BCancelOrderRequest IsNot Nothing Then
                lTrackingID = lG2BCancelOrderRequest.TrackingID
                lMSOID = lG2BCancelOrderRequest.MSOID
                lAddressID = lG2BCancelOrderRequest.AddressID
                lOrderConfirmationID = lG2BCancelOrderRequest.OrderConfirmationID
                Select Case lG2BCancelOrderRequest.ReasonCode
                    Case EntityG2BServices.CancellationReasonEnumumeration.m_ChangedMind
                        lReasonCode = nsWS.CancellationReasonEnum.ChangedMind
                        Exit Select
                    Case EntityG2BServices.CancellationReasonEnumumeration.m_EntryError
                        lReasonCode = nsWS.CancellationReasonEnum.EntryError
                        Exit Select
                    Case EntityG2BServices.CancellationReasonEnumumeration.m_InstallWindows
                        lReasonCode = nsWS.CancellationReasonEnum.InstallWindows
                        Exit Select
                    Case EntityG2BServices.CancellationReasonEnumumeration.m_ReturnedEquipment
                        lReasonCode = nsWS.CancellationReasonEnum.ReturnedEquipment
                        Exit Select
                    Case EntityG2BServices.CancellationReasonEnumumeration.m_SalesError
                        lReasonCode = nsWS.CancellationReasonEnum.SalesError
                        Exit Select
                    Case Else
                        lReasonCode = 0
                        Exit Select
                End Select
                lAffiliateOrderID = lG2BCancelOrderRequest.AffiliateOrderID
                'Configure settings for G2B Submit Order WebService 
                objContext = HttpContext.Current

                _wsCancelOrder = New nsWS.G2BV41()
                '.CancelOrderService(); 
                lobjURI = New Uri(TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_CANCELORDERWEBSERVICE_URL), String))
                _wsCancelOrder.Url = lobjURI.ToString()

                If Convert.ToBoolean(objContext.Application(Constant.G2BSERVICESPROVIDER_CANCELORDERWEBSERVICE_AUTHENTICATIONREQUIRED)) Then
                    netCredential = New NetworkCredential(TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_CANCELORDERWEBSERVICE_USER), String), TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_CANCELORDERWEBSERVICE_PASSWORD), String))
                    objCredentials = netCredential.GetCredential(lobjURI, "Basic")
                    _wsCancelOrder.Credentials = objCredentials
                End If
                If Not objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH") Is Nothing Then
                    If objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH").ToString().Trim() <> "" Then
                        _wsCancelOrder.ClientCertificates.Add(X509Certificate.CreateFromCertFile(objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH")))
                    End If
                End If





                objRequest = New nsWS.CancelOrder()
                objRequest.TrackingID = lTrackingID
                objRequest.MSOID = lMSOID
                objRequest.OrderConfirmationID = lOrderConfirmationID
                objRequest.ReasonCode = lReasonCode
                objRequest.AffiliateOrderID = lAffiliateOrderID
                objRequest.AddressID = lAddressID

                ' make the web service call 
                objTempResponse = _wsCancelOrder.CancelOrder(objRequest)

                If objTempResponse Is Nothing Then
                    If objG2BCancelOrderResponse Is Nothing Then
                        objG2BCancelOrderResponse = New EntityG2BServices.G2BCancelOrderResponse()
                    End If

                    ' Error 8
                    ProviderManager.FormatG2BCommonResponse(objG2BCancelOrderResponse, _
                        Constant.EXCEPTION_NO_RESULT_CANCELORDER_CODE, "No Response Received from CancelOrder call")
                    Return objG2BCancelOrderResponse

                    'Throw New Exception(Constant.EXCEPTION_NO_RESULT)
                End If
                ' formerly 'out' parameters, now just part of the response 
                ' object: 
                lTrackingID = objTempResponse.TrackingID
                lMSOID = objTempResponse.MSOID
                If objTempResponse.AddressID IsNot Nothing Then
                    lAddressID = objTempResponse.AddressID
                End If
                If objTempResponse.CancelOrderConfirmation IsNot Nothing Then
                    lCancelOrderConfirmation = objTempResponse.CancelOrderConfirmation
                End If
                '--------------------------------------------------------- 

                If [String].Compare(objTempResponse.CancelOrderResult.Value, Constant.RESPONSE_SUCCESS, StringComparison.OrdinalIgnoreCase) <> 0 Then
                    'Throw New Exception(objTempResponse.CancelOrderResult.Value)
                    If objG2BCancelOrderResponse Is Nothing Then
                        objG2BCancelOrderResponse = New EntityG2BServices.G2BCancelOrderResponse()
                    End If
                    ' Error 9
                    ProviderManager.FormatG2BCommonResponse(objG2BCancelOrderResponse, _
                        objTempResponse.CancelOrderResult.Code, objTempResponse.CancelOrderResult.Value)
                    Return objG2BCancelOrderResponse
                End If
                If lCancelOrderConfirmation IsNot Nothing Then
                    objConfirmationCancel = New EntityG2BServices.ConfirmationCancelType()
                    objConfirmationCancel.CancelOrderConfirmationID = lCancelOrderConfirmation.CancelOrderConfirmationID
                    objConfirmationCancel.FollowUpMessage = lCancelOrderConfirmation.FollowUpMessage
                    objG2BCancelOrderResponse = New EntityG2BServices.G2BCancelOrderResponse(lTrackingID, lMSOID, lAddressID, objConfirmationCancel)
                Else
                    'Throw New Exception(Constant.EXCEPTION_NO_RESULT)
                    If objG2BCancelOrderResponse Is Nothing Then
                        objG2BCancelOrderResponse = New EntityG2BServices.G2BCancelOrderResponse()
                    End If
                    ' Error 10
                    ProviderManager.FormatG2BCommonResponse(objG2BCancelOrderResponse, _
                        Constant.EXCEPTION_NO_RESULT_CANCELORDER_CODE, "No Response Received from CancelOrder call")
                    Return objG2BCancelOrderResponse
                End If
                Return objG2BCancelOrderResponse
            Else
                '                Throw New Exception(Constant.EXCEPTION_INVALID_INPUT)
                If objG2BCancelOrderResponse Is Nothing Then
                    objG2BCancelOrderResponse = New EntityG2BServices.G2BCancelOrderResponse()
                End If
                ' Error 11
                ProviderManager.FormatG2BCommonResponse(objG2BCancelOrderResponse, _
                    Constant.EXCEPTION_INVALID_Request_CANCELORDER_CODE, "Cancel Order received invalid Input Request")
                Return objG2BCancelOrderResponse
            End If
        Catch ex As System.Web.Services.Protocols.SoapException
            If objG2BCancelOrderResponse Is Nothing Then
                objG2BCancelOrderResponse = New EntityG2BServices.G2BCancelOrderResponse()
            End If
            objG2BCancelOrderResponse.Exception = True
            objG2BCancelOrderResponse.ExceptionMessage = ex.Detail.InnerText + " " + ex.Message
            objG2BCancelOrderResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 12
            objG2BCancelOrderResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_INVALID_RESPONSE_CANCELORDER_CODE, ex.Detail.Name + " " + ex.Detail.InnerText)
            Return objG2BCancelOrderResponse
        Catch ex As Exception
            If objG2BCancelOrderResponse Is Nothing Then
                objG2BCancelOrderResponse = New EntityG2BServices.G2BCancelOrderResponse()
            End If
            objG2BCancelOrderResponse.Exception = True
            objG2BCancelOrderResponse.ExceptionMessage = ex.Message
            objG2BCancelOrderResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 13
            objG2BCancelOrderResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_NO_RESULT_CANCELORDER_CODE, ex.Message)
            Return objG2BCancelOrderResponse
        End Try
    End Function

    ''' <summary> 
    ''' Handle QueryOffers request by calling Cable Labs and 
    ''' building results. USES THE NEW 4.1 INTERFACE 
    ''' </summary> 
    ''' <param name="pobjRequest">IProviderParameters object in G2BQueryOffersRequest format</param> 
    ''' <returns>IProviderResults in G2BQueryOffersResponse format</returns> 
    ''' <remarks>This method acts as a pass-through between the 
    ''' Web Server charter.com front end and the G2B Web Service. 
    ''' It re-formats data [provided by Charter.com for a 
    ''' QueryOffers (version 4.1) message] into the G2B Input request format, 
    ''' calls the G2B web service, and packages the G2B output into 
    ''' something the front-end can utilize.</remarks> 
    Public Overloads Overrides Function QueryOffers(ByVal pobjRequest As IProviderParameters) As IProviderResults
        Dim lG2BQueryOffersRequest As EntityG2BServices.G2BQueryOffersRequest
        Dim objwsQueryOffersRequest As New nsWS.QueryOffers()

        Dim lRequestingAffiliate As nsWS.AffiliateType
        Dim lOriginatingAffiliate As nsWS.AffiliateType
        Dim lUnParsedAddr As nsWS.UnparsedUSAddressType
        Dim lOpt As nsWS.PrivacyNoticeEnum
        Dim lRequest As nsWS.CableServiceEnum()
        Dim lSubscriber As nsWS.AllServiceEnum() = Nothing
        Dim lPhone As String
        Dim lLanguage As String
        Dim lParsedAddr As New nsWS.ParsedUSAddressType()
        Dim lMSOOffersResponse As nsWS.MSOOffersResponseType() = Nothing
        Dim lTrackingID As Integer
        Dim lMSOID As Integer
        Dim lAddressSuggestion As EntityG2BServices.USAddressSuggestionType()
        Dim objTempResponse As New nsWS.QueryOffersResponse()
        Dim objProductCatalog As ProductCatalog = Nothing
        Dim objG2BQueryOffersResponse As EntityG2BServices.G2BQueryOffersResponse = Nothing
        Dim objRules As Rules
        Dim lstDiscount As New List(Of EntityG2BServices.DiscountTypeQueryOffers)()
        Dim netCredential As NetworkCredential
        Dim lobjURI As Uri
        Dim objCredentials As ICredentials
        Dim objContext As HttpContext

        Try
            ' take what the front end provides (EntityG2BServices Query Offers Request
            ' object), and translate that into what the web service wants (nsWS
            ' Query Offers Request object):
            lG2BQueryOffersRequest = TryCast(pobjRequest, EntityG2BServices.G2BQueryOffersRequest)
            lRequestingAffiliate = New nsWS.AffiliateType()
            'lRequestingAffiliate.AffiliateID = Constant.AFFLIATE_ID; 
            lRequestingAffiliate.G2BVersion = Constant.AFFLIATE_G2BVERSION
            lOriginatingAffiliate = Nothing
            lOpt = nsWS.PrivacyNoticeEnum.OptOut
            lPhone = Constant.PHONE
            lLanguage = Constant.LANGUAGE

            If lG2BQueryOffersRequest IsNot Nothing Then
                If lG2BQueryOffersRequest.Address IsNot Nothing Then
                    lUnParsedAddr = New nsWS.UnparsedUSAddressType()
                    lUnParsedAddr.AddressLine = lG2BQueryOffersRequest.Address.Street1
                    lUnParsedAddr.Suite = lG2BQueryOffersRequest.Address.Street2
                    lUnParsedAddr.City = lG2BQueryOffersRequest.Address.City
                    lUnParsedAddr.State = lG2BQueryOffersRequest.Address.State
                    lUnParsedAddr.Zip = lG2BQueryOffersRequest.Address.Zip
                    lUnParsedAddr.Zip4 = lG2BQueryOffersRequest.Address.Zip4
                Else
                    lUnParsedAddr = Nothing
                End If

                lRequest = New nsWS.CableServiceEnum(7) {}
                lRequest(0) = nsWS.CableServiceEnum.CableBasicVideo
                lRequest(1) = nsWS.CableServiceEnum.CableDigitalVideo
                lRequest(2) = nsWS.CableServiceEnum.CableDVR
                lRequest(3) = nsWS.CableServiceEnum.CableHDVideo
                lRequest(4) = nsWS.CableServiceEnum.CableHighSpeedData
                lRequest(5) = nsWS.CableServiceEnum.CableHomeNetwork
                lRequest(6) = nsWS.CableServiceEnum.CableVoice
                lRequest(7) = nsWS.CableServiceEnum.CableWirelessVoice

                lRequestingAffiliate.AffiliateID = lG2BQueryOffersRequest.AffliateID

                _intRegionID = lG2BQueryOffersRequest.RegionID
                _intKMAId = lG2BQueryOffersRequest.KMAID
                _intBillingStationID = lG2BQueryOffersRequest.BillingStationID
                _strFTAID = lG2BQueryOffersRequest.FTA

                '*************************************************************** 
                'for different affiliates 
                If lRequestingAffiliate.AffiliateID <> Constant.AFFLIATE_ID Then
                    _blnaffiliate_notcharter = True
                End If

                'Configure settings for G2B Query Offers WebService 
                objContext = HttpContext.Current

                _wsG2BV41 = New nsWS.G2BV41()
                lobjURI = New Uri(TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_QUERYOFFERSWEBSERVICE_URL), String))
                _wsG2BV41.Url = lobjURI.ToString()

                If Convert.ToBoolean(objContext.Application(Constant.G2BSERVICESPROVIDER_QUERYOFFERSWEBSERVICE_AUTHENTICATIONREQUIRED)) Then
                    netCredential = New NetworkCredential(TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_QUERYOFFERSWEBSERVICE_USER), String), TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_QUERYOFFERSWEBSERVICE_PASSWORD), String))
                    objCredentials = netCredential.GetCredential(lobjURI, "Basic")
                    _wsG2BV41.Credentials = objCredentials
                End If
                If Not objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH") Is Nothing Then
                    If objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH").ToString().Trim() <> "" Then
                        _wsG2BV41.ClientCertificates.Add(X509Certificate.CreateFromCertFile(objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH")))
                    End If
                End If





                ' build input request data from user-supplied parameters 
                objwsQueryOffersRequest.RequestingAffiliate = lRequestingAffiliate
                objwsQueryOffersRequest.OriginatingAffiliate = lOriginatingAffiliate

                objwsQueryOffersRequest.Address = New G2BServicesProvider.WSG2B.UnparsedUSAddressType()
                If lUnParsedAddr IsNot Nothing Then
                    objwsQueryOffersRequest.Address = lUnParsedAddr
                End If

                objwsQueryOffersRequest.PrivacyNotice = lOpt
                If lRequest IsNot Nothing Then
                    objwsQueryOffersRequest.Request = lRequest
                End If

                If lSubscriber IsNot Nothing Then
                    objwsQueryOffersRequest.Subscriber = lSubscriber
                End If

                'If lPhone IsNot Nothing Then
                '    objwsQueryOffersRequest.ServiceAddressPhone = lPhone
                'End If

                If lLanguage IsNot Nothing Then
                    objwsQueryOffersRequest.Language = lLanguage
                End If

                objwsQueryOffersRequest.NumberToPort = lG2BQueryOffersRequest.NumberToPort
                If lG2BQueryOffersRequest.PromotionCode IsNot Nothing Then
                    ' grab first non-blank item from dictionary of Promotions
                    For Each kvp As KeyValuePair(Of String, String) In lG2BQueryOffersRequest.PromotionCode
                        If String.Compare(kvp.Value.ToString(), String.Empty) <> 0 Then
                            objwsQueryOffersRequest.PromotionCode = kvp.Value.ToString()
                            Exit For
                        End If

                    Next
                End If

                If lG2BQueryOffersRequest.NewCustomer IsNot Nothing Then
                    objwsQueryOffersRequest.NewCustomer = New G2BServicesProvider.WSG2B.NewCustomerType()
                    objwsQueryOffersRequest.NewCustomer.MoveDate = lG2BQueryOffersRequest.NewCustomer.MoveDate
                End If

                ' MAKE THE CALL TO THE QUERY OFFERS WEB SERVICE
                objTempResponse = _wsG2BV41.QueryOffers(objwsQueryOffersRequest)

                'If Not _blnLIVE Then
                '    'Use the following XML Deserialzation logic for unit testing with the data in the resource file. 
                '    lMSOOffersResponse = New nsWS.MSOOffersResponseType(0) {}
                '    Dim x As New XmlSerializer(New nsWS.MSOOffersResponseType().[GetType]())
                '    Dim XMLFromFile As String = G2BServicesProvider.Properties.Resources.QueryOffers.ToString()
                '    Dim tr As TextReader = New StringReader(XMLFromFile)
                '    lMSOOffersResponse(0) = TryCast(x.Deserialize(tr), nsWS.MSOOffersResponseType)
                '    lMSOID = 1011000079
                '    lTrackingID = 123456
                '    lAddressSuggestion = Nothing
                'End If

                ' take what the web service returns (nsWS Query Offers Response
                ' object), and translate it into something the front-end can
                ' consume (EntityG2BServices Query Offers Response object):
                If objTempResponse Is Nothing Then
                    'Throw New Exception(Constant.EXCEPTION_NO_RESULT_QUERYOFFERS )
                    If objG2BQueryOffersResponse Is Nothing Then
                        objG2BQueryOffersResponse = New EntityG2BServices.G2BQueryOffersResponse()
                    End If
                    ' Error 14
                    ProviderManager.FormatG2BCommonResponse(objG2BQueryOffersResponse, Constant.EXCEPTION_NO_RESULT_QUERYOFFERS_CODE, "No Response Received from QueryOffers call")
                    Return objG2BQueryOffersResponse
                End If

                lParsedAddr = New G2BServicesProvider.WSG2B.ParsedUSAddressType()
                If objTempResponse.Address IsNot Nothing Then
                    lParsedAddr.City = objTempResponse.Address.City
                    lParsedAddr.Postdir = objTempResponse.Address.Postdir
                    lParsedAddr.Predir = objTempResponse.Address.Predir
                    lParsedAddr.PrimName = objTempResponse.Address.PrimName
                    lParsedAddr.PrimRange = objTempResponse.Address.PrimRange
                    lParsedAddr.SecRange = objTempResponse.Address.SecRange
                    lParsedAddr.State = objTempResponse.Address.State
                    lParsedAddr.Suffix = objTempResponse.Address.Suffix
                    lParsedAddr.Zip = objTempResponse.Address.Zip
                    lParsedAddr.Zip4 = objTempResponse.Address.Zip4
                End If

                If objTempResponse.MSOOffersResponse IsNot Nothing Then
                    lMSOOffersResponse = objTempResponse.MSOOffersResponse
                End If
                lTrackingID = objTempResponse.TrackingID

                'if (String.Compare(objTempResponse.Value, Constant.RESPONSE_SUCCESS, StringComparison.OrdinalIgnoreCase) != 0) 
                '{ 
                ' throw new Exception(objTempResponse.Value); 
                '} 

                If lMSOOffersResponse IsNot Nothing Then
                    ''TODO: The following for loop needs to be modified. 
                    ' We should filter lMSOOffersResponse for one and only one Catalog 
                    For Each lMSOOffer As nsWS.MSOOffersResponseType In lMSOOffersResponse
                        lAddressSuggestion = Nothing
                        If lMSOOffer.Items IsNot Nothing AndAlso lMSOOffer.Name.Trim().ToUpper() = Constant.AFFILIATE_NAME Then
                            lMSOID = lMSOOffer.MSOID
                            objProductCatalog = BuildProductCatalog(lMSOOffer.Items, lG2BQueryOffersRequest.AffliateID, lTrackingID)
                            objRules = BuildRules()
                            Dim objResult As New EntityG2BServices.Result()
                            Dim objCustAuth As New EntityG2BServices.CustomerAuthFieldDefinitionType()

                            If lMSOOffer.MSOOffersResult IsNot Nothing Then
                                objResult.Code = lMSOOffer.MSOOffersResult.Code
                                objResult.Value = lMSOOffer.MSOOffersResult.Value
                            End If

                            If lMSOOffer.Discount IsNot Nothing Then
                                lstDiscount = BuildDiscount(lMSOOffer.Discount)
                            End If
                            If lMSOOffer.CustomerAuthFieldDefinition IsNot Nothing Then
                                objCustAuth = ConvertCustAuth(lMSOOffer.CustomerAuthFieldDefinition)
                            End If

                            ' objG2BQueryOffersResponse is the object that is passed
                            ' back to the front end calling layer
                            objG2BQueryOffersResponse = New EntityG2BServices.G2BQueryOffersResponse(objProductCatalog, _
                                lTrackingID, lMSOID, _
                                lAddressSuggestion, objRules, _
                                objResult, objCustAuth, _
                                lstDiscount)
                        End If
                    Next
                    If objG2BQueryOffersResponse Is Nothing Then
                        ' some G2B Error may be returned 
                        If objTempResponse.MSOOffersResponse.Length > 0 Then
                            If objTempResponse.MSOOffersResponse(0).MSOOffersResult.Code <> 0 Then
                                ' Error 15
                                objG2BQueryOffersResponse = New EntityG2BServices.G2BQueryOffersResponse()
                                objG2BQueryOffersResponse.Exception = True
                                objG2BQueryOffersResponse.ExceptionMessage = "G2B Returned Code " & objTempResponse.MSOOffersResponse(0).MSOOffersResult.Code.ToString() & " " & objTempResponse.MSOOffersResponse(0).MSOOffersResult.Value.ToString()
                                objG2BQueryOffersResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(objTempResponse.MSOOffersResponse(0).MSOOffersResult.Code.ToString(), objTempResponse.MSOOffersResponse(0).MSOOffersResult.Value.ToString())
                                Return objG2BQueryOffersResponse
                            End If
                        End If
                    End If
                    '#If DEBUG Then

                    ' For testing purposes, we set up a new application variable.
                    ' This is NOT to be used in UAT or Production.  It exists to
                    ' allow us to populate fields not yet updated in the Recom Message
                    ' Engine (since Recom does not pass any data for these fields yet,
                    ' it is hard to test changes to the Charter.Com Web Server front
                    ' end to validate the display of these new fields).
                    If (System.Web.HttpContext.Current.Application("G2BV41_DummyData") IsNot Nothing) _
                    AndAlso _
                    System.Web.HttpContext.Current.Application("G2BV41_DummyData").Equals("T") Then
                        'make up dummy data 
                        ' TAKE THIS OUT BEFORE GOING LIVE TO PRODUCTION 
                        If objG2BQueryOffersResponse.ProductCatalog IsNot Nothing Then
                            If objG2BQueryOffersResponse.ProductCatalog.ServicePlans IsNot Nothing Then
                                For Each kvp As KeyValuePair(Of String, ServicePlan) In objG2BQueryOffersResponse.ProductCatalog.ServicePlans
                                    Dim objSP As ServicePlan = TryCast(kvp.Value, ServicePlan)
                                    If objSP IsNot Nothing Then
                                        objSP.ContractDescription = "Contract Description For " + objSP.ID
                                        objSP.ContractTermsAndConditions = "Contract Terms and Conditions for " + objSP.ID
                                        If objSP.Requirements Is Nothing OrElse objSP.Requirements = String.Empty Then
                                            objSP.Requirements = "Requirements for " + objSP.ID
                                        End If
                                    End If
                                Next
                            End If
                            If objG2BQueryOffersResponse.ProductCatalog.Bundles IsNot Nothing Then
                                For Each kvp As KeyValuePair(Of String, Bundle) In objG2BQueryOffersResponse.ProductCatalog.Bundles
                                    Dim objSP As Bundle = TryCast(kvp.Value, Bundle)
                                    If objSP IsNot Nothing Then
                                        objSP.Contract = New EntityG2BServices.ContractType()
                                        objSP.Contract.Description = "Contract Description For " + objSP.ID
                                        objSP.Contract.TermsAndConditions = "Contract Terms and Conditions for " + objSP.ID
                                        If objSP.DataExtension.Requirements Is Nothing _
                                          OrElse _
                                           objSP.DataExtension.Requirements = String.Empty Then
                                            objSP.DataExtension.Requirements = "HSD Requirements for Bundle " + objSP.ID
                                        End If
                                        If objSP.VoiceExtension.Requirements Is Nothing _
                                           OrElse _
                                           objSP.VoiceExtension.Requirements = String.Empty Then
                                            objSP.VoiceExtension.Requirements = "Telephony Requirements for Bundle " + objSP.ID
                                        End If
                                        If objSP.VideoExtension.Requirements Is Nothing _
                                            OrElse _
                                           objSP.VideoExtension.Requirements = String.Empty Then
                                            objSP.VideoExtension.Requirements = "Cable Requirements for Bundle " + objSP.ID
                                        End If
                                    End If
                                Next
                            End If
                        End If
                    End If
                    '#End If



                    Return objG2BQueryOffersResponse
                Else
                    'Throw New Exception(Constant.EXCEPTION_NO_RESULT_QUERYOFFERS )
                    If objG2BQueryOffersResponse Is Nothing Then
                        objG2BQueryOffersResponse = New EntityG2BServices.G2BQueryOffersResponse()
                    End If
                    ' Error 16
                    ProviderManager.FormatG2BCommonResponse(objG2BQueryOffersResponse, _
                        Constant.EXCEPTION_NO_RESULT_QUERYOFFERS_CODE, "No Response Received from QueryOffers call")
                    Return objG2BQueryOffersResponse
                End If
            Else
                'Throw New Exception(Constant.EXCEPTION_INVALID_INPUT)
                If objG2BQueryOffersResponse Is Nothing Then
                    objG2BQueryOffersResponse = New EntityG2BServices.G2BQueryOffersResponse()
                End If
                ' Error 17
                ProviderManager.FormatG2BCommonResponse(objG2BQueryOffersResponse, _
                    Constant.EXCEPTION_INVALID_Request_QUERYOFFERS_CODE, "QueryOffers Call received invalid input Request object")
                Return objG2BQueryOffersResponse
            End If
        Catch ex As System.Web.Services.Protocols.SoapException
            If objG2BQueryOffersResponse Is Nothing Then
                objG2BQueryOffersResponse = New EntityG2BServices.G2BQueryOffersResponse()
            End If
            objG2BQueryOffersResponse.Exception = True
            objG2BQueryOffersResponse.ExceptionMessage = "URL: " & _wsG2BV41.Url & _
                    "<BR/>Message: " & ex.Message & _
                    "<BR/>Detail: " & ex.Detail.InnerText
            objG2BQueryOffersResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 18
            objG2BQueryOffersResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_INVALID_RESPONSE_QUERYOFFERS_CODE, ex.Detail.Name + " " + ex.Detail.InnerText)
            Return objG2BQueryOffersResponse

        Catch ex As Exception
            If objG2BQueryOffersResponse Is Nothing Then
                objG2BQueryOffersResponse = New EntityG2BServices.G2BQueryOffersResponse()
            End If
            objG2BQueryOffersResponse.Exception = True
            objG2BQueryOffersResponse.ExceptionMessage = ex.Message
            objG2BQueryOffersResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 19
            objG2BQueryOffersResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_NO_RESULT_QUERYOFFERS_CODE, "No Response Received from QueryOffers call")
            Return objG2BQueryOffersResponse
        End Try
    End Function

    ''' <summary> 
    ''' ReSubmit a QueryOffers request to G2B 
    ''' </summary> 
    ''' <param name="pobjRequest">Query offers input parameters, in the G2BQueryOffersRequest format</param> 
    ''' <returns>G2BQueryOffersResponse object</returns> 
    ''' <remarks>This method acts as a pass-through between the 
    ''' Web Server charter.com front end and the G2B Web Service. 
    ''' It re-formats data [provided by Charter.com for a 
    ''' QueryOffersResubmit message] into the G2B Input request format, 
    ''' calls the G2B web service, and packages the G2B output into 
    ''' something the front-end can utilize.</remarks> 
    Public Overloads Overrides Function QueryOffersResubmit(ByVal pobjRequest As IProviderParameters) As IProviderResults
        Dim lG2BQueryOffersResubmitRequest As EntityG2BServices.G2BQueryOffersResubmitRequest = Nothing
        Dim objQueryOffersResubmitRequest As New nsWS.QueryOffersResubmit()

        Dim lTrackingID As Integer
        Dim lMSOID As Integer
        Dim lAddressID As String = String.Empty
        Dim objG2BQueryOffersResubmitResponse As EntityG2BServices.G2BQueryOffersResubmitResponse = Nothing
        Dim lItems As nsWS.OfferType() = Nothing
        Dim lstItems As New List(Of EntityG2BServices.OfferType)()
        Dim lstDiscount As New List(Of EntityG2BServices.DiscountTypeQueryOffers)()

        Dim lSubscriber As nsWS.CableServiceEnum()
        Dim lG2BSubscriber As EntityG2BServices.CableServiceEnum() = Nothing
        Dim lName As String = String.Empty
        Dim lURL As String = String.Empty
        Dim lPhone As String = String.Empty
        Dim lLanguage As String = String.Empty

        Dim objTempResponse As nsWS.QueryOffersResubmitResponse
        Dim objProductCatalog As ProductCatalog = Nothing
        Dim objRules As Rules
        Dim objResult As New EntityG2BServices.Result()

        Try
            lG2BQueryOffersResubmitRequest = TryCast(pobjRequest, EntityG2BServices.G2BQueryOffersResubmitRequest)
            If lG2BQueryOffersResubmitRequest IsNot Nothing Then
                lTrackingID = lG2BQueryOffersResubmitRequest.TrackingID
                lMSOID = lG2BQueryOffersResubmitRequest.MSOID
                lAddressID = lG2BQueryOffersResubmitRequest.AddressID
                _intRegionID = lG2BQueryOffersResubmitRequest.RegionID
                _intKMAId = lG2BQueryOffersResubmitRequest.KMAID
                _intBillingStationID = lG2BQueryOffersResubmitRequest.BillingStationID
                _strFTAID = lG2BQueryOffersResubmitRequest.FTA
                ' wsQueryOffers.Url = Constant.URI_QUERYOFFERS; 

                objQueryOffersResubmitRequest.TrackingID = lTrackingID
                objQueryOffersResubmitRequest.MSOID = lMSOID
                objQueryOffersResubmitRequest.AddressID = lAddressID

                ' make the web service call 
                objTempResponse = _wsG2BV41.QueryOffersResubmit(objQueryOffersResubmitRequest)

                If objTempResponse Is Nothing Then
                    If objG2BQueryOffersResubmitResponse Is Nothing Then
                        objG2BQueryOffersResubmitResponse = New EntityG2BServices.G2BQueryOffersResubmitResponse()
                    End If
                    ' Error 20
                    ProviderManager.FormatG2BCommonResponse(objG2BQueryOffersResubmitResponse, _
                        Constant.EXCEPTION_NO_RESULT_QUERYOFFERSRESUBMIT_CODE, "No Response Received from QueryOffersResubmit call")
                    Return objG2BQueryOffersResubmitResponse
                    'Throw New Exception(Constant.EXCEPTION_NO_RESULT)
                End If
                ' formerly 'out' parameters, now just part of 
                ' the returned object 

                If objTempResponse.Subscriber IsNot Nothing Then
                    lSubscriber = objTempResponse.Subscriber
                    lG2BSubscriber = New EntityG2BServices.CableServiceEnum(lSubscriber.Length - 1) {}
                    For iItem As Integer = 0 To lSubscriber.Length - 1
                        lG2BSubscriber(iItem) = New EntityG2BServices.CableServiceEnum()
                        lG2BSubscriber(iItem) = ConvertCableService(lSubscriber(iItem))
                    Next
                End If
                lTrackingID = objTempResponse.TrackingID
                lMSOID = objTempResponse.MSOID
                If objTempResponse.Items IsNot Nothing Then
                    lItems = objTempResponse.Items
                    lstItems = BuildItems(lItems)
                End If

                If objTempResponse.Discount IsNot Nothing Then
                    lstDiscount = BuildDiscount(objTempResponse.Discount)
                End If
                If objTempResponse.Subscriber IsNot Nothing Then
                    lSubscriber = objTempResponse.Subscriber
                End If

                If objTempResponse.Name IsNot Nothing Then
                    lName = objTempResponse.Name
                End If

                If objTempResponse.URL IsNot Nothing Then
                    lURL = objTempResponse.URL
                End If

                If objTempResponse.Phone IsNot Nothing Then
                    lPhone = objTempResponse.Phone
                End If

                If objTempResponse.Language IsNot Nothing Then
                    lLanguage = objTempResponse.Language
                End If

                If objTempResponse.AddressID IsNot Nothing Then
                    lAddressID = objTempResponse.AddressID
                End If
                If objTempResponse.QueryOffersResubmitResult IsNot Nothing Then
                    objResult.Code = objTempResponse.QueryOffersResubmitResult.Code
                    objResult.Value = objTempResponse.QueryOffersResubmitResult.Value
                End If

                objProductCatalog = BuildProductCatalog(lItems, lG2BQueryOffersResubmitRequest.AffliateID, lTrackingID)
                objRules = BuildRules()
                objG2BQueryOffersResubmitResponse = New EntityG2BServices.G2BQueryOffersResubmitResponse(objProductCatalog, objRules, objResult, lstItems, lstDiscount, lG2BSubscriber, _
                lTrackingID, lMSOID, lAddressID, lName, lURL, lPhone, _
                lLanguage)

                Return objG2BQueryOffersResubmitResponse
            Else
                'Throw New Exception(Constant.EXCEPTION_INVALID_INPUT)
                If objG2BQueryOffersResubmitResponse Is Nothing Then
                    objG2BQueryOffersResubmitResponse = New EntityG2BServices.G2BQueryOffersResubmitResponse()
                End If
                ' Error 21
                ProviderManager.FormatG2BCommonResponse(objG2BQueryOffersResubmitResponse, Constant.EXCEPTION_INVALID_Request_QUERYOFFERSRESUBMIT_CODE, "QueryOffersResubmit received empty Input Request object")
                Return objG2BQueryOffersResubmitResponse
            End If

        Catch ex As System.Web.Services.Protocols.SoapException
            If objG2BQueryOffersResubmitResponse Is Nothing Then
                objG2BQueryOffersResubmitResponse = New EntityG2BServices.G2BQueryOffersResubmitResponse()
            End If
            objG2BQueryOffersResubmitResponse.Exception = True
            objG2BQueryOffersResubmitResponse.ExceptionMessage = ex.Detail.InnerText + " " + ex.Message
            objG2BQueryOffersResubmitResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 22
            objG2BQueryOffersResubmitResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_INVALID_RESPONSE_QUERYOFFERSRESUBMIT_CODE, ex.Detail.Name + " " + ex.Detail.InnerText)
            Return objG2BQueryOffersResubmitResponse

        Catch ex As Exception
            If objG2BQueryOffersResubmitResponse Is Nothing Then
                objG2BQueryOffersResubmitResponse = New EntityG2BServices.G2BQueryOffersResubmitResponse()
            End If
            objG2BQueryOffersResubmitResponse.Exception = True
            objG2BQueryOffersResubmitResponse.ExceptionMessage = ex.Message
            objG2BQueryOffersResubmitResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 23
            objG2BQueryOffersResubmitResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_NO_RESULT_QUERYOFFERSRESUBMIT_CODE, "No Response Received from QueryOffersResubmit call")

            Return objG2BQueryOffersResubmitResponse
        End Try

    End Function


    ''' <summary> 
    ''' Authenticate Customer 
    ''' </summary> 
    ''' <param name="pobjParms"></param> 
    ''' <returns>IProviderResults of G2BAuthenticateResponse type</returns> 
    ''' <remarks>This method acts as a pass-through between the 
    ''' Web Server charter.com front end and the G2B Web Service. 
    ''' It re-formats data [provided by Charter.com for a 
    ''' Authenticate message] into the G2B Input request format, 
    ''' calls the G2B web service, and packages the G2B output into 
    ''' something the front-end can utilize.</remarks> 
    Public Overloads Overrides Function Authenticate(ByVal pobjParms As IProviderParameters) As IProviderResults
        ' fields from the app server 
        Dim lAuthRequest As EntityG2BServices.G2BAuthenticateRequest = Nothing
        Dim objAuthResponse As EntityG2BServices.G2BAuthenticateResponse = Nothing

        ' fields for interfacing with G2B 
        Dim objRequest As New nsWS.Authenticate()
        Dim objTempResponse As New nsWS.AuthenticateResponse()

        Dim lTrackingID As Integer
        Dim lMSOID As Integer
        Dim netCredential As NetworkCredential
        Dim lobjURI As Uri
        Dim objCredentials As ICredentials
        Dim objContext As HttpContext

        Try
            lAuthRequest = TryCast(pobjParms, EntityG2BServices.G2BAuthenticateRequest)
            If lAuthRequest IsNot Nothing Then
                lTrackingID = lAuthRequest.TrackingID
                lMSOID = lAuthRequest.MSOID

                'Configure settings for Schedule Install web service 
                objContext = HttpContext.Current
                _wsAuthenticate = New nsWS.G2BV41()
                'if (context.Application[Constant.G2BSERVICESPROVIDER_AUTHENTICATEWEBSERVICE_URL] == null) 
                '{ 
                ' // TODO : For testing only. Set up Application Object to have this new item 
                ' uri = new Uri("https://secure.mso.go2broadband.com/4.1/v41.asmx"); 
                ' wsAuthenticate.Url = uri.ToString(); 
                '} 
                'else 
                '{ 
                lobjURI = New Uri(TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_AUTHENTICATEWEBSERVICE_URL), String))
                _wsAuthenticate.Url = lobjURI.ToString()
                '} 

                If Convert.ToBoolean(objContext.Application(Constant.G2BSERVICESPROVIDER_AUTHENTICATEWEBSERVICE_AUTHENTICATIONREQUIRED)) Then
                    netCredential = New NetworkCredential(TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_AUTHENTICATEWEBSERVICE_USER), String), TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_AUTHENTICATEWEBSERVICE_PASSWORD), String))
                    objCredentials = netCredential.GetCredential(lobjURI, "Basic")
                    _wsAuthenticate.Credentials = objCredentials
                End If
                If Not objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH") Is Nothing Then
                    If objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH").ToString().Trim() <> "" Then
                        _wsAuthenticate.ClientCertificates.Add(X509Certificate.CreateFromCertFile(objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH")))
                    End If
                End If





                ' fill web service interface object with request data 
                objRequest = New nsWS.Authenticate()
                objRequest.MSOID = lMSOID
                objRequest.TrackingID = lTrackingID

                If lAuthRequest.AuthFieldInput IsNot Nothing Then
                    objRequest.AuthFieldInput = New nsWS.AuthFieldInputType(lAuthRequest.AuthFieldInput.Count - 1) {}
                    For iItem As Integer = 0 To lAuthRequest.AuthFieldInput.Count - 1

                        objRequest.AuthFieldInput(iItem) = New nsWS.AuthFieldInputType()
                        objRequest.AuthFieldInput(iItem).AuthFieldID = lAuthRequest.AuthFieldInput(iItem).ID
                        objRequest.AuthFieldInput(iItem).Value = lAuthRequest.AuthFieldInput(iItem).Value
                    Next
                End If

                'If (lAuthRequest.CreditCard IsNot Nothing) Then
                '    objRequest.CreditCard = convertCreditCard(lAuthRequest.CreditCard)
                'End If

                objRequest.DateOfBirth = lAuthRequest.DateOfBirth

                If lAuthRequest.DriversLicense IsNot Nothing Then
                    If lAuthRequest.DriversLicense.Trim() <> String.Empty Then
                        objRequest.DriversLicense = lAuthRequest.DriversLicense
                    End If
                End If

                If lAuthRequest.DriversLicenseState IsNot Nothing Then
                    If lAuthRequest.DriversLicenseState.Trim() <> String.Empty Then
                        objRequest.DriversLicenseState = lAuthRequest.DriversLicenseState
                    End If
                End If

                If lAuthRequest.FirstName IsNot Nothing Then
                    If lAuthRequest.FirstName.Trim() <> String.Empty Then
                        objRequest.FirstName = lAuthRequest.FirstName
                    End If
                End If

                If lAuthRequest.LastName IsNot Nothing Then
                    If lAuthRequest.LastName.Trim() <> String.Empty Then
                        objRequest.LastName = lAuthRequest.LastName
                    End If
                End If

                objRequest.NewCustomer = lAuthRequest.NewCustomer
                If lAuthRequest.ServiceAddress IsNot Nothing Then
                    objRequest.ServiceAddress = ConvertUnparsedUSAddress(lAuthRequest.ServiceAddress)
                End If

                If lAuthRequest.ServiceAddressPhone IsNot Nothing Then
                    If lAuthRequest.ServiceAddressPhone.Trim() <> String.Empty Then
                        objRequest.ServiceAddressPhone = lAuthRequest.ServiceAddressPhone
                    End If
                End If

                If lAuthRequest.SocialSecurityNumber IsNot Nothing Then
                    If lAuthRequest.SocialSecurityNumber.Trim() <> String.Empty Then
                        objRequest.SocialSecurityNumber = lAuthRequest.SocialSecurityNumber
                    End If
                End If

                'If lAuthRequest.SSN4 IsNot Nothing Then
                '    If lAuthRequest.SSN4.Trim() <> String.Empty Then
                '        objRequest.SSN4 = lAuthRequest.SSN4
                '    End If
                'End If

                ' make the web service call 
                objTempResponse = _wsAuthenticate.Authenticate(objRequest)

                If objTempResponse Is Nothing Then
                    'Throw New Exception(Constant.EXCEPTION_NO_RESULT)
                    If objAuthResponse Is Nothing Then
                        objAuthResponse = New EntityG2BServices.G2BAuthenticateResponse()
                    End If
                    ' Error 24
                    ProviderManager.FormatG2BCommonResponse(objAuthResponse, _
                        Constant.EXCEPTION_NO_RESULT_AUTHENTICATE_CODE, "No Response Received from Authenticate call")
                    Return objAuthResponse
                End If

                lTrackingID = objTempResponse.TrackingID
                lMSOID = objTempResponse.MSOID

                Dim authResult As New EntityG2BServices.Result()
                If objTempResponse.AuthenticateResult IsNot Nothing Then
                    authResult.Code = objTempResponse.AuthenticateResult.Code
                    authResult.Value = objTempResponse.AuthenticateResult.Value
                End If

                '------------------------------------------------ 
                'if (String.Compare(objTempResponse.AuthenticateResult.Value, Constant.RESPONSE_SUCCESS, StringComparison.OrdinalIgnoreCase) != 0) 
                '{ 
                ' throw new Exception(objTempResponse.AuthenticateResult.Value); 
                '} 

                objAuthResponse = New EntityG2BServices.G2BAuthenticateResponse(lTrackingID, lMSOID, authResult)

                Return objAuthResponse
            Else
                'Throw New Exception(Constant.EXCEPTION_INVALID_INPUT)
                If objAuthResponse Is Nothing Then
                    objAuthResponse = New EntityG2BServices.G2BAuthenticateResponse()
                End If
                ' Error 25
                ProviderManager.FormatG2BCommonResponse(objAuthResponse, _
                    Constant.EXCEPTION_INVALID_Request_AUTHENTICATE_CODE, "Authenticate received empty Input Request object")
                Return objAuthResponse
            End If

        Catch ex As System.Web.Services.Protocols.SoapException
            If objAuthResponse Is Nothing Then
                objAuthResponse = New EntityG2BServices.G2BAuthenticateResponse()
            End If
            objAuthResponse.Exception = True
            objAuthResponse.ExceptionMessage = ex.Detail.InnerText + " " + ex.Message
            objAuthResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 26
            objAuthResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_INVALID_RESPONSE_AUTHENTICATE_CODE, ex.Detail.Name + " " + ex.Detail.InnerText)
            Return objAuthResponse

        Catch ex As Exception
            If objAuthResponse Is Nothing Then
                objAuthResponse = New EntityG2BServices.G2BAuthenticateResponse()
            End If
            objAuthResponse.Exception = True
            objAuthResponse.ExceptionMessage = ex.Message
            objAuthResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 27
            objAuthResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_NO_RESULT_AUTHENTICATE_CODE, "No Response Received from Authenticate call")
            Return objAuthResponse
        End Try

    End Function

    ''' <summary> 
    ''' Schedule installation 
    ''' </summary> 
    ''' <param name="pobjParms">Installation Parameters of G2BScheduleInstallRequest Type</param> 
    ''' <returns>Provider Results of G2BScheduleInstallResponse type</returns> 
    ''' <remarks>This method acts as a pass-through between the 
    ''' Web Server charter.com front end and the G2B Web Service. 
    ''' It re-formats data [provided by Charter.com for a 
    ''' ScheduleInstall message] into the G2B Input request format, 
    ''' calls the G2B web service, and packages the G2B output into 
    ''' something the front-end can utilize.</remarks> 
    Public Overloads Overrides Function ScheduleInstall(ByVal pobjParms As IProviderParameters) As IProviderResults
        Dim lScheduleInstallRequest As EntityG2BServices.G2BScheduleInstallRequest = Nothing
        Dim objScheduleInstallResponse As EntityG2BServices.G2BScheduleInstallResponse = Nothing
        Dim objRequest As New nsWS.ScheduleInstall()
        Dim objTempResponse As New nsWS.ScheduleInstallResponse()

        Dim lOfferOrder As nsWS.OfferOrderInstallType() = Nothing
        Dim lTrackingID As Integer
        Dim lAddressID As String
        Dim lMSOID As Integer
        Dim lInstallWindowConfirmation As nsWS.InstallWindowConfirmationType() = Nothing
        Dim lItemsChoiceType As nsWS.ItemsChoiceType() = Nothing
        Dim items As String() = Nothing
        Dim counterI As Integer = 0
        Dim counterK As Integer = 0
        Dim objInstallWindowConfirmationType As New List(Of EntityG2BServices.InstallWindowConfirmationType)()
        Dim netCredential As NetworkCredential
        Dim lobjURI As Uri
        Dim objCredentials As ICredentials
        Dim objContext As HttpContext

        Try
            lScheduleInstallRequest = TryCast(pobjParms, EntityG2BServices.G2BScheduleInstallRequest)
            If lScheduleInstallRequest IsNot Nothing Then
                If lScheduleInstallRequest.OfferOrder IsNot Nothing Then
                    lOfferOrder = New nsWS.OfferOrderInstallType(lScheduleInstallRequest.OfferOrder.Count - 1) {}
                    counterI = 0
                    For Each offer As EntityG2BServices.OfferOrderTypeG2BScheduleInstall In lScheduleInstallRequest.OfferOrder
                        lOfferOrder(counterI) = New nsWS.OfferOrderInstallType()
                        If offer.Items IsNot Nothing Then
                            items = New String(offer.Items.Count - 1) {}
                            counterK = 0
                            For Each item As String In offer.Items
                                items(counterK) = item
                                counterK += 1
                            Next
                        End If
                        lOfferOrder(counterI).Items = items

                        'if (offer.ServiceLineID != null) 
                        ' lOfferOrder[counterI].ServiceLineID = offer.ServiceLineID; 

                        If offer.ItemsElementName IsNot Nothing Then
                            lItemsChoiceType = New nsWS.ItemsChoiceType(offer.ItemsElementName.Count - 1) {}
                            counterK = 0

                            For Each itemsChoice As nsWS.ItemsChoiceType In offer.ItemsElementName
                                lItemsChoiceType(counterK) = itemsChoice
                                counterK += 1
                            Next
                        End If
                        lOfferOrder(counterI).ItemsElementName = lItemsChoiceType
                        lOfferOrder(counterI).OfferID = offer.OfferID
                        lOfferOrder(counterI).OrderConfirmationID = offer.OrderConfirmationID
                        counterI += 1
                    Next
                End If
                lTrackingID = lScheduleInstallRequest.TrackingID
                lMSOID = lScheduleInstallRequest.MSOID
                lAddressID = lScheduleInstallRequest.AddressID
                'Configure settings for Schedule Install web service 
                objContext = HttpContext.Current

                _wsScheduleInstall = New nsWS.G2BV41()
                lobjURI = New Uri(TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_SCHEDULEINSTALLWEBSERVICE_URL), String))
                _wsScheduleInstall.Url = lobjURI.ToString()

                If Convert.ToBoolean(objContext.Application(Constant.G2BSERVICESPROVIDER_SCHEDULEINSTALLWEBSERVICE_AUTHENTICATIONREQUIRED)) Then
                    netCredential = New NetworkCredential(TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_SCHEDULEINSTALLWEBSERVICE_USER), String), TryCast(objContext.Application(Constant.G2BSERVICESPROVIDER_SCHEDULEINSTALLWEBSERVICE_PASSWORD), String))
                    objCredentials = netCredential.GetCredential(lobjURI, "Basic")
                    _wsScheduleInstall.Credentials = objCredentials
                End If
                If Not objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH") Is Nothing Then
                    If objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH").ToString().Trim() <> "" Then
                        _wsScheduleInstall.ClientCertificates.Add(X509Certificate.CreateFromCertFile(objContext.Application("G2B4_1_CERTIFICATE_FILE_PATH")))
                    End If
                End If







                objRequest = New nsWS.ScheduleInstall()
                objRequest.AddressID = lAddressID
                objRequest.MSOID = lMSOID
                objRequest.TrackingID = lTrackingID
                objRequest.OfferOrder = lOfferOrder

                ' make the web service call 
                objTempResponse = _wsScheduleInstall.ScheduleInstall(objRequest)

                If objTempResponse Is Nothing Then
                    'Throw New Exception(Constant.EXCEPTION_NO_RESULT)
                    If objScheduleInstallResponse Is Nothing Then
                        objScheduleInstallResponse = New EntityG2BServices.G2BScheduleInstallResponse()
                    End If
                    ' Error 28
                    ProviderManager.FormatG2BCommonResponse(objScheduleInstallResponse, _
                        Constant.EXCEPTION_NO_RESULT_SCHEDULEINSTALL_CODE, "No Response Received from ScheduleInstall call")
                    Return objScheduleInstallResponse
                End If

                ' formerly "out" parameters, now just part of the 
                ' returned object Response 
                lTrackingID = objTempResponse.TrackingID
                lMSOID = objTempResponse.MSOID
                If objTempResponse.AddressID IsNot Nothing Then
                    lAddressID = objTempResponse.AddressID
                End If
                If objTempResponse.InstallWindowConfirmation IsNot Nothing Then
                    lInstallWindowConfirmation = objTempResponse.InstallWindowConfirmation
                End If
                '------------------------------------------------ 
                If [String].Compare(objTempResponse.ScheduleInstallResult.Value, Constant.RESPONSE_SUCCESS, StringComparison.OrdinalIgnoreCase) <> 0 Then
                    'Throw New Exception(objTempResponse.ScheduleInstallResult.Value)
                    If objScheduleInstallResponse Is Nothing Then
                        objScheduleInstallResponse = New EntityG2BServices.G2BScheduleInstallResponse()
                    End If
                    ' Error 29
                    ProviderManager.FormatG2BCommonResponse(objScheduleInstallResponse, _
                        objTempResponse.ScheduleInstallResult.Code, objTempResponse.ScheduleInstallResult.Value)
                    Return objScheduleInstallResponse
                End If

                If lInstallWindowConfirmation IsNot Nothing Then
                    For Each confirmation As nsWS.InstallWindowConfirmationType In lInstallWindowConfirmation
                        objInstallWindowConfirmationType.Add(New EntityG2BServices.InstallWindowConfirmationType(confirmation.OfferID, confirmation.InstallConfirmationID, confirmation.InstallWindowID, confirmation.FollowUpMessage, confirmation.ServiceLineID))
                    Next
                End If

                objScheduleInstallResponse = New EntityG2BServices.G2BScheduleInstallResponse(objInstallWindowConfirmationType, lTrackingID, lMSOID, lAddressID)
                objScheduleInstallResponse.Results = New EntityG2BServices.Result(objTempResponse.ScheduleInstallResult.Code, objTempResponse.ScheduleInstallResult.Value)

                Return objScheduleInstallResponse
            Else
                'Throw New Exception(Constant.EXCEPTION_INVALID_INPUT)
                If objScheduleInstallResponse Is Nothing Then
                    objScheduleInstallResponse = New EntityG2BServices.G2BScheduleInstallResponse()
                End If
                ' Error 30
                ProviderManager.FormatG2BCommonResponse(objScheduleInstallResponse, _
                    Constant.EXCEPTION_INVALID_Request_SCHEDULEINSTALL_CODE, "QueryOffersResubmit received empty Input Request object")
                Return objScheduleInstallResponse

            End If
        Catch ex As System.Web.Services.Protocols.SoapException
            If objScheduleInstallResponse Is Nothing Then
                objScheduleInstallResponse = New EntityG2BServices.G2BScheduleInstallResponse()
            End If
            objScheduleInstallResponse.Exception = True
            objScheduleInstallResponse.ExceptionMessage = ex.Detail.InnerText + " " + ex.Message
            objScheduleInstallResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 31
            objScheduleInstallResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_INVALID_RESPONSE_SCHEDULEINSTALL_CODE, ex.Detail.Name + " " + ex.Detail.InnerText)
            Return objScheduleInstallResponse

        Catch ex As Exception
            If objScheduleInstallResponse Is Nothing Then
                objScheduleInstallResponse = New EntityG2BServices.G2BScheduleInstallResponse()
            End If
            objScheduleInstallResponse.Exception = True
            objScheduleInstallResponse.ExceptionMessage = ex.Message
            objScheduleInstallResponse.ExceptionStackTrace = ex.StackTrace
            ' Error 32
            objScheduleInstallResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_NO_RESULT_SCHEDULEINSTALL_CODE, "No Response Received from ScheduleInstall call")
            Return objScheduleInstallResponse
        End Try
    End Function

#End Region

#Region "Convert From G2B to Local Objects"

    ''' <summary> 
    ''' Convert a g2b-web service Promotion into a local common 
    ''' Promotion object 
    ''' </summary> 
    ''' <param name="pobjPromo">G2B Promotion object</param> 
    ''' <returns>local PromotionType object</returns> 
    Private Function ConvertPromotion(ByVal pobjPromo As nsWS.PromotionType) As EntityG2BServices.PromotionType
        Dim objPromo As EntityG2BServices.PromotionType = Nothing

        If pobjPromo IsNot Nothing Then
            objPromo = New EntityG2BServices.PromotionType(pobjPromo.PromotionID, pobjPromo.Name, pobjPromo.StartDate, pobjPromo.StartDateSpecified, pobjPromo.EndDate, pobjPromo.EndDateSpecified, _
            pobjPromo.Disclaimer, pobjPromo.Value, pobjPromo.ValueSpecified, pobjPromo.Value1)
        End If
        Return objPromo
    End Function

    ''' <summary> 
    ''' Convert G2B Marketing data into local MarketingInfoType 
    ''' </summary> 
    ''' <param name="pobjMktInfo">G2B Marketing Info</param> 
    ''' <returns>MarketingInfoType</returns> 
    Private Function ConvertMarketingInfo(ByVal pobjMktInfo As nsWS.MarketingInfoType) As EntityG2BServices.MarketingInfoType
        Dim objMktInfo As EntityG2BServices.MarketingInfoType = Nothing
        Dim strBullets As String() = New String(-1) {}
        Dim strText As String() = New String(-1) {}
        Dim strMain As String = String.Empty

        If pobjMktInfo.Bullet IsNot Nothing Then
            strBullets = New String(pobjMktInfo.Bullet.Length - 1) {}
            For iItem As Integer = 0 To pobjMktInfo.Bullet.Length - 1
                strBullets(iItem) = pobjMktInfo.Bullet(iItem).ToString()
            Next
        End If

        If pobjMktInfo.Text IsNot Nothing Then
            strText = New String(pobjMktInfo.Text.Length - 1) {}
            For iItem As Integer = 0 To pobjMktInfo.Text.Length - 1
                strText(iItem) = pobjMktInfo.Text(iItem).ToString()
            Next
        End If

        If pobjMktInfo.Main IsNot Nothing Then
            strMain = pobjMktInfo.Main
        End If

        objMktInfo = New EntityG2BServices.MarketingInfoType(strMain, strBullets, strText)
        Return objMktInfo
    End Function

    ''' <summary>
    ''' Convert a G2B Data Extension into local DataExtension type
    ''' </summary>
    ''' <param name="pobjDataExt">G2B Data Extension to be converted</param>
    ''' <returns>EntityG2BServices.DataExtensionType</returns>
    Private Function ConvertDataExtension(ByVal pobjDataExt As ServicePlan) As EntityG2BServices.DataExtensionType
        Dim objDataExt As New EntityG2BServices.DataExtensionType()

        If pobjDataExt IsNot Nothing Then
            objDataExt.DialUpAccess = pobjDataExt.dialupAccess

            objDataExt.DownloadSpeed = pobjDataExt.downloadSpeed
            objDataExt.DynamicIPAddresses = pobjDataExt.dynamicIPAddresses
            objDataExt.EmailAccounts = pobjDataExt.emailAccounts
            objDataExt.Requirements = pobjDataExt.Requirements
            objDataExt.ServiceLineID = pobjDataExt.ServiceType.ToString()
            objDataExt.StaticIPAddresses = pobjDataExt.staticIPAddresses
            objDataExt.UploadSpeed = pobjDataExt.uploadSpeed
            objDataExt.Webspace = pobjDataExt.webspace
            objDataExt.ServiceLineID = pobjDataExt.ServiceType.ToString()

            objDataExt.Requirements = pobjDataExt.Requirements
        End If
        Return objDataExt
    End Function

    ''' <summary>
    ''' Convert a G2B Voice Extension object into local VoiceExtension Type
    ''' </summary>
    ''' <param name="pobjVoiceExt">G2B Voice Extension to be converted</param>
    ''' <returns>EntityG2BServices.VoiceExtensionType</returns>
    Private Function ConvertVoiceExtension(ByVal pobjVoiceExt As ServicePlan) As EntityG2BServices.VoiceExtensionType
        Dim objVoiceExt As New EntityG2BServices.VoiceExtensionType()

        If pobjVoiceExt IsNot Nothing Then
            objVoiceExt.AdditionalLinePrice = pobjVoiceExt.additionalLinePrice
            objVoiceExt.Includes3WayCalling = pobjVoiceExt.includes3WayCalling
            objVoiceExt.IncludesCallerID = pobjVoiceExt.includesCallerID
            objVoiceExt.IncludesCallerIDWithCallWaiting = pobjVoiceExt.includesCallerIDWithCallWaiting
            objVoiceExt.IncludesCallReturn = pobjVoiceExt.includesCallReturn
            objVoiceExt.IncludesCallWaiting = pobjVoiceExt.includesCallWaiting
            objVoiceExt.InternationalPrice = pobjVoiceExt.internationalPrice
            objVoiceExt.LongDistanceCharges = pobjVoiceExt.longDistanceCharges
            objVoiceExt.LongDistanceMinutes = DefaultString(pobjVoiceExt.longDistanceMinutes)
            objVoiceExt.ServiceLineID = pobjVoiceExt.ServiceType.ToString()
            objVoiceExt.VoiceMailPrice = pobjVoiceExt.voiceMailPrice
            objVoiceExt.Requirements = pobjVoiceExt.Requirements
        End If
        Return objVoiceExt
    End Function

    ''' <summary>
    ''' Convert a G2B Video Extension object into local VideoExtension Type
    ''' </summary>
    ''' <param name="pobjVideoExt">G2B Video Extension to be converted</param>
    ''' <returns>EntityG2BServices.VideoExtensionType</returns>
    Private Function ConvertVideoExtension(ByVal pobjVideoExt As ServicePlan) As EntityG2BServices.VideoExtensionType
        Dim objVideoExt As New EntityG2BServices.VideoExtensionType()

        If pobjVideoExt IsNot Nothing Then
            objVideoExt.Category = pobjVideoExt.VideoCategory
            objVideoExt.Channels = pobjVideoExt.channels
            objVideoExt.ServiceLineID = pobjVideoExt.ServiceType.ToString()
            objVideoExt.Requirements = pobjVideoExt.Requirements
        End If
        Return objVideoExt
    End Function

    ''' <summary>
    ''' Convert local Customer Hardware Type List into G2B Customer Hardware Type List 
    ''' </summary>
    ''' <param name="plstCustHardware">Local Customer Hardware List</param>
    ''' <returns>G2B Customer Hardware Type List</returns>
    ''' <remarks></remarks>
    Private Function ConvertCustomerHardware(ByVal plstCustHardware As List(Of EntityG2BServices.CustomerHardwareType)) As nsWS.CustomerHardwareType()

        Dim objHWOut As nsWS.CustomerHardwareType() = Nothing
        If plstCustHardware IsNot Nothing AndAlso plstCustHardware.Count > 0 Then
            objHWOut = New nsWS.CustomerHardwareType(plstCustHardware.Count - 1) {}
            For iItem As Integer = 0 To plstCustHardware.Count - 1

                objHWOut(iItem) = New G2BServicesProvider.WSG2B.CustomerHardwareType()
                objHWOut(iItem).Category = Convert_ToWSHWCategory(plstCustHardware(iItem).Category)
                objHWOut(iItem).CategorySpecified = plstCustHardware(iItem).CategorySpecified
                If plstCustHardware(iItem).MACAddress IsNot Nothing Then
                    objHWOut(iItem).MACAddress = plstCustHardware(iItem).MACAddress
                End If
                If plstCustHardware(iItem).SerialNumber IsNot Nothing Then
                    objHWOut(iItem).SerialNumber = plstCustHardware(iItem).SerialNumber
                End If
            Next
        End If

        Return objHWOut
    End Function

    ''' <summary> 
    ''' Build a local (EntityG2BServices namespace)  CustomizationType from a Web Service G2B Customization Type 
    ''' </summary> 
    ''' <param name="pobjCustomization">G2B CustomizationType list</param> 
    ''' <returns>CustomizationType Query offers object</returns> 
    Private Function ConvertCustomization(ByVal pobjCustomization As nsWS.CustomizationType) As EntityG2BServices.CustomizationTypeQueryOffers
        Dim objCustomization As EntityG2BServices.CustomizationTypeQueryOffers = Nothing
        Dim objItems As Object() = Nothing
        Dim strName As String = String.Empty
        Dim enumCategory As EntityG2BServices.CustomizationCategoryEnum = EntityG2BServices.CustomizationCategoryEnum.m_Other

        Dim dctIntItems As New Dictionary(Of Int32, Int32)()
        Dim dctSelType As Dictionary(Of Int32, EntityG2BServices.SelectionType) = New Dictionary(Of Integer, EntityG2BServices.SelectionType)()
        Dim dctInputText As Dictionary(Of Int32, EntityG2BServices.InputTextType) = New Dictionary(Of Integer, EntityG2BServices.InputTextType)()
        Dim dctInputNumber As Dictionary(Of Int32, EntityG2BServices.InputNumberType) = New Dictionary(Of Integer, EntityG2BServices.InputNumberType)()

        If pobjCustomization.Items IsNot Nothing Then
            objItems = New Object(pobjCustomization.Items.Length - 1) {}
            For iItem As Integer = 0 To pobjCustomization.Items.Length - 1
                If pobjCustomization.Items(iItem) IsNot Nothing Then
                    objItems(iItem) = pobjCustomization.Items(iItem)

                    ' build special, distinctly typed dictionaries 
                    ' for each of the three possible types of a 
                    ' customization. The "Object" array cannot be 
                    ' de-serialized by the front-end. 
                    If objItems(iItem).[GetType]().FullName = GetType(Integer).FullName Then
                        dctIntItems.Add(iItem, Convert.ToInt32(objItems(iItem)))
                    Else
                        If (objItems(iItem).[GetType]().Name = GetType(nsWS.InputTextType).Name) Then
                            dctInputText.Add(iItem, ConvertInputText(TryCast(objItems(iItem), nsWS.InputTextType)))
                        Else
                            If (objItems(iItem).[GetType]().Name = GetType(nsWS.InputNumberType).Name) Then
                                dctInputNumber.Add(iItem, ConvertInputNumber(TryCast(objItems(iItem), nsWS.InputNumberType)))
                            Else
                                If objItems(iItem).[GetType]().Name = GetType(nsWS.SelectionType).Name Then
                                    dctSelType.Add(iItem, ConvertSelectionType(TryCast(objItems(iItem), nsWS.SelectionType)))
                                Else
                                    Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " method found a problem with Item in Customization Collection in not of a valid type. The type was " + objItems(iItem).[GetType]().FullName)
                                End If
                            End If
                        End If
                    End If
                End If
            Next
        End If

        strName = DefaultString(pobjCustomization.Name)

        enumCategory = ConvertCustomizationCategory(pobjCustomization.Category)

        objCustomization = New EntityG2BServices.CustomizationTypeQueryOffers(pobjCustomization.CustomizationID, strName, enumCategory, pobjCustomization.Description)

        objCustomization.IntItems = dctIntItems
        objCustomization.InputNumberItems = dctInputNumber
        objCustomization.InputTextItems = dctInputText
        objCustomization.SelTypeItems = dctSelType
        Return objCustomization
    End Function

    ''' <summary> 
    ''' Convert a G2B web service "InputNumber Type" to a common entity 
    ''' library "InputNumber Type 
    ''' </summary> 
    ''' <param name="pobj">G2B InputNumber Type</param> 
    ''' <returns>EntityG2BServices common entity InputNumber Type</returns> 
    Private Function ConvertInputNumber(ByVal pobj As nsWS.InputNumberType) As EntityG2BServices.InputNumberType
        Dim objReturn As New EntityG2BServices.InputNumberType()

        If pobj IsNot Nothing Then
            objReturn.Max = pobj.Max
            objReturn.Min = pobj.Min
            objReturn.Required = pobj.Required
        End If
        Return objReturn
    End Function

    ''' <summary> 
    ''' Convert a G2B web service "Input Text Type" to a common entity 
    ''' library "Input Text Type 
    ''' </summary> 
    ''' <param name="pobj">G2B Input Text Type</param> 
    ''' <returns>EntityG2BServices common entity Input Text Type</returns> 
    Private Function ConvertInputText(ByVal pobj As nsWS.InputTextType) As EntityG2BServices.InputTextType
        Dim objReturn As New EntityG2BServices.InputTextType()

        If pobj IsNot Nothing Then
            objReturn.Label = pobj.Label
            objReturn.MaxLen = pobj.MaxLen
            objReturn.Required = pobj.Required
        End If
        Return objReturn
    End Function

    ''' <summary> 
    ''' Convert a G2B web service "Selection Type" to a common entity 
    ''' library "Selection Type 
    ''' </summary> 
    ''' <param name="pobj">G2B Selection Type</param> 
    ''' <returns>EntityG2BServices common entity Selection Type</returns> 
    Private Function ConvertSelectionType(ByVal pobj As nsWS.SelectionType) As EntityG2BServices.SelectionType
        Dim objReturn As New EntityG2BServices.SelectionType()

        If pobj IsNot Nothing Then
            objReturn.Min = pobj.Min
            objReturn.Max = pobj.Max
            If pobj.Choice IsNot Nothing AndAlso pobj.Choice.Length > 0 Then
                objReturn.Choice = New EntityG2BServices.ChoiceType(pobj.Choice.Length - 1) {}
                For iItem As Integer = 0 To pobj.Choice.Length - 1
                    objReturn.Choice(iItem) = New EntityG2BServices.ChoiceType()
                    objReturn.Choice(iItem).ChoiceID = pobj.Choice(iItem).ChoiceID
                    objReturn.Choice(iItem).Description = pobj.Choice(iItem).Description
                    objReturn.Choice(iItem).Name = pobj.Choice(iItem).Name
                    If (objReturn.Choice(iItem).ChoiceID = "5257") Then
                        Debug.Write("Got it")
                    End If
                    objReturn.Choice(iItem).Price = ConvertPriceType(pobj.Choice(iItem).Price)
                Next
            End If
        End If
        Return objReturn
    End Function

    ''' <summary> 
    ''' Build a local (EntityG2BServices namespace)  IncludedItemsType from a Web Service G2B Included Items Type 
    ''' </summary> 
    ''' <param name="pobjIncItem"></param> 
    ''' <returns>IncludedItemsType</returns> 
    Private Function ConvertIncludedItem(ByVal pobjIncItem As nsWS.IncludedItemsType) As EntityG2BServices.IncludedItemsType
        Dim objIncItem As EntityG2BServices.IncludedItemsType = Nothing
        Dim strItems As String() = Nothing
        Dim strName As String = String.Empty
        Dim enumCategory As EntityG2BServices.CustomizationCategoryEnum = EntityG2BServices.CustomizationCategoryEnum.m_Other

        If pobjIncItem.Item IsNot Nothing Then
            strItems = New String(pobjIncItem.Item.Length - 1) {}
            For iItem As Integer = 0 To pobjIncItem.Item.Length - 1
                strItems(iItem) = "ID: " + pobjIncItem.Item(iItem).ItemID.ToString() + " Value: " + pobjIncItem.Item(iItem).Value.ToString()
            Next
        End If

        strName = DefaultString(pobjIncItem.Name)

        Select Case pobjIncItem.Category
            Case nsWS.CustomizationCategoryEnum.DataEquipment
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_DataEquipment
                Exit Select
            Case nsWS.CustomizationCategoryEnum.DataFeature
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_DataFeature
                Exit Select
            Case nsWS.CustomizationCategoryEnum.Deposit
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_Deposit
                Exit Select
            Case nsWS.CustomizationCategoryEnum.HDUpgrade
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_HDUpgrade
                Exit Select
            Case nsWS.CustomizationCategoryEnum.Installation
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_Installation
                Exit Select
            Case nsWS.CustomizationCategoryEnum.Other
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_Other
                Exit Select
            Case nsWS.CustomizationCategoryEnum.Premium
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_Premium
                Exit Select
            Case nsWS.CustomizationCategoryEnum.Software
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_Software
                Exit Select
            Case nsWS.CustomizationCategoryEnum.VideoEquipment
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_VideoEquipment
                Exit Select
            Case nsWS.CustomizationCategoryEnum.VideoFeature
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_VideoFeature
                Exit Select
            Case nsWS.CustomizationCategoryEnum.VoiceEquipment
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_VoiceEquipment
                Exit Select
            Case nsWS.CustomizationCategoryEnum.VoiceFeature
                enumCategory = EntityG2BServices.CustomizationCategoryEnum.m_VoiceFeature
                Exit Select
            Case Else
                Exit Select
        End Select
        objIncItem = New EntityG2BServices.IncludedItemsType(strItems, strName, enumCategory)
        Return objIncItem
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  HardwareType from a Web Service G2B HardwareType
    ''' </summary>
    ''' <param name="pobjHWType">Web Service G2B HardwareType</param>
    ''' <returns>HardwareType</returns>
    Private Function ConvertHWType(ByVal pobjHWType As nsWS.HardwareType) As EntityG2BServices.HardwareType
        Dim strMake As String = String.Empty
        Dim strModel As String = String.Empty
        Dim enumHWCategory As EntityG2BServices.HardwareCategoryEnum
        Dim hwType As EntityG2BServices.HardwareType = Nothing

        If pobjHWType.Make IsNot Nothing Then
            strMake = pobjHWType.Make
        End If

        If pobjHWType.Model IsNot Nothing Then
            strModel = pobjHWType.Model
        End If

        enumHWCategory = ConvertHWCategory(pobjHWType.Value)

        hwType = New EntityG2BServices.HardwareType(strMake, strModel, enumHWCategory)
        Return hwType
    End Function

    ''' <summary>
    ''' Build a Web Service HardwareCategoryEnum value from a local G2B HardwareCategoryEnum
    ''' </summary>
    ''' <param name="pobjHWType">Local G2B HardwareCategory Enum value</param>
    ''' <returns>Web Service HardwareCategoryEnum value</returns>
    Private Function Convert_ToWSHWCategory(ByVal pobjHWType As EntityG2BServices.HardwareCategoryEnum) As nsWS.HardwareCategoryEnum
        Dim enumHWCategory As nsWS.HardwareCategoryEnum = nsWS.HardwareCategoryEnum.SetTopBox

        Select Case pobjHWType
            Case EntityG2BServices.HardwareCategoryEnum.m_CableCARD
                enumHWCategory = nsWS.HardwareCategoryEnum.CableCARD
                Exit Select
            Case EntityG2BServices.HardwareCategoryEnum.m_CableModem
                enumHWCategory = nsWS.HardwareCategoryEnum.CableModem
                Exit Select
            Case EntityG2BServices.HardwareCategoryEnum.m_DVRSetTopBox
                enumHWCategory = nsWS.HardwareCategoryEnum.DVRSetTopBox
                Exit Select
            Case EntityG2BServices.HardwareCategoryEnum.m_HDDVRSetTopBox
                enumHWCategory = nsWS.HardwareCategoryEnum.HDDVRSetTopBox
                Exit Select
            Case EntityG2BServices.HardwareCategoryEnum.m_HDSetTopBox
                enumHWCategory = nsWS.HardwareCategoryEnum.HDSetTopBox
                Exit Select
            Case EntityG2BServices.HardwareCategoryEnum.m_MobilePhone
                enumHWCategory = nsWS.HardwareCategoryEnum.MobilePhone
                Exit Select
            Case EntityG2BServices.HardwareCategoryEnum.m_SetTopBox
                enumHWCategory = nsWS.HardwareCategoryEnum.SetTopBox
                Exit Select
            Case EntityG2BServices.HardwareCategoryEnum.m_VoiceModem
                enumHWCategory = nsWS.HardwareCategoryEnum.VoiceModem
                Exit Select
            Case Else
                Exit Select
        End Select
        Return enumHWCategory
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B HardwareCategoryEnum value from a Web Service HardwareCategoryEnum 
    ''' </summary>
    ''' <param name="pobjHWType">Web Service HardwareCategoryEnum value</param>
    ''' <returns>Local G2B HardwareCategory Enum value</returns>
    Private Function ConvertHWCategory(ByVal pobjHWType As nsWS.HardwareCategoryEnum) As EntityG2BServices.HardwareCategoryEnum
        Dim enumHWCategory As EntityG2BServices.HardwareCategoryEnum = EntityG2BServices.HardwareCategoryEnum.m_SetTopBox

        Select Case pobjHWType
            Case nsWS.HardwareCategoryEnum.CableCARD
                enumHWCategory = EntityG2BServices.HardwareCategoryEnum.m_CableCARD
                Exit Select
            Case nsWS.HardwareCategoryEnum.CableModem
                enumHWCategory = EntityG2BServices.HardwareCategoryEnum.m_CableModem
                Exit Select
            Case nsWS.HardwareCategoryEnum.DVRSetTopBox
                enumHWCategory = EntityG2BServices.HardwareCategoryEnum.m_DVRSetTopBox
                Exit Select
            Case nsWS.HardwareCategoryEnum.HDDVRSetTopBox
                enumHWCategory = EntityG2BServices.HardwareCategoryEnum.m_HDDVRSetTopBox
                Exit Select
            Case nsWS.HardwareCategoryEnum.HDSetTopBox
                enumHWCategory = EntityG2BServices.HardwareCategoryEnum.m_HDSetTopBox
                Exit Select
            Case nsWS.HardwareCategoryEnum.MobilePhone
                enumHWCategory = EntityG2BServices.HardwareCategoryEnum.m_MobilePhone
                Exit Select
            Case nsWS.HardwareCategoryEnum.SetTopBox
                enumHWCategory = EntityG2BServices.HardwareCategoryEnum.m_SetTopBox
                Exit Select
            Case nsWS.HardwareCategoryEnum.VoiceModem
                enumHWCategory = EntityG2BServices.HardwareCategoryEnum.m_VoiceModem
                Exit Select
            Case Else
                Exit Select
        End Select
        Return enumHWCategory
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B Eligibility object from a Web Service Eligibility object
    ''' </summary>
    ''' <param name="pobjElig">Web Service Eligibility</param>
    ''' <returns>Local G2B Eligibility</returns>
    Private Function ConvertEligibility(ByVal pobjElig As nsWS.EligibilityType) As EntityG2BServices.EligibilityType
        Dim objOutElig As New EntityG2BServices.EligibilityType()

        objOutElig.accountNumber = DefaultString(pobjElig.AccountNumber)
        objOutElig.billingCycle = pobjElig.BillingCycle
        objOutElig.billingCycleFieldSpecified = pobjElig.BillingCycleSpecified
        objOutElig.creditClassField = DefaultString(pobjElig.CreditClass)
        objOutElig.depositAmountField = pobjElig.DepositAmount
        objOutElig.depositAmountFieldSpecified = pobjElig.DepositAmountSpecified

        Return objOutElig
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B FeatureCategory enum value from a Web Service CustomizationCategoryEnum
    ''' </summary>
    ''' <param name="pobjCustomCatEnum">Web Service CustomizationCategoryEnum value</param>
    ''' <returns>Local G2B FeatureCategory Enum value</returns>
    Private Function ConvertFeatureCategory(ByVal pobjCustomCatEnum As nsWS.CustomizationCategoryEnum) As FeatureCategory
        Try
            Select Case pobjCustomCatEnum
                Case nsWS.CustomizationCategoryEnum.DataEquipment
                    Return FeatureCategory.DataEquipment
                Case nsWS.CustomizationCategoryEnum.DataFeature
                    Return FeatureCategory.DataFeature
                Case nsWS.CustomizationCategoryEnum.Deposit
                    Return FeatureCategory.Deposit
                Case nsWS.CustomizationCategoryEnum.HDUpgrade
                    Return FeatureCategory.HDUpgrade
                Case nsWS.CustomizationCategoryEnum.Installation
                    Return FeatureCategory.Installation
                Case nsWS.CustomizationCategoryEnum.Other
                    Return FeatureCategory.Other
                Case nsWS.CustomizationCategoryEnum.Premium
                    Return FeatureCategory.Premium
                Case nsWS.CustomizationCategoryEnum.Software
                    Return FeatureCategory.Software
                Case nsWS.CustomizationCategoryEnum.VideoEquipment
                    Return FeatureCategory.VideoEquipment
                Case nsWS.CustomizationCategoryEnum.VideoFeature
                    Return FeatureCategory.VideoFeature
                Case nsWS.CustomizationCategoryEnum.VoiceEquipment
                    Return FeatureCategory.VoiceEquipment
                Case nsWS.CustomizationCategoryEnum.VoiceFeature
                    Return FeatureCategory.VoiceFeature
                Case Else
                    Return FeatureCategory.Other
            End Select

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)
        End Try
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B CustomizationCategoryEnum value from a Web Service HardwareCategoryEnum 
    ''' </summary>
    ''' <param name="pobjCustomizationCatEnum">Web Service CustomizationCategoryEnum value</param>
    ''' <returns>Local G2B CustomizationCategory value</returns>
    Private Function ConvertCustomizationCategory(ByVal pobjCustomizationCatEnum As nsWS.CustomizationCategoryEnum) As EntityG2BServices.CustomizationCategoryEnum
        Try
            Select Case pobjCustomizationCatEnum
                Case nsWS.CustomizationCategoryEnum.DataEquipment
                    Return EntityG2BServices.CustomizationCategoryEnum.m_DataEquipment
                Case nsWS.CustomizationCategoryEnum.DataFeature
                    Return EntityG2BServices.CustomizationCategoryEnum.m_DataFeature
                Case nsWS.CustomizationCategoryEnum.Deposit
                    Return EntityG2BServices.CustomizationCategoryEnum.m_Deposit
                Case nsWS.CustomizationCategoryEnum.HDUpgrade
                    Return EntityG2BServices.CustomizationCategoryEnum.m_HDUpgrade
                Case nsWS.CustomizationCategoryEnum.Installation
                    Return EntityG2BServices.CustomizationCategoryEnum.m_Installation
                Case nsWS.CustomizationCategoryEnum.Other
                    Return EntityG2BServices.CustomizationCategoryEnum.m_Other
                Case nsWS.CustomizationCategoryEnum.Premium
                    Return EntityG2BServices.CustomizationCategoryEnum.m_Premium
                Case nsWS.CustomizationCategoryEnum.Software
                    Return EntityG2BServices.CustomizationCategoryEnum.m_Software
                Case nsWS.CustomizationCategoryEnum.VideoEquipment
                    Return EntityG2BServices.CustomizationCategoryEnum.m_VideoEquipment
                Case nsWS.CustomizationCategoryEnum.VideoFeature
                    Return EntityG2BServices.CustomizationCategoryEnum.m_VideoFeature
                Case nsWS.CustomizationCategoryEnum.VoiceEquipment
                    Return EntityG2BServices.CustomizationCategoryEnum.m_VoiceEquipment
                Case nsWS.CustomizationCategoryEnum.VoiceFeature
                    Return EntityG2BServices.CustomizationCategoryEnum.m_VoiceFeature
                Case Else
                    Return EntityG2BServices.CustomizationCategoryEnum.m_Other
            End Select

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)
        End Try
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B VideoCategory value from a Web Service VideoCategory 
    ''' </summary>
    ''' <param name="pobjVideoCat">Web Service VideoCategory value</param>
    ''' <returns>Local G2B VideoCategory value</returns>
    Private Function ConvertVideoCategory(ByVal pobjVideoCat As nsWS.VideoCategoryEnum) As EntityG2BServices.VideoCategoryEnum
        Select Case pobjVideoCat
            Case nsWS.VideoCategoryEnum.Basic
                Return EntityG2BServices.VideoCategoryEnum.m_Basic
            Case nsWS.VideoCategoryEnum.Digital
                Return EntityG2BServices.VideoCategoryEnum.m_Digital
            Case nsWS.VideoCategoryEnum.DVRDigital
                Return EntityG2BServices.VideoCategoryEnum.m_DVRDigital
            Case nsWS.VideoCategoryEnum.DVRUpgrade
                Return EntityG2BServices.VideoCategoryEnum.m_DVRUpgrade
            Case nsWS.VideoCategoryEnum.HDDigital
                Return EntityG2BServices.VideoCategoryEnum.m_HDDigital
            Case nsWS.VideoCategoryEnum.HDDVRDigital
                Return EntityG2BServices.VideoCategoryEnum.m_HDDVRDigital
            Case nsWS.VideoCategoryEnum.HDDVRUpgrade
                Return EntityG2BServices.VideoCategoryEnum.m_HDDVRUpgrade
            Case nsWS.VideoCategoryEnum.HDUpgrade
                Return EntityG2BServices.VideoCategoryEnum.m_HDUpgrade
            Case Else
                Return EntityG2BServices.VideoCategoryEnum.m_Basic
        End Select
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B PriceFrequency Enum value from a Web Service PriceFrequency 
    ''' </summary>
    ''' <param name="pobjPriceEnum">Web Service PriceFrequency value</param>
    ''' <returns>Local G2B PriceFrequency Enum value</returns>
    Private Function ConvertPriceFrequency(ByVal pobjPriceEnum As nsWS.PriceFrequencyEnum) As PriceFrequency
        Try
            Select Case pobjPriceEnum
                Case nsWS.PriceFrequencyEnum.Monthly
                    Return PriceFrequency.Monthly
                Case nsWS.PriceFrequencyEnum.Once
                    Return PriceFrequency.OneTime
                Case Else
                    Return PriceFrequency.Monthly
            End Select

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)
        End Try
    End Function

    ''' <summary>
    ''' Covnert a Web Service PriceFrequency into a local PriceFrequency Enum
    ''' </summary>
    ''' <param name="pobjPriceEnum">Web Service PriceFrequency Enum</param>
    ''' <returns>local PriceFrequencyEnum value</returns>
    Private Function ConvertPriceFrequencyEnum(ByVal pobjPriceEnum As nsWS.PriceFrequencyEnum) As EntityG2BServices.PriceFrequencyEnum
        Try
            Select Case pobjPriceEnum
                Case nsWS.PriceFrequencyEnum.Monthly
                    Return EntityG2BServices.PriceFrequencyEnum.m_Monthly
                Case nsWS.PriceFrequencyEnum.Once
                    Return EntityG2BServices.PriceFrequencyEnum.m_Once
                Case Else
                    Return EntityG2BServices.PriceFrequencyEnum.m_Monthly
            End Select

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)
        End Try
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B OfferTypeEnum value from a Web Service OfferTypeEnum 
    ''' </summary>
    ''' <param name="pobjType">Web Service OfferTypeEnum value</param>
    ''' <returns>Local G2B OfferTypeEnum value</returns>
    Private Function ConvertOfferType(ByVal pobjType As nsWS.OfferTypeEnum) As EntityG2BServices.OfferTypeEnum
        Select Case pobjType
            Case nsWS.OfferTypeEnum.Data
                Return EntityG2BServices.OfferTypeEnum.m_Data
            Case nsWS.OfferTypeEnum.Video
                Return EntityG2BServices.OfferTypeEnum.m_Video
            Case nsWS.OfferTypeEnum.Voice
                Return EntityG2BServices.OfferTypeEnum.m_Voice
            Case nsWS.OfferTypeEnum.WirelessVoice
                Return EntityG2BServices.OfferTypeEnum.m_WirelessVoice
            Case Else
                Return EntityG2BServices.OfferTypeEnum.m_Data
        End Select
    End Function

    Private Function ConvertRequires(ByVal pobjRequires As nsWS.OfferTypeEnum()) As EntityG2BServices.OfferTypeEnum()
        Dim objTypeOut As EntityG2BServices.OfferTypeEnum() = Nothing

        If pobjRequires IsNot Nothing AndAlso pobjRequires.Length > 0 Then
            objTypeOut = New EntityG2BServices.OfferTypeEnum(pobjRequires.Length - 1) {}
            For iItem As Integer = 0 To pobjRequires.Length - 1

                objTypeOut(iItem) = ConvertOfferType(pobjRequires(iItem))
            Next
        End If

        Return objTypeOut
    End Function

    ''' <summary> 
    ''' Convert a G2B Price to our local PriceType 
    ''' </summary> 
    ''' <param name="pobjG2BPrice">Web Service G2B Price Type</param> 
    ''' <returns>local PriceType object</returns> 
    Private Function ConvertPriceType(ByVal pobjG2BPrice As nsWS.PriceType) As EntityG2BServices.PriceType
        Dim objPriceOut As New EntityG2BServices.PriceType(EntityG2BServices.PriceFrequencyEnum.m_Monthly, String.Empty, 0)

        If pobjG2BPrice IsNot Nothing Then
            If pobjG2BPrice.Frequency = nsWS.PriceFrequencyEnum.Monthly Then
                objPriceOut.Frequency = EntityG2BServices.PriceFrequencyEnum.m_Monthly
            Else
                objPriceOut.Frequency = EntityG2BServices.PriceFrequencyEnum.m_Once
            End If

            objPriceOut.Description = DefaultString(pobjG2BPrice.Description)
        End If

        objPriceOut.DisplayField = pobjG2BPrice.Display
        objPriceOut.DisplayFieldSpecified = pobjG2BPrice.DisplaySpecified
        objPriceOut.Value = pobjG2BPrice.Value

        Return objPriceOut
    End Function

    ''' <summary> 
    ''' Convert a G2B Customizable Price to our local CustomizablePriceType 
    ''' </summary> 
    ''' <param name="pobjG2BPrice">Web Service G2B Customizable Price Type</param> 
    ''' <returns>local CustomizablePriceType object</returns> 
    Private Function ConvertPriceType(ByVal pobjG2BPrice As nsWS.CustomizablePriceType) As EntityG2BServices.CustomizablePriceType
        Dim objPriceOut As New EntityG2BServices.CustomizablePriceType(EntityG2BServices.PriceFrequencyEnum.m_Monthly, String.Empty, "0")

        If pobjG2BPrice IsNot Nothing Then
            If pobjG2BPrice.Frequency = nsWS.PriceFrequencyEnum.Monthly Then
                objPriceOut.Frequency = EntityG2BServices.PriceFrequencyEnum.m_Monthly
            Else
                objPriceOut.Frequency = EntityG2BServices.PriceFrequencyEnum.m_Once
            End If

            objPriceOut.Description = DefaultString(pobjG2BPrice.Description)
        End If
        objPriceOut.DisplayField = pobjG2BPrice.Display
        objPriceOut.DisplayFieldSpecified = pobjG2BPrice.DisplaySpecified
        objPriceOut.Value = pobjG2BPrice.Value

        Return objPriceOut
    End Function

    ''' <summary> 
    ''' Convert a G2B Data Speed to our local DataSpeedType 
    ''' </summary> 
    ''' <param name="pobjG2BSpeed">Web Service G2B Data Speed Type</param> 
    ''' <returns>local DataSpeedType object</returns> 
    Private Function ConvertDataSpeedType(ByVal pobjG2BSpeed As nsWS.DataSpeedType) As EntityG2BServices.DataSpeedType
        Dim objSpeedOut As New EntityG2BServices.DataSpeedType()
        If pobjG2BSpeed IsNot Nothing Then
            objSpeedOut.Value = pobjG2BSpeed.Value
        End If

        Select Case pobjG2BSpeed.Unit
            Case nsWS.DataRateEnum.Kbps
                objSpeedOut.Unit = EntityG2BServices.DataRateEnum.m_Kbps
                Exit Select
            Case nsWS.DataRateEnum.Mbps
                objSpeedOut.Unit = EntityG2BServices.DataRateEnum.m_Mbps
                Exit Select
            Case Else
                objSpeedOut.Unit = EntityG2BServices.DataRateEnum.m_Kbps
                Exit Select
        End Select

        Return objSpeedOut
    End Function

    ''' <summary> 
    ''' Convert a G2B Cable Service Enum value to our local CableServiceEnum
    ''' </summary> 
    ''' <param name="pobj">Web Service CableServiceEnum</param> 
    ''' <returns>local CableServiceEnum value</returns> 
    Private Function ConvertCableService(ByVal pobj As nsWS.CableServiceEnum) As EntityG2BServices.CableServiceEnum

        Select Case pobj
            Case nsWS.CableServiceEnum.CableBasicVideo
                Return EntityG2BServices.CableServiceEnum.m_CableBasicVideo
            Case nsWS.CableServiceEnum.CableDigitalVideo

                Return EntityG2BServices.CableServiceEnum.m_CableDigitalVideo
            Case nsWS.CableServiceEnum.CableDVR

                Return EntityG2BServices.CableServiceEnum.m_CableDVR
            Case nsWS.CableServiceEnum.CableHDVideo

                Return EntityG2BServices.CableServiceEnum.m_CableHDVideo
            Case nsWS.CableServiceEnum.CableHighSpeedData

                Return EntityG2BServices.CableServiceEnum.m_CableHighSpeedData
            Case nsWS.CableServiceEnum.CableHomeNetwork

                Return EntityG2BServices.CableServiceEnum.m_CableHomeNetwork
            Case nsWS.CableServiceEnum.CableVoice

                Return EntityG2BServices.CableServiceEnum.m_CableVoice
            Case nsWS.CableServiceEnum.CableWirelessVoice

                Return EntityG2BServices.CableServiceEnum.m_CableWirelessVoice
            Case Else

                Return EntityG2BServices.CableServiceEnum.m_CableBasicVideo
        End Select

    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B ChannelsType value from a Web Service ChannelsType 
    ''' </summary>
    ''' <param name="pobjChannels">Web Service ChannelsType value</param>
    ''' <returns>Local G2B ChannelsType Enum value</returns>
    Private Function ConvertChannels(ByVal pobjChannels As nsWS.ChannelsType) As EntityG2BServices.ChannelsType
        Dim objChannels As New EntityG2BServices.ChannelsType()

        objChannels.Number = DefaultString(pobjChannels.Number)
        If objChannels.Channel IsNot Nothing Then
            objChannels.Channel = New String(pobjChannels.Channel.Length - 1) {}
            For iChan As Integer = 0 To pobjChannels.Channel.Length - 1
                objChannels.Channel(iChan) = DefaultString(pobjChannels.Channel(iChan))
            Next
        End If
        Return objChannels
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B ContractType value from a Web Service ContractType 
    ''' </summary>
    ''' <param name="pobj">Web Service ContractType value</param>
    ''' <returns>Local G2B ContractType Enum value</returns>
    Private Function ConvertContract(ByVal pobj As nsWS.ContractType) As EntityG2BServices.ContractType
        Dim objOut As New EntityG2BServices.ContractType()

        If pobj IsNot Nothing Then
            objOut.Description = pobj.Description
            objOut.EarlyTermFee = pobj.EarlyTermFee
            Select Case pobj.LengthRate
                Case nsWS.ContractLengthRateEnum.Days
                    objOut.LengthRate = EntityG2BServices.ContractLengthRateEnum.m_Days
                    Exit Select
                Case nsWS.ContractLengthRateEnum.Months

                    objOut.LengthRate = EntityG2BServices.ContractLengthRateEnum.m_Months
                    Exit Select
                Case nsWS.ContractLengthRateEnum.Weeks
                    objOut.LengthRate = EntityG2BServices.ContractLengthRateEnum.m_Weeks
                    Exit Select
                Case nsWS.ContractLengthRateEnum.Years
                    objOut.LengthRate = EntityG2BServices.ContractLengthRateEnum.m_Years
                    Exit Select
                Case Else
                    objOut.LengthRate = EntityG2BServices.ContractLengthRateEnum.m_Days
                    Exit Select
            End Select
            objOut.TermsAndConditions = String.Empty

            objOut.Value = pobj.Value
        End If
        Return objOut
    End Function

    Private Function ConvertUnparsedUSAddress(ByVal pobjG2B As EntityG2BServices.UnparsedUSAddressType) As nsWS.UnparsedUSAddressType
        Dim objAddrOut As New nsWS.UnparsedUSAddressType

        If pobjG2B.AddressLine IsNot Nothing Then
            objAddrOut.AddressLine = pobjG2B.AddressLine
        End If

        If pobjG2B.City IsNot Nothing Then
            objAddrOut.City = pobjG2B.City
        End If
        If pobjG2B.State IsNot Nothing Then
            objAddrOut.State = pobjG2B.State
        End If
        If pobjG2B.Suite IsNot Nothing Then
            objAddrOut.Suite = pobjG2B.Suite
        End If
        If pobjG2B.Zip IsNot Nothing Then
            objAddrOut.Zip = pobjG2B.Zip
        End If
        If pobjG2B.Zip4 IsNot Nothing Then
            objAddrOut.Zip4 = pobjG2B.Zip4
        End If

        Return objAddrOut
    End Function
    Private Function ConvertCreditCard(ByVal pobjG2B As EntityG2BServices.CreditCardType) As nsWS.CreditCardType
        Dim objCCOut As New nsWS.CreditCardType

        If pobjG2B.BillingAddress IsNot Nothing Then
            objCCOut.BillingAddress = New nsWS.UnparsedUSAddressType
            With pobjG2B.BillingAddress
                If .Street1 IsNot Nothing Then
                    objCCOut.BillingAddress.AddressLine = .Street1
                End If
                If .City IsNot Nothing Then
                    objCCOut.BillingAddress.City = .City
                End If
                If .State IsNot Nothing Then
                    objCCOut.BillingAddress.State = .State
                End If
                If .Street2 IsNot Nothing Then
                    objCCOut.BillingAddress.Suite = .Street2
                End If
                If .Zip IsNot Nothing Then
                    objCCOut.BillingAddress.Zip = .Zip
                End If
                If .Zip4 IsNot Nothing Then
                    objCCOut.BillingAddress.Zip4 = .Zip4
                End If
            End With
        End If

        If pobjG2B.BillingFullName IsNot Nothing Then
            objCCOut.BillingFullName = pobjG2B.BillingFullName
        End If
        If pobjG2B.BillingPhone IsNot Nothing Then
            objCCOut.BillingPhone = pobjG2B.BillingPhone
        End If
        If pobjG2B.Expiration IsNot Nothing Then
            objCCOut.Expiration = pobjG2B.Expiration
        End If
        objCCOut.Name = ConvertCreditCardname(pobjG2B.Name)
        If pobjG2B.Number IsNot Nothing Then
            objCCOut.Number = pobjG2B.Number
        End If
        If pobjG2B.SecurityCode IsNot Nothing Then
            objCCOut.SecurityCode = pobjG2B.SecurityCode
        End If
        Return objCCOut
    End Function
    Private Function ConvertCreditCardname(ByVal poName As EntityG2BServices.CreditCardEnum) As nsWS.CreditCardEnum
        Select Case poName
            Case EntityG2BServices.CreditCardEnum.m_Amex
                Return nsWS.CreditCardEnum.Amex
            Case EntityG2BServices.CreditCardEnum.m_Diners
                Return nsWS.CreditCardEnum.Diners
            Case EntityG2BServices.CreditCardEnum.m_Discover
                Return nsWS.CreditCardEnum.Discover
            Case EntityG2BServices.CreditCardEnum.m_MC
                Return nsWS.CreditCardEnum.MC

            Case EntityG2BServices.CreditCardEnum.m_Visa
                Return nsWS.CreditCardEnum.Visa
            Case Else
                Return Nothing
        End Select
    End Function
    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B CustomerAuthField value from a Web Service CustomerAuthField 
    ''' </summary>
    ''' <param name="pobjG2B">Web Service CustomerAuthField value</param>
    ''' <returns>Local G2B CustomerAuthField value</returns>
    Private Function ConvertCustAuth(ByVal pobjG2B As nsWS.CustomerAuthFieldDefinitionType) As EntityG2BServices.CustomerAuthFieldDefinitionType
        Dim objCustAuthOut As New EntityG2BServices.CustomerAuthFieldDefinitionType()
        Dim objItemOut As EntityG2BServices.AuthFieldDefinitionType = Nothing
        Dim objStdItem As EntityG2BServices.StandardAuthFieldEnum
        Dim objCustItem As EntityG2BServices.AuthFieldType = Nothing

        If pobjG2B.ExistingCustomer IsNot Nothing Then
            objCustAuthOut.ExistingCustomer = New List(Of EntityG2BServices.AuthFieldDefinitionType)()
            For iItem As Integer = 0 To pobjG2B.ExistingCustomer.Length - 1
                objItemOut = New EntityG2BServices.AuthFieldDefinitionType()

                objItemOut.StandardAuth = New List(Of EntityG2BServices.StandardAuthFieldEnum)()
                If pobjG2B.ExistingCustomer(iItem).StandardAuthField IsNot Nothing Then
                    For iStdAuth As Integer = 0 To pobjG2B.ExistingCustomer(iItem).StandardAuthField.Length - 1
                        objStdItem = ConvertStandardAuthField(pobjG2B.ExistingCustomer(iItem).StandardAuthField(iStdAuth))
                        objItemOut.StandardAuth.Add(objStdItem)
                    Next
                End If

                If pobjG2B.ExistingCustomer(iItem).CustomAuthField IsNot Nothing Then
                    objItemOut.CustomAuth = New List(Of EntityG2BServices.AuthFieldType)()
                    For iStdAuth As Integer = 0 To pobjG2B.ExistingCustomer(iItem).CustomAuthField.Length - 1
                        objCustItem = ConvertCustomAuthField(pobjG2B.ExistingCustomer(iItem).CustomAuthField(iStdAuth))
                        objItemOut.CustomAuth.Add(objCustItem)
                    Next
                End If
                objCustAuthOut.ExistingCustomer.Add(objItemOut)
            Next
        End If

        If pobjG2B.NewCustomer IsNot Nothing Then
            objCustAuthOut.NewCustomer = New List(Of EntityG2BServices.AuthFieldDefinitionType)()
            For iItem As Integer = 0 To pobjG2B.NewCustomer.Length - 1
                objItemOut = New EntityG2BServices.AuthFieldDefinitionType()
                objItemOut.StandardAuth = New List(Of EntityG2BServices.StandardAuthFieldEnum)()
                If pobjG2B.NewCustomer(iItem).StandardAuthField IsNot Nothing Then
                    For iStdAuth As Integer = 0 To pobjG2B.NewCustomer(iItem).StandardAuthField.Length - 1
                        objStdItem = ConvertStandardAuthField(pobjG2B.NewCustomer(iItem).StandardAuthField(iStdAuth))
                        objItemOut.StandardAuth.Add(objStdItem)
                    Next
                End If

                objItemOut.CustomAuth = New List(Of EntityG2BServices.AuthFieldType)()
                If pobjG2B.NewCustomer(iItem).CustomAuthField IsNot Nothing Then
                    For iStdAuth As Integer = 0 To pobjG2B.NewCustomer(iItem).CustomAuthField.Length - 1
                        objCustItem = ConvertCustomAuthField(pobjG2B.NewCustomer(iItem).CustomAuthField(iStdAuth))
                        objItemOut.CustomAuth.Add(objCustItem)
                    Next

                End If
            Next
            objCustAuthOut.NewCustomer.Add(objItemOut)
        End If
        Return objCustAuthOut
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B CustomAuthField value from a Web Service CustomAuthField 
    ''' </summary>
    ''' <param name="pobjAuth">Web Service CustomAuthField value</param>
    ''' <returns>Local G2B CustomAuthField value</returns>
    Private Function ConvertCustomAuthField(ByVal pobjAuth As nsWS.AuthFieldType) As EntityG2BServices.AuthFieldType
        Dim pAuthOut As New EntityG2BServices.AuthFieldType()

        If pobjAuth.AuthFieldID IsNot Nothing Then
            pAuthOut.authFieldID = pobjAuth.AuthFieldID
        End If

        pAuthOut.booleanField = pobjAuth.[Boolean]
        If pobjAuth.Description IsNot Nothing Then
            pAuthOut.description = pobjAuth.Description
        End If

        pAuthOut.maxLen = pobjAuth.MaxLen

        If pobjAuth.Name IsNot Nothing Then
            pAuthOut.name = pobjAuth.Name
        End If

        pAuthOut.privateField = pobjAuth.[Private]

        Return pAuthOut
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  G2B StandardAuthEnum value from a Web Service StandardAuthFieldEnum 
    ''' </summary>
    ''' <param name="pobjStdAuth">Web Service StandardAuthFieldEnum value</param>
    ''' <returns>Local G2B StandardAuth Enum value</returns>
    Private Function ConvertStandardAuthField(ByVal pobjStdAuth As nsWS.StandardAuthFieldEnum) As EntityG2BServices.StandardAuthFieldEnum
        Select Case pobjStdAuth
            Case G2BServicesProvider.WSG2B.StandardAuthFieldEnum.CreditCard
                Return EntityG2BServices.StandardAuthFieldEnum.m_CreditCard
            Case G2BServicesProvider.WSG2B.StandardAuthFieldEnum.DateOfBirth

                Return EntityG2BServices.StandardAuthFieldEnum.m_DateOfBirth
            Case G2BServicesProvider.WSG2B.StandardAuthFieldEnum.DriversLicense

                Return EntityG2BServices.StandardAuthFieldEnum.m_DriversLicense
            Case G2BServicesProvider.WSG2B.StandardAuthFieldEnum.DriversLicenseState

                Return EntityG2BServices.StandardAuthFieldEnum.m_DriversLicenseState
            Case G2BServicesProvider.WSG2B.StandardAuthFieldEnum.FirstName

                Return EntityG2BServices.StandardAuthFieldEnum.m_FirstName
            Case G2BServicesProvider.WSG2B.StandardAuthFieldEnum.LastName

                Return EntityG2BServices.StandardAuthFieldEnum.m_LastName
            Case G2BServicesProvider.WSG2B.StandardAuthFieldEnum.ServiceAddress

                Return EntityG2BServices.StandardAuthFieldEnum.m_ServiceAddress
            Case G2BServicesProvider.WSG2B.StandardAuthFieldEnum.ServiceAddressPhone

                Return EntityG2BServices.StandardAuthFieldEnum.m_ServiceAddressPhone
            Case G2BServicesProvider.WSG2B.StandardAuthFieldEnum.SSN

                Return EntityG2BServices.StandardAuthFieldEnum.m_SSN
            Case G2BServicesProvider.WSG2B.StandardAuthFieldEnum.SSN4

                Return EntityG2BServices.StandardAuthFieldEnum.m_SSN4
            Case Else

                Return EntityG2BServices.StandardAuthFieldEnum.m_FirstName
        End Select
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace) G2B DiskSpaceType value from a Web Service DiskSpaceType 
    ''' </summary>
    ''' <param name="pobjG2BSpace">Web Service DiskSpaceType value</param>
    ''' <returns>Local G2B DiskSpaceType value</returns>
    Private Function ConvertDiskSpaceType(ByVal pobjG2BSpace As nsWS.DiskSpaceType) As EntityG2BServices.DiskSpaceType
        Dim objSpaceOut As New EntityG2BServices.DiskSpaceType()

        If pobjG2BSpace IsNot Nothing Then
            objSpaceOut.Value = pobjG2BSpace.Value
        End If
        Select Case pobjG2BSpace.Unit
            Case nsWS.DiskSpaceEnum.GB
                objSpaceOut.Unit = EntityG2BServices.DiskSpaceEnum.m_GB
                Exit Select
            Case nsWS.DiskSpaceEnum.MB
                objSpaceOut.Unit = EntityG2BServices.DiskSpaceEnum.m_MB
                Exit Select
            Case Else
                objSpaceOut.Unit = EntityG2BServices.DiskSpaceEnum.m_GB
                Exit Select
        End Select
        Return objSpaceOut
    End Function

    ''' <summary>
    ''' Convert a string description into a GWYCategory enum value
    ''' </summary>
    ''' <param name="description">Description of service line</param>
    ''' <returns>GWYCategory enum value</returns>
    Private Function GetCategory(ByVal description As String) As GWYCategory
        Try
            Select Case description
                Case "HSI", "HSD", "High Speed Data"
                    Return GWYCategory.HSD
                Case "Cable", "Digital", "Digital Cable", "Basic", "VOD", "DVR", _
                "HDTV", "Analog Video"
                    Return GWYCategory.Cable
                Case "Telephony"
                    Return GWYCategory.Telephoney
                Case Else
                    Return GWYCategory.UnSpecified
            End Select

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)

        End Try
    End Function

#End Region

#Region "Build Composite Objects from G2b and other data"

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  address from a Web Service UnparsedUSAddress object
    ''' </summary>
    ''' <param name="pobjAddress">Web Service UnparsedUSAddress</param>
    ''' <returns>Local Address object</returns>
    Private Function BuildAddress(ByVal pobjAddress As Address) As nsWS.UnparsedUSAddressType
        Dim unparsedAddress As New nsWS.UnparsedUSAddressType()
        Try
            unparsedAddress.AddressLine = pobjAddress.Street1
            unparsedAddress.Suite = pobjAddress.Street2
            unparsedAddress.City = pobjAddress.City
            unparsedAddress.State = pobjAddress.State
            unparsedAddress.Zip = pobjAddress.Zip
            unparsedAddress.Zip4 = pobjAddress.Zip4

            Return unparsedAddress

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)

        End Try
    End Function

    ''' <summary> 
    ''' Add an Offer to the Bundle sub-types 
    ''' </summary> 
    ''' <param name="pobjBundleOfferList">Dictionary of Bundle Offer Types</param> 
    ''' <param name="pobjOffer">Offer object returned from G2B</param> 
    ''' <returns>Generic List of String objects</returns> 
    Private Shared Function AddToBundle(ByVal pobjBundleOfferList As Dictionary(Of nsWS.BundledOfferType, List(Of String)), ByVal pobjOffer As nsWS.OfferType) As List(Of String)
        Dim objServicePlansInBundle As List(Of String) = Nothing
        Dim objBundleOfferType As nsWS.BundledOfferType = TryCast(pobjOffer, nsWS.BundledOfferType)
        objServicePlansInBundle = New List(Of String)()
        If objBundleOfferType.DataExtension IsNot Nothing Then
            objServicePlansInBundle.Add(objBundleOfferType.DataExtension.ServiceLineID)
        End If
        If objBundleOfferType.VideoExtension IsNot Nothing Then
            objServicePlansInBundle.Add(objBundleOfferType.VideoExtension.ServiceLineID)
        End If
        If objBundleOfferType.VoiceExtension IsNot Nothing Then
            objServicePlansInBundle.Add(objBundleOfferType.VoiceExtension.ServiceLineID)
        End If
        If objBundleOfferType.WirelessVoiceExtension IsNot Nothing Then
            objServicePlansInBundle.Add(objBundleOfferType.WirelessVoiceExtension.ServiceLineID)
        End If
        pobjBundleOfferList.Add(objBundleOfferType, objServicePlansInBundle)
        Return objServicePlansInBundle
    End Function

    ''' <summary> 
    ''' Version 4.1 spec of ProductCatalog function 
    ''' </summary> 
    ''' <param name="pobjMSOOfferList">List Of Offers returned from QueryOffers WS Call</param> 
    ''' <returns>ProductCatalog object</returns> 
    Private Function BuildProductCatalog(ByVal pobjMSOOfferList As nsWS.OfferType(), ByVal pintAffiliateID As Integer, ByVal pintTrackingID As Integer) As ProductCatalog
        Dim objServicePlanListInBundle As New Dictionary(Of String, ServicePlan)()
        Dim objServicePlansInBundle As New List(Of String)()

        Dim objBundleOffer As New Dictionary(Of nsWS.BundledOfferType, List(Of String))()

        Dim objFeatureListInSvcPlan As New Dictionary(Of String, Feature)()
        Dim objHWTypeListInSvcPlan As New Dictionary(Of String, EntityG2BServices.HardwareType)()

        Dim objServicePlan As ServicePlan = Nothing
        Dim objServicePlanList As New Dictionary(Of String, ServicePlan)()

        Dim objBundle As Bundle = Nothing
        Dim objBundleList As New Dictionary(Of String, Bundle)()

        Dim objProductCatalog As ProductCatalog = Nothing
        Dim dtContent As DataTable
        Dim dsContent As DataSet
        Dim rowArray As String() = {Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, _
        Nothing, Nothing}

        Dim objIncItemListInSvcPlan As New Dictionary(Of String, EntityG2BServices.IncludedItemsType)()
        Dim objCustomizationListInSvcPlan As New Dictionary(Of String, EntityG2BServices.CustomizationTypeQueryOffers)()
        Dim objPromotionListInSvcPlan As New Dictionary(Of String, EntityG2BServices.PromotionType)()
        Dim objMktInfo As EntityG2BServices.MarketingInfoType = Nothing

        Dim f As Feature
        Dim selection As nsWS.SelectionType
        Dim choiceItem As Object
        Dim strtemp As String = ""
        Dim strtempdetail As String = ""
        Dim videoAlaCarteOffer As nsWS.OfferType = Nothing
        'namespaceWSQueryOffers.OfferType voiceAlaCarteOffer; 
        Dim dataAlaCarteOffer As nsWS.OfferType = Nothing

        Try
            dtContent = New DataTable("ContentKey")
            dtContent.Columns.Add("USERCONTROL", Type.[GetType]("System.String"))
            dtContent.Columns.Add("OWNER", Type.[GetType]("System.String"))
            dtContent.Columns.Add("OWNERTYPE", Type.[GetType]("System.String"))
            dtContent.Columns.Add("LOCALE", Type.[GetType]("System.String"))
            dtContent.Columns.Add("REGION", Type.[GetType]("System.String"))
            dtContent.Columns.Add("KMA", Type.[GetType]("System.String"))
            dtContent.Columns.Add("BILLINGSTATION", Type.[GetType]("System.String"))
            dtContent.Columns.Add("FTA", Type.[GetType]("System.String"))

            For Each offer As nsWS.OfferType In pobjMSOOfferList
                If _blnLIVE Then
                    ' Don't Build the Al-A-Carte Plan 
                    If Not ((offer.OfferID = TryCast(System.Web.HttpContext.Current.Application("VideoAlaCartePlanID"), String)) OrElse (offer.OfferID = TryCast(System.Web.HttpContext.Current.Application("DataAlaCartePlanID"), String))) Then
                        'TODO: just for todays testing 
                        'if (offer.OfferID == "5187") 
                        '{ 
                        If offer.[GetType]().FullName = GetType(nsWS.BundledOfferType).FullName Then
                            objServicePlansInBundle = AddToBundle(objBundleOffer, offer)

                            Dim dar As DataRow = dtContent.NewRow()
                            rowArray(0) = "Offer"
                            rowArray(1) = offer.OfferID
                            rowArray(2) = "1"
                            rowArray(3) = "1"
                            If (_intRegionID <> 0) Then
                                rowArray(4) = _intRegionID.ToString()
                            End If
                            If (_intKMAId <> 0) Then
                                rowArray(5) = _intKMAId.ToString()
                            End If
                            If (_intBillingStationID <> 0) Then
                                rowArray(6) = _intBillingStationID.ToString()
                            End If
                            If Not (_strFTAID Is Nothing OrElse _strFTAID = "") Then
                                rowArray(7) = _strFTAID
                            End If
                            dar.ItemArray = rowArray
                            dtContent.Rows.Add(dar)
                        Else
                            Dim enumCategory As GWYCategory = GetCategoryFromOfferName(offer)

                            objFeatureListInSvcPlan = ConvertG2BCustomizationsToFeatures(objCustomizationListInSvcPlan, offer, enumCategory)

                            objHWTypeListInSvcPlan = ConvertHWTypesFromG2B(offer)

                            If offer.MarketingInfo IsNot Nothing Then
                                objMktInfo = ConvertMarketingInfo(offer.MarketingInfo)
                            Else
                                ' marketing info 
                                ' no marketing info returned 
                                objMktInfo = New EntityG2BServices.MarketingInfoType(String.Empty, New String() {String.Empty}, New String() {String.Empty})
                            End If

                            objIncItemListInSvcPlan = FormatIncludedItems(objFeatureListInSvcPlan, offer, enumCategory)

                            objPromotionListInSvcPlan = FormatPromotionList(offer)

                            Dim dar As DataRow = dtContent.NewRow()
                            rowArray(0) = "Offer"
                            rowArray(1) = offer.OfferID
                            rowArray(2) = "2"
                            rowArray(3) = "1"
                            If (_intRegionID <> 0) Then
                                rowArray(4) = _intRegionID.ToString()
                            End If
                            If (_intKMAId <> 0) Then
                                rowArray(5) = _intKMAId.ToString()
                            End If
                            If (_intBillingStationID <> 0) Then
                                rowArray(6) = _intBillingStationID.ToString()
                            End If
                            If Not (_strFTAID Is Nothing OrElse _strFTAID = "") Then
                                rowArray(7) = _strFTAID
                            End If
                            dar.ItemArray = rowArray
                            dtContent.Rows.Add(dar)

                            objServicePlan = BuildServicePlan(offer, objFeatureListInSvcPlan, enumCategory, objHWTypeListInSvcPlan, objIncItemListInSvcPlan, objMktInfo, _
                            objCustomizationListInSvcPlan, objPromotionListInSvcPlan)
                            objServicePlanList.Add(offer.OfferID, objServicePlan)
                            '} 
                        End If
                    End If
                Else
                    If Not ((offer.OfferID = TryCast(System.Web.HttpContext.Current.Application("VideoAlaCartePlanID"), String)) OrElse (offer.OfferID = TryCast(System.Web.HttpContext.Current.Application("DataAlaCartePlanID"), String))) Then
                        If offer.[GetType]().FullName = GetType(nsWS.BundledOfferType).FullName Then
                            objServicePlansInBundle = AddToBundle(objBundleOffer, offer)
                        Else
                            Dim enumCategory As GWYCategory = GetCategoryFromOfferName(offer)
                            objFeatureListInSvcPlan = ConvertG2BCustomizationsToFeatures(objCustomizationListInSvcPlan, offer, enumCategory)

                            objHWTypeListInSvcPlan = ConvertHWTypesFromG2B(offer)

                            If offer.MarketingInfo IsNot Nothing Then
                                objMktInfo = ConvertMarketingInfo(offer.MarketingInfo)
                            End If
                            ' marketing info 
                            objPromotionListInSvcPlan = FormatPromotionList(offer)

                            objIncItemListInSvcPlan = FormatIncludedItems(objFeatureListInSvcPlan, offer, enumCategory)

                            objServicePlan = BuildServicePlan(offer, objFeatureListInSvcPlan, enumCategory, objHWTypeListInSvcPlan, objIncItemListInSvcPlan, objMktInfo, _
                            objCustomizationListInSvcPlan, objPromotionListInSvcPlan)
                            objServicePlanList.Add(offer.OfferID, objServicePlan)
                        End If
                    End If
                End If
            Next
            If _blnaffiliate_notcharter = False Then
                If dtContent.Rows.Count > 0 Then
                    dsContent = New DataSet("Content")
                    dsContent.Tables.Add(dtContent)
                    _strContentParams = dsContent.GetXml()
                End If
                If Not (_strContentParams Is Nothing) Then
                    Try
                        dtContent = GetMultipleContent(_strContentParams)

                        If Not (dtContent Is Nothing) Then
                            _dctCatalogContent = New Dictionary(Of String, String)()
                            For Each dr As DataRow In dtContent.Rows
                                If Not (dr.ItemArray(0).ToString() = "" OrElse dr.ItemArray(1).ToString() = "") Then
                                    _dctCatalogContent.Add(TryCast(dr.ItemArray(0), String), TryCast(dr.ItemArray(1), String))
                                End If
                            Next
                        End If
                        _strContentParams = _strContentParams.Replace(">Offer<", ">offerdetail:body<")
                        dtContent = GetMultipleContent(_strContentParams)

                        If Not (dtContent Is Nothing) Then
                            _dctCatalogContentDetail = New Dictionary(Of String, String)()
                            For Each dr As DataRow In dtContent.Rows
                                If Not (dr.ItemArray(0).ToString() = "" OrElse dr.ItemArray(1).ToString() = "") Then
                                    _dctCatalogContentDetail.Add(TryCast(dr.ItemArray(0), String), TryCast(dr.ItemArray(1), String))
                                End If
                            Next
                        End If
                    Catch ex As Exception
                        ex.ToString()
                    End Try
                End If
            End If

            ' Build Bundle from Service Plans 
            For Each Offers As nsWS.BundledOfferType In objBundleOffer.Keys
                Dim blnSkip As Boolean = False
                objServicePlanListInBundle = New Dictionary(Of String, ServicePlan)()

                For Each servicePlanID As String In objBundleOffer(Offers)
                    If objServicePlanList.ContainsKey(servicePlanID) Then
                        objServicePlanListInBundle.Add(servicePlanID, objServicePlanList(servicePlanID))
                    Else
                        ' 8/2007 jwg G2B 4.1 TESTING
                        ' TODO: Restore this exception - taken out 9/10 for 
                        ' temp adjustment of bundles in the dev database 

                        ' 7/2008 Jonathan Parks
                        ' mod to skip adding this bundle and send an email when this condition occurs, but continue processing...
                        ' and we no longer throw the exception...
                        blnSkip = True

                        'send email
                        Dim strSubject As String
                        Select Case ConfigurationManager.AppSettings("ConfigLocation").ToLower
                            Case "prod.remotinghost"
                                strSubject = "Charter.com - Bundling Issue (PROD)"
                            Case "test.remotinghost"
                                strSubject = "Charter.com - Bundling Issue (UAT)"
                            Case "dev.remotinghost"
                                strSubject = "Charter.com - Bundling Issue (DEV)"
                            Case "localhost.remotinghost"
                                strSubject = "Charter.com - Bundling Issue (DEV)"
                            Case Else
                                strSubject = "Charter.com - Bundling Issue (" & ConfigurationManager.AppSettings("ConfigLocation").ToString & ")"
                        End Select

                        Dim strSendTo As String = "DLCHARTERCOM-SUPPORT@chartercom.com, Stephanie.Boone@chartercom.com, Joe.Kessler@chartercom.com, Daniel.Clegg@chartercom.com"

                        ''####################################################################################################
                        '' ISSUE ID #5053   07-08-2009  JLN
                        ''####################################################################################################
                        '' Description:  G2B tracking-id was needed on bundling error emails.
                        ''      Change:  Added tracking-id as a parameter for this private method, to all of the calls to
                        ''               this method within this class file, and to the text of the email sent below.
                        ''####################################################################################################
                        SendEMail("support@chartercom.com", strSendTo, strSubject, "Service Plan (" & servicePlanID & ") does not exist in Bundle (" & Offers.OfferID & ") for Affiliate (" & pintAffiliateID & ") with TrackingID (" & pintTrackingID.ToString & ").")
                        Exit For

                        'Throw New Exception(Constant.EXCEPTION_SERVICEPLAN_NOTFOUND & " Bundle: " & Offers.OfferID + ", Service Plan: " & servicePlanID)
                    End If
                Next

                If blnSkip = False And objServicePlanListInBundle.Count > 0 Then
                    If Not (_dctCatalogContent Is Nothing) Then
                        _dctCatalogContent.TryGetValue(Offers.OfferID, strtemp)
                    End If
                    If Not (_dctCatalogContentDetail Is Nothing) Then
                        _dctCatalogContentDetail.TryGetValue(Offers.OfferID, strtempdetail)
                    End If
                    objBundle = BuildBundle(Offers, objServicePlanListInBundle, strtemp, strtempdetail)
                    objBundleList.Add(Offers.OfferID, objBundle)
                End If
            Next

            ' Al-A- Carte plan 
            'Populate price from AL-A-Carte Plan 
            For Each alaCarteOffer As nsWS.OfferType In pobjMSOOfferList
                If alaCarteOffer.OfferID = TryCast(System.Web.HttpContext.Current.Application("VideoAlaCartePlanID"), String) Then
                    videoAlaCarteOffer = alaCarteOffer
                ElseIf alaCarteOffer.OfferID = TryCast(System.Web.HttpContext.Current.Application("DataAlaCartePlanID"), String) Then
                    dataAlaCarteOffer = alaCarteOffer
                End If
            Next

            For Each sp As ServicePlan In objServicePlanList.Values
                'if (!(catalogcontent == null)) 
                '{ 
                ' catalogcontent.TryGetValue(sp.ID, out strtemp); 
                ' sp.MarketingInfo = strtemp; 
                '} 

                If Not (_dctCatalogContentDetail Is Nothing) Then
                    _dctCatalogContentDetail.TryGetValue(sp.ID, strtempdetail)
                    sp.MarketingDetail = strtempdetail
                End If

                Select Case sp.Category
                    Case (GWYCategory.Cable)
                        If Not ((videoAlaCarteOffer Is Nothing) OrElse (videoAlaCarteOffer.Customization Is Nothing)) Then
                            For Each alaCarateCustomization As nsWS.CustomizationType In videoAlaCarteOffer.Customization
                                choiceItem = alaCarateCustomization.Items(0)
                                If choiceItem.[GetType]().FullName = GetType(nsWS.SelectionType).FullName Then
                                    selection = TryCast(choiceItem, nsWS.SelectionType)
                                    For Each alaCarteChoice As nsWS.ChoiceType In selection.Choice
                                        If sp.Features.ContainsKey("99" + alaCarteChoice.ChoiceID) Then
                                            f = sp.Features("99" + alaCarteChoice.ChoiceID)
                                            If f.FeatureType = GWYFeatureType.IsIncluded Then
                                                f.Price = alaCarteChoice.Price.Value
                                                f.ListPrice = alaCarteChoice.Price.Value
                                            End If

                                        End If
                                    Next
                                End If
                            Next
                        End If
                        Exit Select
                    Case (GWYCategory.HSD)

                        If Not ((dataAlaCarteOffer Is Nothing) OrElse (dataAlaCarteOffer.Customization Is Nothing)) Then
                            For Each alaCarateCustomization As nsWS.CustomizationType In dataAlaCarteOffer.Customization
                                choiceItem = alaCarateCustomization.Items(0)
                                If choiceItem.[GetType]().FullName = GetType(nsWS.SelectionType).FullName Then
                                    selection = TryCast(choiceItem, nsWS.SelectionType)
                                    For Each alaCarteChoice As nsWS.ChoiceType In selection.Choice
                                        If sp.Features.ContainsKey("99" + alaCarteChoice.ChoiceID) Then
                                            f = sp.Features("99" + alaCarteChoice.ChoiceID)
                                            If f.FeatureType = GWYFeatureType.IsIncluded Then
                                                f.Price = alaCarteChoice.Price.Value
                                                f.ListPrice = alaCarteChoice.Price.Value
                                            End If
                                        End If
                                    Next
                                End If
                            Next
                        End If
                        Exit Select
                End Select
            Next

            objProductCatalog = New ProductCatalog(objBundleList, objServicePlanList)
            Return objProductCatalog

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)

        End Try
    End Function

    ''' <summary>
    ''' Build a list of local OfferTypes from a list of G2B Offer Types
    ''' </summary>
    ''' <param name="pobjItems">List of Web Service OfferType objects</param>
    ''' <returns>List of local OfferTypes objects</returns>
    Private Function BuildItems(ByVal pobjItems As nsWS.OfferType()) As List(Of EntityG2BServices.OfferType)
        Dim lstOut As New List(Of EntityG2BServices.OfferType)()
        Dim objItem As EntityG2BServices.OfferType = Nothing

        If pobjItems IsNot Nothing Then
            For Each objDisc As nsWS.OfferType In pobjItems
                objItem = New EntityG2BServices.OfferType()
                objItem.Contract = ConvertContract(objDisc.Contract)
                If objDisc.Customization IsNot Nothing Then
                    objItem.Customization = New EntityG2BServices.CustomizationTypeQueryOffers(objDisc.Customization.Length - 1) {}
                    For iItem As Integer = 0 To objItem.Customization.Length - 1
                        objItem.Customization(iItem) = ConvertCustomization(objDisc.Customization(iItem))
                    Next
                End If
                objItem.DepositPrice = ConvertPriceType(objDisc.DepositPrice)
                objItem.Disclaimer = objDisc.Disclaimer
                objItem.HardwarePrice = ConvertPriceType(objDisc.HardwarePrice)
                If objDisc.IncludedItems IsNot Nothing Then
                    objItem.IncludedItems = New EntityG2BServices.IncludedItemsType(objDisc.IncludedItems.Length - 1) {}
                    For iItem As Integer = 0 To objItem.IncludedItems.Length - 1
                        objItem.IncludedItems(iItem) = ConvertIncludedItem(objDisc.IncludedItems(iItem))
                    Next
                End If
                objItem.InstallPrice = ConvertPriceType(objDisc.InstallPrice)
                objItem.LongName = objDisc.LongName
                objItem.MarketingInfo = ConvertMarketingInfo(objDisc.MarketingInfo)
                objItem.MediumName = objDisc.MediumName
                objItem.MovesOffer = objDisc.MovesOffer
                objItem.MovesOfferSpecified = objDisc.MovesOfferSpecified
                objItem.OfferID = objDisc.OfferID
                objItem.Price = ConvertPriceType(objDisc.Price)
                If objDisc.Promotion IsNot Nothing Then
                    objItem.Promotion = New EntityG2BServices.PromotionType(objDisc.Promotion.Length - 1) {}
                    For iItem As Integer = 0 To objItem.Promotion.Length - 1
                        objItem.Promotion(iItem) = ConvertPromotion(objDisc.Promotion(iItem))
                    Next
                End If

                If objDisc.QualifiedHardware IsNot Nothing Then
                    objItem.QualifiedHardware = New EntityG2BServices.HardwareType(objDisc.QualifiedHardware.Length - 1) {}
                    For iItem As Integer = 0 To objItem.QualifiedHardware.Length - 1
                        objItem.QualifiedHardware(iItem) = ConvertHWType(objDisc.QualifiedHardware(iItem))
                    Next
                End If

                objItem.ShortName = objDisc.ShortName
                objItem.TechSupport = objDisc.TechSupport
                objItem.TermsAndConditions = objDisc.TermsAndConditions
                objItem.Version = objDisc.Version

                lstOut.Add(objItem)

            Next
        End If

        Return lstOut
    End Function

    ''' <summary>
    ''' Build a local (EntityG2BServices namespace)  DiscountTypeQueryOffers value from a Web Service Discount array
    ''' </summary>
    ''' <param name="pobjDiscount">Array of Web Service Discounts</param>
    ''' <returns>Local DiscountTypeQueryOffers object</returns>
    Private Function BuildDiscount(ByVal pobjDiscount As nsWS.DiscountType()) As List(Of EntityG2BServices.DiscountTypeQueryOffers)
        Dim lstOut As New List(Of EntityG2BServices.DiscountTypeQueryOffers)()
        Dim objDiscount As EntityG2BServices.DiscountTypeQueryOffers = Nothing

        If pobjDiscount IsNot Nothing Then
            For Each objDisc As nsWS.DiscountType In pobjDiscount
                objDiscount = New EntityG2BServices.DiscountTypeQueryOffers()
                objDiscount.Amount = objDisc.Amount
                objDiscount.Description = objDisc.Description
                objDiscount.DiscountID = objDisc.DiscountID
                objDiscount.Frequency = ConvertPriceFrequencyEnum(objDisc.Frequency)
                'objDiscount.OfferID = objDisc.OfferID; 
                objDiscount.OfferType = ConvertOfferType(objDisc.OfferType)
                objDiscount.Requires = ConvertRequires(objDisc.Requires)

                lstOut.Add(objDiscount)
            Next
        End If
        Return lstOut
    End Function

    ''' <summary>
    ''' Build a Feature from a Web Service customization and Service Category 
    ''' </summary>
    ''' <param name="customization">Web Service Customization object</param>
    ''' <param name="enumCategory">Service Category</param>
    ''' <returns>Feature object</returns>
    Private Function BuildFeature(ByVal customization As nsWS.CustomizationType, ByVal enumCategory As GWYCategory) As Feature
        Dim objFeature As Feature
        Dim objChildFeature As Feature = Nothing
        Dim objChildFeatureList As New Dictionary(Of String, Feature)()
        Dim customizationCategory As FeatureCategory
        Dim InputNumberTypeItem As nsWS.InputNumberType
        Dim SelectionTypeItem As nsWS.SelectionType
        Dim InputTextTypeItem As nsWS.InputTextType
        Dim MinChoiceSelection As Integer = 0
        Dim MaxChoiceSelection As Integer = 0
        Dim MinSelection As Integer = 0
        Dim MaxSelection As Integer = 0
        Dim maxLength As Integer = 0
        Dim type As GwyCustomizationInputType = GwyCustomizationInputType.Other
        Try
            customizationCategory = ConvertFeatureCategory(customization.Category)

            If customization.Items IsNot Nothing Then
                For Each item As Object In customization.Items
                    If item.[GetType]().FullName = GetType(nsWS.InputNumberType).FullName Then
                        InputNumberTypeItem = TryCast(item, nsWS.InputNumberType)
                        MinSelection = InputNumberTypeItem.Min
                        MaxSelection = InputNumberTypeItem.Max
                        type = GwyCustomizationInputType.Number
                    ElseIf item.[GetType]().FullName = GetType(nsWS.SelectionType).FullName Then
                        SelectionTypeItem = TryCast(item, nsWS.SelectionType)
                        MinChoiceSelection = SelectionTypeItem.Min
                        MaxChoiceSelection = SelectionTypeItem.Max
                        type = GwyCustomizationInputType.Selection
                        For i As Integer = 0 To SelectionTypeItem.Choice.GetUpperBound(0)
                            Dim priceFreq As PriceFrequency = ConvertPriceFrequency(SelectionTypeItem.Choice(i).Price.Frequency)
                            If (SelectionTypeItem.Choice(i).ChoiceID = "5257") Then
                                Debug.Write("Got 5257 Feature")
                            End If
                            objChildFeature = New Feature("99" + SelectionTypeItem.Choice(i).ChoiceID, _
                                SelectionTypeItem.Choice(i).Name, SelectionTypeItem.Choice(i).Description, _
                                enumCategory, 0, customizationCategory, _
                                GWYFeatureType.IsPlaceholder, SelectionTypeItem.Choice(i).Price.Value, _
                                SelectionTypeItem.Choice(i).Price.Value, priceFreq, _
                                SelectionTypeItem.Choice(i).Price.Display, Nothing, SelectionTypeItem.Min, _
                                SelectionTypeItem.Max, 0, 0, String.Empty, 0, GwyCustomizationInputType.Other, _
                                Nothing)

                            objChildFeatureList.Add(objChildFeature.ID, objChildFeature)
                        Next
                    ElseIf item.[GetType]().FullName = GetType(nsWS.InputTextType).FullName Then
                        InputTextTypeItem = TryCast(item, nsWS.InputTextType)
                        maxLength = InputTextTypeItem.MaxLen
                        'objChildFeature = new Feature(); 
                        'objChildFeatureList.Add(objChildFeature.ID, objChildFeature); 
                        type = GwyCustomizationInputType.Text
                    End If
                Next
            End If
            objFeature = New Feature(customization.CustomizationID, DefaultString(customization.Name), DefaultString(customization.Description), enumCategory, 0, customizationCategory, _
            GWYFeatureType.IsOptional, 0, 0, 0, True, objChildFeatureList, MinChoiceSelection, _
            MaxChoiceSelection, MinSelection, MaxSelection, String.Empty, maxLength, type, _
            Nothing)
            Return objFeature

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)

        End Try
    End Function

    ''' <summary>
    ''' Build a Feature object from a list of included items, the line of service, and
    ''' the type of included items
    ''' </summary>
    ''' <param name="includedItems">List of Web Service Included items</param>
    ''' <param name="enumCategory">Service Type Category</param>
    ''' <param name="includedItemsCategory">FeatureCategory</param>
    ''' <returns>Feature object</returns>
    Private Function BuildFeature(ByVal includedItems As nsWS.IncludedItemsItemType, ByVal enumCategory As GWYCategory, ByVal includedItemsCategory As FeatureCategory) As Feature
        Dim objFeature As Feature = Nothing

        Try
            If includedItems IsNot Nothing Then
                Dim itemID As String
                itemID = includedItems.ItemID

                If itemID IsNot Nothing Then
                    If (itemID = "5257") Then
                        Debug.WriteLine("Adding 5257 as included item")
                    End If
                    objFeature = New Feature("99" + itemID, includedItems.Value, includedItems.Value, enumCategory, 0, includedItemsCategory, _
                    GWYFeatureType.IsIncluded, 0, 0, 0, True, Nothing, 0, _
                    0, 0, 0, String.Empty, 0, GwyCustomizationInputType.Other, _
                    Nothing)

                End If
            End If
            Return objFeature

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)

        End Try
    End Function

    ''' <summary>
    ''' Build a Bundle object that contains all Bundle properties plus the 
    ''' Video, Data, and VoiceExtension properties
    ''' </summary>
    ''' <param name="item">Web Service OfferType</param>
    ''' <param name="objFeatureList">List of Features (Customizations)</param>
    ''' <param name="marketingtext">Text for Marketing section</param>
    ''' <param name="marketingdetail">Text for Marketing Detail</param>
    ''' <returns>Bundle object</returns>
    Private Function BuildBundle(ByVal item As nsWS.OfferType, ByVal objFeatureList As Dictionary(Of String, ServicePlan), ByVal marketingtext As String, ByVal marketingdetail As String) As Bundle
        Dim objTempSP As ServicePlan = Nothing

        Dim objBundle As Bundle
        Dim objContract As New EntityG2BServices.ContractType()
        Dim disclaimer As String
        Dim price As Decimal
        Dim promoDisclaimer As String
        'string offerName; 
        Dim promoName As String
        Dim marketinginfo As String = ""
        Dim objFeatureListInSvcPlan As New Dictionary(Of String, Feature)()
        Dim objCustomizationListInSvcPlan As New Dictionary(Of String, EntityG2BServices.CustomizationTypeQueryOffers)()
        Dim objHWTypeListInSvcPlan As New Dictionary(Of String, EntityG2BServices.HardwareType)()
        Dim objIncItemListInSvcPlan As New Dictionary(Of String, EntityG2BServices.IncludedItemsType)()
        Dim objPromotionListInSvcPlan As New Dictionary(Of String, EntityG2BServices.PromotionType)()
        Dim objMktInfo As EntityG2BServices.MarketingInfoType = Nothing

        Try
            If item.Promotion IsNot Nothing Then
                ' evnthough promotion is a collection, there will be only one promotion coming from G2B 
                disclaimer = item.Promotion(0).Disclaimer
                price = item.Promotion(0).Value
                promoDisclaimer = item.Promotion(0).Disclaimer
                ' offerName = item.Promotion[0].Name; 
                promoName = item.Promotion(0).Name
            Else
                disclaimer = String.Empty
                price = item.Price.Value
                promoDisclaimer = item.Disclaimer
                ' offerName = item.ShortName; 
                promoName = String.Empty
            End If
            'if (affiliate_notcharter == true) 
            '{ 
            If item.MarketingInfo IsNot Nothing Then

                marketinginfo = GenerateMarketingText(item.MarketingInfo)
            End If
            '} 
            'else 
            '{ 
            ' marketinginfo = marketingtext; 
            '} 

            If item.Contract IsNot Nothing Then
                objContract = ConvertContract(item.Contract)
            End If
            Dim installPrice As Decimal = 0
            Decimal.TryParse(item.InstallPrice.Value, installPrice)
            objBundle = New Bundle(item.OfferID, item.ShortName, item.LongName, price, item.Price.Value, installPrice, _
            item.InstallPrice.Description, promoName, promoDisclaimer, marketinginfo, objFeatureList, objContract)

            objBundle.PriceFrequencyG2B = ConvertPriceFrequency(item.Price.Frequency)

            If item.Customization IsNot Nothing Then
                objFeatureListInSvcPlan = ConvertG2BCustomizationsToFeatures(objCustomizationListInSvcPlan, item, GWYCategory.UnSpecified)
                objBundle.Features = objFeatureListInSvcPlan
                If objCustomizationListInSvcPlan IsNot Nothing AndAlso objCustomizationListInSvcPlan.Count > 0 Then
                    objBundle.Customizations = objCustomizationListInSvcPlan
                End If
            End If
            If item.MediumName IsNot Nothing Then
                objBundle.MediumName = item.MediumName
            End If
            If item.TechSupport IsNot Nothing Then
                objBundle.TechSupport = item.TechSupport
            End If
            If item.Price.Description IsNot Nothing Then
                objBundle.PriceDescription = item.Price.Description
            End If
            If item.HardwarePrice.Description IsNot Nothing Then
                objBundle.HWPriceDescription = item.HardwarePrice.Description
            End If
            If item.DepositPrice.Description IsNot Nothing Then
                objBundle.DepositPriceDescription = item.DepositPrice.Description
            End If

            objBundle.InstallPriceFrequency = ConvertPriceFrequency(item.InstallPrice.Frequency)
            objBundle.HWPriceFrequency = ConvertPriceFrequency(item.HardwarePrice.Frequency)
            objBundle.DepositPriceFrequency = ConvertPriceFrequency(item.DepositPrice.Frequency)

            If item.DepositPrice IsNot Nothing Then
                objBundle.DepositPrice = Convert.ToDecimal(item.DepositPrice.Value)
            End If
            If item.HardwarePrice IsNot Nothing Then
                objBundle.HWPrice = Convert.ToDecimal(item.HardwarePrice.Value)
            End If
            objBundle.MovesOffer = item.MovesOffer

            objBundle.Version = item.Version

            objHWTypeListInSvcPlan = ConvertHWTypesFromG2B(item)
            If objHWTypeListInSvcPlan IsNot Nothing AndAlso objHWTypeListInSvcPlan.Count > 0 Then
                objBundle.HardwareTypes = objHWTypeListInSvcPlan
            End If

            objIncItemListInSvcPlan = FormatIncludedItems(objFeatureListInSvcPlan, item, GWYCategory.UnSpecified)
            If objIncItemListInSvcPlan IsNot Nothing AndAlso objIncItemListInSvcPlan.Count > 0 Then
                objBundle.IncludedItems = objIncItemListInSvcPlan
            End If

            If item.MarketingInfo IsNot Nothing Then
                objMktInfo = ConvertMarketingInfo(item.MarketingInfo)
            Else
                ' marketing info 
                ' no marketing info returned 
                objMktInfo = New EntityG2BServices.MarketingInfoType(String.Empty, New String() {String.Empty}, New String() {String.Empty})
            End If
            objBundle.MarketingInfoG2B = objMktInfo

            For Each kvp As KeyValuePair(Of String, ServicePlan) In objFeatureList
                objTempSP = TryCast(kvp.Value, ServicePlan)

                If objTempSP IsNot Nothing Then
                    Select Case objTempSP.Category
                        Case GWYCategory.Cable
                            objBundle.VideoExtension = ConvertVideoExtension(objTempSP)
                            Exit Select
                        Case GWYCategory.HSD
                            objBundle.DataExtension = ConvertDataExtension(objTempSP)
                            Exit Select
                        Case GWYCategory.Telephoney
                            objBundle.VoiceExtension = ConvertVoiceExtension(objTempSP)
                            Exit Select
                        Case Else
                            Exit Select
                    End Select
                End If
            Next
            ' foreach 
            If _blnaffiliate_notcharter = False Then
                objBundle.MarketingDetail = marketingdetail
            End If
            Return objBundle

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)

        End Try
    End Function

    ''' <summary> 
    ''' Build a ServicePlan object to be returned to the caller, using 
    ''' the G2B version 4.1 layout 
    ''' </summary> 
    ''' <param name="item">OfferType item containing plan details</param> 
    ''' <param name="objFeatureList">Features Dictionary containing customizations</param> 
    ''' <param name="enumCategory">Type of product (HSD, Video, Voice, etc.)</param> 
    ''' <param name="objHWTypeList">Dictionary of Hardware Types </param> 
    ''' <param name="objIncItemList">Dictionary of Included Items</param> 
    ''' <param name="objMktInfo">Marketing Info</param> 
    ''' <param name="objCustomizationList">Dictionary of Customizations</param> 
    ''' <param name="objPromoList">Dictionary of Promotions</param> 
    ''' <returns>CharterDotCom.CommonEntities.Library.ServicePlan object</returns> 
    Private Function BuildServicePlan(ByVal item As nsWS.OfferType, ByVal objFeatureList As Dictionary(Of String, Feature), ByVal enumCategory As GWYCategory, ByVal objHWTypeList As Dictionary(Of String, EntityG2BServices.HardwareType), ByVal objIncItemList As Dictionary(Of String, EntityG2BServices.IncludedItemsType), ByVal objMktInfo As EntityG2BServices.MarketingInfoType, _
    ByVal objCustomizationList As Dictionary(Of String, EntityG2BServices.CustomizationTypeQueryOffers), ByVal objPromoList As Dictionary(Of String, EntityG2BServices.PromotionType)) As ServicePlan
        Dim objServicePlan As ServicePlan
        Dim strDisclaimer As String
        Dim decPrice As Decimal
        Dim strPromoDisclaimer As String
        'string offerName; 
        Dim strPromoName As String
        Dim strMarketinginfo As String = ""
        Dim objPriceFreq As PriceFrequency
        Dim objInstallPriceFreq As PriceFrequency
        Dim objHWPriceFreq As PriceFrequency
        Dim objDepositPriceFreq As PriceFrequency
        Dim decHWPrice As Decimal
        Dim decDepositPrice As Decimal
        Dim objContractLength As EntityG2BServices.ContractLengthRateEnum = EntityG2BServices.ContractLengthRateEnum.m_Days
        Dim objDataOffer As nsWS.DataOfferType = Nothing
        Dim objVoiceOffer As nsWS.VoiceOfferType = Nothing
        Dim objVideoOffer As nsWS.VideoOfferType = Nothing

        Try
            If item.Promotion IsNot Nothing Then
                ' even though promotion is a collection, there will be only one promotion coming from G2B 
                strDisclaimer = item.Promotion(0).Disclaimer
                decPrice = item.Promotion(0).Value
                strPromoDisclaimer = item.Promotion(0).Disclaimer
                strPromoName = item.Promotion(0).Name
            Else
                strDisclaimer = String.Empty
                decPrice = item.Price.Value
                strPromoDisclaimer = item.Disclaimer
                strPromoName = String.Empty
            End If
            'if (affiliate_notcharter == true) 
            '{ 
            If item.MarketingInfo IsNot Nothing Then
                strMarketinginfo = GenerateMarketingText(item.MarketingInfo)
            End If
            '} 

            objPriceFreq = ConvertPriceFrequency(item.Price.Frequency)

            Dim installPrice As Decimal = 0
            Decimal.TryParse(item.InstallPrice.Value, installPrice)

            objInstallPriceFreq = ConvertPriceFrequency(item.InstallPrice.Frequency)

            Decimal.TryParse(item.HardwarePrice.Value, decHWPrice)
            objHWPriceFreq = ConvertPriceFrequency(item.HardwarePrice.Frequency)

            Decimal.TryParse(item.DepositPrice.Value, decDepositPrice)
            objDepositPriceFreq = ConvertPriceFrequency(item.DepositPrice.Frequency)

            If item.Contract.LengthRate = nsWS.ContractLengthRateEnum.Days Then
                objContractLength = EntityG2BServices.ContractLengthRateEnum.m_Days
            ElseIf item.Contract.LengthRate = nsWS.ContractLengthRateEnum.Months Then
                objContractLength = EntityG2BServices.ContractLengthRateEnum.m_Months
            ElseIf item.Contract.LengthRate = nsWS.ContractLengthRateEnum.Weeks Then
                objContractLength = EntityG2BServices.ContractLengthRateEnum.m_Weeks
            ElseIf item.Contract.LengthRate = nsWS.ContractLengthRateEnum.Years Then
                objContractLength = EntityG2BServices.ContractLengthRateEnum.m_Years
            End If

            'added for g2b 4.1 

            objServicePlan = New ServicePlan(item.OfferID, _
                item.ShortName, _
                item.LongName, _
                decPrice, _
                item.Price.Value, _
                enumCategory, _
                installPrice, _
                item.InstallPrice.Description, _
                strPromoName, _
                strPromoDisclaimer, _
                strMarketinginfo, _
                ServiceType.Basic, _
                objFeatureList, _
                item.MediumName, _
                item.TechSupport, _
                objPriceFreq, _
                item.Price.Description, _
                objInstallPriceFreq, _
                objHWPriceFreq, _
                decHWPrice, _
                item.HardwarePrice.Description, _
                objDepositPriceFreq, _
                decDepositPrice, _
                item.DepositPrice.Description, _
                item.Version, _
                item.Contract.EarlyTermFee, _
                item.Contract.Value, _
                objContractLength, _
                objHWTypeList, _
                objIncItemList, _
                objMktInfo, _
                objCustomizationList, _
                objPromoList, _
                item.Contract.Description, _
                item.TermsAndConditions, _
                item.MovesOffer)
            'objServicePlan.MediumName = item.MediumName; 
            'objServicePlan.techSupport = item.TechSupport; 
            'objServicePlan.PriceFrequencyG2B = pf; 
            'objServicePlan.PriceDescription = item.Price.Description; 
            'objServicePlan.InstallPriceFrequency = pf_I; 
            'objServicePlan.HWPriceFrequency = pf_HW; 
            'objServicePlan.HWPrice = hw_price; 
            'objServicePlan.HWPriceDescription =item.HardwarePrice.Description; 
            'objServicePlan.DepositPriceFrequency =pf_Dep; 
            'objServicePlan.DepositPrice =dep_price; 
            'objServicePlan.DepositPriceDescription =item.DepositPrice.Description; 
            'objServicePlan.Version =item.Version; 
            'objServicePlan.contractEarlyTermFee = item.Contract.EarlyTermFee; 
            'objServicePlan.contractValue =item.Contract.Value; 
            'objServicePlan.contractLength = cl_Contract; 

            ' these are our four suspects in the Deserialization error 
            'objServicePlan.HardwareTypes =objHWTypeList; 
            'objServicePlan.IncludedItems =objIncItemList; 
            'objServicePlan.MarketingInfoG2B =objMktInfo; 
            'objServicePlan.Customizations = objCustomizationList; 

            'objServicePlan.Promotions = objPromoList; 
            'objServicePlan.ContractDescription =item.Contract.Description; 
            'objServicePlan.ContractTermsAndConditions = item.TermsAndConditions; 
            'objServicePlan.MovesOffer =item.MovesOffer; 

            ' fields specific to a certain offer type: 
            Select Case enumCategory
                Case GWYCategory.Cable
                    objVideoOffer = TryCast(item, nsWS.VideoOfferType)
                    If objVideoOffer IsNot Nothing Then
                        objServicePlan.channels = ConvertChannels(objVideoOffer.Channels)
                        objServicePlan.premiumchannels = ConvertChannels(objVideoOffer.PremiumChannels)
                        objServicePlan.VideoCategory = ConvertVideoCategory(objVideoOffer.Category)
                        objServicePlan.Requirements = objVideoOffer.Requirements
                    End If
                    Exit Select

                Case GWYCategory.HSD
                    objDataOffer = TryCast(item, nsWS.DataOfferType)
                    If objDataOffer IsNot Nothing Then
                        objServicePlan.uploadSpeed = ConvertDataSpeedType(objDataOffer.UploadSpeed)
                        objServicePlan.downloadSpeed = ConvertDataSpeedType(objDataOffer.DownloadSpeed)
                        objServicePlan.emailAccounts = DefaultInt(objDataOffer.EmailAccounts)
                        objServicePlan.webspace = ConvertDiskSpaceType(objDataOffer.Webspace)
                        objServicePlan.dialupAccess = DefaultBool(objDataOffer.DialUpAccess)

                        objServicePlan.staticIPAddresses = DefaultInt(objDataOffer.StaticIPAddresses)
                        objServicePlan.dynamicIPAddresses = DefaultInt(objDataOffer.DynamicIPAddresses)
                        objServicePlan.Requirements = DefaultString(objDataOffer.Requirements)
                    End If
                    Exit Select

                Case GWYCategory.Telephoney
                    objVoiceOffer = TryCast(item, nsWS.VoiceOfferType)
                    If objVoiceOffer IsNot Nothing Then
                        objServicePlan.longDistanceMinutes = DefaultString(objVoiceOffer.LongDistanceMinutes)
                        objServicePlan.longDistanceCharges = objVoiceOffer.LongDistanceCharges
                        objServicePlan.voiceMailPrice = ConvertPriceType(objVoiceOffer.VoiceMailPrice)
                        objServicePlan.internationalPrice = ConvertPriceType(objVoiceOffer.InternationalPrice)
                        objServicePlan.additionalLinePrice = ConvertPriceType(objVoiceOffer.AdditionalLinePrice)

                        objServicePlan.includes3WayCalling = DefaultBool(objVoiceOffer.Includes3WayCalling)
                        objServicePlan.includesCallerID = DefaultBool(objVoiceOffer.IncludesCallerID)
                        objServicePlan.includesCallerIDWithCallWaiting = DefaultBool(objVoiceOffer.IncludesCallerIDWithCallWaiting)
                        objServicePlan.includesCallReturn = DefaultBool(objVoiceOffer.IncludesCallReturn)
                        objServicePlan.includesCallWaiting = DefaultBool(objVoiceOffer.IncludesCallWaiting)

                        objServicePlan.Requirements = DefaultString(objVoiceOffer.Requirements)
                    End If

                    Exit Select

                Case Else
                    Exit Select

            End Select
            Return objServicePlan

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)

        End Try
    End Function

    ''' <summary>
    ''' Build a Rules object
    ''' </summary>
    ''' <returns>Rules</returns>
    Private Function BuildRules() As Rules
        Dim xString As String
        Dim rules As Rules = Nothing
        Dim xDoc As New XmlDocument()
        Dim node As XmlNode
        Dim cnl As XmlNodeList, pnl As XmlNodeList
        Dim conflictRule As Rules.ConflictFeatureRule
        Dim priorityRule As Rules.ServicePlanPriority
        Dim conflictList As New Dictionary(Of String, Rules.ConflictFeatureRule)()
        Dim priorityList As New Dictionary(Of String, Rules.ServicePlanPriority)()

        Try
            xString = TryCast(System.Web.HttpContext.Current.Application("BUSINESSRULES"), String)
            'Properties.Resources.Rules.ToString(); 

            xDoc.LoadXml(xString)
            node = xDoc.DocumentElement
            cnl = node.SelectNodes("./ConflictingFeatures/Feature")
            For Each cn As XmlNode In cnl
                conflictRule = LoadConflictFeature(cn)
                conflictList.Add(conflictRule.FeatureID, conflictRule)
            Next
            pnl = node.SelectNodes("./ServicePlanPriorities/ServicePlanPriority")
            For Each pn As XmlNode In pnl
                priorityRule = LoadServicePlanPriorities(pn)
                priorityList.Add(priorityRule.ServiceID, priorityRule)
            Next
            rules = New Rules(conflictList, priorityList)
            Return rules

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)

        End Try
    End Function

    ''' <summary>
    ''' Build a string from a Web Service MarketingInfoType object
    ''' </summary>
    ''' <param name="lMarketingInfo">Web Service MarketingInfoType value</param>
    ''' <returns>String</returns>
    Private Function GenerateMarketingText(ByVal lMarketingInfo As nsWS.MarketingInfoType) As String
        Dim marketingtext As String

        Try
            marketingtext = "<p><strong>" + lMarketingInfo.Main + "</strong></p>"
            If lMarketingInfo.Bullet IsNot Nothing Then
                marketingtext = marketingtext + "<ul>"
                For i As Integer = 0 To lMarketingInfo.Bullet.Length - 1
                    marketingtext = marketingtext + "<li>" + lMarketingInfo.Bullet(i) + "</li>"
                Next
                marketingtext = marketingtext + "</ul>"
            End If
            If lMarketingInfo.Text IsNot Nothing Then
                marketingtext = marketingtext + "<BR>"
                For i As Integer = 0 To lMarketingInfo.Text.Length - 1
                    marketingtext = marketingtext + lMarketingInfo.Text(i) + "<BR>"
                Next
            End If
            Return marketingtext

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)
        End Try
    End Function


    ''' <summary> 
    ''' Build the list of Included Items based on the G2B Offer. Also 
    ''' update the Feature list. 
    ''' </summary> 
    ''' <param name="pobjSvcPlanFeatureList">Dictionary of Service Plan Features</param> 
    ''' <param name="pobjOffer">G2B Offer object returned from Web Service Call</param> 
    ''' <param name="penumCategory">Offer Category</param> 
    ''' <returns>Dictionary of Included Item Types. Also updates 
    ''' list of Features.</returns> 
    Private Function FormatIncludedItems(ByVal pobjSvcPlanFeatureList As Dictionary(Of String, Feature), ByVal pobjOffer As nsWS.OfferType, ByVal penumCategory As GWYCategory) As Dictionary(Of String, EntityG2BServices.IncludedItemsType)
        Dim objSvcPlanItemList As New Dictionary(Of String, EntityG2BServices.IncludedItemsType)()
        Dim objIncItemType As EntityG2BServices.IncludedItemsType = Nothing
        Dim objFeatureInSvcPlan As Feature = Nothing
        Dim includedItemsCategory As FeatureCategory

        If pobjOffer.IncludedItems IsNot Nothing Then
            objSvcPlanItemList = New Dictionary(Of String, EntityG2BServices.IncludedItemsType)()
            For Each includedItem As nsWS.IncludedItemsType In pobjOffer.IncludedItems
                includedItemsCategory = ConvertFeatureCategory(includedItem.Category)
                If includedItem.Item IsNot Nothing Then
                    For Each item As nsWS.IncludedItemsItemType In includedItem.Item
                        objFeatureInSvcPlan = BuildFeature(item, penumCategory, includedItemsCategory)
                        If objFeatureInSvcPlan IsNot Nothing Then
                            If item.ItemID = _strtelephoneFeatureID Then
                                If pobjOffer.Promotion IsNot Nothing Then
                                    ' evnthough promotion is a collection, there will be only one promotion coming from G2B 
                                    objFeatureInSvcPlan.Price = pobjOffer.Promotion(0).Value
                                    objFeatureInSvcPlan.ListPrice = pobjOffer.Promotion(0).Value
                                Else
                                    objFeatureInSvcPlan.Price = pobjOffer.Price.Value
                                    objFeatureInSvcPlan.ListPrice = pobjOffer.Price.Value
                                End If
                            End If
                            pobjSvcPlanFeatureList.Add(objFeatureInSvcPlan.ID, objFeatureInSvcPlan)
                        End If
                    Next
                End If
                objIncItemType = ConvertIncludedItem(includedItem)
                If objIncItemType IsNot Nothing Then
                    objSvcPlanItemList.Add(objIncItemType.Name + objIncItemType.Category.ToString(), objIncItemType)
                End If
                ' loop thru web svc included items 
            Next
        End If
        Return objSvcPlanItemList
    End Function

    ''' <summary> 
    ''' Build a local (EntityG2BServices namespace)  Promotion Dictionary from the G2b OFFER object's 
    ''' promotion list. 
    ''' </summary> 
    ''' <param name="pobjOffer">G2B Offer object returned from Web Service Call</param> 
    ''' <returns>Dictionary of PromotionTypes</returns> 
    Private Function FormatPromotionList(ByVal pobjOffer As nsWS.OfferType) As Dictionary(Of String, EntityG2BServices.PromotionType)
        Dim objPromotionListInSvcPlan As New Dictionary(Of String, EntityG2BServices.PromotionType)()
        Dim objPromotion As EntityG2BServices.PromotionType = Nothing

        If pobjOffer.Promotion IsNot Nothing Then
            objPromotionListInSvcPlan = New Dictionary(Of String, EntityG2BServices.PromotionType)()
            For Each objTempPromo As nsWS.PromotionType In pobjOffer.Promotion
                objPromotion = ConvertPromotion(objTempPromo)
                If objPromotion IsNot Nothing Then
                    objPromotionListInSvcPlan.Add(objPromotion.PromotionID, objPromotion)
                End If
            Next
        End If

        Return objPromotionListInSvcPlan
    End Function

    ''' <summary> 
    ''' Format a Dictionary of Hardware Types based on the Offer 
    ''' object returned from G2B 
    ''' </summary> 
    ''' <param name="pobjOffer">G2B Offer object returned from Web Service Call</param> 
    ''' <returns>Dictionary of HardwareType objects</returns> 
    Private Function ConvertHWTypesFromG2B(ByVal pobjOffer As nsWS.OfferType) As Dictionary(Of String, EntityG2BServices.HardwareType)
        Dim objHWTypeListInSvcPlan As New Dictionary(Of String, EntityG2BServices.HardwareType)()
        Dim objHWTypeInSvcPlan As EntityG2BServices.HardwareType = Nothing

        objHWTypeListInSvcPlan = New Dictionary(Of String, EntityG2BServices.HardwareType)()
        If pobjOffer.QualifiedHardware IsNot Nothing Then
            For Each hwType As nsWS.HardwareType In pobjOffer.QualifiedHardware
                If hwType IsNot Nothing Then
                    objHWTypeInSvcPlan = ConvertHWType(hwType)
                    If objHWTypeInSvcPlan IsNot Nothing Then
                        objHWTypeListInSvcPlan.Add(objHWTypeInSvcPlan.Make.ToString() + objHWTypeInSvcPlan.Model.ToString() + objHWTypeInSvcPlan.Value.ToString(), objHWTypeInSvcPlan)
                    End If
                End If
            Next
        End If
        Return objHWTypeListInSvcPlan
    End Function


    ''' <summary> 
    ''' Create a Dictionary of Features and a second one of Customizations 
    ''' based on the G2B Offer 
    ''' </summary> 
    ''' <param name="pobjSvcPlanCustomizationList">Dictionary of Customizations</param> 
    ''' <param name="pobjOffer">G2B Offer object</param> 
    ''' <param name="penumCategory">Offer Category</param> 
    ''' <returns>Dictionary of Feature objects</returns> 
    Private Function ConvertG2BCustomizationsToFeatures(ByRef pobjSvcPlanCustomizationList As Dictionary(Of String, EntityG2BServices.CustomizationTypeQueryOffers), ByVal pobjOffer As nsWS.OfferType, ByVal penumCategory As GWYCategory) As Dictionary(Of String, Feature)
        Dim objCustomization As EntityG2BServices.CustomizationTypeQueryOffers = Nothing
        Dim objFeatureInSvcPlan As Feature = Nothing
        Dim objFeatureListInSvcPlan As New Dictionary(Of String, Feature)()

        objFeatureListInSvcPlan = New Dictionary(Of String, Feature)()
        pobjSvcPlanCustomizationList = New Dictionary(Of String, EntityG2BServices.CustomizationTypeQueryOffers)()

        If pobjOffer.Customization IsNot Nothing Then
            pobjSvcPlanCustomizationList = New Dictionary(Of String, EntityG2BServices.CustomizationTypeQueryOffers)()

            For Each customization As nsWS.CustomizationType In pobjOffer.Customization
                objFeatureInSvcPlan = BuildFeature(customization, penumCategory)
                If objFeatureInSvcPlan IsNot Nothing Then
                    If customization.CustomizationID = _strnumOfComputersID Then
                        ' this customization is for the number of computers option in data plan 
                        ' get price from data base( application object) since we don't get price for this from G2B 
                        objFeatureInSvcPlan.Price = _decnumOfComputersPrice
                        objFeatureInSvcPlan.ListPrice = _decnumOfComputersPrice
                        objFeatureInSvcPlan.PriceFrequency = PriceFrequency.OneTime
                    End If
                    objFeatureListInSvcPlan.Add(objFeatureInSvcPlan.ID, objFeatureInSvcPlan)
                End If
                ' build new full object property list: 
                objCustomization = ConvertCustomization(customization)
                If objCustomization IsNot Nothing Then
                    pobjSvcPlanCustomizationList.Add(objCustomization.CustomizationID.ToString() + objCustomization.Name, objCustomization)
                End If
            Next
        End If
        Return objFeatureListInSvcPlan
    End Function

#End Region

#Region "Misc Utilities"

    ''' <summary>
    ''' Update an object that can be returned to the caller, utilizing the 
    ''' ProviderResults base class Exception/Error Message properties.
    ''' </summary>
    ''' <param name="pstrCode">Error Message Code Number</param>
    ''' <param name="pstrText">Error Message Text</param>
    ''' <remarks></remarks>
    Private Shared Sub FormatG2BCommonResponse(ByVal pobjResponse As ProviderResults, _
        ByVal pstrCode As String, ByVal pstrText As String)
        Dim objResponse As New EntityG2BServices.G2BCommonResponse
        Dim lErrorMappingProvider As New ErrorMappingProvider.ProviderManager
        Try
            '#################################
            'ERROR CODE MAPPING SOLUTION
            '#################################

            pobjResponse.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(pstrCode, pstrText)
            pobjResponse.Exception = True
            pobjResponse.ExceptionMessage = pstrText

        Catch ex As Exception
            pobjResponse.Exception = True
            pobjResponse.ExceptionMessage = ex.Message
            pobjResponse.ExceptionStackTrace = ex.StackTrace

        Finally

        End Try
    End Sub

    Private Sub SendEMail(ByVal FromMailID As String, ByVal ToMailID As String, ByVal Subject As String, ByVal Body As String, Optional ByVal isHTML As Boolean = False)
        Try
            Dim from_Config As String = CType(HttpContext.Current.Application("SMTP_SERVER"), String)
            Dim client As New SmtpClient(from_Config)
            Dim mailMsg As New MailMessage(FromMailID, ToMailID)
            With mailMsg
                .Subject = Subject
                .Body = Body
            End With
            mailMsg.IsBodyHtml = isHTML
            client.Send(mailMsg)

        Catch ex As Exception

        End Try
    End Sub

    Private Shared Function GetFriendlyMessage(ByVal pstrCode As String, ByVal pstrText As String) As String

        Dim strResponse As String = String.Empty
        Dim lErrorMappingProvider As New ErrorMappingProvider.ProviderManager

        strResponse = lErrorMappingProvider.GetErrorMessageList("G2BSERVICESPROVIDER", _
            pstrCode, _
            pstrText)

        Return strResponse
    End Function
    ''' <summary> 
    ''' Determine the Category type from the G2B Offer 
    ''' </summary> 
    ''' <param name="pobjOffer">G2B Offer objcet</param> 
    ''' <returns>GWYCategory type</returns> 
    Private Shared Function GetCategoryFromOfferName(ByVal pobjOffer As nsWS.OfferType) As GWYCategory

        If String.Compare(pobjOffer.[GetType]().FullName, GetType(nsWS.VideoOfferType).FullName, True) = 0 Then
            Return GWYCategory.Cable
        End If

        If String.Compare(pobjOffer.[GetType]().FullName, GetType(nsWS.DataOfferType).FullName, True) = 0 Then
            Return GWYCategory.HSD
        End If

        If String.Compare(pobjOffer.[GetType]().FullName, GetType(nsWS.VoiceOfferType).FullName, True) = 0 Then
            Return GWYCategory.Telephoney
        End If
        Return GWYCategory.UnSpecified
    End Function

    ''' <summary> 
    ''' 
    ''' </summary> 
    ''' <returns></returns> 
    Public Overloads Overrides Function GetChooseOptionsXml() As IProviderResults
        Dim objresult As EntityG2BServices.EntityUIRules
        objresult = New EntityG2BServices.EntityUIRules()
        Try
            objresult.Data = TryCast(System.Web.HttpContext.Current.Application("CHOOSEOPTIONS"), String)
            Return (objresult)
        Catch ex As Exception
            objresult.Exception = True
            objresult.ExceptionMessage = ex.Message
            objresult.ExceptionStackTrace = ex.StackTrace
            objresult.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_CHOOSEOPTIONS_CODE, ex.Message)
            Return (objresult)
        End Try
    End Function

    ''' <summary> 
    ''' 
    ''' </summary> 
    ''' <returns></returns> 
    Public Overloads Overrides Function GetBuildYourOwnXml() As IProviderResults
        Dim objresult As EntityG2BServices.EntityUIRules
        objresult = New EntityG2BServices.EntityUIRules()
        Try
            objresult.Data = TryCast(System.Web.HttpContext.Current.Application("BUILDYOUROWN"), String)
            Return (objresult)
        Catch ex As Exception
            objresult.Exception = True
            objresult.ExceptionMessage = ex.Message
            objresult.ExceptionStackTrace = ex.StackTrace
            objresult.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_BUILDYOUROWN_CODE, ex.Message)
            Return (objresult)
        End Try
    End Function

    ''' <summary> 
    ''' 
    ''' </summary> 
    ''' <returns></returns> 
    Public Overloads Overrides Function GetShowPriceList() As IProviderResults
        Dim objresult As EntityG2BServices.EntityUIRules
        objresult = New EntityG2BServices.EntityUIRules()
        Try
            objresult.Data = TryCast(System.Web.HttpContext.Current.Application("SHOWPRICELIST"), String)

            Return (objresult)
        Catch ex As Exception
            objresult.Exception = True
            objresult.ExceptionMessage = ex.Message
            objresult.ExceptionStackTrace = ex.StackTrace
            objresult.CharterDotCom_Friendly_Messages = ProviderManager.GetFriendlyMessage(Constant.EXCEPTION_SHOWPRICE_CODE, ex.Message)
            Return (objresult)
        End Try
    End Function

    ''' <summary> 
    ''' 
    ''' </summary> 
    ''' <param name="contentparams"></param> 
    ''' <returns></returns> 
    Public Function GetMultipleContent(ByVal contentparams As String) As DataTable
        Dim ds As DataSet
        Dim cmd As DbCommand = Nothing
        Dim strTemp As String = Nothing
        strTemp = strTemp & ""
        Dim i As Integer = strTemp.Length
        Dim db As Database
        Try
            db = DatabaseFactory.CreateDatabase("Charter.Website.WS.CommerceEngineConnectionString")
            cmd = db.GetStoredProcCommand(Constant.STOREDPROC_GETMULTIPLE_CONTENT)
            db.AddInParameter(cmd, "@ContentParams", DbType.[String], contentparams)
            ds = db.ExecuteDataSet(cmd)
            ds.DataSetName = "CONTENT"
            If ds.Tables.Count <> 0 Then
                Return (ds.Tables(0))
            End If
            Return Nothing

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)

        Finally
            If Not (cmd Is Nothing) Then
                cmd.Dispose()
            End If
        End Try
    End Function

    Private Function DefaultString(ByVal pobj As Object) As String
        Return DefaultString(pobj, String.Empty)
    End Function

    Private Function DefaultString(ByVal pobj As Object, ByVal psDefault As String) As String
        If pobj Is Nothing Then
            Return psDefault
        End If

        Return pobj.ToString()
    End Function

    Private Function DefaultBool(ByVal pobj As Object) As Boolean
        If (pobj IsNot Nothing) Then
            Return pobj
        Else
            Return False
        End If
    End Function

    Private Function DefaultInt(ByVal pobj As Object) As Integer
        If (pobj IsNot Nothing) Then
            Return pobj
        Else
            Return 0
        End If
    End Function

    Private Function LoadConflictFeature(ByVal node As XmlNode) As Rules.ConflictFeatureRule
        Dim conflictRule As Rules.ConflictFeatureRule
        Dim conflictList As New List(Of String)()
        Dim featureID As String
        Dim cfnl As XmlNodeList
        Try
            featureID = node("FeatureID").InnerText
            cfnl = node.SelectNodes("./ConflictFeatures/FeatureID")
            conflictRule = New Rules.ConflictFeatureRule(featureID)
            For Each cfn As XmlNode In cfnl
                conflictRule.AddToConflictingFeatures(cfn.InnerText)
            Next
            Return conflictRule

        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)

        End Try
    End Function

    Private Function LoadServicePlanPriorities(ByVal node As XmlNode) As Rules.ServicePlanPriority
        Dim priorityRule As Rules.ServicePlanPriority
        Dim serviceID As String
        Dim category As GWYCategory
        Dim priority As Integer
        Try
            serviceID = node("ServiceID").InnerText
            category = GetCategory(node("Category").InnerText)
            priority = Convert.ToInt32(node("Priority").InnerText)
            priorityRule = New Rules.ServicePlanPriority(serviceID, category, priority)
            Return priorityRule
        Catch ex As Exception
            'In .Net , when you do "throw ex;", ex is being re-thrown, 
            'but the original stack trace info gets overriden. 
            'The point where exception is re-thrown is now becoming the 
            'exception's origin. 
            'So in .NET you have to use "throw" keyword ("Throw" in VB.NET) 
            'with no argument to perform a pure re-throwing of an exception .
            'Now you can see the full exception stack trace.
            Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " " + ex.Message)

        End Try
    End Function

    '############################ 
    'USED FOR ORDER LOG CURRENTLY 
    '############################ 
    Private Sub LogOrder(ByVal obj As IProviderParameters)
        Try
            Dim ds As DataSet
            Dim lOrderAddressID As Integer = 0
            Dim lOrderID As Integer = 0
            Dim lOfferOrder As nsWS.OfferOrderType() = Nothing
            Dim lCustomization As nsWS.CustomizationOrderType() = Nothing
            Dim lG2BSubmitOrderRequest As EntityG2BServices.G2BSubmitOrderRequest
            lG2BSubmitOrderRequest = TryCast(obj, EntityG2BServices.G2BSubmitOrderRequest)

            If lG2BSubmitOrderRequest IsNot Nothing Then
                If lG2BSubmitOrderRequest.ShippingAddress IsNot Nothing Then
                    '########################### 
                    'DO INSERT FOR ORDER ADDRESS 
                    '########################### 
                    CMD = DB.GetStoredProcCommand(Constant.STOREDPROC_CREATE_ADDRESS)
                    DB.AddInParameter(CMD, "@ADDRESS1", DbType.[String], lG2BSubmitOrderRequest.ShippingAddress.Street1)
                    DB.AddInParameter(CMD, "@ADDRESS2", DbType.[String], lG2BSubmitOrderRequest.ShippingAddress.Street2)
                    DB.AddInParameter(CMD, "@CITY", DbType.[String], lG2BSubmitOrderRequest.ShippingAddress.City)
                    DB.AddInParameter(CMD, "@STATE", DbType.[String], lG2BSubmitOrderRequest.ShippingAddress.State)
                    DB.AddInParameter(CMD, "@ZIP", DbType.[String], lG2BSubmitOrderRequest.ShippingAddress.Zip)
                    DB.AddInParameter(CMD, "@ZIP4", DbType.[String], lG2BSubmitOrderRequest.ShippingAddress.Zip4)

                    ds = DB.ExecuteDataSet(CMD)

                    lOrderAddressID = CInt(ds.Tables(0).Rows(0)(0))
                End If
                '########################### 
                'DO INSERT FOR ORDER 
                '########################### 
                CMD = DB.GetStoredProcCommand(Constant.STOREDPROC_CREATE_ORDER)
                DB.AddInParameter(CMD, "@ADDRESS_TABLE_ID", DbType.Int32, lOrderAddressID)
                DB.AddInParameter(CMD, "@FIRSTNAME", DbType.[String], lG2BSubmitOrderRequest.FirstName)
                DB.AddInParameter(CMD, "@LASTNAME", DbType.[String], lG2BSubmitOrderRequest.LastName)
                DB.AddInParameter(CMD, "@SERVICEADDRESSPHONE", DbType.[String], lG2BSubmitOrderRequest.ServiceAddressPhone)
                DB.AddInParameter(CMD, "@CONTACTPHONE", DbType.[String], lG2BSubmitOrderRequest.ContactPhone)
                DB.AddInParameter(CMD, "@EMAIL", DbType.[String], lG2BSubmitOrderRequest.Email)
                DB.AddInParameter(CMD, "@CONTACTINSTRUCTIONS", DbType.[String], lG2BSubmitOrderRequest.ContactInstructions)
                DB.AddInParameter(CMD, "@ADDITIONALINFO", DbType.[String], lG2BSubmitOrderRequest.AdditionalInfo)
                DB.AddInParameter(CMD, "@TRACKINGID", DbType.Int32, lG2BSubmitOrderRequest.TrackingID)
                DB.AddInParameter(CMD, "@MSOID", DbType.Int32, lG2BSubmitOrderRequest.MSOID)
                DB.AddInParameter(CMD, "@ADDRESSID", DbType.Int32, lG2BSubmitOrderRequest.AddressID)
                DB.AddInParameter(CMD, "@RESEND", DbType.Int32, lG2BSubmitOrderRequest.Resend)

                ds = DB.ExecuteDataSet(CMD)
                lOrderID = CInt(ds.Tables(0).Rows(0)(0))

                'if (lG2BSubmitOrderRequest.CreditCard != null) 
                '{ 
                ' if (lG2BSubmitOrderRequest.CreditCard.BillingAddress != null) 
                ' { 
                ' //################################## 
                ' //DO INSERT FOR CREDIT CARD ADDRESS 
                ' //################################## 
                ' CMD = DB.GetStoredProcCommand(Constant.STOREDPROC_CREATE_ADDRESS); 
                ' DB.AddInParameter(CMD, "@ADDRESS1", DbType.String, lG2BSubmitOrderRequest.CreditCard.BillingAddress.Street1); 
                ' DB.AddInParameter(CMD, "@ADDRESS2", DbType.String, lG2BSubmitOrderRequest.CreditCard.BillingAddress.Street2); 
                ' DB.AddInParameter(CMD, "@CITY", DbType.String, lG2BSubmitOrderRequest.CreditCard.BillingAddress.City); 
                ' DB.AddInParameter(CMD, "@STATE", DbType.String, lG2BSubmitOrderRequest.CreditCard.BillingAddress.State); 
                ' DB.AddInParameter(CMD, "@ZIP", DbType.String, lG2BSubmitOrderRequest.CreditCard.BillingAddress.Zip); 
                ' DB.AddInParameter(CMD, "@ZIP4", DbType.String, lG2BSubmitOrderRequest.CreditCard.BillingAddress.Zip4); 

                ' ds = DB.ExecuteDataSet(CMD); 
                ' lCreditCardAddressID = (int)ds.Tables[0].Rows[0][0]; 
                ' } 

                ' if (lCreditCardAddressID > 0) 
                ' { 
                ' //########################### 
                ' //DO INSERT FOR CREDIT CARD 
                ' //########################### 
                ' CMD = DB.GetStoredProcCommand(Constant.STOREDPROC_CREATE_CREDITCARD); 
                ' DB.AddInParameter(CMD, "@ORDER_TABLE_ID", DbType.Int32, lOrderID); 
                ' DB.AddInParameter(CMD, "@ADDRESS_TABLE_ID", DbType.Int32, lCreditCardAddressID); 
                ' DB.AddInParameter(CMD, "@CARDNAME", DbType.String, lG2BSubmitOrderRequest.CreditCard.Name); 
                ' DB.AddInParameter(CMD, "@EXPIRATION", DbType.String, lG2BSubmitOrderRequest.CreditCard.Expiration); 
                ' DB.AddInParameter(CMD, "@SECURITYCODE", DbType.String, lG2BSubmitOrderRequest.CreditCard.SecurityCode); 
                ' DB.AddInParameter(CMD, "@BILLINGFULLNAME", DbType.String, lG2BSubmitOrderRequest.CreditCard.BillingFullName); 
                ' DB.AddInParameter(CMD, "@BILLINGPHONE", DbType.String, lG2BSubmitOrderRequest.CreditCard.BillingPhone); 

                ' ds = DB.ExecuteDataSet(CMD); 

                ' lCreditCardID = (int)ds.Tables[0].Rows[0][0]; 
                ' } 
                '} 

                'if (lG2BSubmitOrderRequest.Discount != null) 
                '{ 
                ' lDiscount = new namespaceWSSubmit.DiscountType[lG2BSubmitOrderRequest.Discount.Count]; 
                ' int counterI = 0; 
                ' foreach (EntityG2BServices.DiscountType discount in lG2BSubmitOrderRequest.Discount) 
                ' { 
                ' //########################### 
                ' //DO INSERT FOR DISCOUNT 
                ' //########################### 
                ' CMD = DB.GetStoredProcCommand(Constant.STOREDPROC_CREATE_DISCOUNT); 
                ' DB.AddInParameter(CMD, "@ORDER_TABLE_ID", DbType.Int32, lOrderID); 
                ' DB.AddInParameter(CMD, "@DISCOUNTID", DbType.String, discount.DiscountID); 
                ' ds = DB.ExecuteDataSet(CMD); 

                ' counterI++; 
                ' } 
                '} 

                If lG2BSubmitOrderRequest.OfferOrder IsNot Nothing Then
                    lOfferOrder = New nsWS.OfferOrderType(lG2BSubmitOrderRequest.OfferOrder.Count - 1) {}
                    Dim counterI As Integer = 0
                    For Each offerOrder As EntityG2BServices.OfferOrderTypeG2BOrder In lG2BSubmitOrderRequest.OfferOrder
                        '########################### 
                        'DO INSERT FOR OFFER ORDER 
                        '########################### 
                        CMD = DB.GetStoredProcCommand(Constant.STOREDPROC_CREATE_OFFERORDER)
                        DB.AddInParameter(CMD, "@ORDER_TABLE_ID", DbType.Int32, lOrderID)
                        DB.AddInParameter(CMD, "@OFFERID", DbType.[String], offerOrder.OfferID)
                        DB.AddInParameter(CMD, "@VERSION", DbType.[Double], offerOrder.Version)
                        DB.AddInParameter(CMD, "@AFFILIATEORDERID", DbType.[String], offerOrder.AffiliateOrderID)
                        DB.AddInParameter(CMD, "@AFFILIATELINEID", DbType.[String], offerOrder.AffiliateLineID)
                        DB.AddInParameter(CMD, "@AFFILIATEINSTALL", DbType.[Boolean], offerOrder.AffiliateInstall)
                        ds = DB.ExecuteDataSet(CMD)
                        Dim lOfferOrderID As Integer = CInt(ds.Tables(0).Rows(0)(0))

                        If offerOrder.Customization IsNot Nothing Then
                            lCustomization = New nsWS.CustomizationOrderType(offerOrder.Customization.Count - 1) {}
                            Dim counterJ As Integer = 0
                            For Each customization As EntityG2BServices.CustomizationTypeOrder In offerOrder.Customization
                                '########################### 
                                'DO INSERT FOR CUSTOMIZATION 
                                '########################### 
                                CMD = DB.GetStoredProcCommand(Constant.STOREDPROC_CREATE_CUSTOMIZATION)
                                DB.AddInParameter(CMD, "@OFFERORDER_TABLE_ID", DbType.Int32, lOfferOrderID)
                                DB.AddInParameter(CMD, "@CUSTOMIZATIONID", DbType.[String], customization.CustomizationID)
                                ds = DB.ExecuteDataSet(CMD)
                                Dim lCustomizationID As Integer = CInt(ds.Tables(0).Rows(0)(0))

                                If customization.Items IsNot Nothing Then
                                    Dim counterK As Integer = 0
                                    Dim item As Object = offerOrder.Customization(counterJ).Items
                                    Dim choices As String = String.Empty

                                    If (item.[GetType]().FullName = GetType(Integer).FullName) OrElse (item.[GetType]().FullName = GetType(String).FullName) Then
                                        CMD = DB.GetStoredProcCommand(Constant.STOREDPROC_CREATE_ITEM)
                                        DB.AddInParameter(CMD, "@CUSTOMIZATION_TABLE_ID", DbType.Int32, lCustomizationID)
                                        DB.AddInParameter(CMD, "@CHOICEID", DbType.[String], item)
                                        ds = DB.ExecuteDataSet(CMD)
                                    ElseIf item.[GetType]().FullName = GetType(EntityG2BServices.SelectionTypeOrder).FullName Then
                                        Dim selections As EntityG2BServices.SelectionTypeOrder = TryCast(item, EntityG2BServices.SelectionTypeOrder)
                                        For Each selection As String In selections.ChoiceIDs
                                            CMD = DB.GetStoredProcCommand(Constant.STOREDPROC_CREATE_ITEM)
                                            DB.AddInParameter(CMD, "@CUSTOMIZATION_TABLE_ID", DbType.Int32, lCustomizationID)
                                            DB.AddInParameter(CMD, "@CHOICEID", DbType.[String], selection)
                                            ds = DB.ExecuteDataSet(CMD)
                                        Next
                                    ElseIf item.[GetType]().FullName = GetType(EntityG2BServices.InputTextTypeOrder).FullName Then
                                        Dim selections As EntityG2BServices.InputTextTypeOrder = TryCast(item, EntityG2BServices.InputTextTypeOrder)
                                        If (selections IsNot Nothing) Then
                                            CMD = DB.GetStoredProcCommand(Constant.STOREDPROC_CREATE_ITEM)
                                            DB.AddInParameter(CMD, "@CUSTOMIZATION_TABLE_ID", DbType.Int32, lCustomizationID)
                                            DB.AddInParameter(CMD, "@CHOICEID", DbType.[String], selections.TextID)
                                            ds = DB.ExecuteDataSet(CMD)
                                        End If

                                    Else
                                        Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod().Name + " Item Collection in not of a valid type.")
                                    End If

                                    '########################### 
                                    'DO INSERT FOR ITEM 
                                    '########################### 
                                    ' } 
                                    counterK += 1
                                End If
                                counterJ += 1
                            Next
                        End If
                        counterI += 1
                    Next
                End If
            End If
        Catch ex As Exception
            'throw ex; 
            ex.ToString()
        End Try
    End Sub


#End Region

End Class