Example #1
0
        public void InsertContent(string command, string dbName)
        {
            var tableName = DbApiHelper.GetName(command);

            DbApiHelper.OpenDbForAction(_сontentFolder, dbName, database =>
            {
                return(DbApiHelper.OpenTableForAction(database, tableName, table =>
                {
                    var metaInfoNodes =
                        table.Descendants(_columnInfoTagName)
                        .First()
                        .Elements()
                        .Select(x => new { x.Name, x.Value }).ToArray();

                    var insertingLines = DbApiHelper.GetValues(command);
                    foreach (var line in insertingLines)
                    {
                        var newRecord = new XElement(AnyRecordName,
                                                     line.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries)
                                                     .Select((value, i) => new XAttribute(metaInfoNodes[i].Name, value)));

                        table.Descendants(_columnContentTagName).First().Add(newRecord);
                    }

                    return null;
                }));
            });
        }
Example #2
0
        public void CreateTable(string command, string dbName)
        {
            var tableName = DbApiHelper.GetName(command);
            var xmlFile   = new XDocument(
                new XDeclaration("1.0", "Unicode", "yes"),
                new XComment(string.Format("{0}.{1}", dbName, tableName)));

            var columns      = DbApiHelper.ParseColumnInfo(command);
            var metaInfoNode = new XElement(_columnInfoTagName);

            metaInfoNode.AddFirst(columns.Select(c => new XElement(c.Name, c.Type)));
            var columnContentNode = new XElement(_columnContentTagName);

            var rootNode = new XElement(tableName, metaInfoNode, columnContentNode);

            xmlFile.AddFirst(rootNode);

            DbApiHelper.OpenDbForAction(_сontentFolder, dbName, database =>
            {
                using (var xmlStream = database.CreateEntry(tableName).Open())
                {
                    xmlFile.Save(xmlStream);
                    return(null);
                }
            });
        }
Example #3
0
 public void CreateDataBase(string command)
 {
     using (ZipFile.Open(Path.Combine(_сontentFolder, DbApiHelper.GetName(command)),
                         ZipArchiveMode.Create))
     {
     }
 }
Example #4
0
        public void DropTable(string command, string dbName)
        {
            var tableName = DbApiHelper.GetName(command);

            DbApiHelper.OpenDbForAction(_сontentFolder, dbName, database =>
            {
                database.GetEntry(tableName).Delete();
                return(null);
            });
        }
Example #5
0
 public void DropDatabase(string command)
 {
     File.Delete(Path.Combine(ContentFolderKey, DbApiHelper.GetName(command)));
 }
Example #6
0
 public string UseDb(string command)
 {
     return(DbApiHelper.GetName(command));
 }