protected override void register(string registerGuid, ServiceDescription[] info) { StringBuilder message = new StringBuilder(); message.AppendLine("Service " + ProcessAgentDB.ServiceAgent.codeBaseUrl + " recieved a 'Register' webService call."); if (info == null) { //message.AppendLine("Register called without any ServiceDescriptions"); throw new ArgumentNullException("Register called without any ServiceDescriptions"); } base.register(registerGuid, info); bool hasProvider = false; bool hasConsumer = false; //string ns = ""; BrokerDB brokerDB = new BrokerDB(); int lssID = 0; int lsID = 0; ProcessAgentInfo ls = null; ProcessAgentInfo lss = null; ProcessAgentInfo uss = null; //LabClient labClient; GroupCredential credential = null; try { ResourceDescriptorFactory rFactory = ResourceDescriptorFactory.Instance(); string jobGuid = registerGuid; message.AppendLine(" Register called at " + DateTime.UtcNow + " UTC \t registerGUID: " + registerGuid); ProcessAgent sourceAgent = brokerDB.GetProcessAgent(agentAuthHeader.agentGuid); message.AppendLine("Source Agent: " + sourceAgent.agentName); for (int i = 0; i < info.Length; i++) { Coupon coupon = null; if (info[i].coupon != null) { coupon = info[i].coupon; } if (info[i].serviceProviderInfo != null && info[i].serviceProviderInfo.Length > 0) { // ProviderInfo is simple add to database and create qualifier if (!hasProvider) { message.AppendLine("Provider Info:"); hasProvider = true; } XmlQueryDoc xdoc = new XmlQueryDoc(info[i].serviceProviderInfo); string descriptorType = xdoc.GetTopName(); if (descriptorType.Equals("processAgentDescriptor")) { string paGuid = xdoc.Query("/processAgentDescriptor/agentGuid"); string paType = xdoc.Query("/processAgentDescriptor/type"); if (paType.Equals(ProcessAgentType.LAB_SCHEDULING_SERVER)) { lssID = brokerDB.GetProcessAgentID(paGuid); if (lssID > 0) { // Already in database //message.AppendLine("Reference to existing LSS: " + lssID + " GUID: " + paGuid); } else { lss = rFactory.LoadProcessAgent(xdoc, ref message); lssID = lss.agentId; } } else if (paType.Equals(ProcessAgentType.LAB_SERVER)) { lsID = brokerDB.GetProcessAgentID(paGuid); if (lsID > 0) { // Already in database //message.AppendLine("Reference to existing LS: " + lsID + " GUID: " + paGuid); } else { ls = rFactory.LoadProcessAgent(xdoc, ref message); lsID = ls.agentId; } int myLssID = brokerDB.FindProcessAgentIdForAgent(lsID, ProcessAgentType.LAB_SCHEDULING_SERVER); if ((lssID > 0) && (myLssID <= 0) && (lssID != myLssID)) { brokerDB.AssociateLSS(lsID, lssID); } } } else if (descriptorType.Equals("clientDescriptor")) { int clientId = -1; string clientGuid = xdoc.Query("/clientDescriptor/clientGuid"); clientId = AdministrativeAPI.GetLabClientID(clientGuid); if (clientId > 0) { // Already in database message.Append(" Attempt to Register a LabClient that is already in the database. "); message.AppendLine(" GUID: " + clientGuid); } else { // LabServer should already be in the Database, once multiple LS supported may need work // LS is specified in clientDescriptor int clientID = rFactory.LoadLabClient(xdoc, ref message); message.AppendLine("Adding LabClient: GUID " + clientGuid); } } else if (descriptorType.Equals("systemSupport")) { SystemSupport ss = SystemSupport.Parse(xdoc); if (ss.agentGuid != null && ss.agentGuid.Length > 0) { int id = brokerDB.GetProcessAgentID(ss.agentGuid); if (id > 0) { brokerDB.SaveSystemSupport(ss.agentGuid, ss.contactEmail, ss.bugEmail, ss.infoUrl, ss.description, ss.location); message.AppendLine("Adding SystemSupport information for " + ss.agentGuid); } } } // Add Relationships: LSS, LS Client } // end of ServiceProvider if (info[i].consumerInfo != null && info[i].consumerInfo.Length > 0) { if (!hasConsumer) message.AppendLine("Consumer Info:"); hasConsumer = true; XmlQueryDoc xdoc = new XmlQueryDoc(info[i].consumerInfo); string descriptorType = xdoc.GetTopName(); if (descriptorType.Equals("processAgentDescriptor")) { string paGuid = xdoc.Query("/processAgentDescriptor/agentGuid"); ProcessAgentInfo paInfo = brokerDB.GetProcessAgentInfo(paGuid); if (paInfo == null) { // Not in database paInfo = rFactory.LoadProcessAgent(xdoc, ref message); message.Append("Loaded new "); } else { message.Append("Reference to existing "); if (paInfo.retired) { throw new Exception("The ProcessAgent is retired"); } } if (paInfo.agentType == ProcessAgentType.AgentType.LAB_SCHEDULING_SERVER) { lss = paInfo; message.AppendLine("LSS: " + paGuid); } else if (paInfo.agentType == ProcessAgentType.AgentType.LAB_SERVER) { ls = paInfo; message.AppendLine("LS: " + paGuid); } else if (paInfo.agentType == ProcessAgentType.AgentType.SCHEDULING_SERVER) { uss = paInfo; message.AppendLine("USS: " + paGuid); if (lss != null) { if (lss.domainGuid.Equals(ProcessAgentDB.ServiceGuid)) { message.AppendLine("Registering USSinfo on LSS: " + lss.agentName); LabSchedulingProxy lssProxy = new LabSchedulingProxy(); lssProxy.AgentAuthHeaderValue = new AgentAuthHeader(); lssProxy.AgentAuthHeaderValue.coupon = lss.identOut; lssProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; lssProxy.Url = lss.webServiceUrl; lssProxy.AddUSSInfo(uss.agentGuid, uss.agentName, uss.webServiceUrl, coupon); } else { message.AppendLine("LSS is not from this domain"); } } } } else if (descriptorType.Equals("clientDescriptor")) { //int newClientId = -1; string clientGuid = xdoc.Query("/clientDescriptor/clientGuid"); int clientId = AdministrativeAPI.GetLabClientID(clientGuid); if (clientId > 0) { // Already in database message.Append(" Attempt to Register a LabClient that is already in the database. "); message.AppendLine(" GUID: " + clientGuid); } else { clientId = rFactory.LoadLabClient(xdoc, ref message); message.AppendLine("Adding Lab Client GUID: " + clientGuid); } } else if (descriptorType.Equals("credentialDescriptor")) { credential = rFactory.ParseCredential(xdoc, ref message); if (lss != null) { if (lss.domainGuid.Equals(ProcessAgentDB.ServiceGuid)) { message.AppendLine("Registering Group Credentials on LSS: " + lss.agentName); message.AppendLine("Group: " + credential.groupName + " DomainServer: " + credential.domainServerName); LabSchedulingProxy lssProxy = new LabSchedulingProxy(); lssProxy.AgentAuthHeaderValue = new AgentAuthHeader(); lssProxy.AgentAuthHeaderValue.coupon = lss.identOut; lssProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; lssProxy.Url = lss.webServiceUrl; lssProxy.AddCredentialSet(credential.domainGuid, credential.domainServerName, credential.groupName, credential.ussGuid); } else { message.AppendLine("LSS is not from this domain"); } } } } } // End of info loop } // End of Try catch (Exception ex) { message.Append("Exception in Register: " + Utilities.DumpException(ex)); throw; } finally { // Send a mail Message //StringBuilder sb = new StringBuilder(); //MailMessage mail = new MailMessage(); //mail.To = ConfigurationManager.AppSettings["supportMailAddress"]; ////mail.To = "*****@*****.**"; //mail.From = ConfigurationManager.AppSettings["genericFromMailAddress"]; //mail.Subject = "Register called on " + ProcessAgentDB.ServiceAgent.agentName; //mail.Body = message.ToString(); //SmtpMail.SmtpServer = "127.0.0.1"; string subject = "Register called on " + ProcessAgentDB.ServiceAgent.agentName; string body = message.ToString(); string from = ConfigurationManager.AppSettings["genericFromMailAddress"]; string to = ConfigurationManager.AppSettings["supportMailAddress"]; MailMessage mailMessage = new MailMessage(from, to, subject, body); SmtpClient smtpClient = new SmtpClient(Consts.STR_LocalhostIP); try { //SmtpMail.Send(mail); smtpClient.Send(mailMessage); } catch (Exception ex) { // Report detailed SMTP Errors StringBuilder smtpErrorMsg = new StringBuilder(); smtpErrorMsg.Append("Exception: " + ex.Message); //check the InnerException if (ex.InnerException != null) smtpErrorMsg.Append("<br>Inner Exceptions:"); while (ex.InnerException != null) { smtpErrorMsg.Append("<br>" + ex.InnerException.Message); ex = ex.InnerException; } Utilities.WriteLog(smtpErrorMsg.ToString()); } } }