Beispiel #1
0
        public void ProcessGadget(Guid id, GadgetSetValueRequest value, Action <string> logCallback)
        {
            Gadget gadget = Get(id, false);

            if (gadget == null)
            {
                logCallback(string.Format("Gadget '{0}' not found.", id));
                return;
            }
            else
            {
                logCallback(string.Format("Gadget {0} is found. Item will be updated.", gadget.Name));
            }

            _database.ExecuteScalar <string>(
                ConstantStrings.SqlQueries.Gadget.Update.UpdateValue,
                new List <SqliteParameter> {
                new SqliteParameter("Id", id),
                new SqliteParameter("Value", value.Value),
                new SqliteParameter("ComplexValue", value.ComplexValue)
            }
                );

            logCallback(string.Format("Gadget {0} is updated with values ({1},{2}).", gadget.Name, value.Value, value.ComplexValue));

            var actions = _gadgetActionService.GetByGadgetSource(id);

            actions.ForEach(action =>
            {
                logCallback(string.Format("Action {0} - ({1}) checking.", action.Order, action.Id));

                Gadget targetGadget = Get(action.TargetGadget, false);

                var scriptResult = _scriptingService.Execute(
                    action,
                    new ScriptParameter()
                {
                    SourceNewValue        = value.Value,
                    SourceNewComplexValue = value.ComplexValue,
                    SourceOldValue        = gadget.Value,
                    SourceOldComplexValue = gadget.ComplexValue,
                    TargetOldValue        = targetGadget.Value,
                    TargetOldComplexValue = targetGadget.ComplexValue
                });

                if (scriptResult.CanExecute)
                {
                    ProcessGadget(action.TargetGadget, new GadgetSetValueRequest()
                    {
                        Value = scriptResult.TargetNewValue, ComplexValue = scriptResult.TargetNewComplexValue
                    }, logCallback);
                }
            });
        }