Esempio n. 1
0
        public void RemoveTable(ITable table)
        {
            string     path   = ITableManager.Instance.GetFilePath(table);
            SmartTable target = FindSmartTable(ITableManager.Instance.GetTableAttribute(table).Path);

            target.Files.Remove(target.GetTablePair(path));
        }
Esempio n. 2
0
        private void Read()
        {
            BinaryReader reader = new BinaryReader(new FileStream(Path, FileMode.Open));

            string header = reader.ReadString();

            if (header != HEADER)
            {
                throw new Exception(System.IO.Path.GetFileName(Path) + " is not a valid SmartFile.");
            }

            Tables = new Dictionary <string, SmartTable>();
            int count = reader.ReadInt32();


            for (int i = 0; i < count; i++)
            {
                SmartTable sTable = new SmartTable();

                string path = reader.ReadString();
                sTable.Files = new List <TablePair>();
                int tableFilesCount = reader.ReadInt32();


                for (int w = 0; w < tableFilesCount; w++)
                {
                    sTable.Files.Add(new TablePair(reader.ReadString(), reader.ReadString()));
                }

                Tables.Add(path, sTable);
            }

            reader.Dispose();
        }
Esempio n. 3
0
        public void AddTable(ITable table)
        {
            string     path    = ITableManager.Instance.GetFilePath(table);
            string     json    = JsonConvert.SerializeObject(table);
            string     dirName = ITableManager.Instance.GetTableAttribute(table).Path;
            SmartTable target  = FindSmartTable(dirName);

            target.Files.Add(new TablePair(path, json));
        }
Esempio n. 4
0
 private SmartTable FindSmartTable(string path)
 {
     if (Tables.ContainsKey(path))
     {
         return(Tables[path]);
     }
     else
     {
         SmartTable newTable = new SmartTable();
         newTable.Files = new List <TablePair>();
         Tables.Add(path, newTable);
         return(newTable);
     }
 }
Esempio n. 5
0
        public ITable[] ConvertToRecord(string path, Type type)
        {
            List <ITable> records = new List <ITable>();

            if (Tables.ContainsKey(path) == false)
            {
                throw new Exception("Table is missing: " + path);
            }
            SmartTable table = Tables[path];

            foreach (var file in table.Files)
            {
                records.Add((ITable)JsonConvert.DeserializeObject(file.Value, type));
            }

            return(records.ToArray());
        }