Esempio n. 1
0
        public Batch CreateBatch(string site, DocumentProcessOptions options)
        {
            List <UpdatedDoc> itemsForBatch = GetDocumentsFromEktron(options);
            Batch             batch         = CreateBatchForItems(itemsForBatch, options);

            return(batch);
        }
Esempio n. 2
0
        /// <summary>
        /// Processes the ektron documents for anything updated since last batch run.
        /// </summary>
        /// <param name="site">The site.</param>
        /// <returns></returns>
        public DocumentProcessResults ProcessEktronDocuments(DocumentProcessOptions processingOptions, List <int> listExcludeFromProcessing)
        {
            if (null == processingOptions)
            {
                throw new ArgumentNullException("processingOptions");
            }
            if (String.IsNullOrEmpty(processingOptions.Site))
            {
                throw new ArgumentOutOfRangeException("processingOptions.Site");
            }

            try
            {
                List <UpdatedDoc> updateDocuments = GetDocumentsFromEktron(processingOptions);

                if (listExcludeFromProcessing.Count > 0)
                {
                    foreach (int item in listExcludeFromProcessing)
                    {
                        updateDocuments.RemoveAt(Convert.ToInt16(item));
                    }
                }

                if (updateDocuments.Count == 0)
                {
                    return(new DocumentProcessResults
                    {
                        Status = "Success - No Documents to Proccess Batch was not created",
                        DocumentsInBatch = 0,
                        BatchId = 0,
                    });
                }

                Batch currentBatch = CreateBatchForItems(updateDocuments, processingOptions);
                return(new DocumentProcessResults
                {
                    Status = "Success",
                    StartDate = currentBatch.startDate,
                    EndDate = currentBatch.endDate,
                    DocumentsInBatch = (null == updateDocuments) ? 0 : updateDocuments.Count,
                    BatchId = currentBatch.batchId,
                });
            }
            catch (Exception e)
            {
                String errorMessage = "Error: Something happened in the processing of documents, please see the errors above for clarification.";
                log.Error(errorMessage, e);

                return(new DocumentProcessResults
                {
                    Status = String.Format("{0}: {1}", errorMessage, e),
                });
            }
        }
Esempio n. 3
0
        private Batch CreateBatchForItems(List <UpdatedDoc> itemsForBatch, DocumentProcessOptions options)
        {
            //TODO: Transaction!
            using (NotificationTablesDataContext notificationDataContext = new NotificationTablesDataContext())
            {
                Batch batch = new Batch();
                batch.startDate = options.StartDate;
                batch.endDate   = options.EndDate;
                batch.site      = options.Site;

                notificationDataContext.Batches.InsertOnSubmit(batch);
                notificationDataContext.SubmitChanges();

                // Add the updated docs for this batch
                foreach (UpdatedDoc docToAddToBatch in itemsForBatch)
                {
                    //TODO: why not use UpdatedDocument here instead of Updated Doc
                    notificationDataContext.UpdatedDocuments.InsertOnSubmit
                    (
                        new UpdatedDocument
                    {
                        batch        = batch.batchId,
                        dateUpdated  = docToAddToBatch.dateUpdated,
                        documentType = docToAddToBatch.documentType,
                        documentName = docToAddToBatch.documentName,
                        fileSize     = docToAddToBatch.fileSize,
                        url          = docToAddToBatch.url
                    }
                    );
                }
                ;
                batch.finishDate = DateTime.Now;
                notificationDataContext.SubmitChanges();
                return(batch);
            }
        }
Esempio n. 4
0
        private List <UpdatedDoc> GetDocumentsFromEktron(DocumentProcessOptions processingOptions)
        {
            if (null == processingOptions)
            {
                throw new ArgumentNullException("processingOptions");
            }
            if (String.IsNullOrEmpty(processingOptions.Site))
            {
                throw new ArgumentOutOfRangeException("processingOptions.Site");
            }

            if (String.IsNullOrEmpty(processingOptions.TaxonomyName) && !String.IsNullOrEmpty(processingOptions.Site))
            {
                processingOptions.TaxonomyName = GetTaxonomyName(processingOptions.Site);
            }


            DateTime startDate = (DateTime.MinValue.Equals(processingOptions.StartDate)) ? System.Data.SqlTypes.SqlDateTime.MinValue.Value : processingOptions.StartDate;
            DateTime endDate   = (DateTime.MinValue.Equals(processingOptions.EndDate) || processingOptions.EndDate > System.Data.SqlTypes.SqlDateTime.MaxValue.Value) ? System.Data.SqlTypes.SqlDateTime.MaxValue.Value : processingOptions.EndDate;

            try
            {
                using (EktronDataContext ektronDataContext = new EktronDataContext())
                {
                    Taxonomy parentTaxonomy = ektronDataContext.Taxonomies.FirstOrDefault(tax => tax.taxonomy_name == processingOptions.TaxonomyName);
                    long     metaTypeId     = (from metatype in ektronDataContext.metadata_types where metatype.meta_name == "DocumentFileSize" select metatype.meta_type_id).FirstOrDefault();

                    var taxonomyItems = (from childTaxonomy in ektronDataContext.Taxonomies
                                         join taxonomyItem in ektronDataContext.TaxonomyItems on childTaxonomy.taxonomy_id equals taxonomyItem.taxonomy_id
                                         join sizeInfo in ektronDataContext.content_meta_tbls on taxonomyItem.EKContents.content_id equals sizeInfo.content_id
                                         where
                                         childTaxonomy.taxonomy_parent_id == parentTaxonomy.taxonomy_id &&
                                         ((taxonomyItem.taxonomy_item_date_modified.CompareTo(startDate) >= 0 &&
                                           taxonomyItem.taxonomy_item_date_modified.CompareTo(endDate) <= 0) ||
                                          (taxonomyItem.EKContents.last_edit_date.CompareTo(startDate) >= 0 &&
                                           taxonomyItem.EKContents.last_edit_date.CompareTo(endDate) <= 0)) &&
                                         sizeInfo.meta_type_id == metaTypeId &&
                                         (null != taxonomyItem.EKContents.Document) &&
                                         (null == processingOptions.FileTypes ||
                                          processingOptions.FileTypes.Contains(taxonomyItem.EKContents.Document.handle.Substring(taxonomyItem.EKContents.Document.handle.LastIndexOf(".") + 1).Trim().ToLower()))
                                         select new UpdatedDoc
                    {
                        url = "http://" + processingOptions.Site + "/assets/" + taxonomyItem.EKContents.Document.pubFolderPath + taxonomyItem.EKContents.Document.storage +
                              taxonomyItem.EKContents.Document.handle.Substring(taxonomyItem.EKContents.Document.handle.LastIndexOf(".")),
                        dateUpdated = (DateTime.Compare(taxonomyItem.taxonomy_item_date_modified, taxonomyItem.EKContents.last_edit_date) > 0 ? taxonomyItem.taxonomy_item_date_modified : taxonomyItem.EKContents.last_edit_date),
                        documentName = taxonomyItem.EKContents.content_title.Replace("’", "'").Replace("&amp;", "&").Replace("“", "\"").Replace("”", "\""),                    // taxonomyItem.EKContents.Document.handle,
                        documentType = childTaxonomy.taxonomy_name,
                        fileSize = sizeInfo.meta_value
                    }).Distinct();


                    System.Diagnostics.Debug.WriteLine("Documents Found = " + taxonomyItems.Count());
                    return(taxonomyItems.ToList());
                }
            }
            catch (Exception e)
            {
                log.Error("Unable to retrieve Ektron Documents or create Updated Documents", e);
                throw e;
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Processes the ektron documents
 /// </summary>
 /// <param name="site">The site.</param>
 /// <returns></returns>
 public List <UpdatedDoc> GetUpdatedDocumentList(DocumentProcessOptions options)
 {
     return(GetDocumentsFromEktron(options));
 }
Esempio n. 6
0
 public DocumentProcessResults ProcessEktronDocuments(DocumentProcessOptions processingOptions)
 {
     return(ProcessEktronDocuments(processingOptions, new List <int>()));
 }