Exemplo n.º 1
0
        public IEnumerable <Category> QueryCategories(TextContent content)
        {
            List <Category> list = new List <Category>();
            MySqlConnection connection;

            using (var dataReader = MysqlHelper.ExecuteReader(content.GetRepository(),
                                                              dbCommands.QueryCategories(content), out connection))
            {
                try
                {
                    while (dataReader.Read())
                    {
                        Category category = new Category()
                        {
                            CategoryFolder = dataReader.GetString(dataReader.GetOrdinal("CategoryFolder")),
                            CategoryUUID   = dataReader.GetString(dataReader.GetOrdinal("CategoryUUID")),
                            ContentUUID    = dataReader.GetString(dataReader.GetOrdinal("UUID")),
                        };
                        list.Add(category);
                    }
                }
                finally
                {
                    dataReader.Close();
                    connection.Close();
                }
            }
            return(list);
        }
Exemplo n.º 2
0
        public void Add(Models.TextContent content)
        {
            try
            {
                content.StoreFiles();

                ((IPersistable)content).OnSaving();
                var command = dbCommands.Add(content);
                if (command != null)
                {
                    if (MySQLTransactionUnit.Current != null)
                    {
                        MySQLTransactionUnit.Current.RegisterCommand(command);
                        MySQLTransactionUnit.Current.RegisterPostAction(delegate() { ((IPersistable)content).OnSaved(); });
                    }
                    else
                    {
                        MysqlHelper.BatchExecuteNonQuery(content.GetRepository(), command);
                        ((IPersistable)content).OnSaved();
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 3
0
        //        private static void CreateMediaContentTable(Repository repository)
        //        {
        //            string ddl = string.Format(@"
        //IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = `{0}`)
        //    CREATE TABLE `{0}` (
        //	    Id int IDENTITY (100,1),
        //	    UUID nvarchar(36) NOT NULL PRIMARY KEY,
        //	    UserKey nvarchar(526),
        //	    UtcCreationDate datetime,
        //	    UtcLastModificationDate datetime,
        //	    Published bit,
        //	    OriginalUUID nvarchar(36),
        //	    FolderName nvarchar(256),
        //	    FileName nvarchar(256),
        //	    VirtualPath nvarchar(256),
        //        UserId nvarchar(256)
        //	    );", repository.GetMediaContentTableName());
        //            ExecuteDDL(repository, ddl);
        //        }

        protected static void ExecuteDDL(Repository repository, string ddl)
        {
            if (!string.IsNullOrEmpty(ddl))
            {
                MysqlHelper.BatchExecuteNonQuery(repository,
                                                 ddl.Split(';').Where(it => !string.IsNullOrEmpty(it)).Select(it => new MySqlCommand(it, null)).ToArray());
            }
        }
Exemplo n.º 4
0
        private static bool CheckTableExists(Schema schema)
        {
            string sql = string.Format(@"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{0}.{1}'", schema.Repository.Name, schema.GetTableName());

            MySqlCommand command = new MySqlCommand()
            {
                CommandText = sql
            };

            return((long)MysqlHelper.ExecuteScalar(schema.Repository, command) != 0);
        }
Exemplo n.º 5
0
        public void Delete(Models.TextContent content)
        {
            var command = dbCommands.Delete(content);

            if (MySQLTransactionUnit.Current != null)
            {
                MySQLTransactionUnit.Current.RegisterCommand(command);
                MySQLTransactionUnit.Current.RegisterPostAction(delegate() { ((IPersistable)content).OnSaved(); });
            }
            else
            {
                MysqlHelper.BatchExecuteNonQuery(content.GetRepository(), command);
            }
        }
Exemplo n.º 6
0
        public void Update(Models.TextContent @new, Models.TextContent old)
        {
            @new.StoreFiles();

            ((IPersistable)@new).OnSaving();
            var command = dbCommands.Update(@new);

            if (MySQLTransactionUnit.Current != null)
            {
                MySQLTransactionUnit.Current.RegisterCommand(command);
                MySQLTransactionUnit.Current.RegisterPostAction(delegate() { ((IPersistable)@new).OnSaved(); });
            }
            else
            {
                MysqlHelper.BatchExecuteNonQuery(@new.GetRepository(), command);
                ((IPersistable)@new).OnSaved();
            }
        }
Exemplo n.º 7
0
        public IEnumerable <IDictionary <string, object> > ExportSchemaData(Schema schema)
        {
            string             sql  = string.Format("SELECT * FROM `{0}` ", schema.GetTableName());
            List <TextContent> list = new List <TextContent>();
            MySqlConnection    connection;

            using (var reader = MysqlHelper.ExecuteReader(schema.Repository, new MySqlCommand()
            {
                CommandText = sql
            }, out connection))
            {
                while (reader.Read())
                {
                    list.Add(reader.ToContent <TextContent>(new TextContent()));
                }
                connection.Close();
            }
            return(list);
        }
Exemplo n.º 8
0
        public IEnumerable <Category> ExportCategoryData(Repository repository)
        {
            string          sql  = string.Format("SELECT UUID,CategoryFolder,CategoryUUID FROM `{0}` ", repository.GetCategoryTableName());
            List <Category> list = new List <Category>();
            MySqlConnection connection;

            using (var reader = MysqlHelper.ExecuteReader(repository, new MySqlCommand()
            {
                CommandText = sql
            }, out connection))
            {
                while (reader.Read())
                {
                    Category category = new Category();
                    category.ContentUUID    = reader.GetString(0);
                    category.CategoryFolder = reader.GetString(1);
                    category.CategoryUUID   = reader.GetString(2);
                    list.Add(category);
                }
                connection.Close();
            }
            return(list);
        }
Exemplo n.º 9
0
        public void Commit()
        {
            var connectionString = repository.GetConnectionString();

            using (var conn = new MySqlConnection(connectionString))
            {
                conn.Open();

                using (var trans = conn.BeginTransaction())
                {
                    foreach (var command in commands)
                    {
                        MysqlHelper.LogCommand(repository, command);
                        try
                        {
                            MysqlHelper.ResetParameterNullValue(command);
                            command.Transaction = trans;
                            command.Connection  = conn;
                            command.ExecuteNonQuery();
                        }
                        catch (Exception e)
                        {
                            throw new KoobooException(e.Message + "SQL:" + command.CommandText, e);
                        }
                    }

                    trans.Commit();
                }
            }
            //Execute post content events
            foreach (var action in postActions)
            {
                action();
            }
            Clear();
        }
Exemplo n.º 10
0
        public override bool TestDbConnection()
        {
            var shareConnectionString = MysqlSettings.Instance.ConnectionString;

            return(MysqlHelper.TestConnection(shareConnectionString));
        }
Exemplo n.º 11
0
 public void ImportCategoryData(Repository repository, IEnumerable <Category> data)
 {
     MysqlHelper.ExecuteNonQuery(repository,
                                 data.Select(it => dbCommands.AddCategory(repository, it)).ToArray());
 }
Exemplo n.º 12
0
 public void ImportSchemaData(Schema schema, IEnumerable <IDictionary <string, object> > data)
 {
     MysqlHelper.ExecuteNonQuery(schema.Repository,
                                 data.Select(it => dbCommands.Add(GetContent(schema, it))).Where(it => it != null).ToArray());
 }
Exemplo n.º 13
0
 public void ClearCategories(TextContent content)
 {
     MysqlHelper.BatchExecuteNonQuery(content.GetRepository(),
                                      dbCommands.ClearCategories(content));
 }
Exemplo n.º 14
0
 public void DeleteCategories(Models.TextContent content, params Models.Category[] categories)
 {
     MysqlHelper.BatchExecuteNonQuery(content.GetRepository(),
                                      categories.Select(it => dbCommands.DeleteCategory(content.GetRepository(), it)).ToArray());
 }