Beispiel #1
0
        public ContentModel GetContentModel(int itemId, ContentItemType itemType)
        {
            var repository = GetRepository(itemType);

            var item = repository.Set().Include(i => i.Content).FirstOrDefault(i => i.Id == itemId);

            if (item == null)
            {
                throw new Exception($"item {itemId} not found");
            }

            var content = item.Content;

            if (content == null)
            {
                throw new Exception($"no content for item {itemId}");
            }

            var model = GetBaseContentModel(content);

            model.ContentItemId = itemId;
            model.Type          = itemType;

            return(model);
        }
Beispiel #2
0
        public Content UpdateContentFromModel(ContentModel model, int itemId, ContentItemType itemType)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var repository = GetRepository(itemType);

            var item = repository.Set().Include(i => i.Content).FirstOrDefault(i => i.Id == itemId);

            if (item == null)
            {
                throw new Exception($"item with id {itemId} not found");
            }

            var content = item.Content;

            if (content == null)
            {
                throw new Exception($"item {itemId} has no content to update");
            }

            var newContent = GetContentFromModel(model);

            content.Datetime     = newContent.Datetime;
            content.IsPublished  = newContent.IsPublished;
            content.ShowComments = newContent.ShowComments;

            item.Content = content;

            repository.Update(item);

            return(content);
        }
Beispiel #3
0
 public ContentItem(ContentItemType type, string[] commandParams)
 {
     this.Type   = type;
     this.Title  = commandParams[(int)acpi.Title];
     this.Author = commandParams[(int)acpi.Author];
     this.Size   = Int64.Parse(commandParams[(int)acpi.Size]);
     this.URL    = commandParams[(int)acpi.Url];
 }
Beispiel #4
0
 public ContentItem(ContentItemType type, string[] commandParams)
 {
     this.Type = type;
     this.Title = commandParams[(int)acpi.Title];
     this.Author = commandParams[(int)acpi.Author];
     this.Size = Int64.Parse(commandParams[(int)acpi.Size]);
     this.URL = commandParams[(int)acpi.Url];
 }
Beispiel #5
0
 private IRepository <IDBEntityWithContent> GetRepository(ContentItemType itemType)
 {
     return(itemType switch
     {
         ContentItemType.VideoContent => _videoRepository,
         ContentItemType.CommentContent => _commentRepository,
         ContentItemType.ArticleContent => _articleRepository,
         ContentItemType.ViewContent => _viewsRepository,
         _ => throw new ArgumentException("invalid enum", nameof(itemType))
     });
        public Task <IChangeToken> BuildAsync(ISchema schema)
        {
            var serviceProvider = _httpContextAccessor.HttpContext.RequestServices;

            var contentDefinitionManager = serviceProvider.GetService <IContentDefinitionManager>();
            var contentTypeBuilders      = serviceProvider.GetServices <IContentTypeBuilder>().ToList();

            var changeToken = contentDefinitionManager.ChangeToken;

            foreach (var typeDefinition in contentDefinitionManager.ListTypeDefinitions())
            {
                var typeType = new ContentItemType(_contentOptionsAccessor)
                {
                    Name        = typeDefinition.Name,
                    Description = S["Represents a {0}.", typeDefinition.DisplayName]
                };

                var query = new ContentItemsFieldType(typeDefinition.Name, schema, _contentOptionsAccessor, _settingsAccessor)
                {
                    Name         = typeDefinition.Name,
                    Description  = S["Represents a {0}.", typeDefinition.DisplayName],
                    ResolvedType = new ListGraphType(typeType)
                };

                query.RequirePermission(CommonPermissions.ViewContent, typeDefinition.Name);

                foreach (var builder in contentTypeBuilders)
                {
                    builder.Build(query, typeDefinition, typeType);
                }

                var settings = typeDefinition.GetSettings <ContentTypeSettings>();

                // Only add queries over standard content types
                if (settings == null || String.IsNullOrWhiteSpace(settings.Stereotype))
                {
                    schema.Query.AddField(query);
                }
                else
                {
                    // Register the content item type explicitly since it won't be discovered from the root 'query' type.
                    schema.RegisterType(typeType);
                }
            }

            foreach (var builder in contentTypeBuilders)
            {
                builder.Clear();
            }

            return(Task.FromResult(changeToken));
        }
Beispiel #7
0
        public void DeleteContentFromItem(int itemId, ContentItemType itemType)
        {
            var repository = GetRepository(itemType);

            var item = repository.Set().Include(i => i.Content).FirstOrDefault(i => i.Id == itemId);

            if (item == null)
            {
                throw new Exception($"item with id {itemId} not found");
            }

            DeleteContent(item.Content.Id);
        }
Beispiel #8
0
        public void ParseContentList(string text)
        {
            try
            {
                var json = JArray.Parse(text);
                foreach (var t in json)
                {
                    if (t is JArray)
                    {
                        var items           = t.ToObject <JArray>();
                        var contentItemType = ContentItemType.ValueOfRaw(items[0].ToString());
                        var item            = JsonConvert.SerializeObject(items);
                        switch (contentItemType.Name.ToUpper())
                        {
                        case "FACE":
                            AddContentItem(new FaceItem(item));
                            break;

                        case "FONT":
                            AddContentItem(new FontItem(item));
                            break;

                        case "CFACE":
                            AddContentItem(new CFaceItem(item));
                            break;

                        case "OFFPIC":
                            AddContentItem(new OffPicItem(item));
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        AddContentItem(new TextItem(JsonConvert.SerializeObject(t)));
                    }
                }
            }
            catch (JsonException e)
            {
                throw new QQException(QQErrorCode.JSON_ERROR, e);
            }
            catch (Exception e)
            {
                throw new QQException(QQErrorCode.UNKNOWN_ERROR, e);
            }
        }
Beispiel #9
0
        public Content AddContentFromModel(ContentModel model, int itemId, ContentItemType itemType)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            var repository = GetRepository(itemType);

            var content = GetContentFromModel(model);

            var item = repository.GetById(itemId);

            item.Content = content;

            repository.Insert(item);

            return(content);
        }
Beispiel #10
0
        private ContentItem Bundle(ContentItemType targetContentItemType, string outputDirectory, string outputFile, string sourceDirectory)
        {
            var contentBuilder = new StringBuilder();

            using (
                var writer = targetContentItemType == ContentItemType.Path
                                 ? new StreamWriter(outputFile, false, Encoding.UTF8)
                                 : new StringWriter(contentBuilder, CultureInfo.InvariantCulture) as TextWriter)
            {
                this.context.Log.Information("Start bundling output file: {0}".InvariantFormat(outputFile));
                foreach (var file in this.Inputs.GetFiles(sourceDirectory, this.context.Log, true))
                {
                    this.Append(writer, file, sourceDirectory, this.PreprocessingConfig);
                }

                this.context.Log.Information("End bundling output file: {0}".InvariantFormat(outputFile));
            }

            return(targetContentItemType == ContentItemType.Path
                ? ContentItem.FromFile(outputFile, outputFile.MakeRelativeTo(outputDirectory))
                : ContentItem.FromContent(contentBuilder.ToString(), outputFile.MakeRelativeTo(outputDirectory)));
        }
        public void Build(FieldType contentQuery, ContentTypeDefinition contentTypeDefinition, ContentItemType contentItemType)
        {
            var settings = contentTypeDefinition.Settings?.ToObject <ContentTypeSettings>();

            if (settings != null && settings.Stereotype != "Widget")
            {
                return;
            }

            contentItemType.Field <FlowMetadataQueryObjectType>("metadata",
                                                                resolve: context => context.Source.As <FlowMetadata>()
                                                                );
        }
Beispiel #12
0
        /// <summary>The execute method for the activity under question.</summary>
        /// <param name="resultContentItemType">The result Content Type.</param>
        /// <returns>The <see cref="ContentItem"/> or null if it failed.</returns>
        internal ContentItem Execute(ContentItemType resultContentItemType = ContentItemType.Path)
        {
            if (string.IsNullOrWhiteSpace(this.OutputFile))
            {
                throw new ArgumentException("AssemblerActivity - The output file path cannot be null or whitespace.");
            }

            var assembleType = Path.GetExtension(this.OutputFile);

            if (!string.IsNullOrWhiteSpace(assembleType))
            {
                assembleType = assembleType.Trim('.');
            }

            ContentItem contentItem = null;

            this.context.SectionedAction(SectionIdParts.AssemblerActivity, assembleType)
            .MakeCachable(new { this.Inputs, this.PreprocessingConfig, this.AddSemicolons, output = resultContentItemType == ContentItemType.Path ? this.OutputFile : null })
            .RestoreFromCacheAction(cacheSection =>
            {
                var cachedContentItem = cacheSection.GetCachedContentItem(CacheFileCategories.AssemblerResult);
                if (cachedContentItem == null)
                {
                    return(false);
                }

                contentItem = ContentItem.FromContentItem(
                    cachedContentItem,
                    Path.GetFileName(this.OutputFile));
                return(true);
            })
            .Execute(cacheSection =>
            {
                try
                {
                    // Add source inputs
                    this.Inputs.ForEach(this.context.Cache.CurrentCacheSection.AddSourceDependency);

                    // Create if the directory does not exist.
                    var outputDirectory = Path.GetDirectoryName(this.OutputFile);
                    if (resultContentItemType == ContentItemType.Path && !string.IsNullOrWhiteSpace(outputDirectory))
                    {
                        Directory.CreateDirectory(outputDirectory);
                    }

                    // set the semicolon flag to true so the first file doesn't get a semicolon added before it.
                    // IF we are interesting in adding semicolons between bundled files (eg: JavaScript), then this flag
                    // will get set after outputting each file, depending on whether or not that file ends in a semicolon.
                    // the NEXT file will look at the flag and add one if the previous one didn't end in a semicolon.
                    this.endedInSemicolon = true;

                    contentItem = this.Bundle(resultContentItemType, outputDirectory, this.OutputFile, this.context.Configuration.SourceDirectory);

                    cacheSection.AddResult(contentItem, CacheFileCategories.AssemblerResult);
                }
                catch (Exception exception)
                {
                    throw new WorkflowException("AssemblerActivity - Error happened while executing the assembler activity", exception);
                }

                return(true);
            });

            return(contentItem);
        }
        public void Build(FieldType contentQuery, ContentTypeDefinition contentTypeDefinition, ContentItemType contentItemType)
        {
            var settings = contentTypeDefinition.Settings?.ToObject <ContentTypeSettings>();

            if (settings != null && settings.Stereotype != "MenuItem")
            {
                return;
            }

            contentItemType.Field <MenuItemsListQueryObjectType>(
                nameof(MenuItemsListPart).ToFieldName(),
                resolve: context => context.Source.As <MenuItemsListPart>()
                );

            contentItemType.Interface <MenuItemInterface>();
        }
 public ContentItem(ContentItemType type)
 {
     Type = type;
 }