Ejemplo n.º 1
0
        private static WeatherEvent CreateWeatherEvent(string eventType, Int32 temperature, bool isAlert, string affectedArea, string zipCode)
        {
            WeatherEvent weatherEvent = new WeatherEvent();

            weatherEvent.EventType    = eventType;
            weatherEvent.Temperature  = temperature;
            weatherEvent.IsAlert      = isAlert;
            weatherEvent.AffectedArea = affectedArea;
            weatherEvent.ZipCode      = zipCode;
            return(weatherEvent);
        }
Ejemplo n.º 2
0
        public static void SendToTopic(WeatherEvent weatherEvent)
        {
            TokenProvider credentials = TokenProvider.CreateSharedSecretTokenProvider(TopicSender.IssuerName, TopicSender.IssuerKey);
            Uri           serviceUri  = ServiceBusEnvironment.CreateServiceUri("sb", TopicSender.ServiceNamespace, string.Empty);

            MessagingFactory factory = null;

            factory = MessagingFactory.Create(serviceUri, credentials);

            TopicClient topicClient = factory.CreateTopicClient(TopicSender.TopicName);

            BrokeredMessage brokeredMessage = new BrokeredMessage(weatherEvent, new DataContractSerializer(typeof(WeatherEvent)));

            brokeredMessage.Properties.Add("ZipCode", weatherEvent.ZipCode);
            brokeredMessage.Properties.Add("EventType", weatherEvent.EventType);
            brokeredMessage.Properties.Add("AlertType", "Weather");
            brokeredMessage.Properties.Add("IsAlert", true);

            topicClient.Send(brokeredMessage);

            Console.WriteLine("Sent to Topic...press enter to exit");
            Console.Read();
        }