Esempio n. 1
0
        private void Functions_CollectionChanged(object sender,
                                                 System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove ||
                e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace)
            {
                foreach (NetworkFunction function in e.OldItems)
                {
                    Triggers.RemoveSlave(function.Triggers);
                    Actions.RemoveSlave(function.Actions);
                    Values.RemoveSlave(function.Values);

                    foreach (ExportDataElement element in function.GetDataElements())
                    {
                        if (_main.FunctionsById.ContainsKey(element.ID))
                        {
                            _main.FunctionsById.Remove(element.ID);
                        }
                    }
                }
            }

            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add ||
                e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace)
            {
                foreach (NetworkFunction function in e.NewItems)
                {
                    Triggers.AddSlave(function.Triggers);
                    Actions.AddSlave(function.Actions);
                    Values.AddSlave(function.Values);

                    foreach (ExportDataElement element in function.GetDataElements())
                    {
                        if (!_main.FunctionsById.ContainsKey(element.ID))
                        {
                            _main.FunctionsById.Add(element.ID, function);
                        }
                        else
                        {
                            Logger.Error("UDP interface created duplicate function ID. (Interface=\"" + Name +
                                         "\", Function ID=\"" + element.ID + "\")");
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void AttachToProfileOnMainThread()
        {
            base.AttachToProfileOnMainThread();
            if (Model.Ports.Count == 0)
            {
                // create some ports
                Model.CreateDefaultPorts(4);
            }

            Model.Ports.ForEach(model =>
            {
                model.Initialize(this);

                // we slave these collections so we can clear them later if we remove the port
                Actions.AddSlave(model.Actions);
                Triggers.AddSlave(model.Triggers);
                Values.AddSlave(model.Values);
            });

            // sign up for any compatible controls being touched
            Profile.RoutableControlSelected += Profile_RoutableControlSelected;
        }