public static string ExtractStr(dynamic json, string firstLevel, string secondLevel = null, bool silent = false)
        {
            var path = firstLevel + (secondLevel == null ? "" : "=>" + secondLevel);

            try
            {
                object result = json[firstLevel];

                if (result != null && secondLevel != null)
                {
                    result = json[firstLevel][secondLevel];
                }

                if (result == null)
                {
                    if (!silent)
                    {
                        DebugHelper.JsonFieldParseError(path, json);
                    }

                    return(null);
                }

                return(result.ToString());
            }
            catch
            {
                if (!silent)
                {
                    DebugHelper.JsonFieldParseError(path, json);
                }

                return(null);
            }
        }
        public bool CreateTask()
        {
            var taskJson = GetPostData();

            if (taskJson == null)
            {
                DebugHelper.Out("A task preparing error.", DebugHelper.Type.Error);

                return(false);
            }

            var jsonPostData = new JObject();

            jsonPostData["clientKey"] = ClientKey;
            jsonPostData["task"]      = taskJson;
            jsonPostData["softId"]    = 874;

            DebugHelper.Out("Connecting to " + Host, DebugHelper.Type.Info);
            dynamic postResult = JsonPostRequest(ApiMethod.CreateTask, jsonPostData);

            if (postResult == null || postResult.Equals(false))
            {
                DebugHelper.Out("API error", DebugHelper.Type.Error);

                return(false);
            }

            var response = new CreateTaskResponse(postResult);

            if (!response.ErrorId.Equals(0))
            {
                ErrorMessage = response.ErrorDescription;

                DebugHelper.Out(
                    "API error " + response.ErrorId + ": " + response.ErrorDescription,
                    DebugHelper.Type.Error
                    );

                return(false);
            }

            if (response.TaskId == null)
            {
                DebugHelper.JsonFieldParseError("taskId", postResult);

                return(false);
            }

            TaskId = (int)response.TaskId;
            DebugHelper.Out("Task ID: " + TaskId, DebugHelper.Type.Success);

            return(true);
        }
        public static int?ExtractInt(dynamic json, string firstLevel, string secondLevel = null)
        {
            int    outInt;
            string numberAsStr = JsonHelper.ExtractStr(json, firstLevel, secondLevel);

            if (!int.TryParse(numberAsStr, out outInt))
            {
                var path = firstLevel + (secondLevel == null ? "" : "=>" + secondLevel);
                DebugHelper.JsonFieldParseError(path, json);

                return(null);
            }

            return(outInt);
        }
        public static double?ExtractDouble(dynamic json, string firstLevel, string secondLevel = null)
        {
            double outDouble;
            string numberAsStr = ExtractStr(json, firstLevel, secondLevel);

            if (numberAsStr == null ||
                !double.TryParse(numberAsStr.Replace(",", "."), NumberStyles.Number, CultureInfo.InvariantCulture,
                                 out outDouble))
            {
                var path = firstLevel + (secondLevel == null ? "" : "=>" + secondLevel);
                DebugHelper.JsonFieldParseError(path, json);

                return(null);
            }

            return(outDouble);
        }