internal void EnsureCapacity() { if (this.m_iCount == 0) { this.m_iOffsets = new int[16]; this.m_ScopeActions = new ScopeAction[16]; this.m_localSymInfos = new LocalSymInfo[16]; } else { if (this.m_iCount != this.m_iOffsets.Length) { return; } int length = checked (this.m_iCount * 2); int[] numArray = new int[length]; Array.Copy((Array)this.m_iOffsets, (Array)numArray, this.m_iCount); this.m_iOffsets = numArray; ScopeAction[] scopeActionArray = new ScopeAction[length]; Array.Copy((Array)this.m_ScopeActions, (Array)scopeActionArray, this.m_iCount); this.m_ScopeActions = scopeActionArray; LocalSymInfo[] localSymInfoArray = new LocalSymInfo[length]; Array.Copy((Array)this.m_localSymInfos, (Array)localSymInfoArray, this.m_iCount); this.m_localSymInfos = localSymInfoArray; } }
private ScopeAction StartScope(string name) { if (recursion != 0) { return(null); } ScopeAction scopeAction = new ScopeAction(name); recursion = 1; try { Run(scopeAction); } catch { recursion = 0; state = UndoRedoManagerState.Idle; throw; } return(scopeAction); }
protected void RunAction(ScopeAction action, RegisterTypesAction registerTypesAction = null) { if (action == null) { Assert.Fail("No action specified."); } using (var container = CreateContainer(registerTypesAction)) { action(container); } }
public void Execute_ShouldReturnUrlOfService() { const string testServiceName = "Test Service"; const string version = "v1"; const string url = "http://bogus/"; var services = new List <ServiceConfigurationDto> { new ServiceConfigurationDto { Name = testServiceName, Url = url, Version = version } }; var repositoryResponse = new GetServicesResponse { Services = services }; var repositoryMock = new Mock <IServiceRepository>(); repositoryMock.Setup(x => x.GetServices()).Returns(repositoryResponse); ScopeAction action = scope => { var request = new GetServiceUrlRequest() { ServiceName = testServiceName, ServiceVersion = version }; var response = scope.Resolve <GetServiceUrlCommand>().Execute(request, new Dictionary <string, object>()); Assert.IsNotNull(response); Assert.AreEqual(url, response.ServiceUrl); }; RunAction(action, builder => { builder.RegisterInstance(repositoryMock.Object).As <IServiceRepository>(); builder.RegisterType <GetServiceUrlCommand>() .AsImplementedInterfaces() .AsSelf() .PropertiesAutowired(); }); }
/// <summary> /// Create an instance of the undo and redo scope. /// </summary> /// <param name="undoRedoManager">Instance of the undo and redo manager.</param> /// <param name="name">Scope name.</param> /// <param name="complete">Action complete handler.</param> public Scope(UndoRedoManager undoRedoManager, string name, EventHandler complete) { if (undoRedoManager == null) { throw new ArgumentNullException("undoRedoManager"); } this.undoRedoManager = undoRedoManager; this.scopeAction = undoRedoManager.StartScope(name); this.complete = complete; if (complete != null) { undoRedoManager.Run(new DelegateAction(UndoScope, complete)); } }
private void EndScope(ScopeAction scopeAction) { if (scopeAction == null) { return; } if ((recursion != 1) || (current.prime != scopeAction) || (state != UndoRedoManagerState.ProcessDo)) { throw new InvalidOperationException(); } recursion = 0; Run(scopeAction); }
internal void AddScopeInfo(ScopeAction sa, int iOffset) { if ((sa == ScopeAction.Close) && (this.m_iOpenScopeCount <= 0)) { throw new ArgumentException(Environment.GetResourceString("Argument_UnmatchingSymScope")); } this.EnsureCapacity(); this.m_ScopeActions[this.m_iCount] = sa; this.m_iOffsets[this.m_iCount] = iOffset; this.m_localSymInfos[this.m_iCount] = null; this.m_iCount++; if (sa == ScopeAction.Open) { this.m_iOpenScopeCount++; } else { this.m_iOpenScopeCount--; } }
internal void EnsureCapacity() { if (this.m_iCount == 0) { this.m_iOffsets = new int[0x10]; this.m_ScopeActions = new ScopeAction[0x10]; this.m_localSymInfos = new LocalSymInfo[0x10]; } else if (this.m_iCount == this.m_iOffsets.Length) { int num = this.m_iCount * 2; int[] destinationArray = new int[num]; Array.Copy(this.m_iOffsets, destinationArray, this.m_iCount); this.m_iOffsets = destinationArray; ScopeAction[] actionArray = new ScopeAction[num]; Array.Copy(this.m_ScopeActions, actionArray, this.m_iCount); this.m_ScopeActions = actionArray; LocalSymInfo[] infoArray = new LocalSymInfo[num]; Array.Copy(this.m_localSymInfos, infoArray, this.m_iCount); this.m_localSymInfos = infoArray; } }
// Token: 0x060049DB RID: 18907 RVA: 0x0010AF08 File Offset: 0x00109108 internal void EnsureCapacity() { if (this.m_iCount == 0) { this.m_iOffsets = new int[16]; this.m_ScopeActions = new ScopeAction[16]; this.m_localSymInfos = new LocalSymInfo[16]; return; } if (this.m_iCount == this.m_iOffsets.Length) { int num = checked (this.m_iCount * 2); int[] array = new int[num]; Array.Copy(this.m_iOffsets, array, this.m_iCount); this.m_iOffsets = array; ScopeAction[] array2 = new ScopeAction[num]; Array.Copy(this.m_ScopeActions, array2, this.m_iCount); this.m_ScopeActions = array2; LocalSymInfo[] array3 = new LocalSymInfo[num]; Array.Copy(this.m_localSymInfos, array3, this.m_iCount); this.m_localSymInfos = array3; } }
/************************** * * Helper to ensure arrays are large enough * **************************/ internal void EnsureCapacity() { if (m_iCount == 0) { // First time. Allocate the arrays. m_iOffsets = new int[InitialSize]; m_ScopeActions = new ScopeAction[InitialSize]; m_localSymInfos = new LocalSymInfo[InitialSize]; } else if (m_iCount == m_iOffsets.Length) { // the arrays are full. Enlarge the arrays // It would probably be simpler to just use Lists here. int newSize = checked(m_iCount * 2); int[] temp = new int[newSize]; Array.Copy(m_iOffsets, temp, m_iCount); m_iOffsets = temp; ScopeAction[] tempSA = new ScopeAction[newSize]; Array.Copy(m_ScopeActions, tempSA, m_iCount); m_ScopeActions = tempSA; LocalSymInfo[] tempLSI = new LocalSymInfo[newSize]; Array.Copy(m_localSymInfos, tempLSI, m_iCount); m_localSymInfos = tempLSI; } }
internal void AddScopeInfo(ScopeAction sa, int iOffset) { if (sa == ScopeAction.Close && m_iOpenScopeCount <=0) { throw new ArgumentException(Environment.GetResourceString("Argument_UnmatchingSymScope")); } Contract.EndContractBlock(); // make sure that arrays are large enough to hold addition info EnsureCapacity(); m_ScopeActions[m_iCount] = sa; m_iOffsets[m_iCount] = iOffset; m_localSymInfos[m_iCount] = null; checked { m_iCount++; } if (sa == ScopeAction.Open) { m_iOpenScopeCount++; } else m_iOpenScopeCount--; }
/************************** * * Helper to ensure arrays are large enough * **************************/ internal void EnsureCapacity() { if (m_iCount == 0) { // First time. Allocate the arrays. m_iOffsets = new int[InitialSize]; m_ScopeActions = new ScopeAction[InitialSize]; m_localSymInfos = new LocalSymInfo[InitialSize]; } else if (m_iCount == m_iOffsets.Length) { // the arrays are full. Enlarge the arrays int[] temp = new int [m_iCount * 2]; Array.Copy(m_iOffsets, temp, m_iCount); m_iOffsets = temp; ScopeAction[] tempSA = new ScopeAction[m_iCount * 2]; Array.Copy(m_ScopeActions, tempSA, m_iCount); m_ScopeActions = tempSA; LocalSymInfo[] tempLSI = new LocalSymInfo[m_iCount * 2]; Array.Copy(m_localSymInfos, tempLSI, m_iCount); m_localSymInfos = tempLSI; } }
/// <summary> /// Runs an action and puts it in the undo list. /// </summary> /// <param name="action">action to run</param> public void Run(IAction action) { if (action == null) { throw new ArgumentNullException("action"); } bool changed = false; recursion++; try { switch (state) { case UndoRedoManagerState.Idle: changed = InternalClearRedo(); state = UndoRedoManagerState.ProcessDo; current.prime = null; current.list = new List <IAction>(); break; case UndoRedoManagerState.ProcessDo: break; default: throw new InvalidOperationException(); } ScopeAction scope = action as ScopeAction; if (action.Run(this, ActionType.Do)) { IAction item = action; Merge(current.list, ref item); if ((item != null) && !IsSecondary(item)) { if ((current.prime == null) || (recursion == 1) && (scope == null)) { current.prime = item; } } } if (recursion != 1) { return; } if (current.prime == null) { // There is no prime action. // We can cancel whole action. UndoCurrent(); return; } bool hasPrimary = false; for (int i = 0, c = current.list.Count; i < c; i++) { IAction item = current.list[i]; if ((current.prime != item) && !IsSecondary(item)) { hasPrimary = true; break; } } // End of scope. if (!hasPrimary && (scope != null)) { UndoCurrent(); return; } changed = true; bool addAction = true; if (!hasPrimary && (actions.Count != 0)) { // Merge previous action with a new one. Action previousAction = actions[actions.Count - 1]; IMergeableAction mergeableAction = previousAction.prime as IMergeableAction; if (mergeableAction != null) { IAction mergedAction; mergeList.Add(current.prime); try { mergedAction = mergeableAction.Merge(this, mergeList); addAction = mergeList.Count != 0; int index = current.list.IndexOf(current.prime); if (addAction) { current.prime = mergeList[0]; if (index != -1) { current.list[index] = current.prime; } } else { current.prime = mergedAction; current.list.RemoveAt(index); } } finally { mergeList.Clear(); } if (!addAction) { if (previousAction.list != null) { Merge(previousAction.list, current.list); current.list = previousAction.list; } if (current.prime == null) { UndoCurrent(); actions.RemoveAt(actions.Count - 1); } else { if (current.list.Count < 2) { current.list = null; } actions[actions.Count - 1] = current; } return; } } } if (addAction) { if (current.list.Count < 2) { current.list = null; } actions.Add(current); } } finally { if (--recursion == 0) { state = UndoRedoManagerState.Idle; redoPosition = actions.Count; if (CheckUndoListSize()) { changed = true; } if (changed) { OnChanged(); } } } }