Example #1
0
            public virtual string ToLog()
            {
                IList <string> list = new List <string>();

                list.Add(string.Format("\n    {0}", FreeLog.ToTrigger()));
                IList <FreeLog.LogKey> parents = GetParents();

                foreach (FreeLog.LogKey lk in parents)
                {
                    list.Add("\n    " + lk.action);
                }
                return(from.GetName() + ":" + from.GetValue() + "->" + to.GetValue() + " at " + StringUtil.GetStringFromStrings(list, string.Empty));
            }
Example #2
0
        private void SetArg(FuncArg arg, IList <ArgValue> funcArgs, IEventArgs args)
        {
            ArgValue fa = GetArgValue(arg, funcArgs, args);

            if (fa != null)
            {
                IPara para = ParaUtil.GetPara(arg.GetType());
                if (para != null)
                {
                    try
                    {
                        IPara old = new ParaExp(fa.GetValue()).GetSourcePara(args);
                        if (old != null)
                        {
                            if (old.GetValue() != null)
                            {
                                para = para.Initial("=", old.GetValue().ToString());
                            }
                            else
                            {
                                para = para.Initial("=", string.Empty);
                            }
                        }
                        else
                        {
                            para = para.Initial("=", FreeUtil.ReplaceNumber(fa.GetValue(), args));
                        }
                    }
                    catch (Exception)
                    {
                        para = para.Initial("=", FreeUtil.ReplaceNumber(fa.GetValue(), args));
                    }
                    para.SetName("arg_" + arg.GetName());
                    args.GetDefault().GetParameters().TempUse(para);
                    IPara p = (IPara)para.Borrow();
                    p.SetName(arg.GetName());
                    if (para.GetValue() != null)
                    {
                        p.SetValue("=", para);
                    }
                    args.GetDefault().GetParameters().TempUse(p);
                    FreeLog.FuncArg(p.ToString());
                }
                else
                {
                    // 非简单变量
                    ((BaseEventArgs)args).TempUse(arg.GetName(), args.GetUnit(fa.GetValue()));
                }
            }
        }
Example #3
0
        public override TestValue GetCaseValue(IEventArgs args)
        {
            TestValue tv = new TestValue();
            FreeData  fd = (FreeData)args.GetUnit(UnitTestConstant.Tester);

            if (fd != null)
            {
                IPara para = fd.GetParameters().Get(field);
                if (para != null)
                {
                    tv.AddField(field, para.GetValue().ToString());
                }
            }

            return(tv);
        }
Example #4
0
 public static void Message(string msg, IEventArgs args)
 {
     if (enable)
     {
         IList <string> list = new List <string>();
         foreach (ParaExp pe in paras)
         {
             IPara pa = GetPara(args, pe);
             if (pa != null)
             {
                 list.Add(pa.GetName() + "=" + pa.GetValue());
             }
         }
         messageCount++;
         messages.Add(messageCount + "  " + DateTime.Now.ToString("u") + " " + msg + "\n   观察值:" + StringUtil.GetStringFromStrings(list, ", "));
         if (messages.Count > 1000)
         {
             messages.Remove(0);
         }
     }
 }
        public override void DoAction(IEventArgs args)
        {
            object target = GetTarget(args);

            if (fields != null && values != null)
            {
                string[] fs = StringUtil.Split(fields, ",");
                string[] vs = StringUtil.Split(values, ",");
                if (fs.Length == vs.Length)
                {
                    for (int i = 0; i < fs.Length; i++)
                    {
                        try
                        {
                            string    fName = fs[i].Trim();
                            FieldInfo f     = ReflectionCache.GetField(target, fName);
                            string    type  = f.GetType().Name.ToLower();
                            IPara     p     = null;
                            string[]  ss    = StringUtil.Split(vs[i].Trim(), ".");
                            if (ss.Length == 2)
                            {
                                if (args.GetUnit(ss[0].Trim()) != null)
                                {
                                    p = args.GetUnit(ss[0].Trim()).GetParameters().Get(ss[1].Trim());
                                }
                            }
                            else
                            {
                                if (ss.Length == 1)
                                {
                                    p = args.GetDefault().GetParameters().Get(ss[0].Trim());
                                }
                            }
                            object v = null;
                            if (p != null)
                            {
                                v = p.GetValue();
                            }
                            if ("long".Equals(type))
                            {
                                if (v == null)
                                {
                                    v = long.Parse(vs[i].Trim());
                                }
                            }
                            else
                            {
                                if ("int".Equals(type))
                                {
                                    if (v == null)
                                    {
                                        v = int.Parse(vs[i].Trim());
                                    }
                                }
                                else
                                {
                                    if ("float".Equals(type))
                                    {
                                        if (v == null)
                                        {
                                            v = float.Parse(vs[i].Trim());
                                        }
                                    }
                                    else
                                    {
                                        if ("double".Equals(type))
                                        {
                                            if (v == null)
                                            {
                                                v = double.Parse(vs[i].Trim());
                                            }
                                        }
                                        else
                                        {
                                            if ("string".Equals(type))
                                            {
                                                if (v == null)
                                                {
                                                    v = vs[i].Trim().ToString();
                                                }
                                            }
                                            else
                                            {
                                                if ("boolean".Equals(type))
                                                {
                                                    if (v == null)
                                                    {
                                                        v = bool.Parse(vs[i].Trim());
                                                    }
                                                }
                                                else
                                                {
                                                    throw new GameConfigExpception(fName + "'s type '" + type + "' is not supported.");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            SetValue(target, f, v);
                            System.Console.Out.WriteLine(target.GetType().FullName + "'s " + fName + " -> " + v);
                        }
                        catch (Exception e)
                        {
                            throw new GameConfigExpception("set " + fields + " to " + values + " failed at " + target.GetType().FullName + "\n" + ExceptionUtil.GetExceptionContent(e));
                        }
                    }
                }
            }
        }
Example #6
0
        public virtual IPara GetPara(IEventArgs args)
        {
            IParable parable = args.GetUnit(unit);

            if (parable != null)
            {
                ParaList pl = args.GetUnit(unit).GetParameters();
                if (pl.HasPara(para))
                {
                    return(pl.Get(para));
                }
                else
                {
                    bool     has  = (para.IndexOf('[') > -1);
                    bool     has2 = (para.IndexOf(']') > -1);
                    string[] vs   = Split(GetPara(), 1);

                    if (has && has2)
                    {
                        vs = new string[] { para };
                    }
                    if (vs.Length != 4)
                    {
                        if (has && has2 && para.Contains("[@") && para.Contains("']/@")) /* ¼õÉÙContainsµ÷ÓÃ */
                        {
                            vs = Split(GetPara(), 2);
                        }
                    }
                    if (vs.Length == 4)
                    {
                        IPara p = pl.Get(vs[0].Trim());
                        if (p != null && p is ParaListSet)
                        {
                            ParaListSet pls = (ParaListSet)p;
                            ParaList    sub = pls.GetParaList(vs[1].Trim(), vs[2].Trim(), args);
                            if (sub != null && sub.HasPara(vs[3].Trim()))
                            {
                                return(sub.Get(vs[3].Trim()));
                            }
                        }
                    }
                    else
                    {
                        if (has && has2)
                        {
                            vs = Split(para, 3);
                            if (vs.Length == 3 && StringUtil.IsNullOrEmpty(vs[2]))
                            {
                                IPara p = pl.Get(vs[0].Trim());
                                if (p != null && (p is MapPara || p is StringPara))
                                {
                                    if (p is MapPara)
                                    {
                                        MapPara mp = (MapPara)p;
                                        if (vs[1].Trim().Equals("length"))
                                        {
                                            return(new IntPara(p.GetName(), mp.Size()));
                                        }
                                        return(mp.GetValue(vs[1].Trim()));
                                    }
                                    if (p is StringPara)
                                    {
                                        if ("length".Equals(vs[1].Trim()))
                                        {
                                            return(new IntPara(p.GetName(), p.GetValue().ToString().Length));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return(null);
            }
            else
            {
                throw new GameConfigExpception("unit " + unit + " is not existed.\n" + GetUnit() + "." + GetPara());
            }
        }