Пример #1
0
        public string ExecutePageCreation(string feedUrl, ContentReference parentContainer)
        {
            var returningMessage = new StringBuilder();

            // Make sure that there is a container given
            if (ContentReference.IsNullOrEmpty(parentContainer))
            {
                return($"Property {parentContainer} not set \n");
            }

            // Set the real name of the Container in the log file
            //returningMessage.AppendFormat("{0} \n", _contentRepository.Get<PageData>(Container).PageName);

            try
            {
                // Read in the XML into a NewsImportItem
                //var detailItem = new NewsImportItemReader(FeedUrl).Item;
                var newsData = EipaFileHelper.Get <NewsItem>(feedUrl);

                // Create page from the news item
                //CreateNewsPage(detailItem);
                CreateNewsPage(newsData, parentContainer, returningMessage);

                if (returningMessage.Capacity >= 0.8 * returningMessage.MaxCapacity)
                {
                    returningMessage = new StringBuilder();
                }
            }
            catch (Exception fe)
            {
                return(returningMessage.AppendFormat("File: {0} \n Error message: {1} \n Stacktrace: {2} \n\n", feedUrl, fe.Message, fe.StackTrace).ToString());
            }

            return(returningMessage.ToString());
        }
Пример #2
0
        private void Export(NewsItemPage newsItemPage, string destinationPath, CancellationToken cancellationToken,
                            ConcurrentQueue <string> exportedPages, ConcurrentQueue <string> errors, Action <string> changeStatus)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            NewsItem eipaNewsFileData;

            try
            {
                eipaNewsFileData = NewsPageMapper.Map(newsItemPage);
            }
            catch (Exception e)
            {
                var message = $"Page with id '{newsItemPage.PageId}' can't be converted to Eipa file. Exception: {e}";
                Logger.LogError(e, message);
                errors.Enqueue(message);
                return;
            }

            if (EipaFileHelper.Put(GetFilePath(newsItemPage, destinationPath), eipaNewsFileData))
            {
                exportedPages.Enqueue($"{newsItemPage.PageId}");
            }
            else
            {
                errors.Enqueue($"Page with id '{newsItemPage.PageId}' wasn't exported correctly");
            }

            changeStatus.Invoke($"Exported '{exportedPages.Count}' news pages. Errors: {errors.Count}");
        }