Exemplo n.º 1
0
        static void Main()
        {
            Console.WriteLine("Creating hub");
            using (var hubConnection = new HubConnection("http://localhost:1906/"))
            {
                var eventHubProxy = hubConnection.CreateHubProxy("EventHub");
                eventHubProxy.On<Message>("Receive", message => OnReceive(message));
                //eventHubProxy.On<Message>("UpdateConfiguration", message => OnUpdateConfiguration(message));
                hubConnection.Start().Wait();
                //eventHubProxy.Invoke<Message>("RequestConfiguration").Wait();

                Console.WriteLine("Hub created");
                while (true)
                {
                    Console.Write("Values: ");
                    var values = JsonConvert.DeserializeObject<Dictionary<string, object>>(Console.ReadLine());
                    var message = new Message
                    {
                        Sender = typeof(Program).FullName,
                        Target = "ArtNet",
                        Time = DateTime.Now,
                        Values = values
                    };
                    Console.WriteLine("Sending message");
                    eventHubProxy.Invoke<Message>("Send", message).Wait();
                    Console.WriteLine("Message sent");
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Extracts key value pairs from the message values.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        static IEnumerable<AddressValuePair> GetValuesFromMessage(Message message)
        {
            // try to get address value pairs from the channels
            var pairs = new List<AddressValuePair>();
            foreach (var channel in message.Values)
            {
                var name = channel.Name;
                var value = channel.Value;

                if (name != null && value != null)
                {
                    short address;
                    if (short.TryParse(name.ToString(), out address))
                    {
                        byte dmxValue;
                        if (byte.TryParse(value.ToString(), out dmxValue))
                        {
                            pairs.Add(new AddressValuePair(address, dmxValue));
                        }
                    }
                }
            }

            return pairs;
        }
 /// <summary>
 /// Called when a message is received.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <returns></returns>
 protected override async Task OnReceiveAsync(Message message)
 {
     switch (message.Method)
     {
         case MethodType.Update:
             UpdateReceived(message);
             break;
     }
 }
        void UpdateReceived(Message message)
        {
            if (message.Values != null)
            {
                var channels = GetChannelsFromMessage(message.Values);

                // send values to art net
                TemperatureManager.UpdateTargetTemperatures(channels);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Called when a message is received.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <returns></returns>
 protected override Task OnReceiveAsync(Message message)
 {
     switch (message.Method)
     {
         case MethodType.Update:
             UpdateReceived(message);
             break;
     }
     return Task.CompletedTask;
 }
        /// <summary>
        /// Called when a message is received.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        protected override async Task OnReceiveAsync(Message message)
        {
            switch (message.Method)
            {
                case MethodType.Get:
                    await GetFixtures(message.Sender);
                    break;

                case MethodType.Update:
                    UpdateChannels(message.Values);
                    await GetFixtures("WebFrontend");
                    break;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Send message values to ArtNet.
        /// </summary>
        /// <param name="message">The message.</param>
        void UpdateReceived(Message message)
        {
            if (message.Values != null)
            {
                var pairs = GetValuesFromMessage(message);

                // send values to art net
                fascade.Set(pairs);
            }
        }
Exemplo n.º 8
0
 static void OnUpdateConfiguration(Message message)
 {
     Console.WriteLine("ConfigUpdate:");
     Console.WriteLine(JsonConvert.SerializeObject(message, Formatting.Indented));
 }
Exemplo n.º 9
0
 static void OnReceive(Message message)
 {
     Console.WriteLine("Received:");
     Console.WriteLine(JsonConvert.SerializeObject(message, Formatting.Indented));
 }
Exemplo n.º 10
0
        /// <summary>
        /// Sends a new message to the event bus.
        /// </summary>
        /// <param name="values">The values that will be sent.</param>
        /// <param name="method">The method type of this message.</param>
        /// <param name="target">The target of this message.</param>
        /// <returns></returns>
        public async Task<Message> SendAsync(IEnumerable<dynamic> values, MethodType method, string target = null)
        {
            var message = new Message
            {
                Method = method,
                Sender = Sender,
                Target = target,
                Time = DateTime.Now,
                Values = values
            };

            Console.WriteLine("Sending " + JsonConvert.SerializeObject(message, Formatting.Indented));

            return await eventHubProxy.Invoke<Message>("Send", message);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Called when a new message from the event bus is received.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <returns></returns>
 protected abstract Task OnReceiveAsync(Message message);