예제 #1
0
        private static List <T> LoadXMLText <T>(string text)
        {
            List <T> list = new List <T>();

            try
            {
                if (String.IsNullOrEmpty(text))
                {
                    return(list);
                }
                Type type = typeof(T);
                var  xml  = XMLParser.LoadXML(text);
                Dictionary <Int32, Dictionary <String, String> > map = XMLParser.LoadIntMap(xml, text);
                var props = type.GetProperties(~System.Reflection.BindingFlags.Static);
                foreach (var item in map)
                {
                    var obj = type.GetConstructor(Type.EmptyTypes).Invoke(null);
                    foreach (var prop in props)
                    {
                        if (prop.Name == "id")
                        {
                            prop.SetValue(obj, item.Key, null);
                        }
                        else
                        {
                            try
                            {
                                if (item.Value.ContainsKey(prop.Name))
                                {
                                    var value = Utils.GetValue(item.Value[prop.Name], prop.PropertyType);
                                    prop.SetValue(obj, value, null);
                                }
                            }
                            catch (Exception ex)
                            {
                                //LoggerHelper.Debug("LoadXML error: " + item.Value[prop.Name] + " " + prop.PropertyType);
                                LoggerHelper.Except(ex);
                            }
                        }
                    }
                    list.Add((T)obj);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Except(ex);
                //LoggerHelper.Error("error text: \n" + text);
            }
            return(list);
        }
예제 #2
0
        private static Dictionary <string, string> LoadCfgInfoList(string text)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            SecurityElement             element    = XMLParser.LoadXML(text);

            if (((element != null) && (element.Children != null)) && (element.Children.Count != 0))
            {
                foreach (SecurityElement element2 in element.Children)
                {
                    dictionary[element2.Tag] = element2.Text;
                }
            }
            return(dictionary);
        }
예제 #3
0
        private static Dictionary <string, string> LoadCfgInfoList(string text)
        {
            Dictionary <string, string> result = new Dictionary <string, string>();
            var children = XMLParser.LoadXML(text);

            if (children != null && children.Children != null && children.Children.Count != 0)
            {
                foreach (System.Security.SecurityElement item in children.Children)
                {
                    result[item.Tag] = item.Text;
                }
            }
            return(result);
        }
예제 #4
0
        public static void LoadMetaOfResource(string path, Action cb = null)
        {
            //meta现已全部拷到sd卡
            //if (!File.Exists(Path.Combine(SystemConfig.ResourceFolder, path)))
            //{
            //    Driver.Instance.StartCoroutine(Driver.Instance.LoadWWWText(Utils.GetStreamPath(path),
            //        (xmlText) =>
            //        {
            //            var xml = XMLParser.LoadXML(xmlText);
            //            if (xml == null)
            //            {
            //                if (cb != null)
            //                {
            //                    cb();
            //                }
            //                return;
            //            }
            //            foreach (SecurityElement item in xml.Children)
            //            {
            //                var meta = new ResourceMetaData();
            //                meta.RelativePath = item.Attribute("path");
            //                meta.MD5 = item.Attribute("md5");

            //                var dependencies = item.Children;
            //                if (dependencies != null && dependencies.Count > 0)
            //                {
            //                    meta.Dependencies = new List<string>();

            //                    foreach (SecurityElement dependency in dependencies)
            //                    {
            //                        meta.Dependencies.Add(dependency.Attribute("path"));
            //                    }
            //                }
            //                metaOfResource[meta.RelativePath] = meta;
            //            }
            //            if (cb != null)
            //            {
            //                cb();
            //            }
            //        }));
            //}
            //else
            //{
            var xml = XMLParser.LoadXML(FileAccessManager.LoadText(path));

            if (xml == null)
            {
                if (cb != null)
                {
                    cb();
                }
                return;
            }
            for (int i = 0; i < xml.Children.Count; i++)
            {
                SecurityElement item = xml.Children[i] as SecurityElement;
                var             meta = new ResourceMetaData();
                meta.RelativePath = item.Attribute("path");
                meta.MD5          = item.Attribute("md5");

                var dependencies = item.Children;
                if (dependencies != null && dependencies.Count > 0)
                {
                    meta.Dependencies = new List <string>();

                    foreach (SecurityElement dependency in dependencies)
                    {
                        meta.Dependencies.Add(dependency.Attribute("path"));
                    }
                }
                metaOfResource[meta.RelativePath] = meta;
            }
            if (cb != null)
            {
                cb();
            }
            //}
        }
예제 #5
0
        public static void LoadMetaOfMeta(Action cb, Action <int, int> process)
        {
            metaOfMeta = new Dictionary <string, string>();
            //meta现已全部拷到sd卡
            //if (!File.Exists(Path.Combine(SystemConfig.ResourceFolder, ResourceManager.MetaFileName)))
            //{
            //    Driver.Instance.StartCoroutine(Driver.Instance.LoadWWWText(Utils.GetStreamPath(ResourceManager.MetaFileName),
            //        (xmlText) =>
            //        {
            //            var xml = XMLParser.LoadXML(xmlText);
            //            if (xml == null)
            //            {
            //                if (cb != null)
            //                {
            //                    cb();
            //                }
            //                return;
            //            }
            //            foreach (SecurityElement item in xml.Children)
            //            {
            //                metaOfMeta[item.Attribute("path")] = item.Attribute("md5");
            //            }

            //            RecursiveLoadMetaOfResource(metaOfMeta.Keys.ToList(), 0, metaOfMeta.Keys.Count, () =>
            //            {
            //                AssetCacheMgr.AssetMgr.SetPathMap();
            //                if (cb != null)
            //                {
            //                    cb();
            //                }
            //            }, process);
            //        }));
            //}
            //else
            //{

            Action action = () =>
            {
                var xml = XMLParser.LoadXML(FileAccessManager.LoadText(ResourceManager.MetaFileName));
                if (xml == null)
                {
                    if (cb != null)
                    {
                                                #if UNITY_ANDROID
                        Driver.Invoke(cb);
                                                #elif UNITY_IPHONE
                        Driver.Invoke(cb);
                                                #else
                        Driver.Invoke(cb);
                                                #endif
                    }
                    return;
                }
                for (int i = 0; i < xml.Children.Count; i++)
                {
                    SecurityElement item = xml.Children[i] as SecurityElement;
                    metaOfMeta[item.Attribute("path")] = item.Attribute("md5");
                }
                RecursiveLoadMetaOfResource(metaOfMeta.Keys.ToList(), 0, metaOfMeta.Keys.Count, () =>
                {
                    AssetCacheMgr.AssetMgr.SetPathMap();
                    if (cb != null)
                    {
                                                #if UNITY_ANDROID
                        Driver.Invoke(cb);
                                                #elif UNITY_IPHONE
                        Driver.Invoke(cb);
                                                #else
                        Driver.Invoke(cb);
                                                #endif
                    }
                }, process);
            };

            action.BeginInvoke(null, null);
            //}
        }
예제 #6
0
        private static List <T> LoadXMLText <T>(string text)
        {
            Exception exception;
            List <T>  list = new List <T>();

            try
            {
                if (string.IsNullOrEmpty(text))
                {
                    return(list);
                }
                Type type = typeof(T);
                Dictionary <int, Dictionary <string, string> > dictionary = XMLParser.LoadIntMap(XMLParser.LoadXML(text), text);
                PropertyInfo[] properties = type.GetProperties(~BindingFlags.Static);
                foreach (KeyValuePair <int, Dictionary <string, string> > pair in dictionary)
                {
                    object obj2 = type.GetConstructor(Type.EmptyTypes).Invoke(null);
                    foreach (PropertyInfo info in properties)
                    {
                        if (info.Name == "id")
                        {
                            info.SetValue(obj2, pair.Key, null);
                        }
                        else
                        {
                            try
                            {
                                if (pair.Value.ContainsKey(info.Name))
                                {
                                    object obj3 = Utils.GetValue(pair.Value[info.Name], info.PropertyType);
                                    info.SetValue(obj2, obj3, null);
                                }
                            }
                            catch (Exception exception1)
                            {
                                exception = exception1;
                                LoggerHelper.Debug(string.Concat(new object[] { "LoadXML error: ", pair.Value[info.Name], " ", info.PropertyType }), true, 0);
                                LoggerHelper.Except(exception, null);
                            }
                        }
                    }
                    list.Add((T)obj2);
                }
            }
            catch (Exception exception2)
            {
                exception = exception2;
                LoggerHelper.Except(exception, null);
                LoggerHelper.Error("error text: \n" + text, true);
            }
            return(list);
        }