private void PreserveFunctionScalarPropertyMapping( CommandProcessorContext cpc, FunctionScalarProperty fsp, Property createdComplexTypeProperty) { // this represents a path to a scalar Property in the original EntityType properties tree var propertiesChain = fsp.GetMappedPropertiesList(); // we need to create a corresponding path in changed EntityType // in order to do that we need to replace first (root) item with a created property from ComplexType... propertiesChain.RemoveAt(0); propertiesChain.Insert(0, createdComplexTypeProperty); // and add the created EntityType complex property as a root of that path propertiesChain.Insert(0, _createdComplexProperty); var mf = fsp.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction; Debug.Assert( null != mf, "PreserveFunctionScalarPropertyMapping(): Could not find ancestor of type + " + typeof(ModificationFunction).FullName); if (null != mf) { var cmd = new CreateFunctionScalarPropertyTreeCommand( mf, propertiesChain, null, fsp.ParameterName.Target, fsp.Version.Value); CommandProcessor.InvokeSingleCommand(cpc, cmd); } }
protected override void InvokeInternal(CommandProcessorContext cpc) { Debug.Assert(cpc != null, "InvokeInternal is called when ExitingFunctionScalarProperty is null."); // safety check, this should never be hit if (_existingFunctionScalarProperty == null) { throw new InvalidOperationException("InvokeInternal is called when ExitingFunctionScalarProperty is null."); } if (_propChain == null && _pointingNavProp == null && _param == null && _version != null) { // setting new version only if (string.Compare(_existingFunctionScalarProperty.Version.Value, _version, StringComparison.CurrentCulture) != 0) { var mfAncestor = _existingFunctionScalarProperty.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction; Debug.Assert( mfAncestor != null, "Bad attempt to set version on FunctionScalarProperty which does not have a ModificationFunction ancestor"); if (mfAncestor != null) { Debug.Assert( mfAncestor.FunctionType == ModificationFunctionType.Update, "Bad attempt to set version on FunctionScalarProperty which has a ModificationFunction ancestor whose FunctionType is " + mfAncestor.FunctionType.ToString() + ". Should be " + ModificationFunctionType.Update.ToString()); if (mfAncestor.FunctionType == ModificationFunctionType.Update) { _existingFunctionScalarProperty.Version.Value = _version; } } } _updatedFunctionScalarProperty = _existingFunctionScalarProperty; return; } // if not just setting version then need to delete and re-create FunctionScalarProperty // to allow for changes in properties chain // where nulls have been passed in, use existing values (except for _pointingNavProp where null // indicates "use no NavProp for the new property") var mf = _existingFunctionScalarProperty.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction; Debug.Assert(mf != null, "Bad attempt to change FunctionScalarProperty which does not have a ModificationFunction ancestor"); if (mf == null) { return; } var propChain = (_propChain != null ? _propChain : _existingFunctionScalarProperty.GetMappedPropertiesList()); var parameter = (_param != null ? _param : _existingFunctionScalarProperty.ParameterName.Target); var version = (_version != null ? _version : _existingFunctionScalarProperty.Version.Value); // now construct delete command for existing FunctionScalarProperty followed by create with new properties var cmd1 = _existingFunctionScalarProperty.GetDeleteCommand(); var cmd2 = new CreateFunctionScalarPropertyTreeCommand(mf, propChain, _pointingNavProp, parameter, version); cmd2.PostInvokeEvent += (o, eventsArgs) => { _updatedFunctionScalarProperty = cmd2.FunctionScalarProperty; Debug.Assert( _updatedFunctionScalarProperty != null, "CreateFunctionScalarPropertyTreeCommand should not result in null FunctionScalarProperty"); }; var cp = new CommandProcessor(cpc, cmd1, cmd2); try { cp.Invoke(); } finally { _updatedFunctionScalarProperty = null; } }
protected override void InvokeInternal(CommandProcessorContext cpc) { Debug.Assert(cpc != null, "InvokeInternal is called when ExitingFunctionScalarProperty is null."); // safety check, this should never be hit if (_existingFunctionScalarProperty == null) { throw new InvalidOperationException("InvokeInternal is called when ExitingFunctionScalarProperty is null."); } if (_propChain == null && _pointingNavProp == null && _param == null && _version != null) { // setting new version only if (string.Compare(_existingFunctionScalarProperty.Version.Value, _version, StringComparison.CurrentCulture) != 0) { var mfAncestor = _existingFunctionScalarProperty.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction; Debug.Assert( mfAncestor != null, "Bad attempt to set version on FunctionScalarProperty which does not have a ModificationFunction ancestor"); if (mfAncestor != null) { Debug.Assert( mfAncestor.FunctionType == ModificationFunctionType.Update, "Bad attempt to set version on FunctionScalarProperty which has a ModificationFunction ancestor whose FunctionType is " + mfAncestor.FunctionType.ToString() + ". Should be " + ModificationFunctionType.Update.ToString()); if (mfAncestor.FunctionType == ModificationFunctionType.Update) { _existingFunctionScalarProperty.Version.Value = _version; } } } _updatedFunctionScalarProperty = _existingFunctionScalarProperty; return; } // if not just setting version then need to delete and re-create FunctionScalarProperty // to allow for changes in properties chain // where nulls have been passed in, use existing values (except for _pointingNavProp where null // indicates "use no NavProp for the new property") var mf = _existingFunctionScalarProperty.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction; Debug.Assert(mf != null, "Bad attempt to change FunctionScalarProperty which does not have a ModificationFunction ancestor"); if (mf == null) { return; } var propChain = (_propChain != null ? _propChain : _existingFunctionScalarProperty.GetMappedPropertiesList()); var parameter = (_param != null ? _param : _existingFunctionScalarProperty.ParameterName.Target); var version = (_version != null ? _version : _existingFunctionScalarProperty.Version.Value); // now construct delete command for existing FunctionScalarProperty followed by create with new properties var cmd1 = _existingFunctionScalarProperty.GetDeleteCommand(); var cmd2 = new CreateFunctionScalarPropertyTreeCommand(mf, propChain, _pointingNavProp, parameter, version); cmd2.PostInvokeEvent += (o, eventsArgs) => { _updatedFunctionScalarProperty = cmd2.FunctionScalarProperty; Debug.Assert( _updatedFunctionScalarProperty != null, "CreateFunctionScalarPropertyTreeCommand should not result in null FunctionScalarProperty"); }; var cp = new CommandProcessor(cpc, cmd1, cmd2); try { cp.Invoke(); } finally { _updatedFunctionScalarProperty = null; } }
private void PreserveFunctionScalarPropertyMapping( CommandProcessorContext cpc, FunctionScalarProperty fsp, Property createdComplexTypeProperty) { // this represents a path to a scalar Property in the original EntityType properties tree var propertiesChain = fsp.GetMappedPropertiesList(); // we need to create a corresponding path in changed EntityType // in order to do that we need to replace first (root) item with a created property from ComplexType... propertiesChain.RemoveAt(0); propertiesChain.Insert(0, createdComplexTypeProperty); // and add the created EntityType complex property as a root of that path propertiesChain.Insert(0, _createdComplexProperty); var mf = fsp.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction; Debug.Assert( null != mf, "PreserveFunctionScalarPropertyMapping(): Could not find ancestor of type + " + typeof(ModificationFunction).FullName); if (null != mf) { var cmd = new CreateFunctionScalarPropertyTreeCommand( mf, propertiesChain, null, fsp.ParameterName.Target, fsp.Version.Value); CommandProcessor.InvokeSingleCommand(cpc, cmd); } }
// <summary> // The mapping view model contains a MappingFunctionScalarProperty for every parameter in the function. The user can clear out the // underlying scalar property, but that doesn't remove or add the MappingFunctionScalarProperty. We need the placeholder // in the view model to show the nodes in the Trid even if there isn't a mapping. Thus, we don't need to call // this.Parent.AddChild(this) since its already there. // </summary> internal void CreateModelItem(CommandProcessorContext cpc, EditingContext context, List<Property> propertiesChain) { Debug.Assert(propertiesChain != null, "The propertiesChain cannot be null"); Debug.Assert(context != null, "The context argument cannot be null"); Debug.Assert(ScalarProperty == null, "Don't call this method if we already have a ModelItem"); Debug.Assert(MappingModificationFunctionMapping.Function != null, "The parent item isn't set up correctly"); if (propertiesChain == null || context == null || ScalarProperty != null || MappingModificationFunctionMapping == null) { return; } Debug.Assert(propertiesChain.Count > 0, "propertiesChain cannot be empty"); if (propertiesChain.Count <= 0) { return; } Context = context; var mf = MappingModificationFunctionMapping.ModificationFunction; if (null == mf) { Debug.Fail("this.MappingModificationFunctionMapping.ModificationFunction is null"); return; } // use the stored Parameter var parameter = StoreParameter; if (parameter == null) { return; } // create a context if we weren't passed one if (cpc == null) { cpc = new CommandProcessorContext( Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_CreateScalarProperty); } // create the FunctionScalarProperty command (including any intermediate ComplexProperty's or AssociationEnd's) var version = (MappingModificationFunctionMapping.ModificationFunctionType == ModificationFunctionType.Update ? ModelConstants.FunctionScalarPropertyVersionCurrent : null); var cmd = new CreateFunctionScalarPropertyTreeCommand(mf, propertiesChain, _pointingNavProperty, parameter, version); // set up our post event to fix up the view model cmd.PostInvokeEvent += (o, eventsArgs) => { var fsp = cmd.FunctionScalarProperty; Debug.Assert(fsp != null, "CreateFunctionScalarPropertyTreeCommand did not create a FunctionScalarProperty"); // fix up our view model (we don't have to add this to the parent's children collection // because we created a placeholder row already for every parameter in the function) ModelItem = fsp; }; try { // now make the change var cp = new CommandProcessor(cpc, cmd); cp.Invoke(); } catch { ModelItem = null; throw; } }