示例#1
0
        protected virtual ProcessAgent installDomainCredentials(ProcessAgent service,
            Coupon inIdentCoupon, Coupon outIdentCoupon)
        {
            ProcessAgent agent = null;
            ProcessAgentDB dbTicketing = new ProcessAgentDB();
            try
            {
                if (ProcessAgentDB.ServiceAgent == null)
                {
                    throw new Exception("The target ProcessAgent has not been configured, please contact the administrator.");
                }

                if (service.type.Equals(ProcessAgentType.SERVICE_BROKER))
                {

                    int[] ids = dbTicketing.GetProcessAgentIDsByType((int)ProcessAgentType.AgentType.SERVICE_BROKER);
                    if (ids != null && ids.Length > 0)
                    {
                        throw new Exception("There is already a domain ServiceBroker assigned to this Service!");
                    }
                    else
                    {
                        int id = dbTicketing.InsertProcessAgent(service, inIdentCoupon, outIdentCoupon);

                        if (id > 0)
                        {
                            dbTicketing.SetDomainGuid(service.agentGuid);
                            ProcessAgentDB.RefreshServiceAgent();
                           Logger.WriteLine("InstallDomainCredentials: " + service.codeBaseUrl);
                            agent = ProcessAgentDB.ServiceAgent;

                        }
                        else
                        {
                           Logger.WriteLine("Error InstallDomainCredentials: " + service.webServiceUrl);
                            throw new Exception("Error Installing DomainCredentials on: " + ProcessAgentDB.ServiceAgent.webServiceUrl);
                        }
                    }
                }
                else
                {
                    int[] ids = dbTicketing.GetProcessAgentIDsByType((int)ProcessAgentType.AgentType.SERVICE_BROKER);
                    if (ids == null || ids.Length == 0)
                    {
                        throw new Exception("This Service is not part of a domain and may not be accessed");
                    }
                    else
                    {
                        int pid = dbTicketing.InsertProcessAgent(service, inIdentCoupon, outIdentCoupon);

                        if (pid > 0)
                        {
                           Logger.WriteLine("InstallDomainCredentials: " + service.codeBaseUrl);
                            agent = ProcessAgentDB.ServiceAgent;
                        }
                        else
                        {
                           Logger.WriteLine("Error InstallDomainCredentials: " + service.webServiceUrl);
                            throw new Exception("Error Installing DomainCredentials on: " + ProcessAgentDB.ServiceAgent.webServiceUrl);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.WriteLine("Error on InstallDomainCredentials: " + service.webServiceUrl + Utilities.DumpException(e));
                throw;
            }
            return agent;
        }