예제 #1
0
        public virtual MediaContent Add(Repository repository, MediaFolder mediaFolder, string fileName, Stream fileStream, bool @overrided,
            string userId, MediaContentMetadata metadata)
        {
            fileName = UrlUtility.ToUrlString(Path.GetFileNameWithoutExtension(fileName)) + Path.GetExtension(fileName);
            IsAllowExtension(fileName, mediaFolder.AllowedExtensions);

            var mediaContent = new MediaContent(repository.Name, mediaFolder.FullName);

            mediaContent.UserId = userId;
            mediaContent.Published = true;

            mediaContent.FileName = fileName;

            mediaContent.UserKey = fileName;
            mediaContent.UUID = fileName;

            mediaContent.ContentFile = new ContentFile()
            {
                Name = fileName,
                FileName = fileName,
                Stream = fileStream
            };

            mediaContent.LastModificationDate = mediaContent.CreationDate = DateTime.UtcNow;
            mediaContent.Metadata = metadata;
            Provider.Add(mediaContent, @overrided);

            return mediaContent;
        }
예제 #2
0
 public virtual void Add(Repository repository)
 {
     if (string.IsNullOrEmpty(repository.Name))
     {
         throw new NameIsReqiredException();
     }
     if (Provider.Get(repository) != null)
     {
         throw new ItemAlreadyExistsException();
     }
     Provider.Add(repository);
 }
예제 #3
0
 protected virtual SendingSetting AllowSending(TextContent content, Repository repository, ContentEventContext eventContext)
 {
     if (!repository.EnableBroadcasting)
     {
         return null;
     }
     var list = Providers.DefaultProviderFactory.GetProvider<ISendingSettingProvider>().All(repository).Select(o => Providers.DefaultProviderFactory.GetProvider<ISendingSettingProvider>().Get(o));
     foreach (var item in list)
     {
         if (AllowSendingSetting(content, item, eventContext))
         {
             return item;
         }
     }
     return null;
 }
예제 #4
0
        public override IContentQuery<Bsc.Dmtds.Content.Models.TextContent> GetContentQuery(DataRuleContext dataRuleContext)
        {
            var site = dataRuleContext.Site;
            var repositoryName = site.Repository;
            if (string.IsNullOrEmpty(repositoryName))
            {
                throw new BscException("The repository for site is null.");
            }
            var repository = new Repository(repositoryName);
            var schema = new Schema(repository, SchemaName);
            var contentQuery = (IContentQuery<Bsc.Dmtds.Content.Models.TextContent>)schema.CreateQuery();

            contentQuery.Where(WhereClauses.Parse(schema, dataRuleContext.ValueProvider));

            return contentQuery;
        }
예제 #5
0
파일: Folder.cs 프로젝트: eyouyou/Bsc
        /// <summary>
        /// Initializes a new instance of the <see cref="Folder"/> class.
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="namePath">The name path.</param>
        public Folder(Repository repository, IEnumerable<string> namePath)
        {
            if (namePath == null || namePath.Count() < 1)
            {
                throw new ArgumentException("The folder name path is invalid.", "namePath");
            }
            if (repository != null)
            {
                this.Repository = new Repository(repository.Name);
            }

            this.Name = namePath.Last();
            if (namePath.Count() > 0)
            {
                foreach (var name in namePath.Take(namePath.Count() - 1))
                {
                    this.Parent = (Folder)Activator.CreateInstance(this.GetType(), repository, name, this.Parent);
                }
            }
        }
예제 #6
0
 public virtual Repository Create(string repositoryName, string templateName)
 {
     if (string.IsNullOrEmpty(templateName))
     {
         var repository = new Repository(repositoryName);
         Add(repository);
         return repository;
     }
     else
     {
         var template = ServiceFactory.RepositoryTemplateManager.GetItemTemplate(templateName);
         if (template == null)
         {
             throw new BscException("该模板文件不存在.");
         }
         using (FileStream fs = new FileStream(template.TemplateFile, FileMode.Open, FileAccess.Read, FileShare.Read))
         {
             return Create(repositoryName, fs);
         }
     }
 }
예제 #7
0
        /// <summary>
        /// Updates the specified field values
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="uuid">The UUID.</param>
        /// <param name="fieldValues">The field values.</param>
        /// <param name="userName">Name of the user.</param>
        public virtual void UpdateSpecifiedFields(Repository repository, Schema schema, string uuid, NameValueCollection fieldValues, string userName = "", bool enableVersion = true)
        {
            var content = schema.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault();
            if (content != null)
            {

                foreach (var name in fieldValues.AllKeys)
                {
                    content[name] = Binder.ConvertToColumnType(schema, name, fieldValues[name]);
                }

                if (!string.IsNullOrEmpty(userName))
                {
                    content.UserId = userName;
                }
                content.___EnableVersion___ = enableVersion;
                content.LastModificationDate = DateTime.UtcNow;

                EventBus.Content.ContentEvent.Fire(ContentAction.PreUpdate, content);

                TextContentProvider.Update(content, content);

                EventBus.Content.ContentEvent.Fire(ContentAction.Update, content);

            }
        }
예제 #8
0
        public virtual void Update(Repository repository, Schema schema, string uuid, IEnumerable<string> fieldNames, IEnumerable<object> fieldValues, string userName = "", bool enableVersion = true)
        {
            var content = schema.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault();
            if (content != null)
            {
                var names = fieldNames.ToArray();
                var values = fieldValues.ToArray();
                for (int i = 0; i < names.Length; i++)
                {
                    content[names[i]] = values[i];
                }

                if (!string.IsNullOrEmpty(userName))
                {
                    content.UserId = userName;
                }
                content.___EnableVersion___ = true;
                content.LastModificationDate = DateTime.UtcNow;

                EventBus.Content.ContentEvent.Fire(ContentAction.PreUpdate, content);

                TextContentProvider.Update(content, content);

                EventBus.Content.ContentEvent.Fire(ContentAction.Update, content);

            }
        }
예제 #9
0
        public virtual ContentBase Update(Repository repository, TextFolder folder, string uuid, NameValueCollection values, HttpFileCollectionBase files,
         DateTime modificationDate, IEnumerable<TextContent> addedCateogries, IEnumerable<TextContent> removedCategories, string userid = "", bool enableVersion = true)
        {
            var textFolder = (TextFolder)folder.AsActual();
            var schema = new Schema(repository, textFolder.SchemaName);
            var textContent = textFolder.CreateQuery().WhereEquals("UUID", uuid).First();
            var old = new TextContent(textContent);

            textContent = Binder.Update(schema, textContent, values);
            textContent.Repository = repository.Name;
            textContent.UserId = userid;
            textContent.LastModificationDate = modificationDate;

            var parentFolder = values["ParentFolder"];
            if (!string.IsNullOrEmpty(parentFolder))
            {
                textContent.ParentFolder = parentFolder;
            }
            var parentUUID = values["ParentUUID"];
            if (!string.IsNullOrEmpty(parentUUID))
            {
                textContent.ParentUUID = parentUUID;
            }

            if (files != null)
            {
                textContent.ContentFiles = GetPostFiles(files);
            }
            textContent.___EnableVersion___ = enableVersion;
            //SaveFiles(textContent, schema, files);
            EventBus.Content.ContentEvent.Fire(ContentAction.PreUpdate, textContent);

            TextContentProvider.Update(textContent, old);

            if (addedCateogries != null)
            {
                AddCategories(repository, textContent, addedCateogries.ToArray());
            }
            if (removedCategories != null)
            {
                RemoveCategories(repository, textContent, removedCategories.ToArray());
            }

            EventBus.Content.ContentEvent.Fire(ContentAction.Update, textContent);
            return textContent;
        }
예제 #10
0
        public virtual void Top(Repository repository, string folderName, string uuid)
        {
            var folder = new TextFolder(repository, folderName).AsActual();
            var content = folder.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault();
            if (content != null)
            {

            }
        }
예제 #11
0
 public virtual void RemoveCategories(Repository repository, TextContent textContent, params TextContent[] categories)
 {
     var relations = categories.Select(it => new Category()
     {
         ContentUUID = textContent.UUID,
         CategoryFolder = it.FolderName,
         CategoryUUID = it.UUID
     });
     TextContentProvider.DeleteCategories(textContent, relations.ToArray());
 }
예제 #12
0
        public virtual void Delete(Repository repository, Schema schema, string uuid)
        {
            var textContent = schema.CreateQuery().WhereEquals("UUID", uuid).First();

            EventBus.Content.ContentEvent.Fire(ContentAction.PreDelete, textContent);
            TextContentProvider.Delete(textContent);

            EventBus.Content.ContentEvent.Fire(ContentAction.Delete, textContent);
        }
예제 #13
0
파일: SearchHelper.cs 프로젝트: eyouyou/Bsc
 public static ISearchService OpenService(Repository repository)
 {
     return ServiceBuilder.OpenService(repository);
 }
예제 #14
0
 public ISearchService OpenService(Repository repository)
 {
     return new SearchService(repository);
 }
예제 #15
0
파일: MediaFolder.cs 프로젝트: eyouyou/Bsc
 public MediaFolder(Repository repository, IEnumerable<string> namePath)
     : base(repository, namePath)
 {
 }
예제 #16
0
 public virtual void ClearCategories(Repository repository, TextContent textContent)
 {
     TextContentProvider.ClearCategories(textContent);
 }
예제 #17
0
        public virtual void Delete(Repository repository, Folder folder, string uuid)
        {
            var textFolder = (TextFolder)folder;

            textFolder = textFolder.AsActual();
            var textContent = textFolder.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault();
            if (textContent != null)
            {
                EventBus.Content.ContentEvent.Fire(ContentAction.PreDelete, textContent);

                TextContentProvider.Delete(textContent);

                EventBus.Content.ContentEvent.Fire(ContentAction.Delete, textContent);
            }
        }
예제 #18
0
파일: DataRuleBase.cs 프로젝트: eyouyou/Bsc
 public abstract Schema GetSchema(Repository repository);
예제 #19
0
        public virtual IEnumerable<CategoryContents> QueryCategories(Repository repository, string folder, string uuid)
        {
            var textFolder = (TextFolder)(FolderHelper.Parse<TextFolder>(repository, folder).AsActual());
            if (textFolder != null)
            {
                if (textFolder.Categories != null && textFolder.Categories.Count() > 0)
                {
                    foreach (var c in textFolder.Categories)
                    {
                        var categoryFolder = new TextFolder(repository, FolderHelper.SplitFullName(c.FolderName));
                        List<TextContent> categoryContents = new List<TextContent>();

                        if (!string.IsNullOrEmpty(uuid))
                        {
                            categoryContents = categoryContents.Concat(textFolder.CreateQuery().WhereEquals("UUID", uuid).Categories(categoryFolder)).ToList();

                            #region query all children folders of category

                            var childrenCategoryFolders = ServiceFactory.TextFolderManager.AllChildFoldersWithSameSchema(categoryFolder);

                            foreach (var sub in childrenCategoryFolders)
                            {
                                categoryContents = categoryContents.Concat(textFolder.CreateQuery().WhereEquals("UUID", uuid).Categories(sub)).ToList();
                            }
                            #endregion

                        }

                        yield return new CategoryContents() { CategoryFolder = categoryFolder, Contents = categoryContents, SingleChoice = c.SingleChoice };
                    }
                }
            }
        }
예제 #20
0
파일: DataRuleBase.cs 프로젝트: eyouyou/Bsc
 public virtual bool IsValid(Repository repository)
 {
     var folder = FolderHelper.Parse<TextFolder>(repository, FolderName);
     return folder.AsActual() != null;
 }
예제 #21
0
        public virtual void RevertTo(Repository repository, string folder, string schemaName, string uuid, int version, string user)
        {
            var textContent = new TextFolder(repository, folder).CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault();
            if (textContent != null)
            {
                var versionInfo = Versioning.VersionManager.GetVersion(textContent, version);
                var @new = new TextContent(versionInfo.TextContent);
                @new.Repository = repository.Name;
                @new.UserId = user;
                @new.LastModificationDate = DateTime.Now;

                TextContentProvider.Update(@new, textContent);
                ClearCategories(repository, textContent);

                if (versionInfo.Categories != null)
                {
                    AddCategories(repository, textContent, versionInfo.Categories
                        .Where(it => it.Contents != null)
                        .SelectMany(it => it.Contents.Select(c => new TextContent(repository.Name, "", it.FolderName) { UUID = c.UUID }))
                            .ToArray());
                }

                if (string.IsNullOrEmpty(textContent.OriginalUUID))
                    EventBus.Content.ContentEvent.Fire(ContentAction.Update, @new);
            }
        }
예제 #22
0
 public override Schema GetSchema(Repository repository)
 {
     return FolderHelper.Parse<TextFolder>(repository, FolderName).GetSchema();
 }
예제 #23
0
 public virtual ContentBase Update(Repository repository, TextFolder folder, string uuid, NameValueCollection values, string userid = "")
 {
     return Update(repository, folder, uuid, values, null, DateTime.UtcNow, null, null, userid);
 }
예제 #24
0
 public override bool IsValid(Repository repository)
 {
     var valid = base.IsValid(repository);
     if (valid && !string.IsNullOrEmpty(CategoryFolderName))
     {
         var folder = FolderHelper.Parse<TextFolder>(repository, CategoryFolderName);
         return folder.AsActual() != null;
     }
     return valid;
 }
예제 #25
0
        public virtual TextContent Update(Repository repository, Schema schema, string uuid, NameValueCollection values,
            HttpFileCollectionBase files, string userid = "")
        {
            var textContent = schema.CreateQuery().WhereEquals("UUID", uuid).First();
            var old = new TextContent(textContent);

            textContent = Binder.Update(schema, textContent, values);
            textContent.LastModificationDate = DateTime.Now.ToUniversalTime();
            textContent.UserId = userid;
            if (files != null)
            {
                textContent.ContentFiles = GetPostFiles(files);
            }

            EventBus.Content.ContentEvent.Fire(ContentAction.PreUpdate, textContent);

            TextContentProvider.Update(textContent, old);

            EventBus.Content.ContentEvent.Fire(ContentAction.Update, textContent);

            return textContent;
        }
예제 #26
0
 public virtual ContentBase Add(Repository repository, TextFolder folder, NameValueCollection values, HttpFileCollectionBase files,
   IEnumerable<TextContent> categories, string userid = "")
 {
     return Add(repository, folder, null, null, values, files, categories, userid);
 }
예제 #27
0
 public virtual void Update(Repository repository, Schema schema, string uuid, string fieldName, object value, string userName = "", bool enableVersion = true)
 {
     Update(repository, schema, uuid, new[] { fieldName }, new[] { value }, userName, enableVersion);
 }
예제 #28
0
        public virtual ContentBase Add(Repository repository, TextFolder folder, string parentFolder, string parentUUID, NameValueCollection values
            , HttpFileCollectionBase files, IEnumerable<TextContent> categories, string userid = "")
        {
            var textFolder = (TextFolder)folder.AsActual();
            var schema = new Schema(repository, textFolder.SchemaName);
            var textContent = new TextContent(repository.Name, schema.Name, textFolder.FullName);

            textContent = Binder.Bind(schema, textContent, values);

            if (!string.IsNullOrEmpty(values["UUID"]))
            {
                textContent.UUID = values["UUID"];
            }
            textContent.ParentFolder = parentFolder;
            textContent.ParentUUID = parentUUID;
            textContent.UserId = userid;
            textContent.LastModificationDate = textContent.CreationDate = DateTime.Now;

            textContent.ContentFiles = GetPostFiles(files);

            EventBus.Content.ContentEvent.Fire(ContentAction.PreAdd, textContent);

            TextContentProvider.Add(textContent);

            if (categories != null)
            {
                AddCategories(repository, textContent, categories.ToArray());
            }

            EventBus.Content.ContentEvent.Fire(ContentAction.Add, textContent);

            return textContent;
        }
예제 #29
0
 public TranslatedMediaContentQuery(Repository repository, MediaFolder mediaFolder)
 {
     this.Repository = repository;
     this.MediaFolder = mediaFolder;
 }
예제 #30
0
        public virtual TextContent Add(Repository repository, Schema schema, string parentUUID, NameValueCollection values, HttpFileCollectionBase files,
           string userid = "")
        {
            var textContent = new TextContent(repository.Name, schema.Name, null);
            textContent.ParentUUID = parentUUID;

            textContent = Binder.Bind(schema, textContent, values);
            textContent.LastModificationDate = textContent.CreationDate = DateTime.Now.ToUniversalTime();
            textContent.UserId = userid;

            if (files != null)
            {
                textContent.ContentFiles = GetPostFiles(files);
            }
            EventBus.Content.ContentEvent.Fire(ContentAction.PreAdd, textContent);

            TextContentProvider.Add(textContent);

            EventBus.Content.ContentEvent.Fire(ContentAction.Add, textContent);

            return textContent;
        }