Exemplo n.º 1
0
        private void ValueDispatchToRule(IDispatchable dispatchable, object o, Guid toRule, RuleInterfaceInstance toInterface)
        {
            lock (_lock)
            {
                Task.Run(async() =>
                {
                    await _ruleInstanceVisuNotifier.NotifyValueChanged(toInterface, o);
                }).ConfigureAwait(false);

                foreach (var rule in _logicInstancesStore.Dictionary())
                {
                    if (rule.Key.ObjId == toRule)
                    {
                        try
                        {
                            SystemLogger.Instance.LogDebug(
                                $"ValueDispatchToRule: {dispatchable.Name} write value {o} to {toInterface.This2RuleInterfaceTemplateNavigation.Name}");
                            var ruleResults = rule.Value.ValueChanged(toInterface, dispatchable, o);

                            foreach (var result in ruleResults)
                            {
                                Task.Run(async() =>
                                {
                                    await _dispatcher.DispatchValue(result.Instance, result.Value);
                                }).ConfigureAwait(false);
                            }
                        }
                        catch (Exception e)
                        {
                            SystemLogger.Instance.LogError(e, $"Error writing value ({o}) to {dispatchable.Name}");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void TestDispatch1()
        {
            var autoResetEvent = new AutoResetEvent(false);

            _dispatcher.RegisterDispatch(DispatchableType.NodeInstance, DispatchableMock.Instance.Id, (dispatchable, o) =>
            {
                Assert.NotNull(o);
                Assert.Equal(100, o);
                autoResetEvent.Set();
            });

            _dispatcher.DispatchValue(DispatchableMock.Instance, 100);

            Assert.True(autoResetEvent.WaitOne(5000));
        }
Exemplo n.º 3
0
        public void SetValue(Guid nodeInstance, JsonElement value)
        {
            object convertedValue = null;

            switch (value.ValueKind)
            {
            case JsonValueKind.Undefined:
                break;

            case JsonValueKind.Object:
                throw new NotImplementedException();

            case JsonValueKind.Array:
                throw new NotImplementedException();

            case JsonValueKind.String:
                convertedValue = value.GetString();
                break;

            case JsonValueKind.Number:
                convertedValue = value.GetDouble();
                break;

            case JsonValueKind.True:
                convertedValue = true;
                break;

            case JsonValueKind.False:
                convertedValue = false;
                break;

            case JsonValueKind.Null:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }


            var dispatchable = new DispatchableInstance(DispatchableType.Visualization, $"Web", nodeInstance, DispatchableSource.Visualization);

            _dispatcher.DispatchValue(dispatchable, convertedValue);
        }
Exemplo n.º 4
0
        public static void MqttDispatch(this IDispatcher self, string topic, string data)
        {
            var split = topic.Split("/");

            if (Enum.TryParse(split[1], out DispatchableType enu))
            {
                var id = new Guid(split[2]);


                var remoteDispatch = new RemoteDispatchable
                {
                    Id   = id,
                    Type = enu,
                    Name = "RemoteUnknown"
                };

                self.DispatchValue(remoteDispatch, BinarySerializer.Deserialize(Encoding.UTF8.GetBytes(data)));
            }
        }
Exemplo n.º 5
0
        private void ValueDispatchToRule(IDispatchable dispatchable, object o, Guid toRule, RuleInterfaceInstance toInterface)
        {
            lock (_lock)
            {
                foreach (var rule in _coreServer.Rules)
                {
                    if (rule.Key.ObjId == toRule)
                    {
                        SystemLogger.Instance.LogDebug($"ValueDispatchToRule: {dispatchable.Name} write value {o} to {toInterface.This2RuleInterfaceTemplateNavigation.Name}");
                        var ruleResults = rule.Value.ValueChanged(toInterface, dispatchable, o);

                        foreach (var result in ruleResults)
                        {
                            _dispatcher.DispatchValue(result.Instance, result.Value);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        public void SetValue(Guid nodeInstance, object value)
        {
            var dispatchable = new DispatchableInstance(DispatchableType.NodeInstance, $"Web", nodeInstance, DispatchableSource.Visualisation);

            _dispatcher.DispatchValue(dispatchable, value);
        }