void OnCasePropertyChanged(DependencyPropertyChangedEventArgs e) { bool isUndoRedoInProgress = this.IsUndoRedoInProgress(); if (!this.internalChange && !isUndoRedoInProgress) { T oldValue = (T)e.OldValue; T newValue = (T)e.NewValue; if (newValue is string && newValue != null) { newValue = (T)((object)((string)((object)newValue)).Trim()); } string oldViewStateKey = string.Empty; if (!this.ContainsKey(newValue)) { using (EditingScope es = (EditingScope)this.flowSwitchModelItem.BeginEdit(SR.FlowSwitchCaseRenameEditingScopeDesc)) { ModelItem flowElementMI = null; flowElementMI = GenericFlowSwitchHelper.GetCaseModelItem(this.flowSwitchModelItem.Properties["Cases"], oldValue); GenericFlowSwitchHelper.RemoveCase(this.flowSwitchModelItem.Properties["Cases"], oldValue); oldViewStateKey = GenericFlowSwitchHelper.GetString(oldValue, typeof(T)) + CaseViewStateKeyAppendString; //Add the new value GenericFlowSwitchHelper.AddCase(this.flowSwitchModelItem.Properties["Cases"], newValue, flowElementMI.GetCurrentValue()); //Update the viewstate for the flowswitch. this.UpdateViewState(oldViewStateKey, GenericFlowSwitchHelper.GetString(newValue, typeof(T)) + CaseViewStateKeyAppendString); //Making sure the value for Case is always trimmed. this.internalChange = true; this.ModelItem.Properties["Case"].SetValue(newValue); es.Complete(); } } else { this.internalChange = true; this.CaseObject = oldValue; throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidFlowSwitchCaseMessage)); } } this.internalChange = false; }
// oldNewFlowNodeMap: <OldFlowNode, NewFlowNode> // sometimes, OldFlowNode == NewFlowNode, say, FlowNode is a FlowDecesion. // if FlowNode is FlowStep, OldFlowNode != NewFlowNode public static void GenericRemapFlowSwitch <T>(FlowNode currentFlowElement, ModelItem modelItem, Dictionary <FlowNode, FlowNode> oldNewFlowNodeMap) { FlowSwitch <T> currentFlowSwitch = (FlowSwitch <T>)currentFlowElement; //Update the default case. FlowNode defaultCase = currentFlowSwitch.Default; if (defaultCase != null && oldNewFlowNodeMap.ContainsKey(defaultCase)) { modelItem.Properties["Default"].SetValue(oldNewFlowNodeMap[defaultCase]); } else { modelItem.Properties["Default"].SetValue(null); } // collect all the cases that should be update Dictionary <object, object> keyValueMap = new Dictionary <object, object>(); foreach (T key in currentFlowSwitch.Cases.Keys) { if (oldNewFlowNodeMap.ContainsKey(currentFlowSwitch.Cases[key])) { keyValueMap.Add(key, oldNewFlowNodeMap[currentFlowSwitch.Cases[key]]); } } // Update the Cases dictionary. ModelProperty casesProperty = modelItem.Properties["Cases"]; // remove all key foreach (ModelItem key in GenericFlowSwitchHelper.GetCaseKeys(casesProperty)) { GenericFlowSwitchHelper.RemoveCase(casesProperty, key.GetCurrentValue()); } // add back keys foreach (T key in keyValueMap.Keys) { GenericFlowSwitchHelper.AddCase(casesProperty, key, keyValueMap[key]); } }
void OnIsDefaultPropertyChanged(DependencyPropertyChangedEventArgs e) { bool isUndoRedoInProgress = this.IsUndoRedoInProgress(); if (!this.internalDefaultCaseChange && !isUndoRedoInProgress) { bool value = (bool)e.NewValue; bool oldValue = (bool)e.OldValue; if (value) { if (object.Equals(this.flowSwitchModelItem.Properties["Default"].Value, null)) { using (EditingScope es = (EditingScope)this.flowSwitchModelItem.BeginEdit(SR.FlowSwitchCaseRenameEditingScopeDesc)) { ModelItem flowNodeMI = GenericFlowSwitchHelper.GetCaseModelItem(this.flowSwitchModelItem.Properties["Cases"], this.CaseObject); GenericFlowSwitchHelper.RemoveCase(this.flowSwitchModelItem.Properties["Cases"], this.CaseObject); this.flowSwitchModelItem.Properties["Default"].SetValue(flowNodeMI); this.UpdateViewState(this.CaseName + CaseViewStateKeyAppendString, DefaultConnectorViewStateKey); this.internalChange = true; es.Complete(); } } else { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; throw FxTrace.Exception.AsError(new InvalidOperationException(SR.DefaultCaseExists)); } } else { if (oldValue) { using (EditingScope es = (EditingScope)this.flowSwitchModelItem.BeginEdit(SR.FlowSwitchCaseRenameEditingScopeDesc)) { ModelItem defaultCase = this.flowSwitchModelItem.Properties["Default"].Value; object uniqueCase = null; string errorMessage = string.Empty; Type typeArgument = typeof(T); if (GenericFlowSwitchHelper.CanBeGeneratedUniquely(typeArgument)) { string caseName = GenericFlowSwitchHelper.GetCaseName(this.flowSwitchModelItem.Properties["Cases"], typeArgument, out errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; throw FxTrace.Exception.AsError(new InvalidOperationException(errorMessage)); } uniqueCase = GenericFlowSwitchHelper.GetObject(caseName, typeArgument); } else { FlowSwitchCaseEditorDialog editor = new FlowSwitchCaseEditorDialog(this.flowSwitchModelItem, ((WorkflowViewElement)this.flowSwitchModelItem.View).Context, this.flowSwitchModelItem.View, SR.ChangeCaseValue, this.flowSwitchModelItem.ItemType.GetGenericArguments()[0]); editor.WindowSizeToContent = SizeToContent.WidthAndHeight; if (!editor.ShowOkCancel()) { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; return; } uniqueCase = editor.Case; if (GenericFlowSwitchHelper.ContainsCaseKey(this.flowSwitchModelItem.Properties["Cases"], uniqueCase)) { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidFlowSwitchCaseMessage)); } } this.flowSwitchModelItem.Properties["Default"].SetValue(null); this.flowSwitchModelItem.Properties[FlowSwitchLabelFeature.DefaultCaseDisplayNamePropertyName].SetValue(FlowSwitchLabelFeature.DefaultCaseDisplayNameDefaultValue); this.internalChange = true; if (typeof(string) != typeof(T)) { this.ModelItem.Properties["Case"].SetValue(uniqueCase); GenericFlowSwitchHelper.AddCase(this.flowSwitchModelItem.Properties["Cases"], uniqueCase, defaultCase.GetCurrentValue()); } else { this.ModelItem.Properties["Case"].SetValue(uniqueCase); GenericFlowSwitchHelper.AddCase(this.flowSwitchModelItem.Properties["Cases"], uniqueCase, defaultCase.GetCurrentValue()); } this.UpdateViewState(DefaultConnectorViewStateKey, GenericFlowSwitchHelper.GetString(uniqueCase, typeof(T)) + CaseViewStateKeyAppendString); es.Complete(); this.internalChange = false; } this.internalDefaultCaseChange = false; } } } this.internalDefaultCaseChange = false; }
private IFlowSwitchLink DeleteLinkImpl(Connector link, bool isMoveOrAutoSplit = false, HashSet <ModelItem> referenceUpdatedModelItems = null) { IFlowSwitchLink caseKey = null; ModelItem linkModelItem = FlowchartDesigner.GetLinkModelItem(link); if (referenceUpdatedModelItems != null && referenceUpdatedModelItems.Contains(linkModelItem)) { return(caseKey); } ConnectionPoint srcConnectionPoint = FreeFormPanel.GetSourceConnectionPoint(link); ConnectionPoint destConnectionPoint = FreeFormPanel.GetDestinationConnectionPoint(link); if (typeof(FlowStep).IsAssignableFrom(linkModelItem.ItemType)) { linkModelItem.Properties["Next"].SetValue(null); } else if (typeof(FlowDecision).IsAssignableFrom(linkModelItem.ItemType)) { //Determine if it is True or False branch. if (srcConnectionPoint.Equals(FlowchartDesigner.GetTrueConnectionPoint(srcConnectionPoint.ParentDesigner))) { //True branch linkModelItem.Properties["True"].SetValue(null); } else { linkModelItem.Properties["False"].SetValue(null); } } else if (typeof(IFlowSwitchLink).IsAssignableFrom(linkModelItem.ItemType)) { IFlowSwitchLink flowSwitchLink = (IFlowSwitchLink)linkModelItem.GetCurrentValue(); caseKey = flowSwitchLink; //Transitioning from the fakeModelItem world to the real ModelItem world. FlowNode fs = flowSwitchLink.ParentFlowSwitch; ModelItem realFlowSwitchMI = (this.ModelItem as IModelTreeItem).ModelTreeManager.WrapAsModelItem(fs); if (referenceUpdatedModelItems != null && referenceUpdatedModelItems.Contains(realFlowSwitchMI)) { return(caseKey); } if (flowSwitchLink.IsDefaultCase) { realFlowSwitchMI.Properties["Default"].SetValue(null); if (!isMoveOrAutoSplit) { realFlowSwitchMI.Properties[FlowSwitchLabelFeature.DefaultCaseDisplayNamePropertyName].SetValue(FlowSwitchLabelFeature.DefaultCaseDisplayNameDefaultValue); } } else { GenericFlowSwitchHelper.RemoveCase(realFlowSwitchMI.Properties["Cases"], flowSwitchLink.CaseObject); } } else // StartNode { this.ModelItem.Properties["StartNode"].SetValue(null); } this.StoreConnectorViewState(linkModelItem, null, srcConnectionPoint, true); return(caseKey); }