Ejemplo n.º 1
0
        private static void RunBusinessLogic()
        {
            var data           = _reader.Read();
            var clearData      = _cleaner.Clean(data);
            var warehouseItems = clearData.Select(datum => _warehouseItemDtoMapper.Map(datum)).ToList();

            _warehouseFillerRepo.Fill(warehouseItems);
            var report = _reportGenerator.GenerateReport(_warehouseRepo.GetAll());

            Console.WriteLine(report);
        }
Ejemplo n.º 2
0
        public ContentItem Import(ImportSettings importSettings, object objectToImport, IContent parentContent)
        {
            Comments commentsToImport = (Comments)objectToImport;

            foreach (var commentToImport in commentsToImport.CommentList)
            {
                var author      = (commentToImport.UserName ?? string.Empty).Truncate(255);
                var dateCreated = commentToImport.DateCreated;

                var comment = _commentService.GetCommentsForCommentedContent(parentContent.Id)
                              .Where(o => o.Author == author)
                              .List()
                              .FirstOrDefault(o => o.Record.CommentDateUtc.HasValue && o.Record.CommentDateUtc.Value.Equals(dateCreated));

                if (comment != null)
                {
                    return(comment.ContentItem);
                }
                else
                {
                    comment = _orchardServices.ContentManager.New <CommentPart>("Comment");
                }

                comment.Author         = author;
                comment.CommentText    = (_dataCleaner.Clean(commentToImport.Content.Value, importSettings) ?? string.Empty).Truncate(10000);
                comment.Email          = (commentToImport.UserEmail ?? string.Empty).Truncate(255);
                comment.SiteName       = (commentToImport.UserURL ?? string.Empty).Truncate(255);
                comment.CommentedOn    = parentContent.Id;
                comment.CommentDateUtc = dateCreated;
                comment.UserName       = (commentToImport.UserName ?? "Anonymous").Truncate(255);

                if (parentContent.As <CommentsPart>().Record.CommentPartRecords == null)
                {
                    parentContent.As <CommentsPart>().Record.CommentPartRecords = new List <CommentPartRecord>();
                }

                _orchardServices.ContentManager.Create(comment);

                if (commentToImport.Approved)
                {
                    _commentService.ApproveComment(comment.Id);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public ContentItem Import(ImportSettings importSettings, object objectToImport, IContent parentContent)
        {
            Post blogPostToImport = (Post)objectToImport;

            var blogPostPart = _blogPostService.Get(parentContent.As <BlogPart>()).FirstOrDefault(rr => rr.As <IAliasAspect>().Path == blogPostToImport.PostUrl);

            if (importSettings.Override && blogPostPart != null)
            {
                blogPostPart = _contentManager.Get(blogPostPart.ContentItem.Id, VersionOptions.DraftRequired).As <BlogPostPart>();
            }

            ContentItem contentItem = null;

            if (blogPostPart != null)
            {
                contentItem = blogPostPart.ContentItem;

                if (!importSettings.Override)
                {
                    if (blogPostToImport.DateModified.IsEarlierThan(contentItem.As <ICommonPart>().ModifiedUtc) ||
                        blogPostToImport.DateModified.Equals(contentItem.As <ICommonPart>().ModifiedUtc))
                    {
                        return(contentItem);
                    }
                }
            }
            else
            {
                contentItem = _contentManager.Create("BlogPost", VersionOptions.Draft);

                contentItem.As <ICommonPart>().Container = parentContent;

                if (!string.IsNullOrEmpty(blogPostToImport.PostUrl))
                {
                    contentItem.As <AutoroutePart>().DisplayAlias = blogPostToImport.PostUrl.TrimStart('/');
                }
            }

            contentItem.As <TitlePart>().Title = blogPostToImport.Title;
            contentItem.As <BodyPart>().Text   = _dataCleaner.Clean(blogPostToImport.Content.Value, importSettings);

            var user = blogPostToImport.Authors.AuthorReferenceList.FirstOrDefault();

            if (user != null)
            {
                contentItem.As <ICommonPart>().Owner = _userServices.GetUser(user.ID, true);
            }

            contentItem.As <CommentsPart>().CommentsActive = blogPostToImport.Comments.Enabled;

            if (blogPostToImport.HasExcerpt)
            {
                ((dynamic)contentItem).ExcerptPart.Excerpt.Value = blogPostToImport.Excerpt.Value;
            }

            ImportAdditionalContentItems(importSettings, blogPostToImport.Categories, contentItem);
            ImportAdditionalContentItems(importSettings, blogPostToImport.Tags, contentItem);

            if (blogPostToImport.Approved)
            {
                _contentManager.Publish(contentItem);

                if (blogPostToImport.DateModified.IsNotEmpty())
                {
                    contentItem.As <ICommonPart>().PublishedUtc        = blogPostToImport.DateModified;
                    contentItem.As <ICommonPart>().VersionPublishedUtc = blogPostToImport.DateModified;
                }
            }

            if (blogPostToImport.DateModified.IsNotEmpty())
            {
                contentItem.As <ICommonPart>().ModifiedUtc        = blogPostToImport.DateModified;
                contentItem.As <ICommonPart>().VersionModifiedUtc = blogPostToImport.DateModified;
            }

            if (blogPostToImport.DateCreated.IsNotEmpty())
            {
                contentItem.As <ICommonPart>().CreatedUtc        = blogPostToImport.DateCreated;
                contentItem.As <ICommonPart>().VersionCreatedUtc = blogPostToImport.DateCreated;
            }

            ImportAdditionalContentItems(importSettings, blogPostToImport.Comments, contentItem);

            //ImportAdditionalContentItems(importSettings,
            //    blogPostToImport.Comments.CommentList.Where(o => DateTime.Parse(o.DateModified).IsLaterThan(contentItem.As<ICommonPart>().ModifiedUtc)), contentItem);

            return(contentItem);
        }