Exemplo n.º 1
0
        public IActionResult RemoveQuery([FromBody] JsonDict jsonDict)
        {
            if (!jsonDict.TryGetValue("id", out object obj))
            {
                obj = jsonDict["queryId"];
            }
            var queryId = obj.ToString();

            eqService.RemoveQuery(queryId);

            var dict = new Dictionary <string, object>();

            dict.Add("result", "ok");

            return(Json(dict));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Merges a preset into a given JSON object.
        ///
        /// For bar items that are of kinds "action" or "application", respectively the "identifier" or "default" fields
        /// of their configuration block are used as a lookup in the appropriate dictionary in this class.
        ///
        /// The object found in the lookup is then merged over the original.
        ///
        /// This is performed during deserialisation, just before the class instantiation so they are unaware of
        /// such hackery.
        /// </summary>
        /// <param name="jo">The BarItem JSON object.</param>
        /// <returns></returns>
        public JObject MergePreset(JObject jo)
        {
            string?kind          = jo.SelectToken("kind")?.ToString();
            bool   isAction      = kind == "action";
            bool   isApplication = kind == "application";

            string?key = null;

            if (isAction || isApplication)
            {
                string?keyField = isAction ? "configuration.identifier" : "configuration.default";
                key = jo.SelectToken(keyField)?.ToString();
            }

            if (!string.IsNullOrEmpty(key))
            {
                JsonDict dict = isAction ? this.Actions : this.Defaults;

                dict.TryGetValue(key, out JObject? preset);

                if (preset != null)
                {
                    jo.Merge(preset.DeepClone());
                }
            }

            // Make "kind = setting" items imply "widget = setting"
            string?newKind = jo.SelectToken("kind")?.ToString();

            if (newKind == "setting")
            {
                if (!jo.ContainsKey("widget"))
                {
                    jo.Add("widget", "setting");
                }
            }

            return(jo);
        }