Example #1
0
        public LogicInput(LogicComponent component, int index, Type inputType)
        {
            if (component == null)
                throw new ArgumentNullException("component");
            if (inputType == null)
                throw new ArgumentNullException("inputType");
            if (!typeof(Value).IsAssignableFrom(inputType))
                throw new ArgumentException("InputType has to inherit from Value", "inputType");

            Component = component;
            Index = index;
            InputType = inputType;
        }
Example #2
0
 public override PhysicalComponent[] GetSupportedComponents(LogicComponent logicComponent)
 {
     //TODO: filter if port is already used by other input/output
     if (logicComponent.GetType() == typeof(Logic.LogicInput))
     {
         return Components.Where(p => p.GetType() == typeof(BinaryIn)).ToArray();
     }
     else if (logicComponent.GetType() == typeof(Logic.LogicOutput))
     {
         //TODO: filter if output component is already assigned to other logic component
         return Components.Where(p => p.GetType() == typeof(BinaryOut)).ToArray();
     }
     return new PhysicalComponent[0];
 }
Example #3
0
 public void RemoveTasksForComponent(LogicComponent component)
 {
     lock (taskQueue)
     {
         LinkedListNode<IDispatcherTask> current = taskQueue.First;
         while (current != null)
         {
             if (current.Value.ConcerningComponent == component)
             {
                 LinkedListNode<IDispatcherTask> next = current.Next;
                 taskQueue.Remove(current);
                 current = next;
             }
             else
             {
                 current = current.Next;
             }
         }
     }
 }
Example #4
0
        public void AddComponent(LogicComponent component)
        {
            if (component == null)
                throw new ArgumentNullException("component");

            if (component.House == this)
                return;
            if (component.House != null)
                throw new InvalidOperationException("component is already assigned");

            component.House = this;
            lock (logicComponents)
            {
                component.Id = currentLogicComponentsId++; //TODO: improve id assignment
                logicComponents.Add(component);
            }

            component.Init();

            EnqueueTask(new UpdateComponentTask(component));
        }
Example #5
0
        public void RemoveComponent(LogicComponent component)
        {
            if (component == null)
                throw new ArgumentNullException("component");
            if (component.House != this)
                throw new InvalidOperationException("component is not assigned to this");

            component.House = null;

            component.RemoveOutputConnections();
            component.RemoveInputConnections();

            lock (logicComponents)
            {
                logicComponents.Remove(component);
            }

            dispatcher.RemoveTasksForComponent(component);
        }