Ejemplo n.º 1
0
        public async Task WorkflowEngine_TriggerAsyncWithEntityWorkflowInstanceAndExistingWorkflowVariable_ReturnsTriggerResult()
        {
            // Arrange
            var instance = new LightSwitcher();

            this.Context.Switchers.Add(instance);

            var workflow = Workflow.Create(instance.Id, instance.Type, instance.State, "tester");

            workflow.AddVariable(new LightSwitcherWorkflowVariable {
                CanSwitch = true
            });

            this.Context.Workflows.Add(workflow);
            await this.Context.SaveChangesAsync();

            var param = new TriggerParam("SwitchOn", instance);

            // Act
            var triggerResult = await this.WorkflowEngine.TriggerAsync(param);

            // Assert
            Assert.IsNotNull(triggerResult);
            Assert.IsFalse(triggerResult.HasErrors);
            Assert.AreEqual(instance.State, triggerResult.CurrentState);
            Assert.AreEqual("On", triggerResult.CurrentState);

            Assert.IsTrue(param.HasVariables);
        }
Ejemplo n.º 2
0
 private void MqttClient_OnTopicRecieved(object sender, string e)
 {
     LightSwitcher.BeginInvokeOnMainThread(() =>
     {
         LightSwitcher.SetState(e == "on", true);
     });
 }
Ejemplo n.º 3
0
    void Start()
    {
        stairwellContents            = GameObject.Find("StairwellContents");
        interactableObjectsContainer = stairwellContents.transform.Find("InteractableObjects").gameObject;
        furnitureContainer           = stairwellContents.transform.Find("Furniture").gameObject;
        houseContainer = stairwellContents.transform.Find("House").gameObject;
        musicSwitcher  = GameObject.Find("Ambient Sound").transform.GetComponent <MusicSwitcher>();
        lightSwitcher  = GameObject.Find("RoomArrangerWithTeleport").GetComponent <LightSwitcher>();

        upperRoomCopyStairwellContents  = GameObject.Find("DummyRoomTop");
        lowerRoomCopyStairwellContents  = GameObject.Find("DummyRoomBottom");
        lowerCopyRoomFurnitureContainer = lowerRoomCopyStairwellContents != null?lowerRoomCopyStairwellContents.transform.Find("Furniture").gameObject : null;

        triggerContainer = GameObject.Find("Gameplay");

        bigCurtains = GameObject.FindGameObjectsWithTag("Curtains").Select(x => x.GetComponent <Animator>()).ToArray();

        UnhighlightAllInteractableObjects();
        DisableAllTriggers();

        foreach (Renderer renderer in GameObject.FindObjectsOfType <Renderer>())
        {
            renderer.material.SetFloat(highlightHideShaderPropertyName, highlightDisabledValue);
        }
    }
Ejemplo n.º 4
0
        public async Task WorkflowEngine_Find_ReturnsTheDesiredIWorkflowInstance()
        {
            // Arrange
            var instance = new LightSwitcher();

            this.Context.Switchers.Add(instance);

            var workflow = Workflow.Create(instance.Id, instance.Type, instance.State, "tester");

            this.Context.Workflows.Add(workflow);
            await this.Context.SaveChangesAsync();

            // Act
            var result = this.WorkflowEngine.Find(instance.Id, typeof(LightSwitcher));

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(LightSwitcher));

            var resultInstance = result as LightSwitcher;

            Assert.AreEqual(resultInstance.Id, instance.Id);
            Assert.AreEqual(resultInstance.Type, instance.Type);
            Assert.AreEqual(resultInstance.State, instance.State);
            Assert.AreEqual(resultInstance.Assignee, instance.Assignee);
        }
Ejemplo n.º 5
0
        public void Initialize()
        {
            LightSwitcher.TurnOff();
            Door.TurnOff();
            LightSensor.TurnOff();
            MotionSensor.TurnOff();

            ClassRoomObjects.Counter = 0;
        }
Ejemplo n.º 6
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(transform.gameObject);
     }
     DontDestroyOnLoad(transform.gameObject);
 }
Ejemplo n.º 7
0
        public MainPage()
        {
            InitializeComponent();


            _lightSwitcher = new LightSwitcher();
            _lightSwitcher.Initialize();

            _listerner = new ReceiveBroker();
            _listerner.OnReceivedMessage += _listerner_OnReceivedMessage;
            _listerner.Initialize();
            _listerner.StartListening();
        }
Ejemplo n.º 8
0
        void ReleaseDesignerOutlets()
        {
            if (LightSwitcher != null)
            {
                LightSwitcher.Dispose();
                LightSwitcher = null;
            }

            if (UISwitchController != null)
            {
                UISwitchController.Dispose();
                UISwitchController = null;
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            ISwitchable switcher = new LightSwitcher();

            ICommand on  = new PowerOnCommand(switcher);
            ICommand off = new PowerOffCommand(switcher);

            var invoker = new SwitchInvoker(on, off);

            Console.WriteLine("Lights ON =>");
            invoker.LightOn();
            Console.WriteLine();
            Console.WriteLine("Lights OFF =>");
            invoker.LightOff();
            Console.WriteLine();
            Console.ReadKey();
        }
Ejemplo n.º 10
0
        public async Task WorkflowEngine_TriggerAsyncWithEntityWorkflowInstance_ReturnsTriggerResult()
        {
            // Arrange
            var instance = new LightSwitcher();
            var param    = new TriggerParam("SwitchOn", instance);

            // Act
            var triggerResult = await this.WorkflowEngine.TriggerAsync(param);

            // Assert
            Assert.IsNotNull(triggerResult);
            Assert.IsFalse(triggerResult.HasErrors);
            Assert.AreEqual(instance.State, triggerResult.CurrentState);
            Assert.AreEqual("On", triggerResult.CurrentState);

            Assert.AreEqual(1, this.Context.Workflows.Count());
            Assert.AreEqual(0, this.Context.Workflows.First().WorkflowVariables.Count());
        }
Ejemplo n.º 11
0
        public async Task WorkflowEngine_TriggerAsyncWithEntityWorkflowInstanceAndSameWorkflowVariable_ReturnsTriggerResult()
        {
            // Arrange
            var instance = new LightSwitcher();

            this.Context.Switchers.Add(instance);

            var workflow = Workflow.Create(instance.Id, instance.Type, instance.State, "tester");
            var variable = new LightSwitcherWorkflowVariable {
                CanSwitch = true
            };

            workflow.AddVariable(variable);

            this.Context.Workflows.Add(workflow);
            await this.Context.SaveChangesAsync();

            variable.CanSwitch = false;
            var param = new TriggerParam("SwitchOn", instance)
                        .AddVariableWithKey <LightSwitcherWorkflowVariable>(variable);;

            // Act
            var triggerResult = await this.WorkflowEngine.TriggerAsync(param);

            // Assert
            Assert.IsNotNull(triggerResult);
            Assert.IsFalse(triggerResult.HasErrors);
            Assert.AreEqual(instance.State, triggerResult.CurrentState);
            Assert.AreEqual("On", triggerResult.CurrentState);

            Assert.IsTrue(param.HasVariables);

            Assert.AreEqual(1, workflow.WorkflowHistories.Count());

            var workflowVariable       = workflow.WorkflowVariables.First();
            var type                   = KeyBuilder.FromKey(workflowVariable.Type);
            var myDeserializedVariable = JsonConvert.DeserializeObject(workflowVariable.Content, type);

            Assert.IsInstanceOfType(myDeserializedVariable, typeof(LightSwitcherWorkflowVariable));

            var variableInstance = myDeserializedVariable as LightSwitcherWorkflowVariable;

            Assert.IsFalse(variableInstance.CanSwitch);
        }
Ejemplo n.º 12
0
        public async Task WorkflowEngineService_TriggerAsyncWithEntityWorkflowInstanceAndNewWorkflowVariable_ReturnsTriggerResult()
        {
            // Arrange
            var instance        = new LightSwitcher();
            var workfowVariable = new LightSwitcherWorkflowVariable {
                CanSwitch = true
            };
            var param = new TriggerParam("SwitchOn", instance)
                        .AddVariableWithKey <LightSwitcherWorkflowVariable>(workfowVariable);

            // Act
            var triggerResult = await this.WorkflowEngineService.TriggerAsync(param);

            // Assert
            Assert.NotNull(triggerResult);
            Assert.False(triggerResult.HasErrors);
            Assert.Equal(instance.State, triggerResult.CurrentState);
            Assert.Equal("On", triggerResult.CurrentState);

            Assert.Equal(1, this.Context.Workflows.Count());
            Assert.Single(this.Context.Workflows.First().WorkflowVariables);
        }