/// <summary>
        /// 
        /// </summary>
        /// <param name="locationId"></param>
        /// <param name="headerArgs"></param>
        /// <returns></returns>
        private static invokeRequest CreateSyncPlantRequest(string locationId, HeaderArgs headerArgs)
        {
            // construct header
            var header = new Header
            {
                Source = "SIMPL",
                Security_T = new CharacteristicSpecification[2],
                ConsumerInfo = new CharacteristicSpecification[4]
            };

            header.Security_T[0] = new CharacteristicSpecification
            {
                name = "employeeID",
                Value = new CharacteristicValue
                {
                    value = headerArgs.CrisId
                }
            };

            header.Security_T[1] = new CharacteristicSpecification
            {
                name = "userID",
                Value = new CharacteristicValue
                {
                    value = headerArgs.CorpId ?? string.Empty
                }
            };

            header.ConsumerInfo[0] = new CharacteristicSpecification
            {
                name = "DPIEnvironment",
                Value = new CharacteristicValue
                {
                    value = headerArgs.DpiRegion ?? string.Empty
                }
            };

            header.ConsumerInfo[1] = new CharacteristicSpecification
            {
                name = "name",
                Value = new CharacteristicValue
                {
                    value = headerArgs.Name ?? string.Empty
                }
            };

            header.ConsumerInfo[2] = new CharacteristicSpecification
            {
                name = "email",
                Value = new CharacteristicValue
                {
                    value = headerArgs.Email ?? string.Empty
                }
            };

            header.ConsumerInfo[3] = new CharacteristicSpecification
            {
                name = "role",
                Value = new CharacteristicValue
                {
                    value = headerArgs.Role ?? string.Empty
                }
            };

            // construct payload
            var searchCharacteristic = new CharacteristicSpecification[1];
            searchCharacteristic[0] = new CharacteristicSpecification
            {
                name = "locationId",
                Value = new CharacteristicValue {value = locationId}
            };

            var searchCriteria = new Entity[1];

            searchCriteria[0] = new Entity
            {
                type = "ResourceId",
                Characteristics = searchCharacteristic
            };

            var esbRequest = new invokeRequest
            {
                invoke = new invoke
                {
                    syncResourceInput = new msg_LookupRequest
                    {
                        Header = header,
                        Payload = new LookupRequest
                        {
                            SearchCriteria = searchCriteria
                        }
                    }
                }
            };
            return esbRequest;
        }
        public invokeRequest CreateGetFacilitiesRequest(GetFacilitiesRequestDto request, HeaderArgs headerArgs)
        {
            //Null checked in caller
            var usi = request.USI;

            // construct header
            var header = new Header
            {
                Source = "SIMPL",
                Security_T = new CharacteristicSpecification[2],
                ConsumerInfo = new CharacteristicSpecification[4]
            };

            header.Security_T[0] = new CharacteristicSpecification
            {
                name = "employeeID",
                Value = new CharacteristicValue
                {
                    value = headerArgs.CrisId
                }
            };

            header.Security_T[1] = new CharacteristicSpecification
            {
                name = "userID",
                Value = new CharacteristicValue
                {
                    value = headerArgs.CorpId ?? string.Empty
                }
            };

            header.ConsumerInfo[0] = new CharacteristicSpecification
            {
                name = "DPIEnvironment",
                Value = new CharacteristicValue
                {
                    value = headerArgs.DpiRegion ?? string.Empty
                }
            };

            header.ConsumerInfo[1] = new CharacteristicSpecification
            {
                name = "name",
                Value = new CharacteristicValue
                {
                    value = headerArgs.Name ?? string.Empty
                }
            };

            header.ConsumerInfo[2] = new CharacteristicSpecification
            {
                name = "email",
                Value = new CharacteristicValue
                {
                    value = headerArgs.Email ?? string.Empty
                }
            };

            header.ConsumerInfo[3] = new CharacteristicSpecification
            {
                name = "role",
                Value = new CharacteristicValue
                {
                    value = headerArgs.Role ?? string.Empty
                }
            };

            // construct payload
            var searchCharacteristic = new CharacteristicSpecification[1];

            searchCharacteristic[0] = new CharacteristicSpecification
            {
                name = "uniqueServiceIdentifier",
                Value = new CharacteristicValue { value = usi }
            };

            var searchCriteria = new Entity[1];

            searchCriteria[0] = new Entity
            {
                type = "accountId",
                Characteristics = searchCharacteristic
            };

            var esbRequest = new invokeRequest()
            {
                retrieveServiceDesignInput = new msg_LookupRequest()
                {
                    Header = header,
                    Payload = new LookupRequest
                    {
                        SearchCriteria = searchCriteria
                    }
                }
            };
            return esbRequest;
        }
        public bool ScheduleServiceDiagnosticTest(string lineTestId, string phoneNumber, HeaderArgs headerArgs)
        {
            Header header = null;
            Service[] service = null;
            invokeRequest esbRequest = null;

            try
            {
                // construct header
                header = new Header
                {
                    Source = "SIMPL",
                    Security_T = new CharacteristicSpecification[2],
                    ConsumerInfo = new CharacteristicSpecification[4],
                    Timestamp = DateTime.Now,
                    MessageId = lineTestId,
                    CorrelationId_T = phoneNumber
                };

                header.Security_T[0] = new CharacteristicSpecification
                {
                    name = "employeeID",
                    Value = new CharacteristicValue
                    {
                        value = headerArgs.CrisId
                    }
                };

                header.Security_T[1] = new CharacteristicSpecification
                {
                    name = "userID",
                    Value = new CharacteristicValue
                    {
                        value = headerArgs.CorpId ?? string.Empty
                    }
                };

                header.ConsumerInfo[0] = new CharacteristicSpecification
                {
                    name = "DPIEnvironment",
                    Value = new CharacteristicValue
                    {
                        value = headerArgs.DpiRegion ?? string.Empty
                    }
                };

                header.ConsumerInfo[1] = new CharacteristicSpecification
                {
                    name = "name",
                    Value = new CharacteristicValue
                    {
                        value = headerArgs.Name ?? string.Empty
                    }
                };

                header.ConsumerInfo[2] = new CharacteristicSpecification
                {
                    name = "email",
                    Value = new CharacteristicValue
                    {
                        value = headerArgs.Email ?? string.Empty
                    }
                };

                header.ConsumerInfo[3] = new CharacteristicSpecification
                {
                    name = "role",
                    Value = new CharacteristicValue
                    {
                        value = headerArgs.Role ?? string.Empty
                    }
                };

                header.CorrelationId_T = string.Format("phoneNbr={0}", phoneNumber);

                // construct payload
                service = new Service[1];
                service[0] = new Service
                {
                    ServiceIdentification = new IBMTelecomRootObject
                    {
                        ID = phoneNumber
                    },
                    hasStarted = false,
                    ServiceLocation = new Place
                    {
                        GeographicAddress = new GeographicAddress
                        {
                            GeographicAddressExtension = new GeographicAddressExtension
                            {
                                isInFootprint = false
                            }
                        }
                    },
                    ServiceDescribedBy = new[]
                    {
                        new CharacteristicSpecification
                        {
                            name = "testType",
                            Value = new CharacteristicValue
                            {
                                value = "DSLDIG"
                            }
                        }
                    }
                };

                esbRequest = new invokeRequest
                {
                    scheduleServiceDiagnosticTestInput = new msg_Service
                    {
                        Header = header,
                        Payload = service
                    }

                };
            }
            catch (System.Exception ex)
            {
                if (_errorLoggingService != null)
                {
                    _errorLoggingService.LogErrorNoContext(ex);
                }
                var myException = new System.Exception("Error getting data for line test", ex);
                throw myException;
            }

            try
            {
                _lineTestClient.invoke(esbRequest);
            }
            catch (System.Exception e)
            {
                var isServiceException = _enterpriseExceptionHandler.HandleGeneralServiceExceptions(e);

                if ((isServiceException) && (_errorLoggingService != null))
                {
                    _errorLoggingService.LogErrorNoContext(e);
                }

                return false;
            }

            return true;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="lineTestId"></param>
        /// <param name="phoneNumber"></param>
        /// <param name="headerArgs"></param>
        public bool InitiateLineTest(string lineTestId, string phoneNumber, HeaderArgs headerArgs)
        {
            var securityT = new CharacteristicSpecification[2];
            var service = new ScheduleServiceDiagnosticTest.Service[1];

            securityT[0] = new CharacteristicSpecification
            {
                name = "employeeID",
                Value = new CharacteristicValue { value = headerArgs.CrisId }
            };

            securityT[1] = new CharacteristicSpecification
            {
                name = "userID",
                Value = new CharacteristicValue { value = headerArgs.CorpId }
            };

            service[0] = new ScheduleServiceDiagnosticTest.Service
            {
                ServiceIdentification = new IBMTelecomRootObject
                {
                    ID = lineTestId
                },
                hasStarted = false,
                ServiceLocation = new Place
                {
                    GeographicAddress = new GeographicAddress
                    {
                        GeographicAddressExtension = new GeographicAddressExtension
                        {
                            isInFootprint = false
                        }
                    }
                }
            };

            var esbRequest = new invokeRequest
            {
                scheduleServiceDiagnosticTestInput = new msg_Service
                {
                    Header = new Header
                    {
                        CorrelationId_T = "CORRELID",
                        Source = "SIMPL",
                        MessageId = lineTestId,
                        Security_T = securityT,
                        Timestamp = DateTime.Now
                    },
                    Payload = service
                }

            };

            _lineTestClient.invoke(esbRequest);

            return true;
        }
        public invokeRequest CreateRetrieveCustomerServiceConfigurationRequest(string emailAddress, HeaderArgs headerArgs)
        {
            var emailAddressParts = emailAddress.Split('@');

            // construct header
            var header = new Header
            {
                Source = "SIMPL",
                Security_T = new CharacteristicSpecification[2],
                ConsumerInfo = new CharacteristicSpecification[4]
            };

            header.Security_T[0] = new CharacteristicSpecification
            {
                name = "employeeID",
                Value = new CharacteristicValue
                {
                    value = headerArgs.CrisId
                }
            };

            header.Security_T[1] = new CharacteristicSpecification
            {
                name = "userID",
                Value = new CharacteristicValue
                {
                    value = headerArgs.CorpId ?? string.Empty
                }
            };

            header.ConsumerInfo[0] = new CharacteristicSpecification
            {
                name = "DPIEnvironment",
                Value = new CharacteristicValue
                {
                    value = headerArgs.DpiRegion ?? string.Empty
                }
            };

            header.ConsumerInfo[1] = new CharacteristicSpecification
            {
                name = "name",
                Value = new CharacteristicValue
                {
                    value = headerArgs.Name ?? string.Empty
                }
            };

            header.ConsumerInfo[2] = new CharacteristicSpecification
            {
                name = "email",
                Value = new CharacteristicValue
                {
                    value = headerArgs.Email ?? string.Empty
                }
            };

            header.ConsumerInfo[3] = new CharacteristicSpecification
            {
                name = "role",
                Value = new CharacteristicValue
                {
                    value = headerArgs.Role ?? string.Empty
                }
            };

            // construct payload
            var searchCharacteristic = new CharacteristicSpecification[3];

            searchCharacteristic[0] = new CharacteristicSpecification
            {
                name = "localPart",
                Value = new CharacteristicValue { value = emailAddressParts[0] }
            };

            searchCharacteristic[1] = new CharacteristicSpecification
            {
                name = "domain",
                Value = new CharacteristicValue { value = emailAddressParts[1] }
            };

            searchCharacteristic[2] = new CharacteristicSpecification
            {
                name = "password",
                Value = new CharacteristicValue { value = "whocares" }
            };

            var filterCharacteristicsEmail = new CharacteristicSpecification[1];

            filterCharacteristicsEmail[0] = new CharacteristicSpecification()
            {
                name = "EmailAddress"
            };

            var filterCharacteristicsIp = new CharacteristicSpecification[1];

            filterCharacteristicsIp[0] = new CharacteristicSpecification()
            {
                name = "internetProtocolAddress"
            };

            var request = new invokeRequest()
            {
                retrieveCustomerServiceConfigurationInput = new msg_LookupRequest
                {
                    Header = header,
                    Payload = new LookupRequest
                    {
                        SearchCriteria = new Entity[1]
                        {
                            new Entity()
                            {
                                name = "EmailAddress",
                                Characteristics = searchCharacteristic

                            }
                        },
                        FilterCriteria = new Entity[2]
                        {
                            new Entity()
                            {
                                name = "IncludeItems",
                                Characteristics = filterCharacteristicsEmail
                            },
                            new Entity()
                            {
                                name = "IncludeItems",
                                Characteristics = filterCharacteristicsIp
                            }
                        }
                    }
                }
            };

            return request;
        }