Example #1
0
        /// <summary>
        /// Deletes CAN object from CAN server.
        /// </summary>
        /// <param name="ObjectPath">CAN path to the object.</param>
        /// <returns>Structure describing whether the function succeeded and response provided by CAN server.</returns>
        public async Task <CanDeleteResult> CanDeleteObject(string ObjectPath)
        {
            log.Trace("(ObjectPath:'{0}')", ObjectPath);

            NameValueCollection args = new NameValueCollection();

            args.Add("arg", ObjectPath);
            CanApiResult apiResult = await SendRequest("pin/rm", args);

            CanDeleteResult res = CanDeleteResult.FromApiResult(apiResult);

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #2
0
        /// <summary>
        /// Creates a new object based on a result from CAN API including validation checks.
        /// </summary>
        /// <param name="ApiResult">CAN API result object to copy values from.</param>
        /// <returns>Structure describing result of CAN upload operation.</returns>
        public static CanDeleteResult FromApiResult(CanApiResult ApiResult)
        {
            log.Trace("()");

            CanDeleteResult res = new CanDeleteResult(ApiResult);

            if (res.Success)
            {
                bool error = false;
                try
                {
                    CanDeleteObjectResponse response = JsonConvert.DeserializeObject <CanDeleteObjectResponse>(res.DataStr);
                    res.Pins = response.Pins;

                    // If the object was deleted previously, we might have empty Pins in response.
                    // We are thus OK if we receive success response and no more validation is done.
                }
                catch (Exception e)
                {
                    log.Error("Exception occurred: {0}", e.ToString());
                    error = true;
                }

                if (error)
                {
                    res.Success    = false;
                    res.Message    = "Invalid CAN response.";
                    res.IsCanError = false;
                }
            }
            else if (res.Message.ToLowerInvariant() == "not pinned")
            {
                res.Success = true;
                res.Pins    = null;
            }

            log.Trace("(-)");
            return(res);
        }