Beispiel #1
0
        private static bool load_xml(byte[] pBuffer)
        {
            try
            {
                Debug.Check(pBuffer != null);
                string xml = System.Text.Encoding.UTF8.GetString(pBuffer);

                SecurityParser xmlDoc = new SecurityParser();
                xmlDoc.LoadXml(xml);

                SecurityElement rootNode = xmlDoc.ToXml();

                if (rootNode.Tag != "agents" && (rootNode.Children == null || rootNode.Children.Count != 1))
                {
                    return(false);
                }

                string versionStr = rootNode.Attribute("version");
                Debug.Check(!string.IsNullOrEmpty(versionStr));

                foreach (SecurityElement bbNode in rootNode.Children)
                {
                    if (bbNode.Tag == "agent" && bbNode.Children != null)
                    {
                        string agentType = bbNode.Attribute("type").Replace("::", ".");

                        AgentProperties bb = new AgentProperties(agentType);
                        agent_type_blackboards[agentType] = bb;

                        foreach (SecurityElement propertiesNode in bbNode.Children)
                        {
                            if (propertiesNode.Tag == "properties" && propertiesNode.Children != null)
                            {
                                foreach (SecurityElement propertyNode in propertiesNode.Children)
                                {
                                    if (propertyNode.Tag == "property")
                                    {
                                        string name      = propertyNode.Attribute("name");
                                        string type      = propertyNode.Attribute("type").Replace("::", ".");
                                        string memberStr = propertyNode.Attribute("member");
                                        bool   bIsMember = false;

                                        if (!string.IsNullOrEmpty(memberStr) && memberStr == "true")
                                        {
                                            bIsMember = true;
                                        }

                                        string isStatic  = propertyNode.Attribute("static");
                                        bool   bIsStatic = false;

                                        if (!string.IsNullOrEmpty(isStatic) && isStatic == "true")
                                        {
                                            bIsStatic = true;
                                        }

                                        //string agentTypeMember = agentType;
                                        string agentTypeMember = null;
                                        string valueStr        = null;

                                        if (!bIsMember)
                                        {
                                            valueStr = propertyNode.Attribute("defaultvalue");
                                        }
                                        else
                                        {
                                            agentTypeMember = propertyNode.Attribute("agent").Replace("::", ".");
                                        }

                                        bb.AddProperty(type, bIsStatic, name, valueStr, agentTypeMember);
                                    }
                                }
                            }
                            else if (propertiesNode.Tag == "methods" && propertiesNode.Children != null)
                            {
                                Agent.CTagObjectDescriptor objectDesc = Agent.GetDescriptorByName(agentType);
                                foreach (SecurityElement methodNode in propertiesNode.Children)
                                {
                                    if (methodNode.Tag == "method")
                                    {
                                        //string eventStr = methodNode.Attribute("isevent");
                                        //bool bEvent = (eventStr == "true");
                                        //string taskStr = methodNode.Attribute("istask");
                                        //bool bTask = (taskStr == "true");
                                        //skip those other custom method
                                        string methodName = methodNode.Attribute("name");
                                        //string type = methodNode.Attribute("returntype").Replace("::", ".");
                                        //string isStatic = methodNode.Attribute("static");
                                        //string agentTypeStr = methodNode.Attribute("agent").Replace("::", ".");
                                        CCustomMethod customeMethod = new CTaskMethod(agentType, methodName);

                                        if (methodNode.Children != null)
                                        {
                                            foreach (SecurityElement paramNode in methodNode.Children)
                                            {
                                                if (paramNode.Tag == "parameter")
                                                {
                                                    string paramName = paramNode.Attribute("name");
                                                    Debug.Check(!string.IsNullOrEmpty(paramName));

                                                    string paramType = paramNode.Attribute("type");

                                                    //string paramFullName = string.Format("{0}::{1}", paramType, paramName);

                                                    customeMethod.AddParamType(paramType);
                                                }
                                            }
                                        }

                                        objectDesc.ms_methods.Add(customeMethod);
                                    }
                                } //end of for methodNode
                            }     //end of methods
                        }         //end of for propertiesNode
                    }
                }                 //end of for bbNode

                return(true);
            }
            catch (Exception e)
            {
                Debug.Check(false, e.Message);
            }

            Debug.Check(false);
            return(false);
        }
Beispiel #2
0
 /// <summary>
 /// 设置字符串
 /// </summary>
 /// <param name="text"></param>
 public void SetText(string text)
 {
     _parser.LoadXml(text);
     _element = _parser.ToXml();
 }
Beispiel #3
0
        private void Parser(WWW www)
        {
            try
            {
                GuLog.Debug("LevelConfigPath WWW::" + www.error);

                if (www.isDone && (www.error == null || www.error.Length == 0))
                {
                    SecurityParser xmlDoc = new SecurityParser();
                    GuLog.Debug("LevelConfigPath" + www.text);

                    xmlDoc.LoadXml(www.text);
                    ArrayList worldXmlList = xmlDoc.ToXml().Children;

                    foreach (SecurityElement xeRoot in worldXmlList)
                    {
                        if (xeRoot.Tag == "Levels")
                        {
                            ArrayList levelsXmlList = xeRoot.Children;
                            foreach (SecurityElement xeLevel in levelsXmlList)
                            {
                                if (xeLevel.Tag == "LevelUp")
                                {
                                    LevelInfo levelInfo = new LevelInfo();
                                    levelInfo.level  = Convert.ToInt32(xeLevel.Attribute("level"));
                                    levelInfo.exp    = Convert.ToInt32(xeLevel.Attribute("exp"));
                                    levelInfo.hunger = Convert.ToInt32(xeLevel.Attribute("hunger"));
                                    levelInfo.coinDL = Convert.ToInt32(xeLevel.Attribute("coinDL"));
                                    levelInfo.coinUL = Convert.ToInt32(xeLevel.Attribute("coinUL"));
                                    ArrayList awardXmlList = xeLevel.Children;
                                    foreach (SecurityElement xeAward in awardXmlList)
                                    {
                                        switch (xeAward.Tag)
                                        {
                                        case "DrinkWater":
                                            levelInfo.awardList.Add(new DrinkWater()
                                            {
                                                CoinDL    = Convert.ToInt32(xeAward.Attribute("coinDL")),
                                                CoinUL    = Convert.ToInt32(xeAward.Attribute("coinUL")),
                                                ExpNormal = Convert.ToInt32(xeAward.Attribute("expN")),
                                                ExpGoal   = Convert.ToInt32(xeAward.Attribute("expG")),
                                                Rate30    = (float)Convert.ToDouble(xeAward.Attribute("rate30")),
                                                RateMore  = (float)Convert.ToDouble(xeAward.Attribute("rateMore"))
                                            });
                                            break;

                                        case "DailyGoal":
                                            levelInfo.awardList.Add(new DailyGoal()
                                            {
                                                Percent = (float)Convert.ToDouble(xeAward.Attribute("percent")),
                                                Coin    = Convert.ToInt32(xeAward.Attribute("coin")),
                                                Award   = Convert.ToInt32(xeAward.Attribute("award")),
                                                ExpDL   = Convert.ToInt32(xeAward.Attribute("expDL")),
                                                ExpUL   = Convert.ToInt32(xeAward.Attribute("expUL"))
                                            });
                                            break;
                                        }
                                    }
                                    levelLists.Add(levelInfo.level, levelInfo);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogErrorFormat("<><LevelConfig.Parser>Error: {0}", ex.Message);
            }
            m_LoadOk = true;
        }
        private void Parser(WWW www)
        {
            m_LoadOk = true;

            if (www.isDone && (www.error == null || www.error.Length == 0))
            {
                SecurityParser xmlDoc = new SecurityParser();
                xmlDoc.LoadXml(www.text);
                ArrayList worldXmlList = xmlDoc.ToXml().Children;

                foreach (SecurityElement xeWorld in worldXmlList)
                {
                    if (xeWorld.Tag == "Items")
                    {
                        ArrayList sceneXmlList = xeWorld.Children;
                        foreach (SecurityElement xeScene in sceneXmlList)
                        {
                            if (xeScene.Tag == "Item")
                            {
                                Item sceneInfo = null;
                                int  type      = Convert.ToInt32(xeScene.Attribute("Type"));
                                switch (type)
                                {
                                case 4:
                                {
                                    NimItem nimInfo = new NimItem();
                                    nimInfo.ItemId   = Convert.ToInt32(xeScene.Attribute("Id"));
                                    nimInfo.Type     = type;
                                    nimInfo.Name     = xeScene.Attribute("Name");
                                    nimInfo.GetImage = xeScene.Attribute("getImage");

                                    nimInfo.PetType   = int.Parse(xeScene.Attribute("PetType"));
                                    nimInfo.Image     = xeScene.Attribute("Image");
                                    nimInfo.Audio     = xeScene.Attribute("Audio");
                                    nimInfo.Animation = xeScene.Attribute("Animation");
                                    nimInfo.Preview   = xeScene.Attribute("Preview");
                                    sceneInfo         = nimInfo;
                                }
                                break;

                                case 6:
                                {
                                    PropsItem propsItem = new PropsItem();
                                    propsItem.ItemId   = Convert.ToInt32(xeScene.Attribute("Id"));
                                    propsItem.Type     = type;
                                    propsItem.Name     = xeScene.Attribute("Name");
                                    propsItem.GetImage = xeScene.Attribute("getImage");
                                    sceneInfo          = propsItem;
                                }
                                break;

                                default:
                                {
                                    sceneInfo        = new Item();
                                    sceneInfo.ItemId = Convert.ToInt32(xeScene.Attribute("Id"));
                                    sceneInfo.Type   = type;
                                    sceneInfo.Name   = xeScene.Attribute("Name");
                                }
                                break;
                                }
                                missionInfo.Add(sceneInfo.ItemId, sceneInfo);
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        /************************************************私  有  方  法************************************************/
        //读取语言配置文件
        private void Parser(WWW www)
        {
            m_LoadOk = true;
            GuLog.Debug("ResConfigPath WWW::" + www.error);

            if (www.isDone && (www.error == null || www.error.Length == 0))
            {
                SecurityParser xmlDoc = new SecurityParser();
                GuLog.Debug("ResConfigPath" + www.text);

                xmlDoc.LoadXml(www.text);
                ArrayList allNodes = xmlDoc.ToXml().Children;
                foreach (SecurityElement xeResConfigs in allNodes)
                {     //根节点
                    if (xeResConfigs.Tag == "ResConfigs")
                    { //ResConfigs节点
                        ArrayList resConfigNodes = xeResConfigs.Children;
                        foreach (SecurityElement xeResConfig in resConfigNodes)
                        {//ResConfig节点
                            if (xeResConfig.Tag == "ResConfig")
                            {
                                string language = xeResConfig.Attribute("Language");
                                if (this.LanConfig.IsValid(language))
                                {
                                    ResConfig resConfig = new ResConfig()
                                    {
                                        Language = language
                                    };
                                    ArrayList elementNodes = xeResConfig.Children;
                                    foreach (SecurityElement xeText in elementNodes)
                                    {
                                        if (xeText.Tag == "Text")
                                        {//TextElement节点
                                            TextElement textElement = new TextElement()
                                            {
                                                Key = xeText.Attribute("Key"), Value = xeText.Attribute("Value")
                                            };
                                            resConfig.TextElements.Add(textElement);
                                        }
                                        else if (xeText.Tag == "Image")
                                        {//ImageElement节点
                                            ImageElement imageElement = new ImageElement()
                                            {
                                                Key = xeText.Attribute("Key"), Value = xeText.Attribute("Value")
                                            };
                                            resConfig.ImageElements.Add(imageElement);
                                        }
                                        else if (xeText.Tag == "Animation")
                                        {//AnimationElement节点
                                            AnimationElement animationElement = new AnimationElement()
                                            {
                                                Key = xeText.Attribute("Key"), Value = xeText.Attribute("Value")
                                            };
                                            resConfig.AnimationElements.Add(animationElement);
                                        }
                                        else if (xeText.Tag == "Audio")
                                        {//AudioElement节点
                                            AudioElement audioElement = new AudioElement()
                                            {
                                                Key = xeText.Attribute("Key"), Value = xeText.Attribute("Value")
                                            };
                                            resConfig.AudioElements.Add(audioElement);
                                        }
                                    }
                                    this.resConfigs.Add(language, resConfig);
                                }
                                else
                                {
                                    GuLog.Error(string.Format("----I18NConfig.Parser----ResConfigs.Language: {0}", language));
                                }
                            }
                        }
                    }
                }
                //GuLog.Debug(string.Format("----I18NConfig.Parser----I18NConfig.xml: {0}", www.text));
            }
        }
Beispiel #6
0
 public SecurityElement LoadXml(string xml)
 {
     m_Sp.LoadXml(xml);
     return(m_Sp.ToXml());
 }
Beispiel #7
0
        /// <summary>
        /// Reconstructs a <see cref="DiffieHellman"/> object from an XML string.
        /// </summary>
        /// <param name="xmlString">The XML string to use to reconstruct the DiffieHellman object.</param>
        /// <exception cref="CryptographicException">One of the values in the XML string is invalid.</exception>
        public override void FromXmlString(string xmlString)
        {
            if (xmlString == null)
                throw new ArgumentNullException();

            DHParameters dhParams = new DHParameters();
            try
            {
                SecurityParser sp = new SecurityParser();
                sp.LoadXml(xmlString);
                SecurityElement se = sp.ToXml();
                if (se.Tag != "DHKeyValue")
                    throw new CryptographicException();

                dhParams.P = GetNamedParam(se, "P");
                dhParams.G = GetNamedParam(se, "G");
                dhParams.X = GetNamedParam(se, "X");
                ImportParameters(dhParams);
            }
            finally
            {
                if (dhParams.P != null)
                    Array.Clear(dhParams.P, 0, dhParams.P.Length);
                if (dhParams.G != null)
                    Array.Clear(dhParams.G, 0, dhParams.G.Length);
                if (dhParams.X != null)
                    Array.Clear(dhParams.X, 0, dhParams.X.Length);
            }
        }
Beispiel #8
0
    //.plist 文件后缀需要改为.xml  xml解析不建议使用system.xml,它会有可能会去访问网络导致app启动时间变长,而且system.xml需要完整的c#库,这样会增加包的体积。
    //Mono.Xml 在文件头里包含!时可能出错,如:<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    //所以想要把它删除再解析
    public void LoadPlist(string file)
    {
        //

        Debug.Log("Plist LoadPlist 1");
        dicRoot = new Dictionary <string, string>();
        //         Debug.Log("Plist LoadPlist 2");
        //        string str = Resources.Load(file).ToString();
        //        Debug.Log(str);
        //         XmlParser parser = new XmlParser(XmlParser.InputType.Text,str );

        //         Debug.Log("Plist LoadPlist 3");

        //         XmlDocument doc = parser.Parse();
        //         Debug.Log("Plist LoadPlist 4");
        //         XmlElement root = doc.RootNode;
        //         Debug.Log("Plist LoadPlist 5");
        //         //plist/dict"
        //         //return;
        //         XmlElement dict = root.Children["plist"].Children["dict"];
        // Debug.Log("Plist LoadPlist 6");
        //         foreach (XmlElement element in dict.Children)
        //         {

        //             if (element.Name == "key")
        //             {
        //                 keyValue = element.Content;
        //             }
        //             if (element.Name == "string")
        //             {
        //                 stringValue = element.Content;
        //                 //Debug.Log(keyValue +":"+stringValue);
        //                 dicRoot.Add(keyValue, stringValue);
        //             }

        //         }
        // Debug.Log("Plist LoadPlist 7");



        //          XMLParser xmlParser = new XMLParser();
        //             XMLNode xn = xmlParser.Parse(Resources.Load(file).ToString());
        //            // server = xn.GetValue("items>0>server>0>_text");
        //            // database = xn.GetValue("items>0>database>0>_text");
        //             XMLNode temp=xn.GetNode("plist/dict");
        //           //  string basePath=temp.GetValue("@basePath");//或直
        // foreach (XMLNode child in temp.ChildNodes)
        //    {

        //    }

        // 假设xml文件路径为 Resources/test.xml
        //string xmlPath = "test";
        SecurityParser sp = new SecurityParser();

        sp.LoadXml(Resources.Load(file).ToString());

        SecurityElement root  = sp.ToXml();
        SecurityElement plist = GetXmlChild(root, "plist");

        if (plist != null)
        {
            SecurityElement dict = GetXmlChild(plist, "dict");
            if (dict != null)
            {
                foreach (SecurityElement child in dict.Children)
                {
                    if (child.Tag == "key")
                    {
                        keyValue = child.Text;
                    }
                    if (child.Tag == "string")
                    {
                        stringValue = child.Text;
                        //Debug.Log(keyValue +":"+stringValue);
                        dicRoot.Add(keyValue, stringValue);
                    }
                }
            }
        }
    }
Beispiel #9
0
    //-----------------------------------------------------------------------------------

    //解析xml数据
    static public VersionInfo ParseData(string xmlContent)
    {
        VersionInfo versionInfo = new VersionInfo();

        try
        {
            SecurityParser securityParser = new SecurityParser();
            securityParser.LoadXml(xmlContent);
            SecurityElement xml = securityParser.ToXml();

            if (xml == null)
            {
                Debug.LogError("VersionInfo.ParseData:XML Data Error");
                return(versionInfo);
            }

            if (xml.Children == null || xml.Children.Count == 0)
            {
                return(versionInfo);
            }

            foreach (SecurityElement se in xml.Children)
            {
                string tag = se.Tag.ToLower();
                switch (tag)
                {
                case "programversion": versionInfo.ProgramVersion = float.Parse(se.Text); break;

                case "apkurl": versionInfo.ApkUrl = se.Text; break;

                case "apkmd5": versionInfo.ApkMd5 = se.Text; break;

                case "iosappurl": versionInfo.IOSAppUrl = se.Text; break;

                case "iosappstoreurl": versionInfo.IOSAppStoreUrl = se.Text; break;

                case "isappleappstore": versionInfo.IsAppleAppStore = StrBoolParse(se.Text); break;

                case "isopenautoupdateinappstore": versionInfo.IsOpenAutoUpdateInAppStore = StrBoolParse(se.Text); break;

                case "isforcetoupdate": versionInfo.IsForceToUpdate = StrBoolParse(se.Text); break;

                case "resinfo":
                {
                    if (se.Children == null || se.Children.Count == 0)
                    {
                        continue;
                    }

                    foreach (SecurityElement record in se.Children)
                    {
                        if (record.Children == null || record.Children.Count == 0)
                        {
                            continue;
                        }

                        ResInfo resInfo = new ResInfo();
                        foreach (SecurityElement node in record.Children)
                        {
                            string resTag = node.Tag.ToLower();
                            switch (resTag)
                            {
                            case "resname": resInfo.resName = node.Text; break;

                            case "resmd5": resInfo.resMD5 = node.Text; break;

                            case "ressize": resInfo.resSize = int.Parse(node.Text); break;

                            case "resurl": resInfo.resURL = node.Text; break;

                            case "resrequire":
                            {
                                if (node.Text == "0")
                                {
                                    resInfo.isResRequire = false;
                                }
                                else if (node.Text == "1")
                                {
                                    resInfo.isResRequire = true;
                                }
                                else
                                {
                                    resInfo.isResRequire = bool.Parse(node.Text);
                                }
                            }
                            break;

                            case "resrequireid":
                                resInfo.resRequireID = int.Parse(node.Text);
                                break;
                            }
                        }

                        if (versionInfo.dictRes.ContainsKey(resInfo.resName) == false)
                        {
                            versionInfo.dictRes.Add(resInfo.resName, resInfo);
                        }
                        else
                        {
                            string strError = string.Format("VersionInfo.ParseData:更新资源包名{0}重复", resInfo.resName);
                            Debug.LogError(strError);
                        }
                    }
                }
                break;
                }
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogException(ex);
        }

        return(versionInfo);
    }
Beispiel #10
0
    public static void Execute()
    {
        if (!System.IO.Directory.Exists(ProtoDir))
        {
            System.IO.Directory.CreateDirectory(ProtoDir);
        }
        var protoCfgPath = GetProtoConfigPath();

        if (string.IsNullOrEmpty(protoCfgPath))
        {
            UnityEngine.Debug.LogError("未找到protocol配置文件");
            return;
        }

        sb = new StringBuilder();
        string text   = System.IO.File.ReadAllText(protoCfgPath);
        var    parser = new SecurityParser();

        parser.LoadXml(text);
        var xml = parser.ToXml();

        foreach (SecurityElement child in xml.Children)
        {
            switch (child.Tag)
            {
            case "custom_type":
                foreach (SecurityElement structNode in child.Children)
                {
                    var typeName = structNode.Attribute("name");
                    ParseStruct(structNode, typeName);
                    System.IO.File.WriteAllText(ProtoDir + typeName + ".lua", sb.ToString());
                    sb.Length = 0;
                }
                break;

            case "section":
                string strModuleID = child.Attribute("id");
                int    moduleID    = int.Parse(strModuleID);
                foreach (SecurityElement msgNode in child.Children)
                {
                    ParseMessage(msgNode, moduleID);
                }
                System.IO.File.WriteAllText
                    (ProtoDir + child.Attribute("name") + "_" + strModuleID + ".lua",
                    sb.ToString());
                sb.Length = 0;
                break;
            }
        }

        sb.Length = 0;
        var manifestName = "ProtoManifest.lua";

        foreach (var f in System.IO.Directory.GetFiles(ProtoDir, "*.lua"))
        {
            if (!f.EndsWith(manifestName))
            {
                var path   = f.Replace("\\", "/");
                int index0 = path.LastIndexOf("/");
                int index1 = path.LastIndexOf(".");
                sb.AppendFormat("require('Protos/{0}')\n", path.Substring(index0 + 1, index1 - index0 - 1));
            }
        }
        System.IO.File.WriteAllText(ProtoDir + manifestName, sb.ToString());
        sb = null;
        UnityEngine.Debug.Log("协议导出成功!");
    }
Beispiel #11
0
        protected string SimplifyXmlText(string xmlText)
        {
            m_parser.LoadXml(xmlText);
            SecurityElement el_0       = m_parser.ToXml();
            int             sheetIndex = 0;
            SecurityElement out_root   = new SecurityElement("table");

            foreach (SecurityElement el_1 in el_0.Children)
            {
                if (sheetIndex >= MAX_SHEET_CHECK_COUNT)
                {
                    break;
                }
                if (el_1.Tag != TAG_WORKSHEET)
                {
                    continue;
                }
                Console.WriteLine("├─" + el_1.Attributes[KEY_SHEET_NAME]);
                foreach (SecurityElement el_2 in el_1.Children)
                {
                    if (el_2.Tag != TAG_TABLE || el_2.Children == null || el_2.Children.Count <= 0)
                    {
                        continue;
                    }
                    int             rowIndex  = 0;
                    int             cellIndex = 0;
                    SecurityElement out_type  = new SecurityElement("type");
                    SecurityElement out_data  = new SecurityElement("data");
                    List <string>   idList    = new List <string>();

                    foreach (SecurityElement row in el_2.Children)
                    {
                        if (row.Tag != TAG_ROW || IsEmptyRow(row))
                        {
                            continue;
                        }
                        cellIndex = 0;
                        SecurityElement out_item = new SecurityElement("item");
                        foreach (SecurityElement cell in row.Children)
                        {
                            if (cell.Tag != TAG_CELL)
                            {
                                continue;
                            }

                            var idxStr = cell.Attribute("ss:Index");
                            if (!string.IsNullOrEmpty(idxStr))
                            {
                                var index = int.Parse(idxStr);
                                while (cellIndex < index - 1)
                                {
                                    out_item.AddAttribute(idList[cellIndex], "");
                                    ++cellIndex;
                                }
                            }
                            string data = GetCellData(cell);
                            if (rowIndex == ROW_INDEX_ID)
                            {
                                idList.Add(data);
                            }
                            else if (rowIndex == ROW_INDEX_TYPE)
                            {
                                out_item.AddAttribute(idList[cellIndex], data);
                            }
                            else if (rowIndex == ROW_INDEX_DESCRIPTION)
                            {
                            }
                            else if (rowIndex >= ROW_INDEX_DATA_BEGIN)
                            {
                                try
                                {
                                    out_item.AddAttribute(idList[cellIndex], data);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                }
                            }
                            cellIndex++;
                        }

                        if (rowIndex == ROW_INDEX_TYPE)
                        {
                            out_type.AddChild(out_item);
                        }
                        else if (rowIndex >= ROW_INDEX_DATA_BEGIN)
                        {
                            out_data.AddChild(out_item);
                        }
                        rowIndex++;
                    }
                    out_root.AddChild(out_type);
                    out_root.AddChild(out_data);
                }
                sheetIndex++;
            }
            out_root = MergeData(out_root);
            string result = FormatXml(out_root);

            return(result);
        }
Beispiel #12
0
    private void ParseCgConfigFile(string cgName, bool isVideo)
    {
        string configsDir = System.IO.Path.Combine(EntryPoint.Instance.ResPath, LuaScriptMgr.Instance.GetConfigsDir());

        var configPath = string.Empty;

        if (isVideo)
        {
            configPath = System.IO.Path.Combine(configsDir, "VideoConfig.xml");
        }
        else
        {
            configPath = System.IO.Path.Combine(configsDir, "CgConfig.xml");
        }

        var bytes = Util.ReadFile(configPath);

        if (bytes == null)
        {
            return;
        }

        try
        {
            string         text = Encoding.UTF8.GetString(bytes);
            SecurityParser sp   = Main.XMLParser;
            sp.LoadXml(text);
            SecurityElement root = sp.ToXml();
            foreach (SecurityElement se1 in root.Children)
            {
                if (se1.Tag != cgName)
                {
                    continue;
                }

                foreach (SecurityElement se2 in se1.Children)
                {
                    if (se2.Tag == "Dialogue")
                    {
                        foreach (SecurityElement se3 in se2.Children)
                        {
                            var dialogue = new Dialogue();
                            dialogue.Name    = se3.Attribute("name");
                            dialogue.Content = se3.Attribute("content");
                            var showStr = se3.Attribute("show");
                            dialogue.ShowTime = string.IsNullOrEmpty(showStr)? 0 : float.Parse(showStr);
                            var closeStr = se3.Attribute("close");
                            dialogue.HideTime = string.IsNullOrEmpty(closeStr) ? 0 : float.Parse(closeStr);

                            if (!_CgXmlConfig.Dialogues.ContainsKey(se3.Tag))
                            {
                                _CgXmlConfig.Dialogues.Add(se3.Tag, dialogue);
                            }
                        }
                    }
                    else if (se2.Tag == "Name")
                    {
                        foreach (SecurityElement se3 in se2.Children)
                        {
                            if (!_CgXmlConfig.Names.ContainsKey(se3.Tag))
                            {
                                _CgXmlConfig.Names.Add(se3.Tag, se3.Attribute("name"));
                            }
                        }
                    }
                    else if (se2.Tag == "CGMask")
                    {
                        _CgXmlConfig.IsMaskShown = bool.Parse(se2.Attribute("mask"));
                    }
                }
                break;
            }
            sp.Clear();
        }
        catch (Exception e)
        {
            Debug.LogError(HobaText.Format(e.Message));
        }
    }
Beispiel #13
0
    public void ConvertTaskSettingXml2Bin()
    {
        taskSettingStorage.Tasksettings.Clear();

        string targetPath = Application.dataPath + "/Config/Tasks";

        DirectoryInfo originDirInfo = new DirectoryInfo(targetPath);

        System.IO.FileInfo[] files = (originDirInfo.GetFiles("*.xml", SearchOption.AllDirectories));

        foreach (FileInfo file in files)
        {
            SecurityParser xmlDoc = new SecurityParser();
            StreamReader   reader = file.OpenText();

            xmlDoc.LoadXml(reader.ReadToEnd());
            reader.Close();
            SecurityElement rootProject = xmlDoc.ToXml().SearchForChildByTag("Quest");

            TaskSetting taskSetting = new TaskSetting();
            taskSetting.TaskId      = Convert.ToUInt32(rootProject.Attribute("Id"));
            taskSetting.QuestType   = Convert.ToUInt32(rootProject.Attribute("QuestType"));
            taskSetting.Difficulty  = Convert.ToUInt32(rootProject.Attribute("Difficulty"));
            taskSetting.IsRepeat    = Convert.ToUInt32(rootProject.Attribute("IsRepeat"));
            taskSetting.CanDisplay  = Convert.ToUInt32(rootProject.Attribute("CanDisplay"));
            taskSetting.IsValidity  = Convert.ToUInt32(rootProject.Attribute("IsValidity"));
            taskSetting.Description = (rootProject.Attribute("Description"));

            ArrayList nodeList = rootProject.Children;

            foreach (SecurityElement xe in nodeList)
            {
                if (xe.Tag == "Rewards")
                {
                    ArrayList rewardList = xe.Children;
                    foreach (SecurityElement xeReward in rewardList)
                    {
                        if (xeReward.Tag == "Reward")
                        {
                            Reward reward = new Reward();
                            reward.ItemID = Convert.ToUInt32(xeReward.Attribute("ItemId"));
                            reward.Value  = Convert.ToSingle(xeReward.Attribute("Value"));
                            taskSetting.Rewards.Add(reward);
                        }
                    }
                }
                else if (xe.Tag == "CommitRequirements")
                {
                    ArrayList rewardList = xe.Children;
                    foreach (SecurityElement xeReward in rewardList)
                    {
                        if (xeReward.Tag == "Requirement")
                        {
                            Requirement requirement = new Requirement();
                            requirement.Type  = Convert.ToUInt32(xeReward.Attribute("Type"));
                            requirement.Value = Convert.ToSingle(xeReward.Attribute("Value"));
                            taskSetting.CommitRequirements.Add(requirement);
                        }
                    }
                }
                else if (xe.Tag == "RecieveRequirements")
                {
                    ArrayList rewardList = xe.Children;
                    foreach (SecurityElement xeReward in rewardList)
                    {
                        if (xeReward.Tag == "Requirement")
                        {
                            Requirement requirement = new Requirement();
                            requirement.Type  = Convert.ToUInt32(xeReward.Attribute("Type"));
                            requirement.Value = Convert.ToSingle(xeReward.Attribute("Value"));
                            taskSetting.RecieveRequirements.Add(requirement);
                        }
                    }
                }
            }

            taskSettingStorage.Tasksettings.Add(taskSetting);
        }



        string accountPath = Application.dataPath + "/StreamingAssets/Tasks.bytes";

        try
        {
            FileStream fs = File.Open(accountPath, FileMode.Create, FileAccess.Write);

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryWriter bw = new BinaryWriter(fs);

                taskSettingStorage.WriteTo(ms);
                ms.Position = 0;
                bw.Write((int)ms.Length);
                bw.Write(ms.GetBuffer(), 0, (int)ms.Length);
                bw.Close();
            }

            fs.Close();
            fs.Dispose();
            Debug.Log("SaveAccountFile:" + accountPath + ", OK!");
        }
        catch (Exception e)
        {
            Debug.Log("SaveAccountFile:" + e.ToString() + accountPath);
        }
    }
Beispiel #14
0
        private static bool load_xml(byte[] pBuffer)
        {
            try
            {
                Debug.Check(pBuffer != null);
                string xml = System.Text.Encoding.UTF8.GetString(pBuffer);

                SecurityParser xmlDoc = new SecurityParser();
                xmlDoc.LoadXml(xml);

                SecurityElement rootNode = xmlDoc.ToXml();

                if (rootNode.Children == null || rootNode.Tag != "agents" && rootNode.Children.Count != 1)
                {
                    return(false);
                }

                string versionStr = rootNode.Attribute("version");
                Debug.Check(!string.IsNullOrEmpty(versionStr));

                string signatureStr = rootNode.Attribute("signature");
                checkSignature(signatureStr);

                foreach (SecurityElement bbNode in rootNode.Children)
                {
                    if (bbNode.Tag == "agent" && bbNode.Children != null)
                    {
                        string    agentType = bbNode.Attribute("type").Replace("::", ".");
                        uint      classId   = Utils.MakeVariableId(agentType);
                        AgentMeta meta      = AgentMeta.GetMeta(classId);

                        if (meta == null)
                        {
                            meta = new AgentMeta();
                            _agentMetas[classId] = meta;
                        }

                        string agentSignature = bbNode.Attribute("signature");
                        if (agentSignature == meta.Signature.ToString())
                        {
                            continue;
                        }

                        foreach (SecurityElement propertiesNode in bbNode.Children)
                        {
                            if (propertiesNode.Tag == "properties" && propertiesNode.Children != null)
                            {
                                foreach (SecurityElement propertyNode in propertiesNode.Children)
                                {
                                    if (propertyNode.Tag == "property")
                                    {
                                        string memberStr = propertyNode.Attribute("member");
                                        bool   bIsMember = (!string.IsNullOrEmpty(memberStr) && memberStr == "true");

                                        if (!bIsMember)
                                        {
                                            string propName  = propertyNode.Attribute("name");
                                            string propType  = propertyNode.Attribute("type").Replace("::", ".");
                                            string valueStr  = propertyNode.Attribute("defaultvalue");
                                            string isStatic  = propertyNode.Attribute("static");
                                            bool   bIsStatic = (!string.IsNullOrEmpty(isStatic) && isStatic == "true");

                                            registerCustomizedProperty(meta, propName, propType, valueStr, bIsStatic);
                                        }
                                    }
                                }
                            }
                        } //end of for propertiesNode
                    }
                }         //end of for bbNode

                return(true);
            }
            catch (Exception e)
            {
                Debug.Check(false, e.Message + e.StackTrace);
            }

            Debug.Check(false);
            return(false);
        }
Beispiel #15
0
        void ReadFile()
        {
            var sp = new SecurityParser();

            sp.LoadXml(File.ReadAllText(file));

            SecurityElement root = sp.ToXml();

            if (root.Tag == "KeyPair")
            {
                SecurityElement keyvalue = root.SearchForChildByTag("KeyValue");
                if (keyvalue.Children.Count == 0)
                {
                    return;
                }

                KeyValue = keyvalue.Children [0].ToString();

                SecurityElement properties = root.SearchForChildByTag("Properties");
                if (properties.Children.Count == 0)
                {
                    return;
                }

                SecurityElement property;
                string          containerName = null, attribute;
                int             providerType = -1;

                foreach (object o in properties.Children)
                {
                    property = o as SecurityElement;
                    if (property == null)
                    {
                        continue;
                    }

                    switch (property.Tag)
                    {
                    case "Provider":
                        attribute = property.Attribute("Type");
                        if (String.IsNullOrEmpty(attribute))
                        {
                            return;
                        }

                        if (!Int32.TryParse(attribute, out providerType))
                        {
                            return;
                        }
                        break;

                    case "Container":
                        attribute = property.Attribute("Name");
                        if (String.IsNullOrEmpty(attribute))
                        {
                            return;
                        }

                        containerName = attribute;
                        break;
                    }
                }

                if (String.IsNullOrEmpty(containerName) || providerType == -1)
                {
                    return;
                }

                ContainerName = containerName;
                ProviderType  = providerType;
                IsValid       = true;
            }
        }
Beispiel #16
0
    private IDictionary LoadTableWithSecurityParser(Type tableType, string content)
    {
        IDictionary    dict    = null;
        Hashtable      typeMap = null;
        SecurityParser parser  = new SecurityParser();

        parser.LoadXml(content);
        SecurityElement element = parser.ToXml();

        for (int i = 0; i < element.Children.Count; i++)
        {
            SecurityElement subElement = element.Children[i] as SecurityElement;
            if (subElement.Tag == TAG_TYPE)
            {
                #region type line
                SecurityElement item = subElement.Children[0] as SecurityElement;
                if (item.Tag == TAG_ITEM)
                {
                    typeMap = item.Attributes;
                    if (typeMap["id"].ToString() == "int")
                    {
                        dict = new Dictionary <int, object>();
                    }
                    else if (typeMap["id"].ToString() == "string")
                    {
                        dict = new Dictionary <string, object>();
                    }
                    else
                    {
                        Logger.LogError("wrong ID type : " + typeMap["id"]);
                    }
                }
                else
                {
                    Logger.LogError("The TAG " + item.Tag + " is not a valid Tag");
                }
                #endregion
            }
            else if (subElement.Tag == TAG_DATA)
            {
                for (int j = 0; subElement.Children != null && j < subElement.Children.Count; j++)
                {
                    SecurityElement item = subElement.Children[j] as SecurityElement;
                    if (item.Tag == TAG_ITEM)
                    {
                        Hashtable hashTable = item.Attributes;
                        Hashtable paramMap  = new Hashtable();
                        var       itr       = hashTable.GetEnumerator();
                        while (itr.MoveNext())
                        {
                            string key   = itr.Key.ToString();
                            string value = itr.Value.ToString();
                            string type  = typeMap[key].ToString();
                            paramMap.Add(key, ParseValue(type, value));
                        }
                        object obj = Activator.CreateInstance(tableType, paramMap);
                        object id  = ParseValue(typeMap["id"].ToString(), hashTable["id"].ToString());
                        if (dict.Contains(id))
                        {
                            Logger.LogError("Table has the repeat ID : " + tableType + " --> " + id);
                        }
                        else
                        {
                            dict.Add(id, obj);
                        }
                    }
                    else
                    {
                        Logger.LogError("The TAG " + item.Tag + " is not a valid Tag");
                    }
                }
            }
            else
            {
                Logger.LogError("The TAG " + subElement.Tag + " is not a valid Tag");
            }
        }
        return(dict);
    }
Beispiel #17
0
        public TableData GetTableData(string tabName, string xmlText)
        {
            LogLine(tabName);
            List <SheetData> sheets = new List <SheetData>();

            m_parser.LoadXml(xmlText);
            SecurityElement el_0 = m_parser.ToXml();

            foreach (SecurityElement el_1 in el_0.Children)
            {
                if (sheets.Count >= m_maxSheetCheckCount)
                {
                    break;
                }
                if (el_1.Tag != TAG_WORKSHEET)
                {
                    continue;
                }

                string sheetname = el_1.Attributes[KEY_SHEET_NAME].ToString();
                Log("├─" + sheetname);
                foreach (SecurityElement el_2 in el_1.Children)
                {
                    if (el_2.Tag != TAG_TABLE || el_2.Children == null || el_2.Children.Count <= 0)
                    {
                        continue;
                    }
                    List <RowData> rows = new List <RowData>();
                    foreach (SecurityElement rowEl in el_2.Children)
                    {
                        if (rowEl.Tag != TAG_ROW || rowEl.Children == null ||
                            rowEl.Children.Count <= 0 || IsEmptyRow(rowEl))
                        {
                            continue;
                        }
                        List <CellData> cells = new List <CellData>();
                        foreach (SecurityElement cellEl in rowEl.Children)
                        {
                            if (cellEl.Tag != TAG_CELL)
                            {
                                continue;
                            }
                            var idxStr = cellEl.Attribute(KEY_CELL_INDEX);
                            if (!string.IsNullOrEmpty(idxStr))
                            {
                                var index = int.Parse(idxStr);
                                while (cells.Count < index - 1)
                                {
                                    cells.Add(new CellData(rows.Count, cells.Count, ""));
                                }
                            }

                            cells.Add(new CellData(rows.Count, cells.Count, GetCellData(cellEl)));
                        }

                        // 补齐行尾
                        while (rows.Count > 0 && cells.Count < rows[0].cells.Count)
                        {
                            cells.Add(new CellData(rows.Count, cells.Count, ""));
                        }

                        RowData row = new RowData(cells);
                        rows.Add(row);
                    }

                    // Set Head
                    for (int i = 3; i < rows.Count; i++)
                    {
                        for (int j = 0; j < rows[i].cells.Count; j++)
                        {
                            var      cell  = rows[i].cells[j];
                            string[] heads = new string[3];
                            for (int k = 0; k < 3; k++)
                            {
                                if (j < rows[k].cells.Count)
                                {
                                    heads[k] = rows[k].cells[j].value;
                                }
                            }
                            // name, type, desc
                            cell.SetHead(heads[0], heads[1], heads[2]);
                        }
                    }

                    if (rows.Count > 0)
                    {
                        sheets.Add(new SheetData(sheetname, rows));
                    }
                    else
                    {
                        Log("(empty)");
                    }
                    LogLine();
                }
            }
            LogLine();
            return(new TableData(tabName, sheets));
        }