public UnicornOperationContext() { _sd = new SecurityDisabler(); _ed = new EventDisabler(); // events, e.g. indexing, et al. This is what Sitecore's serialization API uses, and it's a superset of BulkUpdateContext _fd = new ItemFilterDisabler(); // disable all item filtering (if we're running in live mode we need this to get unadulterated items) _tds = new TransparentSyncDisabler(); }
private void ItemInstaller(PullItemModel args, BlockingCollection <IItemData> itemsToInstall, CancellationToken cancellationToken) { Thread.CurrentThread.Priority = ThreadPriority.Lowest; BulkUpdateContext bu = null; EventDisabler ed = null; try { if (args.BulkUpdate) { bu = new BulkUpdateContext(); } if (args.EventDisabler) { ed = new EventDisabler(); } using (new SecurityDisabler()) using (new SyncOperationContext()) { while (!Completed) { if (!itemsToInstall.TryTake(out var remoteData, int.MaxValue, cancellationToken)) { break; } if (!args.UseItemBlaster) { CurrentlyProcessing.Add(remoteData.Id); } IItemData localData = _sitecore.GetItemData(remoteData.Id); ProcessItem(args, localData, remoteData); lock (_locker) { ItemsInstalled++; if (!args.UseItemBlaster) { CurrentlyProcessing.Remove(remoteData.Id); } } } } } catch (OperationCanceledException e) { Log.Warn("Content migration operation was cancelled", e, this); Status.Cancelled = true; lock (_locker) { if (!Completed) { Finalize(ItemsInstalled, args); } } } catch (Exception e) { Log.Error("Catastrophic error when installing items", e, this); } finally { if (args.BulkUpdate) { bu?.Dispose(); } if (args.EventDisabler) { ed?.Dispose(); } } }
public void RunDatabaseWriterProcess() { Task.Run(() => { using (new SecurityDisabler()) { BulkUpdateContext bu = null; if (_args.bulkUpdate) bu = new BulkUpdateContext(); EventDisabler ed = null; if (_args.eventDisabler) ed = new EventDisabler(); ProcessItemQueue(); bu?.Dispose(); ed?.Dispose(); if (Completed) return; lock (finishLocker) { if (Completed) return; if (_args.mirror && !Cancelled) foreach (Guid guid in allowedItems) { try { Item item = db.GetItem(new ID(guid)); if (item != null) { RecordEvent(item.Name, item.ID.ToString(), item.Paths.FullPath, "Recycle", GetSrc(ThemeManager.GetIconImage(item, 32, 32, "", "")), item.Database.Name); if (!_args.preview) item.Recycle(); } } catch (Exception e) { Log.Error("Problem recycling item", e, this); } } Completed = true; dynamic last = new ExpandoObject(); last.Date = $"{DateTime.Now:F}"; last.Time = sw.Elapsed.TotalSeconds; last.Items = _lines.Count; last.Cancelled = Cancelled; lock (_listLocker) Lines.Add(last); } } }); }
public void StartInstallingItems(PullItemModel args, BlockingCollection <IItemData> itemsToInstall, int threads, CancellationTokenSource cancellation) { Status.StartedTime = DateTime.Now; Status.RootNodes = args.Ids.Select(x => new ContentTreeNode(x)); Status.IsPreview = args.Preview; Status.Server = args.Server; int items = 0; for (int i = 0; i < threads; i++) { Task.Run(async() => { Thread.CurrentThread.Priority = ThreadPriority.Lowest; BulkUpdateContext bu = null; EventDisabler ed = null; try { if (args.BulkUpdate) { bu = new BulkUpdateContext(); } if (args.EventDisabler) { ed = new EventDisabler(); } using (new SecurityDisabler()) { while (!Completed) { IItemData remoteData; if (!itemsToInstall.TryTake(out remoteData, int.MaxValue, cancellation.Token)) { lock (_locker) { if (!Completed && !_currentlyProcessing.Any()) { Finalize(items, args); } } break; } _currentlyProcessing.Add(remoteData.Id); Item localItem = _sitecore.GetItem(remoteData.Id); IItemData localData = localItem == null ? null : new Rainbow.Storage.Sc.ItemData(localItem); await ProcessItem(args, localData, remoteData, localItem); lock (_locker) { items++; _currentlyProcessing.Remove(remoteData.Id); if (_currentlyProcessing.Any() || !itemsToInstall.IsAddingCompleted || itemsToInstall.Count != 0) { continue; } if (!Completed) { Finalize(items, args); } } } } } catch (OperationCanceledException e) { Log.Warn("Content migration operation was cancelled", e, this); Status.Cancelled = true; lock (_locker) { if (!Completed) { Finalize(items, args); } } } catch (Exception e) { Log.Error("Catastrophic error when installing items", e, this); } finally { if (args.BulkUpdate) { bu?.Dispose(); } if (args.EventDisabler) { ed?.Dispose(); } } }); } }
public void RunDatabaseWriterProcess() { Task.Run(() => { using (new SecurityDisabler()) { BulkUpdateContext bu = null; if (_args.bulkUpdate) { bu = new BulkUpdateContext(); } EventDisabler ed = null; if (_args.eventDisabler) { ed = new EventDisabler(); } ProcessItemQueue(); bu?.Dispose(); ed?.Dispose(); if (Completed) { return; } lock (finishLocker) { if (Completed) { return; } if (_args.mirror && !Cancelled) { foreach (Guid guid in allowedItems) { try { Item item = db.GetItem(new ID(guid)); if (item != null) { RecordEvent(item.Name, item.ID.ToString(), item.Paths.FullPath, "Recycle", GetSrc(ThemeManager.GetIconImage(item, 32, 32, "", "")), item.Database.Name); if (!_args.preview) { item.Recycle(); } } } catch (Exception e) { Log.Error("Problem recycling item", e, this); } } } Completed = true; dynamic last = new ExpandoObject(); last.Date = $"{DateTime.Now:F}"; last.Time = sw.Elapsed.TotalSeconds; last.Items = _lines.Count; last.Cancelled = Cancelled; lock (_listLocker) Lines.Add(last); } } }); }
private async Task ItemInstaller(PullItemModel args, BlockingCollection <IItemData> itemsToInstall, CancellationToken cancellationToken) { Thread.CurrentThread.Priority = ThreadPriority.Lowest; BulkUpdateContext bu = null; EventDisabler ed = null; try { if (args.BulkUpdate) { bu = new BulkUpdateContext(); } if (args.EventDisabler) { ed = new EventDisabler(); } using (new SecurityDisabler()) { while (!Completed) { IItemData remoteData; if (!itemsToInstall.TryTake(out remoteData, int.MaxValue, cancellationToken)) { lock (_locker) { if (!Completed && !CurrentlyProcessing.Any()) { Finalize(ItemsInstalled, args); } } break; } CurrentlyProcessing.Add(remoteData.Id); IItemData localData = _sitecore.GetItemData(remoteData.Id); await ProcessItem(args, localData, remoteData).ConfigureAwait(false); lock (_locker) { ItemsInstalled++; CurrentlyProcessing.Remove(remoteData.Id); if (CurrentlyProcessing.Any() || !itemsToInstall.IsAddingCompleted || itemsToInstall.Count != 0) { continue; } if (!Completed) { Finalize(ItemsInstalled, args); } } } } } catch (OperationCanceledException e) { Log.Warn("Content migration operation was cancelled", e, this); Status.Cancelled = true; lock (_locker) { if (!Completed) { Finalize(ItemsInstalled, args); } } } catch (Exception e) { Log.Error("Catastrophic error when installing items", e, this); } finally { if (args.BulkUpdate) { bu?.Dispose(); } if (args.EventDisabler) { ed?.Dispose(); } } }