示例#1
0
        //{eventid:<id>, cascade:<bool>, type:<dettype>}
        //      note that cascade is optional, if omitted, treated as false
        //      note that if cascade==true, that means delete both the file and all stored data in the system for that file -- THIS CANNOT BE UNDONE
        //      note that type is optional, if omitted, treated as all det types otherwise it's a single type such as wq
        internal static void Delete(UserSecurityContext user, JToken dat, HttpContext context, CancellationToken cancel)
        {
            if (dat != null)
            {
                JObject payload = dat as JObject;
                if (payload != null)
                {
                    CompoundIdentity seId = JsonUtils.ToId(dat["eventid"]);
                    if (seId != null)
                    {
                        bool   fileOnly = true;
                        JToken t        = payload["cascade"];
                        if (t != null)
                        {
                            string tmp = t.ToString();
                            if (tmp != null)
                            {
                                tmp = tmp.Trim().ToLowerInvariant();
                                if (tmp.StartsWith("tr"))
                                {
                                    fileOnly = false;
                                }
                            }
                            else
                            {
                                context.Response.StatusCode = HttpStatusCodes.Status400BadRequest;
                                return;
                            }
                        }

                        KnownDetType type = KnownDetType.Unknown;
                        t = payload[JsonUtils.Type];
                        if (t != null)
                        {
                            string tmp = KnownDets.Instance.Clean(t.ToString());
                            if (!KnownDets.Instance.IsValid(tmp))
                            {
                                context.Response.StatusCode = HttpStatusCodes.Status400BadRequest;
                                return;
                            }
                            type = ToType(tmp);
                        }

                        GeneralDetProcessor prov = DetProcessorManager.Instance.GetProvider(user);
                        if (prov != null)
                        {
                            bool res = false;
                            if (type != KnownDetType.Unknown)
                            {
                                res = prov.Delete(seId, fileOnly, type);
                            }
                            else
                            {
                                res = prov.Delete(seId, fileOnly);
                            }

                            if (res)
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                            }
                            else
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                            }
                            return;
                        }
                    }
                }
            }
            context.Response.StatusCode = HttpStatusCodes.Status400BadRequest;
        }