Exemplo n.º 1
0
        public object Clone()
        {
            var item = new sWalls();

            item.Description = Description;
            item.Name        = Name;
            item.types       = types.ToList();
            return(item);
        }
Exemplo n.º 2
0
        public static bool InitData()
        {
            var docFileName = Path.Combine(Application.StartupPath, @"data\TypeWalls.xml");

            data.Clear();

            var xmldoc = new XmlDocument();
            var fs     = new FileStream(docFileName, FileMode.Open, FileAccess.Read);

            xmldoc.Load(fs);
            fs.Close();


            var xmlnode = xmldoc.GetElementsByTagName("WallsType");

            if (xmlnode.Count == 0)
            {
                return(false);
            }

            foreach (XmlNode item in xmlnode[0].ChildNodes)
            {
                sWalls tp = new sWalls();

                tp.Name        = XmlHelper.GetInnerValueXml(item, "Name");
                tp.Description = XmlHelper.GetInnerValueXml(item, "Description");


                var listWallsTypes = item["Types"];
                if (listWallsTypes == null)
                {
                    continue;
                }

                foreach (XmlNode wall in listWallsTypes)
                {
                    var wl = new sWallsTypes();

                    if (!XmlHelper.GetAttribute(wall, "Tp", out wl.Tp))
                    {
                        continue;
                    }

                    if (!XmlHelper.GetAttribute(wall, "Tu", out wl.Ti))
                    {
                        continue;
                    }

                    if (!XmlHelper.GetAttribute(wall, "Rw", out wl.Rw))
                    {
                        continue;
                    }

                    if (!XmlHelper.GetAttribute(wall, "EI", out wl.EI))
                    {
                        continue;
                    }

                    if (!XmlHelper.GetAttribute(wall, "N", out wl.N))
                    {
                        continue;
                    }

                    XmlHelper.GetAttribute(wall, "Img", out wl.ImageName);


                    var xmlnodeFiles = wall["Files"];
                    if (xmlnodeFiles != null)
                    {
                        foreach (XmlNode fl in xmlnodeFiles)
                        {
                            var    type  = sFile._type.FileName;
                            String value = fl.InnerText;
                            if (value == null || value.Length == 0)
                            {
                                type = sFile._type.FileDescription;
                                XmlHelper.GetAttribute(fl, "Text", out value);
                                if (value == null || value.Length == 0)
                                {
                                    value = "Ошибка извлечения имени файла или текста описания";
                                }
                            }
                            sFile file = new sFile(type, value);

                            wl._files.Add(file);
                        }
                    }
                    else
                    {
                        if (tp.types.Count > 0)
                        {
                            foreach (var itm in tp.types[0]._files)
                            {
                                wl._files.Add((sFile)itm.Clone());
                            }
                        }
                    }

                    if (wl.Rw >= maxRW)
                    {
                        maxRW = wl.Rw;
                    }

                    tp.types.Add(wl);
                }

                data.Add(tp);
            }


            foreach (var item in data)
            {
                item.DumpItem();
            }
            return(true);
        }