Beispiel #1
0
 public void Delete(Models.MediaContent content)
 {
     string sql = string.Format("DELETE FROM {0} WHERE UUID=@UUID", content.GetRepository().GetMediaContentTableName());
     SqlCeCommand command = new SqlCeCommand();
     command.CommandText = sql;
     command.Parameters.Add(new SqlCeParameter("UUID", content.UUID));
     SQLCeHelper.ExecuteNonQuery(content.GetRepository().GetConnectionString(), command);
 }
Beispiel #2
0
        public void ClearCategories(Models.TextContent content)
        {
            var bucket = content.GetRepository().GetClient();

            var view = bucket.GetView(content.GetRepository().GetDefaultViewDesign(), "CategorisData_By_ContentUUID").Stale(StaleMode.False).Reduce(false);
            var ret = view.Where(it => it.Info["value"].ToString().Equals(content.UUID)).Select(it => it.ItemId);
            ret.ForEach((key, index) =>
            {
                bucket.Remove(key);
            });
        }
Beispiel #3
0
 public void Update(Models.MediaContent @new, Models.MediaContent old)
 {
     ((IPersistable)@new).OnSaving();
     string sql = string.Format("UPDATE {0} SET FolderName = @FolderName,FileName = @FileName,VirtualPath=@VirtualPath) WHERE UUID=@UUID"
         , @new.GetRepository().GetMediaContentTableName());
     SqlCeCommand command = new SqlCeCommand();
     command.CommandText = sql;
     command.Parameters.Add(new SqlCeParameter("UUID", @new.UUID));
     command.Parameters.Add(new SqlCeParameter("FolderName", @new.FolderName));
     command.Parameters.Add(new SqlCeParameter("FileName", @new.FileName));
     command.Parameters.Add(new SqlCeParameter("VirtualPath", @new.VirtualPath));
     SQLCeHelper.ExecuteNonQuery(@new.GetRepository().GetConnectionString(), command);
     ((IPersistable)@new).OnSaved();
 }
Beispiel #4
0
 public void Add(Models.MediaContent content)
 {
     ((IPersistable)content).OnSaving();
     string sql = string.Format("INSERT INTO {0}(UUID,FolderName,FileName,VirtualPath,UserId) VALUES(@UUID,@FolderName,@FileName,@VirtualPath,@UserId)"
         , content.GetRepository().GetMediaContentTableName());
     SqlCeCommand command = new SqlCeCommand();
     command.CommandText = sql;
     command.Parameters.Add(new SqlCeParameter("UUID", content.UUID));
     command.Parameters.Add(new SqlCeParameter("FolderName", content.FolderName));
     command.Parameters.Add(new SqlCeParameter("FileName", content.FileName));
     command.Parameters.Add(new SqlCeParameter("VirtualPath", content.VirtualPath));
     command.Parameters.Add(new SqlCeParameter("UserId", content.UserId));
     SQLCeHelper.ExecuteNonQuery(content.GetRepository().GetConnectionString(), command);
     ((IPersistable)content).OnSaved();
 }
Beispiel #5
0
        public override string Generate(Models.ContentBase content)
        {
            string userKey = content.UserKey;
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = GetColumnValueForUserKey(content);
            }
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = content.UUID;
            }
            else
            {
                string sperator = content.GetRepository().AsActual().UserKeyHyphens;
                userKey = PinyinConverter.GetPinyin(userKey, sperator);
                if (userKey.Length > 256)
                {
                    userKey = userKey.Substring(0, 256);
                }
                var tmpUserKey = EscapeUserKey(content, userKey);

                int tries = 0;
                while (IfUserKeyExists(content, tmpUserKey))
                {
                    tries++;
                    tmpUserKey = userKey + sperator + tries.ToString();
                }
                userKey = tmpUserKey;
            }

            return userKey;
        }
Beispiel #6
0
 public void ClearCategories(Models.TextContent content)
 {
     //((IPersistable)content).OnSaving();
     MongoCollection<BsonDocument> collection = content.GetRepository().GetCategoriesCollection();
     var query = new QueryDocument { { "ContentUUID", content.UUID } };
     collection.Remove(query);
     //((IPersistable)content).OnSaved();
 }
Beispiel #7
0
 public void Delete(Models.TextContent content)
 {
     var database = content.GetRepository().GetDatabase();
     MongoCollection<BsonDocument> collection = database.GetCollection(content.GetSchema().GetSchemaCollectionName());
     var query = new QueryDocument { { "UUID", content.UUID } };
     collection.Remove(query);
     TextContentFileHelper.DeleteFiles(content);
 }
Beispiel #8
0
        public void DeleteCategories(Models.TextContent content, params Models.Category[] categories)
        {
            var bucket = content.GetRepository().GetClient();

            categories.ForEach((it, index) =>
            {
                bucket.ExecuteRemove(it.GetDocumentKey(), PersistTo.One);
            });
        }
Beispiel #9
0
        public void AddCategories(Models.TextContent content, params Models.Category[] categories)
        {
            //((IPersistable)content).OnSaving();
            if (categories != null && categories.Length > 0)
            {
                MongoCollection<BsonDocument> collection = content.GetRepository().GetCategoriesCollection();
                collection.InsertBatch(categories.Select(it => it.ToBsonDocument()).ToArray());
            }

            //((IPersistable)content).OnSaved();
        }
Beispiel #10
0
 public void DeleteCategories(Models.TextContent content, params Models.Category[] categories)
 {
     //((IPersistable)content).OnSaving();
     if (categories != null && categories.Length > 0)
     {
         MongoCollection<BsonDocument> collection = content.GetRepository().GetCategoriesCollection();
         var query = MongoDBQuery.Query.Or(categories.Select(it => new QueryComplete(it.ToBsonDocument())).ToArray());
         collection.Remove(query);
     }
     //((IPersistable)content).OnSaved();
 }
Beispiel #11
0
        public void Add(Models.TextContent content)
        {
            content.Remove("_id");

            content.StoreFiles();

            ((IPersistable)content).OnSaving();
            var database = content.GetRepository().GetDatabase();
            MongoCollection<BsonDocument> collection = database.GetCollection(content.GetSchema().GetSchemaCollectionName());
            collection.Insert(content.ToBsonDocument());
            ((IPersistable)content).OnSaved();
        }
Beispiel #12
0
        public void AddCategories(Models.TextContent content, params Models.Category[] categories)
        {
            if (categories != null && categories.Length > 0)
            {
                var bucket = content.GetRepository().GetClient();

                categories.ForEach((it, index) =>
                {
                    bucket.ExecuteStore(StoreMode.Set, it.GetDocumentKey(), it.ToJson(), PersistTo.One);
                });
            }
        }
Beispiel #13
0
        public void Update(Models.TextContent @new, Models.TextContent old)
        {
            @new.StoreFiles();

            ((IPersistable)@new).OnSaving();
            var command = dbCommands.Update(@new);
            if (SQLCeTransactionUnit.Current != null)
            {
                SQLCeTransactionUnit.Current.RegisterCommand(command);
                SQLCeTransactionUnit.Current.RegisterPostAction(delegate() { ((IPersistable)@new).OnSaved(); });
            }
            else
            {
                SQLCeHelper.ExecuteNonQuery(@new.GetRepository().GetConnectionString(), command);
                ((IPersistable)@new).OnSaved();
            }
        }
Beispiel #14
0
 public void Delete(Models.TextContent content)
 {
     var command = dbCommands.Delete(content);
     if (SQLCeTransactionUnit.Current != null)
     {
         SQLCeTransactionUnit.Current.RegisterCommand(command);
         SQLCeTransactionUnit.Current.RegisterPostAction(delegate() { TextContentFileHelper.DeleteFiles(content); });
     }
     else
     {
         SQLCeHelper.ExecuteNonQuery(content.GetRepository().GetConnectionString(), command);
         TextContentFileHelper.DeleteFiles(content);
     }
 }
Beispiel #15
0
 public void DeleteCategories(Models.TextContent content, params Models.Category[] categories)
 {
     SQLCeHelper.ExecuteNonQuery(content.GetRepository().GetConnectionString(),
          categories.Select(it => dbCommands.DeleteCategory(content.GetRepository(), it)).ToArray());
 }
Beispiel #16
0
 public IEnumerable<Models.Category> QueryCategories(Models.TextContent content)
 {
     return content.GetRepository().QueryCategoriesBy(content.UUID).Select(it => it.ToCategory()).Where(it => it.ContentUUID.Equals(content.UUID));
 }
Beispiel #17
0
        public void Add(Models.TextContent content)
        {
            content.StoreFiles();

            ((IPersistable)content).OnSaving();
            var command = dbCommands.Add(content);
            if (command != null)
            {
                if (SQLCeTransactionUnit.Current != null)
                {
                    SQLCeTransactionUnit.Current.RegisterCommand(command);
                    SQLCeTransactionUnit.Current.RegisterPostAction(delegate() { ((IPersistable)content).OnSaved(); });
                }
                else
                {
                    SQLCeHelper.ExecuteNonQuery(content.GetRepository().GetConnectionString(), command);
                    ((IPersistable)content).OnSaved();
                }
            }
        }
Beispiel #18
0
        public void Update(Models.TextContent @new, Models.TextContent old)
        {
            @new.StoreFiles();

            ((IPersistable)@new).OnSaving();

            var folder = @new.GetFolder().GetActualFolder();
            var schema = @new.GetSchema().GetActualSchema();
            if (folder != null && folder.StoreInAPI)
            {
                var proxyBackend = new BackendProxy();

                //Add additional data
                //
                var additionalData = new Dictionary<string, object>
                {
                    {"ModifiedBy", AuthHelper.GetCurrentUserName()}
                };

                //Get payload
                //
                var payload = JsonConvert.SerializeObject(@new, new CustomJsonDictionaryConverter(schema.GetJsonSerializationIgnoreProperties(), additionalData));

                //Send data to API
                //
                proxyBackend.Execute("PUT", string.Format("{0}({1})", schema.Name, @new.Id), payload);
            }
            else
            {
                var command = dbCommands.Update(@new);
                if (SQLServerTransactionUnit.Current != null)
                {
                    SQLServerTransactionUnit.Current.RegisterCommand(command);
                    SQLServerTransactionUnit.Current.RegisterPostAction(delegate () { ((IPersistable)@new).OnSaved(); });
                }
                else
                {
                    SQLServerHelper.BatchExecuteNonQuery(@new.GetRepository(), command);
                    ((IPersistable)@new).OnSaved();
                }
            }
        }
Beispiel #19
0
        public void Add(Models.TextContent content)
        {
            try
            {
                content.StoreFiles();
                ((IPersistable)content).OnSaving();

                var folder = content.GetFolder().GetActualFolder();
                var schema = content.GetSchema().GetActualSchema();
                if (folder != null && folder.StoreInAPI)
                {
                    var proxy = new BackendProxy();

                    var additionalData = new Dictionary<string, object>()
                    {
                        {"CreatedBy", AuthHelper.GetCurrentUserName()},
                        {"ModifiedBy", AuthHelper.GetCurrentUserName()},
                        {"OwnerId", AuthHelper.GetCurrentUserName()}
                    };

                    //Get payload
                    //
                    var payload = JsonConvert.SerializeObject(content,
                        new CustomJsonDictionaryConverter(schema.GetJsonSerializationIgnoreProperties(), additionalData));

                    //Send data to API
                    //
                    proxy.Execute("POST", schema.Name, payload);
                }
                else
                {
                    var command = dbCommands.Add(content);
                    if (command != null)
                    {
                        if (SQLServerTransactionUnit.Current != null)
                        {
                            SQLServerTransactionUnit.Current.RegisterCommand(command);
                            SQLServerTransactionUnit.Current.RegisterPostAction(delegate () { ((IPersistable)content).OnSaved(); });
                        }
                        else
                        {
                            SQLServerHelper.BatchExecuteNonQuery(content.GetRepository(), command);
                            ((IPersistable)content).OnSaved();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #20
0
 public void DeleteCategories(Models.TextContent content, params Models.Category[] categories)
 {
     MysqlHelper.BatchExecuteNonQuery(content.GetRepository(),
          categories.Select(it => dbCommands.DeleteCategory(content.GetRepository(), it)).ToArray());
 }
Beispiel #21
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;
            }

        }
Beispiel #22
0
        public void Delete(Models.TextContent content)
        {
            var bucket = content.GetRepository().GetClient();

            bucket.ExecuteRemove(content.UUID, PersistTo.One);
            TextContentFileHelper.DeleteFiles(content);
        }
Beispiel #23
0
        public void Update(Models.TextContent @new, Models.TextContent old)
        {
            //if (@new["_id"] == null && old["_id"] != null)
            //{
            //    @new["_id"] = old["_id"];
            //}

            @new.StoreFiles();
            ((IPersistable)@new).OnSaving();
            var bucket = old.GetRepository().GetClient();

            bucket.ExecuteStore(StoreMode.Replace, old.UUID, @new.ToJson(), PersistTo.One);
            ((IPersistable)@new).OnSaved();
        }
Beispiel #24
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);
     }
 }
Beispiel #25
0
        public void Update(Models.TextContent @new, Models.TextContent old)
        {
            if (@new["_id"] == null && old["_id"] != null)
            {
                @new["_id"] = old["_id"];
            }

            @new.StoreFiles();
            ((IPersistable)@new).OnSaving();
            var database = old.GetRepository().GetDatabase();
            MongoCollection<BsonDocument> collection = database.GetCollection(old.GetSchema().GetSchemaCollectionName());
            var query = new QueryDocument { { "UUID", old.UUID } };
            collection.Update(query, @new.ToUpdateDocument());
            ((IPersistable)@new).OnSaved();
        }
Beispiel #26
0
        public void Add(Models.TextContent content)
        {
            content.StoreFiles();

            ((IPersistable)content).OnSaving();
            var bucket = content.GetRepository().GetClient();

            //bucket.Store(StoreMode.Set, "Schema." + content.UUID, content.ToJson());
            bucket.ExecuteStore(StoreMode.Set, content.UUID, content.ToJson(), PersistTo.One);
            ((IPersistable)content).OnSaved();
        }