Example #1
0
        private static void init()
        {
            if (mapDB2 == null)
            {
                var m_definitions = DBFilesClient.Load(@"E:\Développement\TheNoobBot\TheNoobBot\docs\updatebase_directory\Data\DBFilesClient\dblayout.xml");
                var definitions   = m_definitions.Tables.Where(t => t.Name == "Map");

                if (!definitions.Any())
                {
                    definitions = m_definitions.Tables.Where(t => t.Name == Path.GetFileName("Map"));
                }
                if (definitions.Count() == 1)
                {
                    var table = definitions.First();
                    mapDB2 = DBReaderFactory.GetReader(@"E:\Développement\TheNoobBot\TheNoobBot\docs\updatebase_directory\Data\DBFilesClient\Map.db2", table) as DB6Reader;
                    if (_cachedMapRows == null || _cachedRecords == null)
                    {
                        if (mapDB2 != null)
                        {
                            _cachedMapRows = mapDB2.Rows.ToArray();
                            _cachedRecords = new MapDbcRecord[_cachedMapRows.Length];
                            for (int i = 0; i < _cachedMapRows.Length - 1; i++)
                            {
                                _cachedRecords[i] = DB6Reader.ByteToType <MapDbcRecord>(_cachedMapRows[i]);
                            }
                        }
                    }
                    //Logging.Write(mapDB2.FileName + " loaded with " + mapDB2.RecordsCount + " entries.");
                }
                else
                {
                    //Logging.Write("DB2 Map not read-able.");
                }
            }
        }
Example #2
0
        public static DBFilesClient Load(string path)
        {
            XmlSerializer deser = new XmlSerializer(typeof(DBFilesClient));

            using (var fs = new FileStream(path, FileMode.Open))
            {
                DBFilesClient cat = (DBFilesClient)deser.Deserialize(fs);
                cat.File = path;
                return(cat);
            }
        }
Example #3
0
        public static void Save(DBFilesClient db)
        {
            string dir = Path.GetDirectoryName(db.File);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            XmlSerializer           ser        = new XmlSerializer(typeof(DBFilesClient));
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            namespaces.Add(string.Empty, string.Empty);
            using (var fs = new FileStream(db.File, FileMode.Create))
                ser.Serialize(fs, db, namespaces);
        }