Example #1
0
        public static object flattenDataDict(String dict)
        {
            object json = DataDict.get(dict);

            if (json == null)
            {
                return("Error: cannot locate data dict object " + dict);
            }
            return(Utils.JsonToExcelObjWithoutTypeInfo(json));
        }
Example #2
0
        public static object getFromDataDict(string dict, string path)
        {
            object json = DataDict.get(dict);

            if (json == null)
            {
                return("Error: cannot locate data dict object " + dict);
            }
            object o = getFromDataDictByPath(json, path);

            if (o is object[])
            {
                object[,] ret = new object[((object[])o).Length, 1];
                for (int i = 0; i < ((object[])o).Length; ++i)
                {
                    ret[i, 0] = ((object[])o)[i];
                }
                return(ret);
            }
            else
            {
                return(o);
            }
        }
Example #3
0
        public static object ExecParallel(object[,] tasks)
        {
            List <string> entries = new List <string>();
            int           rows = tasks.GetLength(0), cols = tasks.GetLength(1);

            List <string> retTypes = new List <string>();

            for (int i = 0; i < rows; ++i)
            {
                for (int j = 0; j < cols; ++j)
                {
                    object task = tasks[i, j];
                    if (task is ExcelError || task is ExcelMissing || task is ExcelEmpty)
                    {
                        continue;
                    }
                    String id = (String)(tasks[i, j]);
                    Utils.QLDelayedCall delayed = (Utils.QLDelayedCall)DataDict.get(id);
                    entries.Add(delayed.body);
                    retTypes.Add(delayed.retType);
                }
            }
            String json    = "[" + String.Join(",", entries) + "]";
            var    request = new RestRequest("excel-service/parallel", Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddParameter("Application/Json", json, ParameterType.RequestBody);
            request.AddHeader("Authorization", "Bearer " + settings.token);
            var response = settings.client.Execute <Utils.QLResult>(request);

            if (response.ErrorException != null)
            {
                return("Exception while executing the API: " + response.ErrorException.Message);
            }
            List <object> results = (List <object>)response.Data.result;

            if ((int)response.StatusCode != 200 || results.Count < 1)
            {
                return("Error: Parallel jobs failed.");
            }

            object[,] ret = new object[rows, cols];
            int count = 0;

            for (int i = 0; i < rows; ++i)
            {
                for (int j = 0; j < cols; ++j)
                {
                    object task = tasks[i, j];
                    if (task is ExcelError || task is ExcelMissing || task is ExcelEmpty)
                    {
                        continue;
                    }
                    Dictionary <string, object> r = (Dictionary <string, object>)results[count];
                    if (r.ContainsKey("error"))
                    {
                        ret[i, 0] = ((Dictionary <string, object>)r["error"])["message"];
                    }
                    else
                    {
                        object o = r["result"];
                        if (o is Dictionary <string, object> || o is List <object> )
                        {
                            ret[i, j] = DataDict.put(o, "DelayedJobResult");
                        }
                        else
                        {
                            ret[i, j] = Utils.JsonToExcelObj(retTypes[i], o);
                        }
                    }
                    count++;
                }
            }
            return(ret);
        }