public BBDeviceConnectStatus(BBDeviceProperties theProperties)
        {
            m_Properties = theProperties;
            var EventGuid = Guid.NewGuid().ToString();

            Event = new Event {
                Guid = EventGuid, Id = EventGuid, Description = "Device Status", Object = this, Keys = new string[] { "Status" }
            };
        }
Esempio n. 2
0
 public BBDeviceRestart(BBDeviceProperties theProperties)
 {
     m_Properties = theProperties;
 }
 public BBDeviceConnect(BBDeviceProperties theProperties)
 {
     m_Properties = theProperties;
     Status       = new BBDeviceConnectStatus(theProperties);
 }
Esempio n. 4
0
        public void Update(BBDeviceProperties theProperties)
        {
            bool FlagSubscriptionUpdated = false;
            bool FlagEventUpdated        = false;

            if (theProperties == null)
            {
                return;
            }

            if (theProperties.Guid != null && theProperties.Guid != Guid)
            {
                return;
            }

            // Don't set this to false, as it may not be set in the first place
            if (theProperties.AutoConnect)
            {
                AutoConnect = true;
            }

            if (theProperties.ConnectButtonEvent != null)
            {
                if (Event.Merge(ConnectButtonEvent, theProperties.ConnectButtonEvent))
                {
                    FlagEventUpdated             = true;
                    ConnectButtonSubscription.Id = theProperties.ConnectButtonEvent.Id;
                    FlagSubscriptionUpdated      = true;
                }
            }

            if (theProperties.RestartButtonEvent != null)
            {
                if (Event.Merge(RestartButtonEvent, theProperties.RestartButtonEvent))
                {
                    FlagEventUpdated             = true;
                    RestartButtonSubscription.Id = theProperties.RestartButtonEvent.Id;
                    FlagSubscriptionUpdated      = true;
                }
            }

            if (theProperties.Name != null && theProperties.Name != Name)
            {
                Name = theProperties.Name;
            }

            if (theProperties.IP != null && theProperties.IP != IP)
            {
                IPAddress address;
                if (IPAddress.TryParse(theProperties.IP, out address))
                {
                    IP = theProperties.IP;
                }
            }

            if (!string.IsNullOrEmpty(theProperties.MACAddress))
            {
                MACAddress = theProperties.MACAddress;
            }

            if (theProperties.IOEvents != null)
            {
                List <BBDeviceEvent> IOEventsList = new List <BBDeviceEvent>(IOEvents);

                foreach (var NewIOEvent in theProperties.IOEvents)
                {
                    BBDeviceEvent Search = IOEventsList.FirstOrDefault(IOEvent => IOEvent.IONumber == NewIOEvent.IONumber);

                    if (Search != null)
                    {
                        if (Search.Id != NewIOEvent.Id)
                        {
                            Search.Id        = NewIOEvent.Id;
                            FlagEventUpdated = true;
                        }

                        if (Search.Description != NewIOEvent.Description)
                        {
                            Search.Description = NewIOEvent.Description;
                            FlagEventUpdated   = true;
                        }

                        if (!string.IsNullOrEmpty(NewIOEvent.RisingEdgeValue))
                        {
                            Search.RisingEdgeValue = NewIOEvent.RisingEdgeValue;
                        }

                        if (!string.IsNullOrEmpty(NewIOEvent.FallingEdgeValue))
                        {
                            Search.FallingEdgeValue = NewIOEvent.FallingEdgeValue;
                        }
                    }
                    else
                    {
                        //   NewIOEvent.Object = new BBEventFire(NewIOEvent.Id, NewIOEvent.Keys[0], NewIOEvent.RisingEdgeValue, NewIOEvent.FallingEdgeValue);
                        IOEventsList.Add(NewIOEvent);
                    }
                }

                if (FlagEventUpdated)
                {
                    IOEvents = IOEventsList.ToArray();
                }
            }

            if (theProperties.Outputs != null && theProperties.Outputs.Any())
            {
                Outputs = theProperties.Outputs.Select(o =>
                {
                    var Output = new BBOutput(o.Name);

                    if (o.Subscriptions != null)
                    {
                        Output.Update(new BBOutputProperties {
                            Name = o.Name, Subscriptions = o.Subscriptions
                        });
                    }

                    return(Output);
                }).ToArray();

                FlagSubscriptionUpdated = true;
            }

            if (FlagSubscriptionUpdated)
            {
                ConstructSubscriptions();
            }
            if (FlagEventUpdated)
            {
                ConstructEvents();
            }
        }