private void UpdateItemMetadata(ContentData item, DataRow row) { foreach (DataColumn column in MetadataColumns) { ContentMetaData metaData = item.MetaData.SingleOrDefault(cmd => cmd.Name == column.ColumnName); if (metaData == null) { row.LogContentWarn( "metadata named '{0}' not found", column.ColumnName); continue; } row.LogContentInfo("setting metadata field '{0}' to '{1}'", metaData.Name, row[column]); metaData.Text = row[column].ToString(); } DoContentUpdate(row, item); }
private void DoUpdate( TaxonomyItemData data, DataRow row, ContentData existingItem, short timeouts = 0, bool failOnFault = false) { try { if (HasAuthentication) { TaxItemManager.Add(data); row.LogContentInfo("updated successfully with id {0}.", existingItem.Id); } else { row.LogContentWarn("does not have authentication."); } } catch (TimeoutException te) { if (timeouts < 10) { row.LogContentInfo("update timed out. Trying again."); Thread.Sleep(TimeoutWait); DoUpdate(data, row, existingItem, ++timeouts); } else { LogUpdateError(row, te); } } catch (FaultException fe) { if (!failOnFault && fe.Message.Contains("The current user does not have permission to carry out this request")) { row.LogContentWarn("had authentication error. Re-authenticating then retrying."); Authenticate(); DoUpdate(data, row, existingItem, failOnFault: true); } else { LogUpdateError(row, fe); } } catch (CommunicationException ce) { if (!failOnFault) { row.LogContentWarn("had communication error. Waiting and then retrying."); Thread.Sleep(TimeoutWait); DoUpdate(data, row, existingItem, failOnFault: true); } else { LogUpdateError(row, ce); } } catch (Exception ex) { LogUpdateError(row, ex); } }
private void UpdateItemTaxonomies(ContentData item, DataRow row) { List<TaxonomyItemData> existingDataItems = FindExistingTaxonomyItemsForContent(item); foreach (DataColumn column in TaxonomyColumns) { string[] taxPaths = row[column].ToString() .Split( new[] { TaxonomySeparator }, StringSplitOptions.RemoveEmptyEntries); foreach (string taxPath in taxPaths) { row.LogContentInfo("setting taxonomy '{0}'", taxPath); TaxonomyData tax = GetTaxonomy(taxPath); if (tax == null || tax.Id <= 0) { Log.WarnFormat("Could not find taxonomy with path '{0}'", taxPath); continue; } Log.InfoFormat("Found taxonomy '{0}' with id {1}", taxPath, tax.Id); TaxonomyItemData data = CheckForExistingTaxonomyDataItem(existingDataItems, tax, row); data.TaxonomyId = tax.Id; data.ItemId = item.Id; data.ItemType = EkEnumeration.TaxonomyItemType.Content; DoUpdate(data, row, item); } } row.LogContentInfo("updated successfully with taxonomies."); }
private static TaxonomyItemData CheckForExistingTaxonomyDataItem( IEnumerable<TaxonomyItemData> existingDataItems, TaxonomyData tax, DataRow row) { TaxonomyItemData data = existingDataItems.FirstOrDefault(d => d.TaxonomyId == tax.Id); if (data != null) { row.LogContentInfo( "Found an existing taxonomy data item for taxonomy '{0}'", tax.Name); } else { data = new TaxonomyItemData(); row.LogContentInfo( "Did not find an existing taxonomy data item for taxonomy '{0}'", tax.Name); } return data; }
protected void DoContentAdd(DataRow row, ContentData content, short timeouts = 0, bool failOnFault = false) { try { if (HasAuthentication) { DoAPIAddCall(content); row.LogContentInfo("saved successfully with id {0}.", content.Id); } else { row.LogContentWarn("does not have authentication."); } } catch (TimeoutException te) { if (timeouts < 10) { row.LogContentInfo("save timed out. Trying again."); Thread.Sleep(TimeoutWait); DoContentAdd(row, content, ++timeouts); } else { row.LogContentError("failed to save.", te); } } catch (FaultException fe) { if (!failOnFault && fe.Message.Contains("The current user does not have permission to carry out this request")) { row.LogContentWarn("had authentication error. Re-authenticating then retrying."); Authenticate(); DoContentAdd(row, content, failOnFault: true); } else { row.LogContentError("failed to save.", fe); } } catch (CommunicationException ce) { if (!failOnFault) { row.LogContentWarn("had communication error. Waiting and then retrying."); Thread.Sleep(TimeoutWait); DoContentAdd(row, content, failOnFault: true); } else { LogUpdateError(row, ce); } } catch (Exception ex) { row.LogContentError("failed to save.", ex); } }
protected static ContentData CheckForExistingItem(DataRow row, IEnumerable<ContentData> existingItems) { row.LogContentInfo("checking for existence in ektron."); ContentData item; if (row.IsNew()) { row.LogContentInfo("no contentId found, checking by title and folder path."); string title = DestinationHelper.EncodeTitle(row["title"].ToString()); string folderPath = row["folderPath"].ToString(); item = existingItems.FirstOrDefault(ei => ei.Title == title && ei.Path == folderPath); } else { long id = (long)row["contentId"]; item = existingItems.FirstOrDefault(ei => ei.Id == id); } if (item != null) { row.LogContentInfo("found existing item."); } else { row.LogContentInfo("did not find existing item."); } return item; }
/// <summary> /// Updates the existing content item as opposed to adding a new one. The /// 'title' and 'html' fields are updated. /// </summary> /// <param name="row">Row containing data to update in existing content item.</param> /// <param name="existingItem">Existing content item to update.</param> protected virtual void UpdateContent(DataRow row, ContentData existingItem) { row.LogContentInfo("updating content with id {0}", row["contentId"]); SetContentFields(row, existingItem); DoContentUpdate(row, existingItem); }
/// <summary> /// Saves a new content item with the values from the data row. /// The 'title' and 'html' fields are saved. The item is placed /// in the folder found using the 'folderPath' column value in the data row. /// </summary> /// <param name="row">Row with content data.</param> protected virtual void SaveContent(DataRow row) { row.LogContentInfo("saving in folder '{0}'", row["folderPath"]); long folderId = _folderUtil.GetFolderId(row); if (folderId <= 0) { row.LogContentWarn("can't save item because no folder was found for it."); return; } ContentData content = GetNewContentDataObject(); SetContentFields(row, content); content.FolderId = folderId; DoContentAdd(row, content); }