Ejemplo n.º 1
0
        private JsonDataMap getComponentTreeMap(IEnumerable <IApplicationComponent> all, IApplicationComponent cmp, int level, string group = null)
        {
            var cmpTreeMap = new JsonDataMap();

            if (level > 7)
            {
                return(cmpTreeMap);  //cyclical ref
            }
            cmpTreeMap = getComponentMap(cmp, group);

            var children = new JsonDataArray();

            foreach (var child in all.Where(c => object.ReferenceEquals(cmp, c.ComponentDirector)))
            {
                var childMap = getComponentTreeMap(all, child, level + 1, group);
                children.Add(childMap);
            }

            if (children.Count() > 0)
            {
                cmpTreeMap["children"] = children;
            }

            return(cmpTreeMap);
        }
Ejemplo n.º 2
0
        private JsonDataArray doArray()
        {
            fetchPrimary(); // skip [

            var arr = new JsonDataArray();

            if (token.Type != JsonTokenType.tSqBracketClose)//empty array  []
            {
                while (true)
                {
                    arr.Add(doAny()); // [any, any, any]
                    fetchPrimary();
                    if (token.Type != JsonTokenType.tComma)
                    {
                        break;
                    }
                    fetchPrimary();
                }

                if (token.Type != JsonTokenType.tSqBracketClose)
                {
                    errorAndAbort(JsonMsgCode.eUnterminatedArray);
                }
            }
            return(arr);
        }
Ejemplo n.º 3
0
        public object LoadComponentTree(string group = null)
        {
            var res = new JsonDataMap();

            var all = App.AllComponents;

            var rootArr = new JsonDataArray();

            foreach (var cmp in all.Where(c => c.ComponentDirector == null))
            {
                rootArr.Add(getComponentTreeMap(all, cmp, 0, group));
            }

            res["root"] = rootArr;

            var otherArr = new JsonDataArray();

            foreach (var cmp in all.Where(c => c.ComponentDirector != null && !(c is ApplicationComponent)))
            {
                rootArr.Add(getComponentTreeMap(all, cmp, 0));
            }

            res["other"] = otherArr;

            return(new { OK = true, tree = res });
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Translates user action coordinates (i.e. screen touches or mouse clicks) into a string.
 /// The coordinates must be supplied as a JSON array of json objects that have '{x: [int], y: [int]}' structure
 /// </summary>
 public string DecipherCoordinates(JsonDataArray coords, int?offsetX = null, int?offsetY = null)
 {
     return(DecipherCoordinates(coords.Where(o => o is JsonDataMap)
                                .Cast <JsonDataMap>()
                                .Select(jp => new Point(jp["x"].AsInt(), jp["y"].AsInt())),
                                offsetX, offsetY
                                ));
 }
Ejemplo n.º 5
0
            public JsonDataObject Push <TKey, TValue>(string Name_, MultiMap <TKey, TValue> Data_)
            {
                var Collection = new JsonDataArray();

                foreach (var i in Data_)
                {
                    Collection.Push(i.Key);
                }

                Add(Name_, Collection);
                return(this);
            }
Ejemplo n.º 6
0
            public JsonDataObject Push <TKey>(string Name_, MultiSet <TKey> Data_)
            {
                var Collection = new JsonDataArray();

                foreach (var i in Data_)
                {
                    Collection.Push(i);
                }

                Add(Name_, Collection);
                return(this);
            }
Ejemplo n.º 7
0
            // 아래 함수들은 C++ 코드와 호환이 필요하지만 C#또는 C#버전의 한계로 인한 임시 코드
            public JsonDataObject Push <TValue>(string Name_, TValue[] Data_)
            {
                var Collection = new JsonDataArray();

                foreach (var i in Data_)
                {
                    Collection.Push(i);
                }

                Add(Name_, Collection);
                return(this);
            }
Ejemplo n.º 8
0
            protected JsonDataArray Push <TKey, TValue>(CMultiMap <TKey, TValue> Data_)
            {
                var Collection = new JsonDataArray();

                foreach (var i in Data_)
                {
                    Collection.Push(i.Key);
                }

                _Array.Add(Collection);

                return(this);
            }
Ejemplo n.º 9
0
            protected JsonDataArray Push <TKey>(CMultiSet <TKey> Data_)
            {
                var Collection = new JsonDataArray();

                foreach (var i in Data_)
                {
                    Collection.Push(i);
                }

                _Array.Add(Collection);

                return(this);
            }
Ejemplo n.º 10
0
            protected JsonDataArray Push <TValue>(List <TValue> Data_)
            {
                var Collection = new JsonDataArray();

                foreach (var i in Data_)
                {
                    Collection.Push(i);
                }

                _Array.Add(Collection);

                return(this);
            }
Ejemplo n.º 11
0
        public void T_14_RowCycle_TransitiveCycle_3()
        {
            var root = new JsonDataMap();

            root["a"]     = 1;
            root["b"]     = true;
            root["array"] = new JsonDataArray()
            {
                1, 2, 3, true, true, root
            };                                                        //TRANSITIVE(via another instance) CYCLE!!!!

            var rc = new DataDocConverter();

            var doc = rc.ConvertCLRtoBSON(null, root, "A");//exception
        }
Ejemplo n.º 12
0
            // 이 함수는 게임프로토콜 에 적용된 C++ 코드와 호환위해 임시 작성
            public JsonDataObject Push <TValue>(string Name_, List <TValue[]> Data_)
            {
                var Collection = new JsonDataArray();

                foreach (var i in Data_)
                {
                    var InnerCollection = new JsonDataArray();
                    foreach (var ii in i)
                    {
                        InnerCollection.Push(ii);
                    }

                    Collection.Add(InnerCollection);
                }

                Add(Name_, Collection);
                return(this);
            }
Ejemplo n.º 13
0
            public JsonDataObject Push <TKey, TValue>(string Name_, Dictionary <TKey, TValue>[] Data_)
            {
                var Collection = new JsonDataArray();

                foreach (var i in Data_)
                {
                    var InnerCollection = new JsonDataArray();

                    foreach (var ii in i)
                    {
                        InnerCollection.Push(ii.Key);
                    }

                    Collection.Add(InnerCollection);
                }

                Add(Name_, Collection);
                return(this);
            }
Ejemplo n.º 14
0
        private static JsonDataArray doArray(JazonLexer lexer, bool senseCase, int maxDepth)
        {
            if (maxDepth < 0)
            {
                throw new JazonDeserializationException(JsonMsgCode.eGraphDepthLimit, "The graph is too deep", lexer.Position);
            }

            var token = fetchPrimary(lexer); // skip [

            var arr = new JsonDataArray();

            if (token.Type != JsonTokenType.tSqBracketClose)//empty array  []
            {
                while (true)
                {
                    var item = doAny(lexer, senseCase, maxDepth);
                    arr.Add(item); // [any, any, any]

                    token = fetchPrimary(lexer);
                    if (token.Type != JsonTokenType.tComma)
                    {
                        break;
                    }
                    token = fetchPrimary(lexer);//eat coma
                    if (token.Type == JsonTokenType.tSqBracketClose)
                    {
                        break;                                   //allow for [el,] trailing coma at the end
                    }
                }

                if (token.Type != JsonTokenType.tSqBracketClose)
                {
                    throw new JazonDeserializationException(JsonMsgCode.eUnterminatedArray, "Unterminated array", lexer.Position);
                }
            }

            return(arr);
        }
Ejemplo n.º 15
0
        public override ExternalCallResponse Execute()
        {
            var rows = new JsonDataArray();

            using (var connection = Context.GetConnection().GetAwaiter().GetResult())
            {
                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandText = SQL;
                    bindParams(cmd);
                    using (var reader = cmd.ExecuteReader())
                    {
                        var cnt = 0;
                        while (cnt < MAX && reader.Read())
                        {
                            cnt++;
                            var row = new JsonDataMap();
                            rows.Add(row);
                            for (var i = 0; i < reader.FieldCount; i++)
                            {
                                var n = reader.GetName(i);
                                var v = reader.GetValue(i);
                                if (v is DBNull)
                                {
                                    v = null;
                                }

                                row[n] = v;
                            }
                        }
                    }
                }
            }

            var json = rows.ToJson(JsonWritingOptions.PrettyPrintASCII);

            return(new ExternalCallResponse(ContentType.JSON, json));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Generates JSON object suitable for passing into WV.RecordModel.Record(...) constructor on the client.
        /// Pass target to select attributes targeted to ANY target or to the specified one, for example
        ///  may get attributes for client data entry screen that sees field metadata differently, in which case target will reflect the name
        ///   of the screen
        /// </summary>
        public virtual JsonDataMap RowToRecordInitJSON(Doc doc,
                                                       Exception validationError,
                                                       Atom isoLang,
                                                       string recID  = null,
                                                       string target = null,
                                                       ModelFieldValueListLookupFunc valueListLookup = null)
        {
            var result = new JsonDataMap();

            if (doc == null)
            {
                return(result);
            }
            if (recID.IsNullOrWhiteSpace())
            {
                recID = Guid.NewGuid().ToString();
            }

            result["OK"] = true;
            result["ID"] = recID;
            if (!isoLang.IsZero)
            {
                result["ISOLang"] = isoLang;
            }

            //20140914 DKh
            var form = doc as Form;

            if (form != null)
            {
                result[Form.JSON_MODE_PROPERTY] = form.FormMode;
                result[Form.JSON_CSRF_PROPERTY] = form.CSRFToken;

                //20160123 DKh
                if (form.HasRoundtripBag)
                {
                    result[Form.JSON_ROUNDTRIP_PROPERTY] = form.RoundtripBag.ToJson(JsonWritingOptions.CompactASCII);
                }
            }

            var fields = new JsonDataArray();

            result["fields"] = fields;

            var schemaName = doc.Schema.Name;

            if (doc.Schema.TypedDocType != null)
            {
                schemaName = doc.Schema.TypedDocType.FullName;
            }

            foreach (var sfdef in doc.Schema.FieldDefs.Where(fd => !fd.NonUI))
            {
                var fdef = doc.GetClientFieldDef(sfdef, target, isoLang);
                if (fdef == null || fdef.NonUI)
                {
                    continue;
                }

                var fld = new JsonDataMap();
                fields.Add(fld);
                fld["def"] = FieldDefToJSON(doc, schemaName, fdef, target, isoLang, valueListLookup);
                var val = doc.GetClientFieldValue(sfdef, target, isoLang);
                if (val is GDID && ((GDID)val).IsZero)
                {
                    val = null;
                }
                fld["val"] = val;
                var ferr = validationError as FieldValidationException;
                //field level exception
                if (ferr != null && ferr.FieldName == fdef.Name)
                {
                    fld["error"]     = ferr.ToMessageWithType();
                    fld["errorText"] = OnLocalizeString(schemaName, "errorText", ferr.ClientMessage, isoLang);
                }
            }

            //record level
            if (validationError != null && !(validationError is FieldValidationException))
            {
                result["error"]     = validationError.ToMessageWithType();
                result["errorText"] = OnLocalizeString(schemaName, "errorText", validationError.Message, isoLang);
            }

            return(result);
        }