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 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 RowConverter();

            var doc = rc.ConvertCLRtoBSON(null, root, "A");//exception
        }
Ejemplo n.º 6
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 static JSONDataMap RowToRecordInitJSON(Row row, Exception validationError, string recID = null, string target = null, string isoLang = null)
      {
        var result = new JSONDataMap();
        if (row==null) return result;
        if (recID.IsNullOrWhiteSpace()) recID = Guid.NewGuid().ToString();

        result["OK"] = true;
        result["ID"] = recID;
        if (isoLang.IsNotNullOrWhiteSpace())
          result["ISOLang"] = isoLang;

        //20140914 DKh
        if (row is FormModel)
        {
          result[FormModel.JSON_MODE_PROPERTY] = ((FormModel)row).FormMode;
          result[FormModel.JSON_CSRF_PROPERTY] = ((FormModel)row).CSRFToken;
        }
        
        var fields = new JSONDataArray();
        result["fields"] = fields;

        var schemaName = row.Schema.Name;
        if (row.Schema.TypedRowType!=null) schemaName = row.Schema.TypedRowType.FullName;

        foreach(var fdef in row.Schema.FieldDefs.Where(fd=>!fd.NonUI))
        {
          var fld = new JSONDataMap();
          fields.Add(fld);
          fld["def"] = fieldDefToJSON(schemaName, fdef, target);
          fld["val"] = row.GetFieldValue(fdef);
          var ferr = validationError as CRUDFieldValidationException;
          //field level exception
          if (ferr!= null && ferr.FieldName==fdef.Name)
          {
            fld["error"] = ferr.ToMessageWithType();
            fld["errorText"] = localizeString(schemaName, "errorText", ferr.ClientMessage);
          }
        }

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

        return result;
      }   
Ejemplo n.º 7
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 RowConverter(); 
      
          var doc = rc.ConvertCLRtoBSON(null, root, "A");//exception
      }
Ejemplo n.º 8
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 static JSONDataMap RowToRecordInitJSON(Row row, Exception validationError, string recID = null, string target = null, string isoLang = null)
        {
            var result = new JSONDataMap();

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

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

            //20140914 DKh
            if (row is FormModel)
            {
                result[FormModel.JSON_MODE_PROPERTY] = ((FormModel)row).FormMode;
                result[FormModel.JSON_CSRF_PROPERTY] = ((FormModel)row).CSRFToken;
            }

            var fields = new JSONDataArray();

            result["fields"] = fields;

            var schemaName = row.Schema.Name;

            if (row.Schema.TypedRowType != null)
            {
                schemaName = row.Schema.TypedRowType.FullName;
            }

            foreach (var fdef in row.Schema.FieldDefs.Where(fd => !fd.NonUI))
            {
                var fld = new JSONDataMap();
                fields.Add(fld);
                fld["def"] = fieldDefToJSON(schemaName, fdef, target);
                fld["val"] = row.GetFieldValue(fdef);
                var ferr = validationError as CRUDFieldValidationException;
                //field level exception
                if (ferr != null && ferr.FieldName == fdef.Name)
                {
                    fld["error"]     = ferr.ToMessageWithType();
                    fld["errorText"] = localizeString(schemaName, "errorText", ferr.ClientMessage);
                }
            }

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

            return(result);
        }
Ejemplo n.º 9
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(Row row,
                                                       Exception validationError,
                                                       string recID   = null,
                                                       string target  = null,
                                                       string isoLang = null,
                                                       ModelFieldValueListLookupFunc valueListLookup = null)
        {
            var result = new JSONDataMap();

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

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

            //20140914 DKh
            var form = row as FormModel;

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

                //20160123 DKh
                if (form.HasRoundtripBag)
                {
                    result[FormModel.JSON_ROUNDTRIP_PROPERTY] = form.RoundtripBag.ToJSON(JSONWritingOptions.CompactASCII);
                }
            }

            var fields = new JSONDataArray();

            result["fields"] = fields;

            var schemaName = row.Schema.Name;

            if (row.Schema.TypedRowType != null)
            {
                schemaName = row.Schema.TypedRowType.FullName;
            }

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

                var fld = new JSONDataMap();
                fields.Add(fld);
                fld["def"] = FieldDefToJSON(row, schemaName, fdef, target, isoLang, valueListLookup);
                var val = row.GetClientFieldValue(this, sfdef, target, isoLang);
                if (val is GDID && ((GDID)val).IsZero)
                {
                    val = null;
                }
                fld["val"] = val;
                var ferr = validationError as CRUDFieldValidationException;
                //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 CRUDFieldValidationException))
            {
                result["error"]     = validationError.ToMessageWithType();
                result["errorText"] = OnLocalizeString(schemaName, "errorText", validationError.Message, isoLang);
            }

            return(result);
        }
Ejemplo n.º 10
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.º 11
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(Row row,
            Exception validationError,
            string recID = null,
            string target = null,
            string isoLang = null,
            ModelFieldValueListLookupFunc valueListLookup = null)
        {
            var result = new JSONDataMap();
            if (row==null) return result;
            if (recID.IsNullOrWhiteSpace()) recID = Guid.NewGuid().ToString();

            result["OK"] = true;
            result["ID"] = recID;
            if (isoLang.IsNotNullOrWhiteSpace())
              result["ISOLang"] = isoLang;

            //20140914 DKh
            var form = row as FormModel;
            if (form != null)
            {
              result[FormModel.JSON_MODE_PROPERTY] = form.FormMode;
              result[FormModel.JSON_CSRF_PROPERTY] = form.CSRFToken;

              //20160123 DKh
              if (form.HasRoundtripBag)
            result[FormModel.JSON_ROUNDTRIP_PROPERTY] = form.RoundtripBag.ToJSON(JSONWritingOptions.CompactASCII);
            }

            var fields = new JSONDataArray();
            result["fields"] = fields;

            var schemaName = row.Schema.Name;
            if (row.Schema.TypedRowType!=null) schemaName = row.Schema.TypedRowType.FullName;

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

              var fld = new JSONDataMap();
              fields.Add(fld);
              fld["def"] = FieldDefToJSON(row, schemaName, fdef, target, isoLang, valueListLookup);
              var val = row.GetClientFieldValue(this, sfdef, target, isoLang);
              if (val is GDID && ((GDID)val).IsZero) val = null;
              fld["val"] = val;
              var ferr = validationError as CRUDFieldValidationException;
              //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 CRUDFieldValidationException))
            {
              result["error"] = validationError.ToMessageWithType();
              result["errorText"] = OnLocalizeString(schemaName, "errorText", validationError.Message, isoLang);
            }

            return result;
        }