예제 #1
0
        public BrokerServiceConfiguration(string fullName, ServiceBroker serviceBroker)
            : base(serviceBroker)
		{
            if (this.ServiceBroker.Services.Contains(fullName))
            {
                BrokerService item = this.ServiceBroker.Services[fullName];

                base.Urn = new Uri(base.Urn.ToString() + "service/");

                m_Name = item.Name.Substring
                    (base.Urn.ToString().Length, item.Name.Length - base.Urn.ToString().Length);

                m_QueueName = item.QueueName;
                this.ServiceOwnerName = item.Owner;

                //Fill ContractNames from ServiceContractMapping
                foreach (ServiceContractMapping map in item.ServiceContractMappings)
                {
                    m_ContractNames.Add(map.Name);
                }

                //CertificateConfiguration for this Service
                //CertificateName is store in ExtendedProperties to match the Service to the Certificate
                if (item.ExtendedProperties.Contains("CertificateName"))
                {
                    CertificateConfiguration cert = new
                        CertificateConfiguration(item.ExtendedProperties["CertificateName"].Value.ToString(),
                        this.ServiceBroker);
                    this.Certificate = cert;

                }

                //RemoteServiceBinding for this Service if it exists
                string bindingFullName = base.BaseUrn + "RemoteServiceBinding/" + this.Name + "Binding";
                if (this.ServiceBroker.RemoteServiceBindings.Contains(bindingFullName))
                {
                    this.EnableRemoteService = true;
                    RemoteServiceBinding binding = this.ServiceBroker.
                        RemoteServiceBindings[bindingFullName];

                    this.RemoteServiceBinding.CertificateUser = binding.CertificateUser;
                    this.RemoteServiceBinding.IsAnonymous = binding.IsAnonymous;
                    this.AllowAnonymous = binding.IsAnonymous;
                    this.RemoteServiceBinding.Name = binding.Name;
                    this.RemoteServiceBinding.Owner = binding.Owner;
                    this.RemoteServiceBinding.RemoteService = binding.RemoteService;
                }

            }
		}
예제 #2
0
        public BrokerServiceConfiguration(string fullName, ServiceBroker serviceBroker)
            : base(serviceBroker)
        {
            if (this.ServiceBroker.Services.Contains(fullName))
            {
                BrokerService item = this.ServiceBroker.Services[fullName];

                base.Urn = new Uri(base.Urn.ToString() + "service/");

                m_Name = item.Name.Substring
                             (base.Urn.ToString().Length, item.Name.Length - base.Urn.ToString().Length);

                m_QueueName           = item.QueueName;
                this.ServiceOwnerName = item.Owner;

                //Fill ContractNames from ServiceContractMapping
                foreach (ServiceContractMapping map in item.ServiceContractMappings)
                {
                    m_ContractNames.Add(map.Name);
                }

                //CertificateConfiguration for this Service
                //CertificateName is store in ExtendedProperties to match the Service to the Certificate
                if (item.ExtendedProperties.Contains("CertificateName"))
                {
                    CertificateConfiguration cert = new
                                                    CertificateConfiguration(item.ExtendedProperties["CertificateName"].Value.ToString(),
                                                                             this.ServiceBroker);
                    this.Certificate = cert;
                }

                //RemoteServiceBinding for this Service if it exists
                string bindingFullName = base.BaseUrn + "RemoteServiceBinding/" + this.Name + "Binding";
                if (this.ServiceBroker.RemoteServiceBindings.Contains(bindingFullName))
                {
                    this.EnableRemoteService = true;
                    RemoteServiceBinding binding = this.ServiceBroker.
                                                   RemoteServiceBindings[bindingFullName];

                    this.RemoteServiceBinding.CertificateUser = binding.CertificateUser;
                    this.RemoteServiceBinding.IsAnonymous     = binding.IsAnonymous;
                    this.AllowAnonymous                     = binding.IsAnonymous;
                    this.RemoteServiceBinding.Name          = binding.Name;
                    this.RemoteServiceBinding.Owner         = binding.Owner;
                    this.RemoteServiceBinding.RemoteService = binding.RemoteService;
                }
            }
        }
예제 #3
0
        public string Export(string fileName)
        {
            //Export Service Listing
            StringBuilder dropScriptSB     = new StringBuilder();
            StringBuilder contractsSB      = new StringBuilder();
            Hashtable     tempMessageTypes = new Hashtable();
            StringBuilder messageTypesSB   = new StringBuilder();
            StringBuilder queueSB          = new StringBuilder();
            StringBuilder serviceSB        = new StringBuilder();
            StringBuilder generalSB        = new StringBuilder();

            ServiceContract contract;
            MessageType     msgType;

            //CREATE USER script
            if (this.ServiceBroker.Parent.Users.Contains(this.ServiceOwnerName))
            {
                generalSB.AppendLine("CREATE USER [" + this.ServiceOwnerName + "] WITHOUT LOGIN");
                generalSB.AppendLine();
            }

            //CREATE CERTIFICATE script
            if (this.ServiceBroker.Parent.Certificates.Contains(this.Certificate.Name))
            {
                string fullFileName = base.ScriptPath + @"\" + this.Name + ".Service.crt";
                generalSB.AppendLine("CREATE CERTIFICATE [" + this.Certificate.Name + "]");
                generalSB.AppendLine("AUTHORIZATION [" + this.ServiceOwnerName + "]");
                generalSB.AppendLine("FROM FILE= '" + fullFileName);
                generalSB.AppendLine();

                //Export certificate
                CertificateConfiguration cert = new CertificateConfiguration(this.Certificate.Name, this.ServiceBroker);
                cert.Export(fullFileName);
            }

            //GRANT SEND script
            generalSB.AppendLine("GRANT SEND ON SERVICE::[" + this.FullName + "]");
            generalSB.AppendLine("TO [" + this.ServiceOwnerName + "]");
            generalSB.AppendLine();

            //Drop service script
            dropScriptSB.AppendLine("--Drop service");
            dropScriptSB.AppendLine("IF EXISTS (SELECT * FROM sys.services ");
            dropScriptSB.AppendLine("WHERE name = '" + this.FullName + "')");
            dropScriptSB.AppendLine("BEGIN");
            dropScriptSB.AppendLine("DROP SERVICE [" + this.FullName + "]");
            dropScriptSB.AppendLine("END");
            dropScriptSB.AppendLine("GO");
            dropScriptSB.AppendLine();


            //Build Contracts script
            foreach (String item in this.ContractNames)
            {
                contract = this.ServiceBroker.ServiceContracts[item];
                contractsSB.AppendLine(contract.Script()[0]);
                contractsSB.AppendLine();

                //Drop Contracts script
                dropScriptSB.AppendLine("--Drop contract: " + item);
                dropScriptSB.AppendLine("IF EXISTS (SELECT * FROM sys.service_contracts ");
                dropScriptSB.AppendLine("WHERE name = '" + item + "')");
                dropScriptSB.AppendLine("BEGIN");
                dropScriptSB.AppendLine("DROP CONTRACT [" + item + "]");
                dropScriptSB.AppendLine("END");
                dropScriptSB.AppendLine("GO");
                dropScriptSB.AppendLine();


                //Build MessageTypes Hashtable to prevent duplicate MessageTypes
                foreach (MessageTypeMapping map in contract.MessageTypeMappings)
                {
                    msgType = this.ServiceBroker.MessageTypes[map.Name];

                    if (!tempMessageTypes.Contains(msgType.Name))
                    {
                        tempMessageTypes.Add(msgType.Name, msgType.Script()[0].ToString());
                    }
                }
            }

            //Build MessageType script
            IDictionaryEnumerator enumerator = tempMessageTypes.GetEnumerator();

            while (enumerator.MoveNext())
            {
                messageTypesSB.AppendLine(enumerator.Value.ToString());
                messageTypesSB.AppendLine();

                //Drop MessageType's script
                dropScriptSB.AppendLine("--Drop MessageType: " + enumerator.Key.ToString());
                dropScriptSB.AppendLine("IF EXISTS (SELECT * FROM sys.service_message_types ");
                dropScriptSB.AppendLine("WHERE name = '" + enumerator.Key.ToString() + "')");
                dropScriptSB.AppendLine("BEGIN");
                dropScriptSB.AppendLine("DROP MESSAGE TYPE [" + enumerator.Key.ToString() + "]");
                dropScriptSB.AppendLine("END");
                dropScriptSB.AppendLine("GO");
                dropScriptSB.AppendLine();
            }

            //Drop Queue Script
            dropScriptSB.AppendLine("--Drop Queue: " + this.QueueName);
            dropScriptSB.AppendLine("IF EXISTS (SELECT * FROM sys.service_queues ");
            dropScriptSB.AppendLine("WHERE name = '" + this.QueueName + "')");
            dropScriptSB.AppendLine("BEGIN");
            dropScriptSB.AppendLine("DROP QUEUE [" + this.QueueName + "]");
            dropScriptSB.AppendLine("END");
            dropScriptSB.AppendLine("GO");
            dropScriptSB.AppendLine();

            //Build Queue script
            queueSB.AppendLine(this.ServiceBroker.Queues[this.QueueName].Script()[0].ToString());
            queueSB.AppendLine();

            //Build Service script
            serviceSB.AppendLine(this.ServiceBroker.Services[this.FullName].Script()[0].ToString());

            string finalScript =
                generalSB.ToString() +
                dropScriptSB.ToString() +
                messageTypesSB.ToString() +
                contractsSB.ToString() +
                queueSB.ToString() +
                serviceSB.ToString();

            base.Export(this.Name + ".Service", finalScript);

            return(finalScript);
        }
예제 #4
0
        public string Export(string fileName)
        {
            //Export Service Listing
            StringBuilder dropScriptSB =  new StringBuilder();
            StringBuilder contractsSB = new StringBuilder();
            Hashtable tempMessageTypes = new Hashtable();
            StringBuilder messageTypesSB = new StringBuilder();
            StringBuilder queueSB = new StringBuilder();
            StringBuilder serviceSB = new StringBuilder();
            StringBuilder generalSB = new StringBuilder();
           
            ServiceContract contract;
            MessageType msgType;

            //CREATE USER script
            if (this.ServiceBroker.Parent.Users.Contains(this.ServiceOwnerName))
            {
                generalSB.AppendLine("CREATE USER [" + this.ServiceOwnerName + "] WITHOUT LOGIN");
                generalSB.AppendLine();
            }

            //CREATE CERTIFICATE script
            if (this.ServiceBroker.Parent.Certificates.Contains(this.Certificate.Name))
            {
                string fullFileName = base.ScriptPath + @"\" + this.Name + ".Service.crt";
                generalSB.AppendLine("CREATE CERTIFICATE [" + this.Certificate.Name + "]");
                generalSB.AppendLine("AUTHORIZATION [" + this.ServiceOwnerName + "]");
                generalSB.AppendLine("FROM FILE= '" + fullFileName);
                generalSB.AppendLine();

                //Export certificate
                CertificateConfiguration cert = new CertificateConfiguration(this.Certificate.Name, this.ServiceBroker);
                cert.Export(fullFileName);
            }

            //GRANT SEND script
            generalSB.AppendLine("GRANT SEND ON SERVICE::[" + this.FullName + "]");
            generalSB.AppendLine("TO [" + this.ServiceOwnerName + "]");
            generalSB.AppendLine();
            
            //Drop service script
            dropScriptSB.AppendLine("--Drop service");
            dropScriptSB.AppendLine("IF EXISTS (SELECT * FROM sys.services ");
            dropScriptSB.AppendLine("WHERE name = '" + this.FullName + "')");
            dropScriptSB.AppendLine("BEGIN");
            dropScriptSB.AppendLine("DROP SERVICE [" +  this.FullName + "]" );
            dropScriptSB.AppendLine("END") ;
            dropScriptSB.AppendLine("GO");
            dropScriptSB.AppendLine();


            //Build Contracts script
            foreach (String item in this.ContractNames)
            {
                contract = this.ServiceBroker.ServiceContracts[item];
                contractsSB.AppendLine(contract.Script()[0]);
                contractsSB.AppendLine();
                
                //Drop Contracts script
                dropScriptSB.AppendLine("--Drop contract: " + item);
                dropScriptSB.AppendLine("IF EXISTS (SELECT * FROM sys.service_contracts ");
                dropScriptSB.AppendLine("WHERE name = '" + item + "')");
                dropScriptSB.AppendLine("BEGIN");
                dropScriptSB.AppendLine("DROP CONTRACT [" +  item + "]") ;
                dropScriptSB.AppendLine("END") ;
                dropScriptSB.AppendLine("GO");
                dropScriptSB.AppendLine();

                
                //Build MessageTypes Hashtable to prevent duplicate MessageTypes
                foreach (MessageTypeMapping map in contract.MessageTypeMappings)
                {
                    msgType = this.ServiceBroker.MessageTypes[map.Name];
                    
                    if (!tempMessageTypes.Contains(msgType.Name))
                        tempMessageTypes.Add(msgType.Name, msgType.Script()[0].ToString());  
                }
            }

            //Build MessageType script
            IDictionaryEnumerator enumerator = tempMessageTypes.GetEnumerator();
            while (enumerator.MoveNext())
            {
                messageTypesSB.AppendLine(enumerator.Value.ToString());
                messageTypesSB.AppendLine();

                //Drop MessageType's script
                dropScriptSB.AppendLine("--Drop MessageType: " + enumerator.Key.ToString());
                dropScriptSB.AppendLine("IF EXISTS (SELECT * FROM sys.service_message_types ");
                dropScriptSB.AppendLine("WHERE name = '" + enumerator.Key.ToString() + "')");
                dropScriptSB.AppendLine("BEGIN");
                dropScriptSB.AppendLine("DROP MESSAGE TYPE [" + enumerator.Key.ToString() + "]");
                dropScriptSB.AppendLine("END");
                dropScriptSB.AppendLine("GO");
                dropScriptSB.AppendLine();
            }

            //Drop Queue Script
            dropScriptSB.AppendLine("--Drop Queue: " + this.QueueName);
            dropScriptSB.AppendLine("IF EXISTS (SELECT * FROM sys.service_queues ");
            dropScriptSB.AppendLine("WHERE name = '" + this.QueueName + "')");
            dropScriptSB.AppendLine("BEGIN");
            dropScriptSB.AppendLine("DROP QUEUE [" + this.QueueName + "]");
            dropScriptSB.AppendLine("END");
            dropScriptSB.AppendLine("GO");
            dropScriptSB.AppendLine();
            
            //Build Queue script
            queueSB.AppendLine(this.ServiceBroker.Queues[this.QueueName].Script()[0].ToString());
            queueSB.AppendLine();

            //Build Service script
            serviceSB.AppendLine(this.ServiceBroker.Services[this.FullName].Script()[0].ToString());
            
            string finalScript =
                generalSB.ToString() +
                dropScriptSB.ToString() +
                messageTypesSB.ToString() +
                contractsSB.ToString() +
                queueSB.ToString() +
                serviceSB.ToString();

            base.Export(this.Name + ".Service", finalScript);

            return finalScript;

        }