Exemplo n.º 1
0
        public void Create()
        {
            BrokerService    brokerService = null;
            ExtendedProperty prop          = null;

            if (!this.ServiceBroker.Services.Contains(this.FullName))
            {
                // Create initiator service
                brokerService           = new BrokerService(this.ServiceBroker, this.FullName);
                brokerService.QueueName = this.QueueName;
                brokerService.Owner     = this.ServiceOwnerName;

                foreach (object item in this.ContractNames)
                {
                    ServiceContractMapping brokerServiceContract
                        = new ServiceContractMapping(brokerService, item.ToString());
                    brokerService.ServiceContractMappings.Add(brokerServiceContract);
                }

                if (!String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    CreateUser();
                }

                //Create Certificate if EnableRemoteServiceBinding = true and AllowAnonymous = false
                if (m_EnableRemoteServiceBinding &&
                    !String.IsNullOrEmpty(this.ServiceOwnerName) && !this.AllowAnonymous)
                {
                    prop = new ExtendedProperty(brokerService,
                                                "CertificateName", this.Certificate.Name);

                    this.Certificate.Owner = this.ServiceOwnerName;
                    this.Certificate.Create();
                }

                //Create ReportServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    this.CreateRemoteServiceBinding();
                }

                //Grant Receive
                if (this.GrantReceive)
                {
                    CreateGrantReceive();
                }

                brokerService.Create();

                //Create property last
                if (prop != null)
                {
                    prop.Create();
                }
            }
        }
Exemplo n.º 2
0
        public void Alter()
        {
            BrokerService    brokerService;
            ExtendedProperty prop = null;

            if (this.ServiceBroker.Services.Contains(this.FullName))
            {
                brokerService = this.ServiceBroker.Services[this.FullName];

                brokerService.QueueName = this.QueueName;

                //Drop Contracts that user removed
                foreach (ServiceContractMapping map in brokerService.ServiceContractMappings)
                {
                    if (!this.ContractNames.Contains(map.Name))
                    {
                        if (map.State != SqlSmoState.ToBeDropped)
                        {
                            map.MarkForDrop(true);
                        }
                    }
                }
                //Add Contracts that user added
                foreach (string name in this.ContractNames)
                {
                    if (!brokerService.ServiceContractMappings.Contains(name))
                    {
                        ServiceContractMapping brokerServiceContract
                            = new ServiceContractMapping(brokerService, name);
                        brokerService.ServiceContractMappings.Add(brokerServiceContract);
                    }
                }

                brokerService.Alter();

                //Drop RemoteServiceBinding and Certificate
                if (!m_EnableRemoteServiceBinding)
                {
                    if (this.ServiceBroker.RemoteServiceBindings.Contains(this.BindingFullName))
                    {
                        RemoteServiceBinding binding = this.ServiceBroker.
                                                       RemoteServiceBindings[this.BindingFullName];
                        binding.Drop();
                    }

                    this.DropCertificate();
                    //Drop extended property
                    if (brokerService.ExtendedProperties.Contains("CertificateName"))
                    {
                        brokerService.ExtendedProperties["CertificateName"].Drop();
                    }
                }

                //Change RemoteServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    if (this.ServiceBroker.RemoteServiceBindings.Contains(this.BindingFullName))
                    {
                        RemoteServiceBinding binding = this.ServiceBroker.
                                                       RemoteServiceBindings[this.BindingFullName];
                        binding.IsAnonymous = this.AllowAnonymous;
                        //Can't change service owner binding.Owner = this.ServiceOwnerName;

                        binding.Alter();
                    }
                }

                //Create Certificate if EnableRemoteServiceBinding = true and AllowAnonymous = false
                if (m_EnableRemoteServiceBinding &&
                    !String.IsNullOrEmpty(this.ServiceOwnerName) && !this.AllowAnonymous)
                {
                    if (!brokerService.ExtendedProperties.Contains("CertificateName"))
                    {
                        prop = new ExtendedProperty(brokerService,
                                                    "CertificateName", this.Certificate.Name);
                    }

                    this.Certificate.Owner = this.ServiceOwnerName;
                    this.Certificate.Create();
                }

                //Create ReportServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    this.CreateRemoteServiceBinding();
                }

                if (this.GrantReceive)
                {
                    CreateGrantReceive();
                }

                //Create property last
                if (prop != null)
                {
                    prop.Create();
                }
            }
        }
Exemplo n.º 3
0
        public void Alter()
        {
            BrokerService brokerService;
            ExtendedProperty prop = null;

            if (this.ServiceBroker.Services.Contains(this.FullName))
            {
                brokerService = this.ServiceBroker.Services[this.FullName];

                brokerService.QueueName = this.QueueName;
                
                //Drop Contracts that user removed
                foreach (ServiceContractMapping map in brokerService.ServiceContractMappings)
                {
                    if (!this.ContractNames.Contains(map.Name))
                    {
                        if (map.State != SqlSmoState.ToBeDropped)
                        {
                            map.MarkForDrop(true);
                        }
                    }
                }
                //Add Contracts that user added
                foreach (string name in this.ContractNames)
                {
                    if (!brokerService.ServiceContractMappings.Contains(name))
                    {
                        ServiceContractMapping brokerServiceContract
                        = new ServiceContractMapping(brokerService, name);
                        brokerService.ServiceContractMappings.Add(brokerServiceContract);
                    }
                
                }

                brokerService.Alter();

                //Drop RemoteServiceBinding and Certificate
                if (!m_EnableRemoteServiceBinding)
                {

                    if (this.ServiceBroker.RemoteServiceBindings.Contains(this.BindingFullName))
                    {
                        RemoteServiceBinding binding = this.ServiceBroker.
                            RemoteServiceBindings[this.BindingFullName];
                        binding.Drop();
                    }

                    this.DropCertificate();
                    //Drop extended property
                    if (brokerService.ExtendedProperties.Contains("CertificateName"))
                        brokerService.ExtendedProperties["CertificateName"].Drop();
                }

                //Change RemoteServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    if (this.ServiceBroker.RemoteServiceBindings.Contains(this.BindingFullName))
                    {
                        RemoteServiceBinding binding = this.ServiceBroker.
                            RemoteServiceBindings[this.BindingFullName];
                        binding.IsAnonymous = this.AllowAnonymous;
                        //Can't change service owner binding.Owner = this.ServiceOwnerName;

                        binding.Alter();
                    }
                }

                //Create Certificate if EnableRemoteServiceBinding = true and AllowAnonymous = false
                if (m_EnableRemoteServiceBinding
                    && !String.IsNullOrEmpty(this.ServiceOwnerName) && !this.AllowAnonymous)
                {
                    if (!brokerService.ExtendedProperties.Contains("CertificateName"))
                        prop = new ExtendedProperty(brokerService,
                            "CertificateName", this.Certificate.Name);

                    this.Certificate.Owner = this.ServiceOwnerName;
                    this.Certificate.Create();
                }

                //Create ReportServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    this.CreateRemoteServiceBinding();
                }

                if (this.GrantReceive)
                {
                    CreateGrantReceive();
                }

                //Create property last
                if (prop != null)
                    prop.Create();
            }
        }
Exemplo n.º 4
0
        public void Create()
        {
            BrokerService brokerService = null;
            ExtendedProperty prop = null;
            if (!this.ServiceBroker.Services.Contains(this.FullName))
            {
                // Create initiator service
                brokerService = new BrokerService(this.ServiceBroker, this.FullName);
                brokerService.QueueName = this.QueueName;
                brokerService.Owner = this.ServiceOwnerName;

                foreach (object item in this.ContractNames)
                {
                    ServiceContractMapping brokerServiceContract
                        = new ServiceContractMapping(brokerService, item.ToString());
                    brokerService.ServiceContractMappings.Add(brokerServiceContract);
                }

                if (!String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    CreateUser();
                }

                //Create Certificate if EnableRemoteServiceBinding = true and AllowAnonymous = false
                if (m_EnableRemoteServiceBinding
                    && !String.IsNullOrEmpty(this.ServiceOwnerName) && !this.AllowAnonymous)
                {
                    prop = new ExtendedProperty(brokerService, 
                        "CertificateName", this.Certificate.Name);
                    
                    this.Certificate.Owner = this.ServiceOwnerName;
                    this.Certificate.Create();
                }

                //Create ReportServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    this.CreateRemoteServiceBinding();
                }

                //Grant Receive
                if (this.GrantReceive)
                {
                    CreateGrantReceive();
                }

                brokerService.Create();

                //Create property last
                if (prop != null)
                    prop.Create();
            }
        }
Exemplo n.º 5
0
        void SetUpObject(object smob)
        {
            switch (ssbType) {
            case SsbEnum.Database:
              SSBIDatabase sdb = (SSBIDatabase)smob;
              Database db = sdb.DataBase;
              txtName.Text = db.Name;
              db_chkMasterKey.Checked = db.MasterKey != null;
              db_chkTrustWorthy.Checked = sdb.IsTrustworthy;
              if (db.MasterKey != null) {
            db_txtMkPwd.Enabled = false;
              }

              break;
            case SsbEnum.MessageType:
              MessageType mt = (MessageType)smob;
              txtName.Text = mt.Name;
              if (mt.Owner != string.Empty)
            cboUser.SelectedItem = mt.Owner;
              cboVal.SelectedItem = mt.MessageTypeValidation;
              if (mt.ValidationXmlSchemaCollection.Length > 0)
            cboValSchema.SelectedItem = mt.ValidationXmlSchemaCollection;

              break;

            case SsbEnum.Queu:
              ServiceQueue q = (ServiceQueue)smob;
              txtName.Text = q.Name;
              chkStatus.Checked = q.IsEnqueueEnabled;
              chkRetention.Checked = q.IsRetentionEnabled;
              chkActivation.Checked = q.IsActivationEnabled;
              if (q.ProcedureDatabase == "")
            cboQDb.SelectedItem = dBase;
              else
            cboQDb.SelectedItem = q.ProcedureDatabase;

              cboProc.Text = q.ProcedureName;
              txtReaders.Text = q.MaxReaders.ToString();
              switch (q.ActivationExecutionContext) {
            case ActivationExecutionContext.Self :
              rdSelf.Checked = true;
              break;

            case ActivationExecutionContext.Owner:
              rdOwner.Checked = true;
              break;

            case ActivationExecutionContext.ExecuteAsUser:
              rdUser.Checked = true;
              txtExecuteAs.Text = q.ExecutionContextPrincipal;
              break;
              }

              break;

            case SsbEnum.Service:
              BrokerService bserv = (BrokerService)smob;
              bserv.Name = txtName.Text;
              if (cboUser.Text != string.Empty)
            bserv.Owner = cboUser.Text;

              ServiceQueue servq = (ServiceQueue)cboQueue.SelectedItem;
              bserv.QueueName = servq.Name;
              bserv.QueueSchema = servq.Schema;

              if (lbChosenCtr.Items.Count > 0) {
            foreach (object o in lbChosenCtr.Items) {
              ServiceContract servctr = o as ServiceContract;
              ServiceContractMapping scm = new ServiceContractMapping(bserv, servctr.Name);
              bserv.ServiceContractMappings.Add(scm);
            }
              }
              break;

            case SsbEnum.Certificate :
              Certificate cert = (Certificate)smob;
              txtName.Text = cert.Name;
              cboUser.Text = cert.Owner;
              cboUser.Enabled = false;
              cert_chkBeginDlg.Checked = cert.ActiveForServiceBrokerDialog;
              cert_txtCertPath.Text = cert.Subject;
              cert_txtCertPath.Enabled = false;

              cert_chkMasterKey.Checked = cert.PrivateKeyEncryptionType == PrivateKeyEncryptionType.MasterKey;

              if (cert.PrivateKeyEncryptionType != PrivateKeyEncryptionType.NoKey) {
            if (cert.Subject == cert.Issuer)
              cert_cboSource.SelectedIndex = 1;
            else
              cert_cboSource.SelectedIndex = 0;

              }
              else
            cert_cboSource.SelectedIndex = 2;

              cert_cboSource.Enabled = false;
              btnNewUser.Visible = false;

              cert_dtValidFrom.Value = cert.StartDate;
              cert_dtExpiry.Value = cert.ExpirationDate;

              cert_dtValidFrom.Enabled = false;
              cert_dtExpiry.Enabled = false;

              cert_grpPvk.Enabled = false;
              cert_chkMasterKey.Enabled = false;

              label64.Visible = true;
              label58.Visible = false;
              break;

            case SsbEnum.EndPoint :
              SSBIEndpoint ep = (SSBIEndpoint)smob;
              txtName.Text = ep.Name;
              cboUser.SelectedItem = ep.EndPoint.Owner;
              ep_cboState.SelectedItem = ep.State;
              ep_txtPort.Text = ep.Port.ToString();
              if (ep.EndPoint.Protocol.Tcp.ListenerIPAddress == System.Net.IPAddress.Any)
            ep_txtIp.Text = "ALL";
              else
            ep_txtIp.Text = ep.EndPoint.Protocol.Tcp.ListenerIPAddress.ToString();

              ep_cboAuth.SelectedItem = ep.Authentication;
              if (ep.Certificate != null)
            ep_cboCert.Text = ep.Certificate;

              ep_cboEncrypt.SelectedItem = ep.Encryption;

              ep_cboAlgorithm.SelectedItem = ep.Algorithm;

              ep_chkFwd.Checked = ep.IsMessageForwardingEnabled;
              ep_txtSize.Text = ep.MessageForwardSize.ToString();

              cboUser.Enabled = false;

              break;
              }

              txtName.Enabled = false;
        }
Exemplo n.º 6
0
        int UpDateSsb()
        {
            updatedobj = null;
              //if (!isDirty)
            //return 0;
              if (!ValidateData()) {
            Cursor crs = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            try {
              Database db = null;

              ServiceBroker sb = null;
              if (ssbType != SsbEnum.Database && ssbType != SsbEnum.Login && ssbType != SsbEnum.EndPoint) {
             sb = dBase.ServiceBroker;
              }
              switch (ssbType) {
            case SsbEnum.Database:
              MasterKey mk = null;
              SSBIDatabase sbd = null;
              if (isEdit) {
                sbd = (SSBIDatabase)objToUpdate;
                db = sbd.DataBase;
              }
              else {
                db = new Database();
                db.Name = txtName.Text;
                db.Parent = dbServ.SMOServer;
              }

              if (isEdit) {
               if(db.MasterKey != null && db_chkMasterKey.Checked == false) {
                 mk = db.MasterKey;
                 mk.Drop();

               }
               else if (db.MasterKey == null && db_chkMasterKey.Checked) {
                 mk = new MasterKey();
                 mk.Parent = db;
                 mk.Create(db_txtMkPwd.Text);
               }

               db.Alter();
               if (sbd.IsTrustworthy != db_chkTrustWorthy.Checked)
                 sbd.IsTrustworthy = db_chkTrustWorthy.Checked;

              }
              else {
                db.Create();
                sbd = new SSBIDatabase(db);

                if (db_chkMasterKey.Checked) {
                  mk = new MasterKey();
                  mk.Parent = db;
                  mk.Create(db_txtMkPwd.Text);

                }

                if (db_chkTrustWorthy.Checked) {
                  sbd.IsTrustworthy = true;
                }

              }
              if (dBase == null)
                dBase = db;

              //Server serv = db.Parent;

              updatedobj = db;
              break;
            case SsbEnum.MessageType:
              MessageType mt = null;
              if (isEdit)
                mt = (MessageType)objToUpdate;
              else {
                mt = new MessageType();
                mt.Parent = sb;
                mt.Name = txtName.Text;
              }
              if (cboUser.Text != string.Empty)
                mt.Owner = cboUser.Text;
              mt.MessageTypeValidation = (MessageTypeValidation)Enum.Parse(typeof(MessageTypeValidation), cboVal.Text);
              if (cboValSchema.Enabled)
                mt.ValidationXmlSchemaCollection = cboValSchema.Text;

              if (isEdit)
                mt.Alter();
              else
                mt.Create();
              updatedobj = mt;
              break;

            case SsbEnum.Contract:
              ServiceContract sc = new ServiceContract();
              sc.Parent = sb;
              sc.Name = txtName.Text;
              if (cboUser.Text != string.Empty)
                sc.Owner = cboUser.Text;
              //get the message types
              foreach (DataGridViewRow row in dvMsgTypes.Rows) {
                sc.MessageTypeMappings.Add(new MessageTypeMapping(sc, row.Cells[0].Value.ToString(), (MessageSource)Enum.Parse(typeof(MessageSource), row.Cells[1].Value.ToString())));
              }

              if (isEdit)
                sc.Alter();
              else
                sc.Create();

              updatedobj = sc;
              break;

            case SsbEnum.Queu:
              ServiceQueue q = null;
              if (isEdit)
                q = (ServiceQueue)objToUpdate;
              else {
                q = new ServiceQueue();
                q.Parent = sb;
                q.Name = txtName.Text;
              }
              q.IsEnqueueEnabled = chkStatus.Checked;
              if (chkRetention.Checked)
                q.IsRetentionEnabled = true;

              //if (chkActivation.Checked) {
              //if(isEdit)
              //  q.IsActivationEnabled = chkActivation.Checked;
              //
              if (chkActivation.Checked) {
                q.IsActivationEnabled = chkActivation.Checked;
                if (dBase.Name != cboQDb.Text)
                  q.ProcedureDatabase = cboQDb.Text;
                StoredProcedure sp = (StoredProcedure)cboProc.SelectedItem;
                q.ProcedureSchema = sp.Schema;
                q.ProcedureName = cboProc.Text;
                q.MaxReaders = short.Parse(txtReaders.Text);
                if (rdOwner.Checked)
                  q.ActivationExecutionContext = ActivationExecutionContext.Owner;
                else if (rdSelf.Checked)
                  q.ActivationExecutionContext = ActivationExecutionContext.Self;
                else if (rdUser.Checked) {
                  q.ActivationExecutionContext = ActivationExecutionContext.ExecuteAsUser;
                  q.ExecutionContextPrincipal = txtExecuteAs.Text;
                }

              }

              if (isEdit)
                q.Alter();
              else
                q.Create();

              updatedobj = q;

              break;

            case SsbEnum.Service:
              BrokerService bserv = null;
              if (isEdit)
                bserv = (BrokerService)objToUpdate;
              else {
                bserv = new BrokerService();
                bserv.Parent = sb;
                bserv.Name = txtName.Text;
              }
              if (cboUser.Text != string.Empty)
                bserv.Owner = cboUser.Text;

              ServiceQueue servq = (ServiceQueue)cboQueue.SelectedItem;
              bserv.QueueName = servq.Name;
              bserv.QueueSchema = servq.Schema;

              if (lbChosenCtr.Items.Count > 0) {
                foreach (object o in lbChosenCtr.Items) {
                  ServiceContract servctr = o as ServiceContract;
                  ServiceContractMapping scm = new ServiceContractMapping(bserv, servctr.Name);
                  bserv.ServiceContractMappings.Add(scm);
                }
              }

              if (isEdit)
                bserv.Alter();
              else
                bserv.Create();

              updatedobj = bserv;

              break;

            case SsbEnum.Route:
              ServiceRoute srt = null;
              if (isEdit)
                srt = (ServiceRoute)objToUpdate;
              else {
                srt = new ServiceRoute();
                srt.Name = txtName.Text;
                srt.Parent = sb;
              }

              if (cboUser.Text != string.Empty)
                srt.Owner = cboUser.Text;

              if (textBroker.Text != string.Empty)
                srt.BrokerInstance = textBroker.Text;

              if (textRemote.Text != string.Empty)
                srt.RemoteService = textRemote.Text;

              if (textLifeTime.Text != string.Empty)
                srt.ExpirationDate = DateTime.Parse(textLifeTime.Text);

              if (rdLocal.Checked)
                srt.Address = "LOCAL";

              if (rdTransport.Checked)
                srt.Address = "TRANSPORT";

              if (rdTCP.Checked)
                srt.Address = "TCP://" + txtAddress.Text;

              if (txtMirror.Text != string.Empty)
                srt.MirrorAddress = "TCP://" + txtMirror.Text;

              //StringCollection sColl = srt.Script();
              //foreach (string s in sColl)
              //  MessageBox.Show(s);

              if (isEdit)
                srt.Alter();
              else
                srt.Create();

              updatedobj = srt;

              break;

            case SsbEnum.RemoteBinding:
              RemoteServiceBinding remBind = null;
              if (isEdit)
                remBind = (RemoteServiceBinding)objToUpdate;
              else {
                remBind = new RemoteServiceBinding();
                remBind.Name = txtName.Text;
                remBind.Parent = sb;
              }

              if (cboUser.Text != string.Empty)
                remBind.Owner = cboUser.Text;

              remBind.RemoteService = textRemServ.Text;

              remBind.CertificateUser = cboRemUser.Text;
              remBind.IsAnonymous = chkAnon.Checked;

              StringCollection sColl = remBind.Script();
              foreach (string s in sColl)
                MessageBox.Show(s);

              if (isEdit)
                remBind.Alter();
              else
                remBind.Create();

              updatedobj = remBind;

              break;

            case SsbEnum.Conversation:
              TimeSpan ts = TimeSpan.Zero;
              Guid grpHandle = Guid.Empty;
              string convContract = "DEFAULT";
              BrokerService bServ = (BrokerService)cnv_cboFrmServ.SelectedItem;

              string toService = cnv_txtToSrv.Text;

              if (cnv_txtLifetime.Text != string.Empty && cnv_txtLifetime.Text != "0")
                ts = TimeSpan.FromSeconds(double.Parse(cnv_txtLifetime.Text));

              if (cnv_cboContract.Text != string.Empty)
                convContract = cnv_cboContract.Text;

              if (cnv_txtRelGrpHndl.Text != string.Empty)
                grpHandle = new Guid(cnv_txtRelGrpHndl.Text);

              //get a service object
              Service smoserv = smo.GetSSBIService(bServ.Parent.Parent, bServ.Name);
              if (smoserv.Connection.State == ConnectionState.Closed)
                smoserv.Connection.Open();

              smoserv.Connection.ChangeDatabase(bServ.Parent.Parent.Name);
              updatedobj = smoserv.BeginDialog(toService, convContract, ts, cnv_chkEncryption.Checked, grpHandle);
              break;

            case SsbEnum.Message:
              SSBIConversation msgConv = (SSBIConversation)msg_cboConv.SelectedItem;
              string servName = msg_txtFrom.Text;
              //we need a service object
              Service msgSsbiServ = smo.GetSSBIService(dBase, msgConv.FromService);
              if (msgSsbiServ.Connection.State== ConnectionState.Closed)
                 msgSsbiServ.Connection.Open();

               msgSsbiServ.Connection.ChangeDatabase(dBase.Name);
              Conversation msgCnv = new Conversation(msgSsbiServ, msgConv.Handle);
              string msgType = msg_cboMsgType.SelectedText;
              string msgString = msg_rchMsg.Text;
              msgType = msg_cboMsgType.Text;
              MemoryStream msgBody = new MemoryStream(Encoding.ASCII.GetBytes(msgString));

              Microsoft.Samples.SqlServer.Message msg = new Microsoft.Samples.SqlServer.Message(msgType, msgBody);
              msgCnv.Send(msg);

              break;

            case SsbEnum.Login :
              string pwd = "";
              Login lg = new Login();
              lg.Parent = dbServ.SMOServer;
              lg.Name = lgn_txtLoginName.Text;
              if (lgn_rdSql.Checked) {
                pwd = lgn_txtPwd.Text;
                lg.PasswordPolicyEnforced = lgn_chkEnforcePolicy.Checked;
                lg.LoginType = LoginType.SqlLogin;
                lg.Create(pwd);
              }
              else {
                lg.Create();
              }

              updatedobj = lg;
              break;

            case SsbEnum.Certificate:
              string certOwner  = "dbo";
              int certSource = cert_cboSource.SelectedIndex;
              Certificate cert = new Certificate();
              if(!isEdit) {
                cert.Name = txtName.Text;
                if(cboUser.Text != "")
                  certOwner = cboUser.Text;
                cert.Parent = dBase;
                cert.Owner = certOwner;

              }

              cert.ActiveForServiceBrokerDialog = cert_chkBeginDlg.Checked;

              if (certSource == 0) {
                if (!isEdit) {
                  if (cert_chkMasterKey.Checked)
                    cert.Create(cert_txtCertPath.Text, CertificateSourceType.File, cert_txtPrivPath.Text, cert_txtDecrypt.Text);
                  else
                    cert.Create(cert_txtCertPath.Text, CertificateSourceType.File, cert_txtPrivPath.Text, cert_txtDecrypt.Text, cert_txtEncrypt.Text);

                }
              }
              else if (certSource == 1) {
                if (!isEdit) {
                  cert.StartDate = cert_dtValidFrom.Value;
                  cert.ExpirationDate = cert_dtExpiry.Value;
                  cert.Subject = cert_txtCertPath.Text;

                  if (cert_chkMasterKey.Checked) {
                    cert.Create();
                  }
                  else {
                    cert.Create(cert_txtEncrypt.Text);
                  }
                }

              }
              else if (certSource == 2) {
                if (!isEdit) {
                  cert.Create(cert_txtCertPath.Text, CertificateSourceType.File);
                }

              }

              if (isEdit)
                cert.Alter();

              updatedobj = cert;
              break;

            case SsbEnum.User :
              User usr;
              if (!isEdit) {
                usr = new User();
                usr.Name = txtName.Text;
                usr.Parent = dBase;
                if(usr_chkLogin.Checked)
                  usr.Login = usr_cboLogin.Text;

              }
              else
                usr = (User)objToUpdate;

              if (usr_cboCerts.SelectedIndex != -1)
                usr.Certificate = usr_cboCerts.Text;

              if (!isEdit)
                if (usr_chkLogin.Checked)
                  usr.Create();
                else
                  smo.CreateUserWithNoLogin(usr);

              else
                usr.Alter();
              updatedobj = usr;
              break;

            case SsbEnum.EndPoint :
              Endpoint ep = null;
              if (!isEdit) {
                ep = new Endpoint();
                ep.Name = txtName.Text;
                ep.Parent = dbServ.SMOServer;
                ep.ProtocolType = ProtocolType.Tcp;
                ep.EndpointType = EndpointType.ServiceBroker;
              }
              else
                ep = ((SSBIEndpoint)objToUpdate).EndPoint;

              ep.Protocol.Tcp.ListenerPort = int.Parse(ep_txtPort.Text);
              if (ep_txtIp.Text == "ALL")
                ep.Protocol.Tcp.ListenerIPAddress = System.Net.IPAddress.Any;
              else {
                ep.Protocol.Tcp.ListenerIPAddress = System.Net.IPAddress.Parse(ep_txtIp.Text);
              }
              ep.Payload.ServiceBroker.EndpointAuthenticationOrder = (EndpointAuthenticationOrder)ep_cboAuth.SelectedItem;
              if (ep_cboCert.SelectedIndex != -1)
                ep.Payload.ServiceBroker.Certificate = ep_cboCert.Text;

              ep.Payload.ServiceBroker.EndpointEncryption = (EndpointEncryption)ep_cboEncrypt.SelectedItem;
              if (ep_cboAlgorithm.SelectedIndex != -1)
                ep.Payload.ServiceBroker.EndpointEncryptionAlgorithm = (EndpointEncryptionAlgorithm)ep_cboAlgorithm.SelectedItem;

              ep.Payload.ServiceBroker.IsMessageForwardingEnabled = ep_chkFwd.Checked;

              if (ep_txtSize.Text != string.Empty)
                ep.Payload.ServiceBroker.MessageForwardingSize = int.Parse(ep_txtSize.Text);

              if(!isEdit)
                ep.Create();

              switch ((EndpointState)ep_cboState.SelectedIndex) {
                case EndpointState.Disabled :
                  ep.Disable();
                  break;

                case EndpointState.Started :
                  ep.Start();
                  break;
                case EndpointState.Stopped :
                  if (isEdit)
                    ep.Stop();
                  break;
              }

              if (isEdit)
                ep.Alter();

              break;

            case SsbEnum.CreateListing :
              CreateListing(true);

              break;

              }

              if (isEdit)
            _state = SsbState.Edited;
              else
            _state = SsbState.New;

              Cursor.Current = crs;

              this.DialogResult = DialogResult.OK;

              ExitAndClose();

            }
            catch (FailedOperationException e) {
              smo.ShowException(e);
            }
            catch (Exception ex) {
              smo.ShowException(ex);
            }

            finally {
              if(dbServ !=null)
            dbServ.SMOServer.ConnectionContext.Disconnect();

            }

              }

              return 0;
        }