Exemple #1
0
        private ServiceResponse parseAddActionRuleResponse(ServiceResponse Response, ActionRule newRule)
        {
            if (Response.IsSuccess)
            {
                try
                {
                    Response.Content = Response.SOAPContent.Element(NS_SOAP_ENV + "Body").Element(NS_ACTION + "AddActionRuleResponse").Element(NS_ACTION + "RuleID").Value;
                    newRule.RuleID   = int.Parse(Response.Content);
                }
                catch (Exception ex)
                {
                    Response.IsSuccess = false;
                    Response.Content   = "[parseAddActionRuleResponse] " + ex.Message;
                }
            }

            return(Response);
        }
Exemple #2
0
        /// <summary>
        /// Method to update an existing action rule
        /// </summary>
        /// <param name="IP"></param>
        /// <param name="User"></param>
        /// <param name="Password"></param>
        /// <param name="Config"></param>
        /// <returns>ServiceResponse, with ServiceResponse.content containing the new ID of the rule stored on the device</returns>
        public async Task <ServiceResponse> Update_ActionRuleAsync(string IP, string User, string Password, ActionRule Rule)
        {
            ServiceResponse response = await this.RemoveActionRuleAsync(IP, User, Password, Rule.RuleID);

            if (response.IsSuccess)
            {
                response = await this.AddActionRuleAsync(IP, User, Password, Rule);
            }
            return(response);
        }
Exemple #3
0
        /// <summary>
        /// Method to create a new ActionRule (Event) on the device.
        /// If success the ID field of the passed ActionRule instance will be set with the ID returned in the response
        /// </summary>
        /// <param name="IP">The device ip address</param>
        /// <param name="User">User to authenticate the http request</param>
        /// <param name="Password">Password to use</param>
        /// <param name="NewRule">ActionRule reference</param>
        /// <returns>ServiceResponse, with ServiceResponse.content containing the ID of the rule stored on the device</returns>
        public async Task <ServiceResponse> AddActionRuleAsync(string IP, string User, string Password, ActionRule NewRule)
        {
            string actionBody = @"<act:AddActionRule><act:NewActionRule>"
                                + NewRule.ToString()
                                + @"</act:NewActionRule></act:AddActionRule>";

            return(this.parseAddActionRuleResponse(await base.sendRequestAsync(IP, User, Password, actionBody), NewRule));
        }
Exemple #4
0
        private GetActionRulesResponse parseGetActionRulesResponse(ServiceResponse Response)
        {
            GetActionRulesResponse response = Response.Factory <GetActionRulesResponse>();

            if (Response.IsSuccess)
            {
                try
                {
                    XElement   configResponse = Response.SOAPContent.Element(NS_SOAP_ENV + "Body").Element(NS_ACTION + "GetActionRulesResponse").Element(NS_ACTION + "ActionRules");
                    ActionRule rule;
                    foreach (XElement el in configResponse.Elements())
                    {
                        rule = new ActionRule();
                        //parse rule base info
                        rule.RuleID  = int.Parse(el.Element(NS_ACTION + "RuleID").Value);
                        rule.Name    = el.Element(NS_ACTION + "Name").Value;
                        rule.Enabled = bool.Parse(el.Element(NS_ACTION + "Enabled").Value);
                        //parse rule startevent
                        if (el.HasElement(NS_ACTION + "StartEvent"))
                        {
                            rule.Trigger = new EventTrigger(
                                el.Element(NS_ACTION + "StartEvent").Element(NS_TOPIC + "TopicExpression").Value, false,
                                el.Element(NS_ACTION + "StartEvent").GetElementValue(NS_TOPIC + "MessageContent")
                                );
                        }
                        //parse rule conditions
                        if (el.HasElement(NS_ACTION + "Conditions"))
                        {
                            foreach (XElement condition in el.Element(NS_ACTION + "Conditions").Elements())
                            {
                                rule.AddExtraCondition(
                                    new EventTrigger(
                                        condition.Element(NS_TOPIC + "TopicExpression").Value, false,
                                        condition.GetElementValue(NS_TOPIC + "MessageContent")
                                        )
                                    );
                            }
                        }
                        //parse rule actionconfiguration id
                        rule.Configuration = new ActionConfiguration()
                        {
                            ConfigID = int.Parse(el.Element(NS_ACTION + "PrimaryAction").Value)
                        };
                        //parse activation timout
                        if (el.HasElement(NS_ACTION + "ActivationTimeout"))
                        {
                            rule.SetActivationTimeout(int.Parse(Regex.Match(el.Element(NS_ACTION + "ActivationTimeout").Value, @"\d+").Value));
                        }

                        response.ActionRules.Add(rule);
                    }
                }
                catch (Exception ex)
                {
                    response.IsSuccess = false;
                    response.Content   = "[ParseActionRulesResponse] " + ex.Message;
                }
            }

            return(response);
        }