void OnConfigureDiscovery(object sender, EventArgs e)
        {
            string serviceNamespace = "";

            if (IsServiceBusAddress(m_MexAddressTextBox.Text))
            {
                serviceNamespace = ServiceBusHelper.ExtractNamespace(new Uri(m_MexAddressTextBox.Text));
            }

            bool announcementsEnables = m_ServiceBusAnnouncementSinks.ContainsKey(serviceNamespace);

            if (m_DisoveryPaths.ContainsKey(serviceNamespace) == false)
            {
                m_DisoveryPaths[serviceNamespace] = DiscoverableServiceHost.DiscoveryPath;
            }

            if (m_AnnouncementsPaths.ContainsKey(serviceNamespace) == false)
            {
                m_AnnouncementsPaths[serviceNamespace] = DiscoverableServiceHost.AnnouncementsPath;
            }

            DiscoveryDialog dialog = new DiscoveryDialog(serviceNamespace, m_DisoveryPaths[serviceNamespace], announcementsEnables, m_AnnouncementsPaths[serviceNamespace]);

            dialog.ShowDialog();

            serviceNamespace = dialog.ServiceNamespace;

            m_MexAddressTextBox.Text = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "").AbsoluteUri;

            m_DisoveryPaths[serviceNamespace] = dialog.DiscoveryPath;

            if (String.IsNullOrWhiteSpace(dialog.AnnouncementsPath) == false)
            {
                m_AnnouncementsPaths[serviceNamespace] = dialog.AnnouncementsPath;

                if (m_NamespaceCredentials.ContainsKey(ServiceBusHelper.ExtractNamespace(new Uri(m_MexAddressTextBox.Text))) == false)
                {
                    OnServiceBusLogOn(this, EventArgs.Empty);
                }

                Uri newAnouncementsAddress = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, m_AnnouncementsPaths[serviceNamespace]);

                if (m_ServiceBusAnnouncementSinks.ContainsKey(serviceNamespace))
                {
                    if (m_ServiceBusAnnouncementSinks[serviceNamespace].AnnouncementsAddress.AbsoluteUri != newAnouncementsAddress.AbsoluteUri)
                    {
                        m_ServiceBusAnnouncementSinks[serviceNamespace].Close();
                        m_ServiceBusAnnouncementSinks.Remove(serviceNamespace);
                    }
                    else
                    {
                        return;
                    }
                }

                TokenProvider tokenPorvider = m_NamespaceCredentials[serviceNamespace];

                m_ServiceBusAnnouncementSinks[serviceNamespace] = new ServiceBusAnnouncementSink <IMetadataExchange>(serviceNamespace, tokenPorvider);
                m_ServiceBusAnnouncementSinks[serviceNamespace].AnnouncementsAddress = newAnouncementsAddress;

                m_ServiceBusAnnouncementSinks[serviceNamespace].OnlineAnnouncementReceived  += OnHelloNotice;
                m_ServiceBusAnnouncementSinks[serviceNamespace].OfflineAnnouncementReceived += OnByeNotice;

                m_ServiceBusAnnouncementSinks[serviceNamespace].Open();
            }
            else
            {
                if (m_ServiceBusAnnouncementSinks.ContainsKey(serviceNamespace))
                {
                    m_ServiceBusAnnouncementSinks[serviceNamespace].Close();
                    m_ServiceBusAnnouncementSinks.Remove(serviceNamespace);
                }
            }
        }
Exemplo n.º 2
0
      void OnConfigureDiscovery(object sender,EventArgs e)
      {
         string serviceNamespace = "";

         if(IsServiceBusAddress(m_MexAddressTextBox.Text))
         {
            serviceNamespace = ServiceBusHelper.ExtractNamespace(new Uri(m_MexAddressTextBox.Text));
         }

         bool announcementsEnables = m_ServiceBusAnnouncementSinks.ContainsKey(serviceNamespace);

         if(m_DisoveryPaths.ContainsKey(serviceNamespace) == false)
         {
            m_DisoveryPaths[serviceNamespace] = DiscoverableServiceHost.DiscoveryPath;
         }
         
         if(m_AnnouncementsPaths.ContainsKey(serviceNamespace) == false)
         {
            m_AnnouncementsPaths[serviceNamespace] = DiscoverableServiceHost.AnnouncementsPath;
         }

         DiscoveryDialog dialog = new DiscoveryDialog(serviceNamespace,m_DisoveryPaths[serviceNamespace],announcementsEnables,m_AnnouncementsPaths[serviceNamespace]);
         dialog.ShowDialog();
                
         serviceNamespace = dialog.ServiceNamespace;

         m_MexAddressTextBox.Text = ServiceBusEnvironment.CreateServiceUri("sb",serviceNamespace,"").AbsoluteUri;        

         m_DisoveryPaths[serviceNamespace] = dialog.DiscoveryPath;

         if(String.IsNullOrWhiteSpace(dialog.AnnouncementsPath) == false)
         {
            m_AnnouncementsPaths[serviceNamespace] = dialog.AnnouncementsPath;

            if(m_NamespaceCredentials.ContainsKey(ServiceBusHelper.ExtractNamespace(new Uri(m_MexAddressTextBox.Text))) == false)
            {
               OnServiceBusLogOn(this,EventArgs.Empty);
            }
               
            Uri newAnouncementsAddress = ServiceBusEnvironment.CreateServiceUri("sb",serviceNamespace,m_AnnouncementsPaths[serviceNamespace]);

            if(m_ServiceBusAnnouncementSinks.ContainsKey(serviceNamespace))
            {

               if(m_ServiceBusAnnouncementSinks[serviceNamespace].AnnouncementsAddress.AbsoluteUri != newAnouncementsAddress.AbsoluteUri)
               {
                  m_ServiceBusAnnouncementSinks[serviceNamespace].Close();
                  m_ServiceBusAnnouncementSinks.Remove(serviceNamespace);
               }
               else
               {
                  return;
               }
            }
            
            TokenProvider tokenPorvider = m_NamespaceCredentials[serviceNamespace];

            m_ServiceBusAnnouncementSinks[serviceNamespace] = new ServiceBusAnnouncementSink<IMetadataExchange>(serviceNamespace,tokenPorvider);
            m_ServiceBusAnnouncementSinks[serviceNamespace].AnnouncementsAddress = newAnouncementsAddress;

            m_ServiceBusAnnouncementSinks[serviceNamespace].OnlineAnnouncementReceived += OnHelloNotice;
            m_ServiceBusAnnouncementSinks[serviceNamespace].OfflineAnnouncementReceived   += OnByeNotice;
 
            m_ServiceBusAnnouncementSinks[serviceNamespace].Open();
         }
         else
         {
            if(m_ServiceBusAnnouncementSinks.ContainsKey(serviceNamespace))
            {
               m_ServiceBusAnnouncementSinks[serviceNamespace].Close();
               m_ServiceBusAnnouncementSinks.Remove(serviceNamespace);
            }
         }
      }