Exemplo n.º 1
0
 public void Mark(params object[] msgs)
 {
     System.Text.StringBuilder sb = new System.Text.StringBuilder();
     sb.Append(FLog.GetStamp(1));
     foreach (object o in msgs)
     {
         sb.Append(FLog.Bracketize(o));
     }
     Status(sb.ToString());
 }
Exemplo n.º 2
0
        /*
         * Assuming the given object is a Dictionary<string,object>,
         * traverse it as a JSON-y thing using the given path.
         */
        public object Get(object root, string path)
        {
            object rv = null;

            FAssert.NotNull(root);
            object cur = root;

            string[] a = path.Split(new char[] { '/', });
            foreach (string s in a)
            {
                string key = s.Trim();
                if (key == "")
                {
                    continue;
                }
                if (cur is Dictionary <string, object> )
                {
                    Dictionary <string, object> dcur = cur as Dictionary <string, object>;
                    FAssert.NotNull(dcur);

/*
 *              if (key == "%DEVICE")
 *                  key = (LayoutManager.Instance.isPhone)?"phone":"tablet";
 *              if (key == "%ASPECT") {
 *                  key = CameraManager.Instance.GetAspectKey();
 *                  if (key != CameraManager.ASPECT_WILDCARD && !dcur.ContainsKey(key))
 *                      key = CameraManager.ASPECT_WILDCARD;
 *              }
 */
                    cur = dcur[key];
                }
                else if (cur is List <object> )
                {
                    List <object> lcur = cur as List <object>;
                    FAssert.NotNull(lcur);
                    int ki = System.Convert.ToInt32(key);
                    cur = lcur[ki];
                }
                else
                {
                    // should we warn here, or just silently stop drilling
                    // and return the last successful hit?
                    FLog.Mark(path, key, cur.GetType().ToString());
                }
            }
            rv = cur;
            return(rv);
        }
Exemplo n.º 3
0
        // ====================================================

        public static void Fail(string condition, object o, params object[] ctx)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("ASSERT! ");
            sb.Append(FLog.GetStamp());
            sb.Append(FLog.Bracketize(condition));
            sb.Append(FLog.Bracketize(o));
            foreach (object co in ctx)
            {
                sb.Append(FLog.Bracketize(co));
            }
            FLog.LogError(sb.ToString());
#if RAISE_EXCEPTIONS
            throw new FAssertException(sb.ToString());
#endif
        }
Exemplo n.º 4
0
        // Convert a JSON object to a vector.
        // The object can be either of two forms:
        //     { "x": 0, "y": 0, "z": 0 }
        //     [ 0, 0, 0 ]
        // In the object form, all three fields are optional.
        // In the array form, you can have two or three fields.
        public static Vector3 jtov(object j, Vector3 defaultValue)
        {
            Vector3 rv = defaultValue;

            if (j is List <object> )
            {
                List <object> jl = j as List <object>;
                if (jl.Count > 0)
                {
                    rv.x = System.Convert.ToSingle(jl[0]);
                }
                if (jl.Count > 1)
                {
                    rv.y = System.Convert.ToSingle(jl[1]);
                }
                if (jl.Count > 2)
                {
                    rv.z = System.Convert.ToSingle(jl[2]);
                }
            }
            else if (j is Dictionary <string, object> )
            {
                Dictionary <string, object> jd = j as Dictionary <string, object>;
                if (jd.ContainsKey("x"))
                {
                    rv.x = System.Convert.ToSingle(jd["x"]);
                }
                if (jd.ContainsKey("y"))
                {
                    rv.y = System.Convert.ToSingle(jd["y"]);
                }
                if (jd.ContainsKey("z"))
                {
                    rv.z = System.Convert.ToSingle(jd["z"]);
                }
            }
            else
            {
                FLog.LogError("invalid JSON vector object [" + j.ToString() + "]");
            }
            return(rv);
        }