/// <inheritdoc />
        /// <summary>
        /// Enable or disable a rule This is helpful for turning off systems rules which cannot be deleted or modified otherwise. &lt;br&gt;&lt;br&gt;&lt;b&gt;Permissions Needed:&lt;/b&gt; BRE_RULE_ENGINE_RULES_ADMIN
        /// </summary>
        /// <param name="id">The id of the rule</param>
        /// <param name="enabled">The boolean value</param>
        public void SetBRERule(string id, BooleanResource enabled)
        {
            // verify the required parameter 'id' is set
            if (id == null)
            {
                throw new KnetikException(400, "Missing required parameter 'id' when calling SetBRERule");
            }

            mWebCallEvent.WebPath = "/bre/rules/{id}/enabled";
            if (!string.IsNullOrEmpty(mWebCallEvent.WebPath))
            {
                mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{format}", "json");
            }
            mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{" + "id" + "}", KnetikClient.ParameterToString(id));

            mWebCallEvent.HeaderParams.Clear();
            mWebCallEvent.QueryParams.Clear();
            mWebCallEvent.AuthSettings.Clear();
            mWebCallEvent.PostBody = null;

            mWebCallEvent.PostBody = KnetikClient.Serialize(enabled); // http body (model) parameter

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_client_credentials_grant");

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_password_grant");

            // make the HTTP request
            mSetBRERuleStartTime      = DateTime.Now;
            mWebCallEvent.Context     = mSetBRERuleResponseContext;
            mWebCallEvent.RequestType = KnetikRequestType.PUT;

            KnetikLogger.LogRequest(mSetBRERuleStartTime, "SetBRERule", "Sending server request...");
            KnetikGlobalEventSystem.Publish(mWebCallEvent);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Enable or disable a rule This is helpful for turning off systems rules which cannot be deleted or modified otherwise. &lt;br&gt;&lt;br&gt;&lt;b&gt;Permissions Needed:&lt;/b&gt; BRE_RULE_ENGINE_RULES_ADMIN
 /// </summary>
 /// <exception cref="com.knetikcloud.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="id">The id of the rule</param>
 /// <param name="enabled">The boolean value (optional)</param>
 /// <returns></returns>
 public void SetBRERule(string id, BooleanResource enabled = null)
 {
     SetBRERuleWithHttpInfo(id, enabled);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Enable or disable a rule This is helpful for turning off systems rules which cannot be deleted or modified otherwise. &lt;br&gt;&lt;br&gt;&lt;b&gt;Permissions Needed:&lt;/b&gt; BRE_RULE_ENGINE_RULES_ADMIN
        /// </summary>
        /// <exception cref="com.knetikcloud.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="id">The id of the rule</param>
        /// <param name="enabled">The boolean value (optional)</param>
        /// <returns>ApiResponse of Object(void)</returns>
        public ApiResponse <Object> SetBRERuleWithHttpInfo(string id, BooleanResource enabled = null)
        {
            // verify the required parameter 'id' is set
            if (id == null)
            {
                throw new ApiException(400, "Missing required parameter 'id' when calling Rule_Engine_RulesApi->SetBRERule");
            }

            var    localVarPath         = "/bre/rules/{id}/enabled";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (id != null)
            {
                localVarPathParams.Add("id", Configuration.ApiClient.ParameterToString(id));             // path parameter
            }
            if (enabled != null && enabled.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(enabled); // http body (model) parameter
            }
            else
            {
                localVarPostBody = enabled; // byte array
            }

            // authentication (oauth2_client_credentials_grant) required
            // oauth required
            if (!String.IsNullOrEmpty(Configuration.AccessToken))
            {
                localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
            }
            // authentication (oauth2_password_grant) required
            // oauth required
            if (!String.IsNullOrEmpty(Configuration.AccessToken))
            {
                localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)Configuration.ApiClient.CallApi(localVarPath,
                                                                                            Method.PUT, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("SetBRERule", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <Object>(localVarStatusCode,
                                            localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                            null));
        }
Ejemplo n.º 4
0
        public override void Execute()
        {
            if (Parameters.Count > 1)
            {
                if (Parameters[0].StartsWith("/"))
                {
                    Parameters[0] = Parameters[0].Substring(1);
                }
                LWM2MResource resource = _Client.GetResource(Parameters[0]) as LWM2MResource;
                if (resource == null)
                {
                    IResource parentResource = _Client.GetParentResource(Parameters[0]);

                    resource = parentResource as LWM2MResource;

                    if (resource == null && parentResource.Parent != null && String.IsNullOrEmpty(parentResource.Parent.Path))
                    {
                        // object instance does not exist
                        LWM2MResources resources  = parentResource as LWM2MResources;
                        string         instanceID = Parameters[0].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[1];
                        parentResource = resource = resources.CreateResource(instanceID);

                        resources.ModifiedResource = resource;

                        resources.Changed();
                        //(parentResource as LWM2MResource).Changed();
                        resource = null;
                    }

                    if (resource == null)
                    {
                        LWM2MResources resources = parentResource as LWM2MResources;

                        if (resources != null)
                        {
                            string[]         paths            = Parameters[0].Split('/');
                            string           name             = paths[paths.Length - 1];
                            LWM2MResource    childResource    = null;
                            BooleanResources booleanResources = resources as BooleanResources;
                            if (booleanResources == null)
                            {
                                DateTimeResources dateTimeResources = resources as DateTimeResources;
                                if (dateTimeResources == null)
                                {
                                    FloatResources floatResources = resources as FloatResources;
                                    if (floatResources == null)
                                    {
                                        IntegerResources integerResources = resources as IntegerResources;
                                        if (integerResources == null)
                                        {
                                            OpaqueResources opaqueResources = resources as OpaqueResources;
                                            if (opaqueResources == null)
                                            {
                                                StringResources stringResources = resources as StringResources;
                                                if (stringResources == null)
                                                {
                                                }
                                                else
                                                {
                                                    childResource = new StringResource(name);
                                                }
                                            }
                                            else
                                            {
                                                childResource = new OpaqueResource(name);
                                            }
                                        }
                                        else
                                        {
                                            childResource = new IntegerResource(name);
                                        }
                                    }
                                    else
                                    {
                                        childResource = new FloatResource(name);
                                    }
                                }
                                else
                                {
                                    childResource = new DateTimeResource(name);
                                }
                            }
                            else
                            {
                                childResource = new BooleanResource(name);
                            }


                            if (childResource != null)
                            {
                                childResource.SetValue(Parameters[1]);
                                resources.Add(childResource);
                            }
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                    resource.SetValue(Parameters[1]);
                    resource.Changed();
                    LWM2MResource parent = resource.Parent as LWM2MResource;
                    if (parent != null)
                    {
                        parent.Changed();
                        LWM2MResources grandparent = parent.Parent as LWM2MResources;
                        if (grandparent != null)
                        {
                            grandparent.Changed();
                        }
                    }
                }
            }
        }