예제 #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);
                }
            });
        }
예제 #2
0
        public SaveResponse SetValue(Guid id, GadgetSetValueRequest value)
        {
            SaveResponse returnValue = new SaveResponse();

            returnValue.AddAction(string.Format("Set Value '{0}' started with values {1}, {2}", id, value.Value, value.ComplexValue));

            ProcessGadget(
                id,
                value,
                (log) => { returnValue.AddAction(string.Format("Process for '{0}' :{1}", id, log)); }
                );

            return(returnValue);
        }
예제 #3
0
 public void Execute(Guid id, GadgetSetValueRequest value, Action <string> logCallback)
 {
     /*
      * var actions = _gadgetActionService.GetByGadget(id);
      *
      * actions.ForEach(action =>
      * {
      *  if (action.SourceValue == value.Value)
      *  {
      *      _gadgetService.ProcessGadget(action.TargetGadget, new GadgetSetValueRequest() { Value = action.TargetValue }, log);
      *  }
      * });
      */
 }