public CentralConnectCode RegisterClient(string environment, string clientName, string domain, string createBy)
        {
            List <RegisterClientMessage> registerClientMessages = this.RetrieveRegisterClientMessageByEnvironmentAndClientNameAndDomain(environment, clientName, domain);

            if (registerClientMessages.Count > 0)
            {
                return(CentralConnectCode.RegisterClientMessageExist);
            }
            DictionaryAction dictionaryAction = new DictionaryAction(this.ConnectString);
            string           serviceUrl       = string.Format("{0}/{1}", dictionaryAction.RetrieveServiceUrl(environment), "ClientRegistration/ClientRegistrationService.asmx");

            Logger.Write(string.Format("ServiceUrl={0},ClientName={1},Domain={2}", serviceUrl, clientName, domain));
            //Client
            List <Client> clients = this.RetrieveClientByClientNameAndDomain(clientName, domain);

            if (clients.Count != 1)
            {
                return(CentralConnectCode.ClientNotFound);
            }
            Logger.Write("Retrieve Client", clients[0]);
            Client client = clients[0];
            //Contact
            ContactAction  contactAction   = new ContactAction(this.ConnectString);
            List <Contact> primaryContacts = contactAction.RetrieveContactByFullName(client.PrimaryContact);

            if (primaryContacts.Count != 1)
            {
                return(CentralConnectCode.PrimaryContactNotFound);
            }
            Logger.Write("Retrieve PrimaryContacts", primaryContacts[0]);
            Contact        primaryContact    = primaryContacts[0];
            List <Contact> secondaryContacts = contactAction.RetrieveContactByFullName(client.SecondaryContact);

            if (secondaryContacts.Count != 1)
            {
                return(CentralConnectCode.SecondaryContactNotFound);
            }
            Logger.Write("Retrieve SecondaryContact", secondaryContacts[0]);
            Contact secondaryContact = secondaryContacts[0];
            //Company
            CompanyAction  companyAction = new CompanyAction(this.ConnectString);
            List <Company> companys      = companyAction.RetrieveCompanyByCompanyName(client.CompanyName);

            if (companys.Count != 1)
            {
                return(CentralConnectCode.CompanyNotFound);
            }
            Logger.Write("Retrieve Company", companys[0]);
            Company company = companys[0];

            //Request
            HP.TS.Devops.CentralConnect.ClientRegistration.RequestBody requestBody = new HP.TS.Devops.CentralConnect.ClientRegistration.RequestBody()
            {
                CoreSystemModel        = client.CoreSystemModel,
                ProductId              = client.ProductNumber,
                FQDN                   = string.Format("{0}.{1}", client.ClientName, client.Domain),
                Hostname               = client.ClientName,
                OSNameAndVersionString = string.Format("{0},{1}", client.OSName, client.OSVersion),
                SystemModel            = client.CoreSystemModel,
                MacAddress             = client.MAC,
                IPAddress              = client.IPAddress,
                PRSCaption             = client.CompanyName,
                PRSDirtyFlag           = 1,
                PRSUniqueName          = client.CompanyName,
                PRSAddress1            = company.Street,
                PRSCity                = company.City,
                PRSRegion              = company.StateProvince,
                PRSPostalCode          = company.PostalCode,
                PRSCountry             = company.CountryCode,
                ISEECusCaption         = client.CompanyName,
                ISEECusPRSUniqueName   = client.CompanyName,
                ISEECusName            = client.CompanyName,
                ISEEEntSerialNumber    = client.SerialNumber,
                ISEEEntProductNumber   = client.ProductNumber,
                ISEEEntProductId       = client.ProductNumber,

                ISEEFirstPersonFirstName       = primaryContact.FirstName,
                ISEEFirstPersonLastName        = primaryContact.LastName,
                ISEEFirstPersonEmailAddress    = primaryContact.EmailAddress,
                ISEEFirstPersonTelephoneNumber = primaryContact.Phone,

                ISEESecondPersonFirstName       = secondaryContact.FirstName,
                ISEESecondPersonLastName        = secondaryContact.LastName,
                ISEESecondPersonEmailAddress    = secondaryContact.EmailAddress,
                ISEESecondPersonTelephoneNumber = secondaryContact.Phone,
            };
            Logger.Write("requestBody", requestBody);
            string xmlEscapedCSID = string.Empty;

            HP.TS.Devops.CentralConnect.ClientRegistration.ClientRegistrationResult result = this.RegisterClientRequest(serviceUrl, requestBody, out xmlEscapedCSID);
            Logger.Write("ClientRegistration Result", result);
            //load to database
            if (!result.IsSuccess)
            {
                return(CentralConnectCode.ClientRegistrationFail);
            }
            RegisterClientMessage registerClientMessage = new RegisterClientMessage();

            registerClientMessage.Environment       = environment;
            registerClientMessage.ClientName        = clientName;
            registerClientMessage.Domain            = domain;
            registerClientMessage.CSID              = xmlEscapedCSID;
            registerClientMessage.OSGDID            = result.Gdid;
            registerClientMessage.RegistrationToken = result.RegistrationToken;
            registerClientMessage.HWGDID            = result.Gdid;
            registerClientMessage.CreateBy          = createBy;

            if (this.AddRegisterClientMessage(registerClientMessage) != 1)
            {
                return(CentralConnectCode.AddRegisterClientMessageFail);
            }
            return(CentralConnectCode.Success);
        }
        public CentralConnectCode RegisterClient(string environment,string clientName,string domain,string createBy)
        {
            List<RegisterClientMessage> registerClientMessages = this.RetrieveRegisterClientMessageByEnvironmentAndClientNameAndDomain(environment, clientName, domain);
            if (registerClientMessages.Count > 0)
            {
                return CentralConnectCode.RegisterClientMessageExist;
            }
            DictionaryAction dictionaryAction = new DictionaryAction(this.ConnectString);
            string serviceUrl = string.Format("{0}/{1}", dictionaryAction.RetrieveServiceUrl(environment), "ClientRegistration/ClientRegistrationService.asmx");
            Logger.Write(string.Format("ServiceUrl={0},ClientName={1},Domain={2}", serviceUrl, clientName, domain));
            //Client
            List<Client> clients = this.RetrieveClientByClientNameAndDomain(clientName, domain);
            if (clients.Count != 1)
            {
                return CentralConnectCode.ClientNotFound;
            }
            Logger.Write("Retrieve Client", clients[0]);
            Client client = clients[0];
            //Contact
            ContactAction contactAction = new ContactAction(this.ConnectString);
            List<Contact> primaryContacts = contactAction.RetrieveContactByFullName(client.PrimaryContact);
            if (primaryContacts.Count != 1)
            {
                return CentralConnectCode.PrimaryContactNotFound;
            }
            Logger.Write("Retrieve PrimaryContacts", primaryContacts[0]);
            Contact primaryContact = primaryContacts[0];
            List<Contact> secondaryContacts = contactAction.RetrieveContactByFullName(client.SecondaryContact);
            if (secondaryContacts.Count != 1)
            {
                return CentralConnectCode.SecondaryContactNotFound;
            }
            Logger.Write("Retrieve SecondaryContact", secondaryContacts[0]);
            Contact secondaryContact = secondaryContacts[0];
            //Company
            CompanyAction companyAction = new CompanyAction(this.ConnectString);
            List<Company> companys = companyAction.RetrieveCompanyByCompanyName(client.CompanyName);
            if (companys.Count != 1)
            {
                return CentralConnectCode.CompanyNotFound;
            }
            Logger.Write("Retrieve Company", companys[0]);
            Company company = companys[0];
            //Request
            HP.TS.Devops.CentralConnect.ClientRegistration.RequestBody requestBody = new HP.TS.Devops.CentralConnect.ClientRegistration.RequestBody()
            {
                CoreSystemModel = client.CoreSystemModel,
                ProductId = client.ProductNumber,
                FQDN = string.Format("{0}.{1}", client.ClientName, client.Domain),
                Hostname = client.ClientName,
                OSNameAndVersionString = string.Format("{0},{1}", client.OSName, client.OSVersion),
                SystemModel = client.CoreSystemModel,
                MacAddress = client.MAC,
                IPAddress = client.IPAddress,
                PRSCaption = client.CompanyName,
                PRSDirtyFlag = 1,
                PRSUniqueName = client.CompanyName,
                PRSAddress1 = company.Street,
                PRSCity = company.City,
                PRSRegion = company.StateProvince,
                PRSPostalCode = company.PostalCode,
                PRSCountry = company.CountryCode,
                ISEECusCaption = client.CompanyName,
                ISEECusPRSUniqueName =client.CompanyName,
                ISEECusName = client.CompanyName,
                ISEEEntSerialNumber = client.SerialNumber,
                ISEEEntProductNumber = client.ProductNumber,
                ISEEEntProductId = client.ProductNumber,

                ISEEFirstPersonFirstName = primaryContact.FirstName,
                ISEEFirstPersonLastName = primaryContact.LastName,
                ISEEFirstPersonEmailAddress = primaryContact.EmailAddress,
                ISEEFirstPersonTelephoneNumber = primaryContact.Phone,

                ISEESecondPersonFirstName = secondaryContact.FirstName,
                ISEESecondPersonLastName = secondaryContact.LastName,
                ISEESecondPersonEmailAddress = secondaryContact.EmailAddress,
                ISEESecondPersonTelephoneNumber = secondaryContact.Phone,
            };
            Logger.Write("requestBody", requestBody);
            string xmlEscapedCSID = string.Empty;
            HP.TS.Devops.CentralConnect.ClientRegistration.ClientRegistrationResult result = this.RegisterClientRequest(serviceUrl, requestBody, out xmlEscapedCSID);
            Logger.Write("ClientRegistration Result", result);
            //load to database
            if (!result.IsSuccess)
            {
                return CentralConnectCode.ClientRegistrationFail;
            }
            RegisterClientMessage registerClientMessage = new RegisterClientMessage();
            registerClientMessage.Environment = environment;
            registerClientMessage.ClientName = clientName;
            registerClientMessage.Domain = domain;
            registerClientMessage.CSID = xmlEscapedCSID;
            registerClientMessage.OSGDID = result.Gdid;
            registerClientMessage.RegistrationToken = result.RegistrationToken;
            registerClientMessage.HWGDID = result.Gdid;
            registerClientMessage.CreateBy = createBy;

            if (this.AddRegisterClientMessage(registerClientMessage) != 1)
            {
                return CentralConnectCode.AddRegisterClientMessageFail;
            }
            return CentralConnectCode.Success;
        }
        private HP.TS.Devops.CentralConnect.ClientRegistration.ClientRegistrationResult RegisterClientRequest(string serviceUrl, HP.TS.Devops.CentralConnect.ClientRegistration.RequestBody requestBody, out string xmlEscapedCSID)
        {
            HP.TS.Devops.CentralConnect.ClientRegistration.ClientRegistrationService clientRegistrationService = new HP.TS.Devops.CentralConnect.ClientRegistration.ClientRegistrationService(serviceUrl);
            HP.TS.Devops.CentralConnect.ClientRegistration.ClientRegistrationRequest clientRegistrationRequest = new HP.TS.Devops.CentralConnect.ClientRegistration.ClientRegistrationRequest(requestBody);
            string requestString = clientRegistrationRequest.RequestString;

            requestString = requestString.Replace("&", @"&amp;");

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(requestString);
            XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(xmlDoc.NameTable);

            xmlnsManager.AddNamespace("isee", "http://www.hp.com/schemas/isee/5.00/event");
            XmlNode csidNode = xmlDoc.SelectSingleNode("/isee:ISEE-Registration/RegistrationSource/HP_OOSIdentifiers/CSID", xmlnsManager);

            xmlEscapedCSID = csidNode.OuterXml;
            Logger.Write("RegisterClientRequest xmlDoc.OuterXml-" + xmlDoc.OuterXml);
            return(clientRegistrationService.RegisterClient2(xmlDoc.InnerXml));
        }