本文整理汇总了C#中UpdateType.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# UpdateType.Equals方法的具体用法?C# UpdateType.Equals怎么用?C# UpdateType.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UpdateType
的用法示例。
在下文中一共展示了UpdateType.Equals方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportToSitecore
/// <summary>
/// This method will import / update a list of videos into the Brightcove Video Library
/// </summary>
/// <param name="Videos">
/// The Videos to import / update
/// </param>
/// <returns>
/// returns a list of the new videos imported
/// </returns>
public static UpdateInsertPair<VideoItem> ImportToSitecore(this AccountItem account, List<BCVideo> Videos, UpdateType utype) {
UpdateInsertPair<VideoItem> uip = new UpdateInsertPair<VideoItem>();
//set all BCVideos into hashtable for quick access
Hashtable ht = new Hashtable();
foreach (VideoItem exVid in account.VideoLib.Videos) {
if (!ht.ContainsKey(exVid.VideoID.ToString())) {
//set as string, Item pair
ht.Add(exVid.VideoID.ToString(), exVid);
}
}
//Loop through the data source and add them
foreach (BCVideo vid in Videos) {
try {
//remove access filter
using (new Sitecore.SecurityModel.SecurityDisabler()) {
VideoItem currentItem;
//if it exists then update it
if (ht.ContainsKey(vid.id.ToString()) && (utype.Equals(UpdateType.BOTH) || utype.Equals(UpdateType.UPDATE))) {
currentItem = (VideoItem)ht[vid.id.ToString()];
//add it to the new items
uip.UpdatedItems.Add(currentItem);
using (new EditContext(currentItem.videoItem, true, false)) {
SetVideoFields(ref currentItem.videoItem, vid);
}
}
//else just add it
else if (!ht.ContainsKey(vid.id.ToString()) && (utype.Equals(UpdateType.BOTH) || utype.Equals(UpdateType.NEW))) {
//Create new item
TemplateItem templateType = account.Database.Templates["Modules/Brightcove/Brightcove Video"];
currentItem = new VideoItem(account.VideoLib.videoLibraryItem.Add(vid.name.StripInvalidChars(), templateType));
//add it to the new items
uip.NewItems.Add(currentItem);
using (new EditContext(currentItem.videoItem, true, false)) {
SetVideoFields(ref currentItem.videoItem, vid);
}
}
}
} catch (System.Exception ex) {
//HttpContext.Current.Response.Write(vid.name + "<br/>");
throw new Exception("Failed on video: " + vid.name + ". " + ex.ToString());
}
}
return uip;
}
示例2: ImportToSitecore
public static UpdateInsertPair<PlaylistItem> ImportToSitecore(this AccountItem account, List<BCPlaylist> Playlists, UpdateType utype) {
UpdateInsertPair<PlaylistItem> uip = new UpdateInsertPair<PlaylistItem>();
//set all BCVideos into hashtable for quick access
Hashtable ht = new Hashtable();
foreach (PlaylistItem exPlay in account.PlaylistLib.Playlists) {
if (!ht.ContainsKey(exPlay.playlistItem.ToString())) {
//set as string, Item pair
ht.Add(exPlay.PlaylistID.ToString(), exPlay);
}
}
//Loop through the data source and add them
foreach (BCPlaylist play in Playlists) {
try {
//remove access filter
using (new Sitecore.SecurityModel.SecurityDisabler()) {
PlaylistItem currentItem;
//if it exists then update it
if (ht.ContainsKey(play.id.ToString()) && (utype.Equals(UpdateType.BOTH) || utype.Equals(UpdateType.UPDATE))) {
currentItem = (PlaylistItem)ht[play.id.ToString()];
//add it to the new items
uip.UpdatedItems.Add(currentItem);
using (new EditContext(currentItem.playlistItem, true, false)) {
SetPlaylistFields(ref currentItem.playlistItem, play);
}
}
//else just add it
else if (!ht.ContainsKey(play.id.ToString()) && (utype.Equals(UpdateType.BOTH) || utype.Equals(UpdateType.NEW))) {
//Create new item
TemplateItem templateType = account.Database.Templates["Modules/Brightcove/Brightcove Playlist"];
currentItem = new PlaylistItem(account.PlaylistLib.playlistLibraryItem.Add(play.name.StripInvalidChars(), templateType));
//add it to the new items
uip.NewItems.Add(currentItem);
using (new EditContext(currentItem.playlistItem, true, false)) {
SetPlaylistFields(ref currentItem.playlistItem, play);
}
}
}
} catch (System.Exception ex) {
throw new Exception("Failed on playlist: " + play.name + ". " + ex.ToString());
}
}
return uip;
}
示例3: HandleNameAndContainerChange
/// <summary>
/// </summary>
/// <param name="type"></param>
/// <param name="directoryEntry"></param>
/// <param name="attributes"></param>
/// <param name="config"></param>
private static void HandleNameAndContainerChange(UpdateType type,
DirectoryEntry directoryEntry, ICollection<ConnectorAttribute> attributes,
ActiveDirectoryConfiguration config)
{
Name nameAttribute = ConnectorAttributeUtil.GetNameFromAttributes(attributes);
if(nameAttribute == null)
{
// no name, so must not be a container change
return;
}
if (!type.Equals(UpdateType.REPLACE))
{
// this only make sense for replace. you can't
// add a name or delete a name
return;
}
String oldName = directoryEntry.Name;
String newName = GetRelativeName(nameAttribute);
bool nameChanged = !NormalizeLdapString(oldName).Equals(NormalizeLdapString(newName), StringComparison.OrdinalIgnoreCase);
String oldContainer = GetParentDn(directoryEntry.Path);
String newContainer = GetParentDn(nameAttribute.GetNameValue());
bool containerChanged = !NormalizeLdapString(oldContainer).Equals(NormalizeLdapString(newContainer), StringComparison.OrdinalIgnoreCase);
if (!nameChanged && !containerChanged)
{
return;
}
if (nameChanged && !containerChanged) // rename without moving
{
LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Renaming {0} to {1}", oldName, newName);
directoryEntry.Rename(newName);
LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Rename OK");
return;
}
// so this is move with or without rename
// step 1: if WITH rename, we have to rename the entry to a temporary name first
String temporaryName = null;
if (nameChanged)
{
temporaryName = oldName + "-" + RandomStr();
LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Renaming {0} to a temporary name of {1}", oldName, temporaryName);
directoryEntry.Rename(temporaryName);
LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Rename OK");
}
// step 2: do the move
try
{
String newContainerLdapPath = ActiveDirectoryUtils.GetLDAPPath(config.LDAPHostName, newContainer);
DirectoryEntry newContainerDe = new DirectoryEntry(newContainerLdapPath, config.DirectoryAdminName, config.DirectoryAdminPassword);
LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Moving from {0} to {1} ({2})", oldContainer, newContainer, newContainerLdapPath);
directoryEntry.MoveTo(newContainerDe);
LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Move OK");
newContainerDe.Dispose();
}
catch (Exception e)
{
LOGGER.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "Exception caught when moving: {0}", e);
if (nameChanged)
{
LOGGER.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "Renaming back from temporary name of {0} to {1}", temporaryName, oldName);
directoryEntry.Rename(oldName);
LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Rename OK");
}
throw e;
}
// step 3: if WITH rename, then rename from temporary name to the new name
if (nameChanged)
{
LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Renaming from temporary name of {0} to a new name of {1}", temporaryName, newName);
directoryEntry.Rename(newName);
LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Rename OK");
}
}
示例4: HandleNameChange
private static void HandleNameChange(UpdateType type,
DirectoryEntry directoryEntry,
ICollection<ConnectorAttribute> attributes)
{
Name nameAttribute = ConnectorAttributeUtil.GetNameFromAttributes(attributes);
if (nameAttribute != null)
{
// this only make sense for replace. you can't
// add a name or delete a name
if (type.Equals(UpdateType.REPLACE))
{
String oldName = directoryEntry.Name;
String newName = GetRelativeName(nameAttribute);
if (!NormalizeLdapString(oldName).Equals(NormalizeLdapString(newName), StringComparison.OrdinalIgnoreCase))
{
directoryEntry.Rename(newName);
}
}
}
}
示例5: HandleContainerChange
/// <summary>
/// This does not work ... for now, don't handle container changes
/// </summary>
/// <param name="type"></param>
/// <param name="directoryEntry"></param>
/// <param name="attributes"></param>
/// <param name="config"></param>
private static void HandleContainerChange(UpdateType type,
DirectoryEntry directoryEntry, ICollection<ConnectorAttribute> attributes,
ActiveDirectoryConfiguration config)
{
Name nameAttribute = ConnectorAttributeUtil.GetNameFromAttributes(attributes);
if(nameAttribute == null)
{
// no name, so must not be a container change
return;
}
if (!type.Equals(UpdateType.REPLACE))
{
// this only make sense for replace. you can't
// add a name or delete a name
return;
}
String oldContainer = GetParentDn(directoryEntry.Path);
String newContainer = GetParentDn(nameAttribute.GetNameValue());
if (!NormalizeLdapString(oldContainer).Equals(NormalizeLdapString(newContainer), StringComparison.OrdinalIgnoreCase))
{
if (newContainer != null)
{
try
{
if (!NormalizeLdapString(oldContainer).Equals(
NormalizeLdapString(newContainer), StringComparison.OrdinalIgnoreCase))
{
String newContainerLdapPath = ActiveDirectoryUtils.GetLDAPPath(
config.LDAPHostName, newContainer);
DirectoryEntry newContainerDe = new DirectoryEntry(newContainerLdapPath,
config.DirectoryAdminName, config.DirectoryAdminPassword);
directoryEntry.MoveTo(newContainerDe);
newContainerDe.Dispose();
}
}
catch (Exception e)
{
throw e;
}
}
}
}