Example #1
0
        static void WriteXml(Stream output, DataTable dataTable, string columnName)
        {
            using (XmlTextWriter writer = new XmlTextWriter(output, Encoding.UTF8))
            {
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement("resources");
                foreach (DataRow row in dataTable.Rows)
                {
                    string key   = (string)row["key"];
                    string type  = (string)row["type"];
                    string value = row[columnName] is DBNull ? null : (string)row[columnName];

                    if (type.EndsWith("-array"))
                    {
                        if (!string.IsNullOrEmpty(value))
                        {
                            writer.WriteStartElement(type);
                            writer.WriteAttributeString("name", key);

                            string[] values = StringSpliter.Split(value, CSV_SPECIAL_CHARS);
                            foreach (string v in values)
                            {
                                writer.WriteStartElement("item");
                                if (!string.IsNullOrEmpty(v) & v.IndexOfAny(XML_SPECIAL_CHARS) != -1)
                                {
                                    writer.WriteCData(v);
                                }
                                else
                                {
                                    writer.WriteValue(v);
                                }
                                writer.WriteEndElement();
                            }
                            writer.WriteEndElement();
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(value))
                        {
                            writer.WriteStartElement(type);
                            writer.WriteAttributeString("name", key);
                            if (value.IndexOfAny(XML_SPECIAL_CHARS) != -1)
                            {
                                writer.WriteCData(value);
                            }
                            else
                            {
                                writer.WriteValue(value);
                            }
                            writer.WriteEndElement();
                        }
                    }
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
Example #2
0
        //加载GameInit模块
        private IEnumerator GameInitPackages(string GameInitTable)
        {
            StringSpliter sp = new StringSpliter(GameInitTable, '\n');

            if (sp.Count >= 1)
            {
                int      loadedCount = 0;
                string[] args;

                GameLogger.Log(TAG, "Gameinit table : {0}", sp.Count);

                foreach (string ar in sp.Result)
                {
                    if (ar.StartsWith(":"))
                    {
                        continue;
                    }

                    bool           required    = false;
                    string         packageName = "";
                    GameModRunMask mask        = GameModRunMask.GameBase;
                    args = ar.Split(':');

                    if (args.Length >= 3)
                    {
                        required    = args[2] == "Required";
                        packageName = args[0];
                        System.Enum.TryParse(args[1], out mask);
                    }

                    bool modNeedRun = (mask & currentLoadMask) != GameModRunMask.None;

                    //状态
                    loadedCount++;
                    GameInitSetUIProgressValue(loadedCount / (float)sp.Count * 0.6f);
                    UIProgressText.text = "Loading " + packageName;

                    //加载
                    GameMod mod = ModManager.LoadGameModByPackageName(packageName, modNeedRun);
                    if (mod != null)
                    {
                        mod.IsModInitByGameinit = true;

                        yield return(new WaitUntil(mod.IsLoadComplete));
                    }

                    if ((mod == null || (modNeedRun && mod.LoadStatus != GameModStatus.InitializeSuccess)) && required)
                    {
                        GameErrorManager.ThrowGameError(GameError.GameInitPartLoadFailed, "加载模块  " + packageName + " 时发生错误");
                    }
                }
            }

            UIProgressText.text = "Loading";
            GameInitSetUIProgressValue(0.6f);
        }
 protected virtual object ParseValue(string typeName, string value)
 {
     if (typeName.EndsWith("-array", StringComparison.OrdinalIgnoreCase))
     {
         string[] array = StringSpliter.Split(value, ',');
         return(this.Parse(typeName.Replace("-array", ""), array));
     }
     else
     {
         return(this.Parse(typeName, value));
     }
 }
Example #4
0
        /// <summary>
        /// 通过上下文字符串设置指定上下文对象的属性值或字段值>
        /// 其中contextSettings参数的格式为:
        ///对象属性名(可以用.号表示层次关系)[=默认值]
        ///如果有多个,用回车或;号分隔
        /// </summary>
        public void LoadContext(string contextSettings)
        {
            if (String.IsNullOrEmpty(contextSettings))
            {
                return;
            }
            string        names = contextSettings.Replace("\r\n", ";");
            StringSpliter dp    = new StringSpliter(names, ";", "=");

            foreach (var key in dp.Keys)
            {
                Load(key, dp[key]);
            }
        }
Example #5
0
        private void SaveParameters(AppFunction func)
        {
            string parameters = Request.Form["Parameter"];

            func.Parameters.Clear();
            if (parameters.IsEmpty())
            {
                return;
            }
            StringSpliter ss = new StringSpliter(parameters, "\n", "=");

            foreach (var ky in ss.Keys)
            {
                func.Parameters.Add(new AppParameter
                {
                    Name         = ky,
                    ValuePattern = ss[ky]
                });
            }
        }
Example #6
0
        /// <summary>
        /// 运行命令
        /// </summary>
        /// <param name="cmd">命令字符串</param>
        /// <returns>返回是否成功</returns>
        public bool RunCommand(string cmd)
        {
            if (string.IsNullOrEmpty(cmd))
            {
                return(false);
            }

            StringSpliter sp = new StringSpliter(cmd, ' ', true);

            if (sp.Count >= 1)
            {
                foreach (CmdItem cmdItem in commands)
                {
                    if (cmdItem.Keyword == sp.Result[0])
                    {
                        //arg
                        if (cmdItem.LimitArgCount > 0 && sp.Count < cmdItem.LimitArgCount - 1)
                        {
                            GameLogger.Log(TAG, "命令 {0} 至少需要 {1} 个参数", sp.Result[0], cmdItem.LimitArgCount);
                            return(false);
                        }

                        List <string> arglist = new List <string>(sp.Result);
                        arglist.RemoveAt(0);

                        //Kernel hander
                        if (cmdItem.KernelCallback != null)
                        {
                            return(cmdItem.KernelCallback(sp.Result[0], cmd, arglist.ToArray()));
                        }
                        //Modul handler
                        if (!string.IsNullOrEmpty(cmdItem.Handler) && cmdItem.HandlerInternal != null)
                        {
                            return(cmdItem.HandlerInternal.RunCommandHandler(sp.Result[0], sp.Count, cmd, arglist.ToArray()));
                        }
                    }
                }
                GameLogger.Warning(TAG, "未找到命令 {0}", sp.Result[0]);
            }
            return(false);
        }
        /// <summary>
        /// 获取文章扩展展性的显示值(来自键值对的下拉列表中的显示内容)
        /// </summary>
        /// <param name="ca"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static object GetExtDisplay(this Base_CatalogArticle ca, Base_CatalogExt catExt)
        {
            if (catExt.DataSource.IsEmpty())
            {
                return(GetExt(ca, catExt));
            }
            else
            {
                var           obj = GetExt(ca, catExt);
                string        str = CommOp.ToStr(obj);
                StringSpliter ss  = new StringSpliter(catExt.DataSource, ";", "=");

                foreach (var key in ss.Keys)
                {
                    if (ss[key] == str)
                    {
                        return(key);
                    }
                }
            }

            return(GetExt(ca, catExt));
        }
        public virtual T[] GetArray <T>(string key, T[] defaultValue)
        {
            object value = GetProperty(key);

            if (value == null)
            {
                return(defaultValue);
            }

            if (value is string)
            {
                string str = (string)value;
                if (string.IsNullOrEmpty(str))
                {
                    return(defaultValue);
                }

                List <T> list  = new List <T>();
                string[] items = StringSpliter.Split(str, ',');
                foreach (string item in items)
                {
                    T ret = default(T);
                    try
                    {
                        ret = (T)ConvertTo(typeof(T), item);
                    }
                    catch (NotSupportedException e)
                    {
                        throw e;
                    }
                    catch (Exception) { }
                    list.Add(ret);
                }
                return(list.ToArray());
            }

            if (value is T[])
            {
                return((T[])value);
            }

            Array array = value as Array;

            if (array != null)
            {
                List <T> list = new List <T>();
                for (int i = 0; i < array.Length; i++)
                {
                    var item = array.GetValue(i);
                    T   ret  = default(T);
                    try
                    {
                        ret = (T)ConvertTo(typeof(T), item);
                    }
                    catch (NotSupportedException e)
                    {
                        throw e;
                    }
                    catch (Exception) { }
                    list.Add(ret);
                }
                return(list.ToArray());
            }

            throw new FormatException(string.Format("This value \"{0}\" cannot be converted to an \"{1}\" array.", value, typeof(T).Name));
        }