protected override void InvokeInternal(CommandProcessorContext cpc) { var cp = new CommandProcessor(cpc); CreateFunctionComplexPropertyCommand preReqCmd = null; for (var i = 0; i < _propertyChain.Count; i++) { var property = _propertyChain[i]; Debug.Assert(property.EntityModel.IsCSDL, "Each Property in the chain must be in the CSDL"); var complexConceptualProperty = property as ComplexConceptualProperty; if (complexConceptualProperty != null) { Debug.Assert(i < _propertyChain.Count - 1, "Last property shouldn't be ComplexConceptualProperty"); CreateFunctionComplexPropertyCommand cmd = null; if (preReqCmd == null) { // first property has a mapping whose parent is the ModificationFunction itself cmd = new CreateFunctionComplexPropertyCommand(_modificationFunction, complexConceptualProperty); } else { // later properties have a mapping whose parent is the ComplexProperty produced from the previous command cmd = new CreateFunctionComplexPropertyCommand(preReqCmd, complexConceptualProperty); } // set up the prereq Command to use for next time around this loop and for the // CreateFunctionScalarPropertyCommand below preReqCmd = cmd; // enqueue the command cp.EnqueueCommand(cmd); } else { Debug.Assert(i == _propertyChain.Count - 1, "This should be the last property"); CreateFunctionScalarPropertyCommand cmd = null; if (preReqCmd == null) { // create the FunctionScalarProperty command without any other properties in the property chain cmd = new CreateFunctionScalarPropertyCommand( _modificationFunction, property, _navPropPointingToProperty, _parameter, _version); } else { // create the FunctionScalarProperty command using the command for the previous property in the property chain cmd = new CreateFunctionScalarPropertyCommand(preReqCmd, property, _navPropPointingToProperty, _parameter, _version); } cp.EnqueueCommand(cmd); cp.Invoke(); _createdProperty = cmd.FunctionScalarProperty; if (_createdProperty != null) { XmlModelHelper.NormalizeAndResolve(_createdProperty); } return; } } }
/// <summary> /// This method lets you change just the version of a FunctionScalarProperty. /// </summary> /// <param name="fspToChange">FunctionScalarProperty to be changed</param> /// <param name="version">New version value</param> internal ChangeFunctionScalarPropertyCommand(FunctionScalarProperty fspToChange, string version) { Debug.Assert(version != null, "Version can't be null"); Debug.Assert( ModelConstants.FunctionScalarPropertyVersionOriginal.Equals(version, StringComparison.Ordinal) || ModelConstants.FunctionScalarPropertyVersionCurrent.Equals(version, StringComparison.Ordinal), "Version must be " + ModelConstants.FunctionScalarPropertyVersionOriginal + " or " + ModelConstants.FunctionScalarPropertyVersionCurrent + ". Actual value: " + version); CommandValidation.ValidateFunctionScalarProperty(fspToChange); _existingFunctionScalarProperty = fspToChange; _version = version; }
internal static FunctionScalarProperty CreateFunctionScalarPropertyCommon( EFElement parent, Property property, Parameter parm, string version) { var fsp = new FunctionScalarProperty(parent, null); fsp.Name.SetRefName(property); fsp.ParameterName.SetRefName(parm); if (string.IsNullOrEmpty(version) == false) { fsp.Version.Value = version; } var mf = parent as ModificationFunction; var fae = parent as FunctionAssociationEnd; var fcp = parent as FunctionComplexProperty; if (mf != null) { mf.AddScalarProperty(fsp); } else if (fae != null) { fae.AddScalarProperty(fsp); } else if (fcp != null) { fcp.AddScalarProperty(fsp); } else { Debug.Fail( "Unknown parent type (" + parent.GetType().FullName + ") sent to CreateFunctionScalarPropertyCommand.CreateFunctionScalarPropertyCommon()"); } XmlModelHelper.NormalizeAndResolve(fsp); return(fsp); }
/// <summary> /// Change the property pointed to by the FunctionScalarProperty. This may involve /// change of property chain, change to/from a NavProp property or change of parameter. /// </summary> /// <param name="fspToChange">FunctionScalarProperty to be changed</param> /// <param name="newPropertiesChain">property chain for new Property</param> /// <param name="newPointingNavProp">NavProp for new Property (null indicates new Property not reached via NavProp)</param> /// <param name="newParameter">Parameter to which new Property should be mapped (null indicates use existing Parameter)</param> /// <param name="newVersion">Version attribute for new Property (null indicates use existing value). Only appropriate for Update Functions</param> internal ChangeFunctionScalarPropertyCommand( FunctionScalarProperty fspToChange, List <Property> newPropertiesChain, NavigationProperty newPointingNavProp, Parameter newParameter, string newVersion) { Debug.Assert( !(newPropertiesChain == null && newPointingNavProp == null && newParameter == null), "Not all of newPropertiesChain, newPointingNavProp, newParameter can be null"); if (newPropertiesChain == null && newPointingNavProp == null && newParameter == null) { return; } Debug.Assert( string.IsNullOrEmpty(newVersion) || ModelConstants.FunctionScalarPropertyVersionOriginal.Equals(newVersion, StringComparison.Ordinal) || ModelConstants.FunctionScalarPropertyVersionCurrent.Equals(newVersion, StringComparison.Ordinal), "newVersion must be empty or " + ModelConstants.FunctionScalarPropertyVersionOriginal + " or " + ModelConstants.FunctionScalarPropertyVersionCurrent + ". Actual value: " + newVersion); CommandValidation.ValidateFunctionScalarProperty(fspToChange); if (newPointingNavProp != null) { CommandValidation.ValidateNavigationProperty(newPointingNavProp); } if (newParameter != null) { CommandValidation.ValidateParameter(newParameter); } _existingFunctionScalarProperty = fspToChange; _propChain = newPropertiesChain; _pointingNavProp = newPointingNavProp; _param = newParameter; _version = newVersion; }
/// <summary> /// Change the property pointed to by the FunctionScalarProperty. This may involve /// change of property chain, change to/from a NavProp property or change of parameter. /// </summary> /// <param name="fspToChange">FunctionScalarProperty to be changed</param> /// <param name="newPropertiesChain">property chain for new Property</param> /// <param name="newPointingNavProp">NavProp for new Property (null indicates new Property not reached via NavProp)</param> /// <param name="newParameter">Parameter to which new Property should be mapped (null indicates use existing Parameter)</param> /// <param name="newVersion">Version attribute for new Property (null indicates use existing value). Only appropriate for Update Functions</param> internal ChangeFunctionScalarPropertyCommand( FunctionScalarProperty fspToChange, List<Property> newPropertiesChain, NavigationProperty newPointingNavProp, Parameter newParameter, string newVersion) { Debug.Assert( !(newPropertiesChain == null && newPointingNavProp == null && newParameter == null), "Not all of newPropertiesChain, newPointingNavProp, newParameter can be null"); if (newPropertiesChain == null && newPointingNavProp == null && newParameter == null) { return; } Debug.Assert( string.IsNullOrEmpty(newVersion) || ModelConstants.FunctionScalarPropertyVersionOriginal.Equals(newVersion, StringComparison.Ordinal) || ModelConstants.FunctionScalarPropertyVersionCurrent.Equals(newVersion, StringComparison.Ordinal), "newVersion must be empty or " + ModelConstants.FunctionScalarPropertyVersionOriginal + " or " + ModelConstants.FunctionScalarPropertyVersionCurrent + ". Actual value: " + newVersion); CommandValidation.ValidateFunctionScalarProperty(fspToChange); if (newPointingNavProp != null) { CommandValidation.ValidateNavigationProperty(newPointingNavProp); } if (newParameter != null) { CommandValidation.ValidateParameter(newParameter); } _existingFunctionScalarProperty = fspToChange; _propChain = newPropertiesChain; _pointingNavProp = newPointingNavProp; _param = newParameter; _version = newVersion; }
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; } }
internal static FunctionScalarProperty CreateFunctionScalarPropertyCommon( EFElement parent, Property property, Parameter parm, string version) { var fsp = new FunctionScalarProperty(parent, null); fsp.Name.SetRefName(property); fsp.ParameterName.SetRefName(parm); if (string.IsNullOrEmpty(version) == false) { fsp.Version.Value = version; } var mf = parent as ModificationFunction; var fae = parent as FunctionAssociationEnd; var fcp = parent as FunctionComplexProperty; if (mf != null) { mf.AddScalarProperty(fsp); } else if (fae != null) { fae.AddScalarProperty(fsp); } else if (fcp != null) { fcp.AddScalarProperty(fsp); } else { Debug.Fail( "Unknown parent type (" + parent.GetType().FullName + ") sent to CreateFunctionScalarPropertyCommand.CreateFunctionScalarPropertyCommon()"); } XmlModelHelper.NormalizeAndResolve(fsp); return fsp; }
/// <summary> /// Deletes the passed in FunctionScalarProperty /// </summary> /// <param name="sp"></param> internal DeleteFunctionScalarPropertyCommand(FunctionScalarProperty sp) : base(sp) { CommandValidation.ValidateFunctionScalarProperty(sp); }
protected override void InvokeInternal(CommandProcessorContext cpc) { // safety check, this should never be hit Debug.Assert(_property != null && _parm != null, "InvokeInternal is called when _property or _parm is null"); if (_property == null || _parm == null) { throw new InvalidOperationException("InvokeInternal is called when _property or _parm is null"); } // check ModificationFunction or ComplexProperty parent exists Debug.Assert( _parentModFunc != null || _parentComplexProperty != null, "Must have either a ModificationFunction or a FunctionComplexProperty parent to house this ScalarProperty"); if (_parentModFunc == null && _parentComplexProperty == null) { throw new CannotLocateParentItemException(); } // check both ModificationFunction and ComplexProperty parents don't exist Debug.Assert( _parentModFunc == null || _parentComplexProperty == null, "Must not have both a ModificationFunction and a FunctionComplexProperty parent to house this ScalarProperty"); if (_parentModFunc != null && _parentComplexProperty != null) { throw new CannotLocateParentItemException(); } // now create it, either directly under this function mapping, or inside an AssociationEnd // if the entity property is via a NavProp, or inside the parent ComplexProperty if (_parentModFunc != null) { if (_pointingNavProperty == null) { // we can directly add a mapping _sp = CreateFunctionScalarPropertyCommon(_parentModFunc, _property, _parm, _version); } else { // create an AssociationEnd and then add it _sp = CreateFunctionScalarPropertyInAssociationEnd(_parentModFunc, _property, _pointingNavProperty, _parm, _version); } } else if (_parentComplexProperty != null) { // should not have _pointingNavProperty if we have a FunctionComplexProperty parent Debug.Assert( _pointingNavProperty == null, "We're creating a FunctionScalarProperty within a FunctionComplexProperty - but _pointingNavProperty is non-null!"); if (_pointingNavProperty == null) { _sp = CreateFunctionScalarPropertyCommon(_parentComplexProperty, _property, _parm, _version); } } if (_sp == null) { throw new ItemCreationFailureException(); } Debug.Assert( _sp.Name.Target != null && _sp.Name.Target.LocalName.Value == _sp.Name.RefName, (_sp.Name.Target == null ? "Broken entity property resolution - Target is null" : "Broken entity property resolution - Target.LocalName.Value (" + _sp.Name.Target.LocalName.Value + ") != RefName (" + _sp.Name.RefName + ")")); Debug.Assert( _sp.ParameterName.Target != null && _sp.ParameterName.Target.LocalName.Value == _sp.ParameterName.RefName, (_sp.ParameterName.Target == null ? "Broken parameter resolution - Target is null" : "Broken parameter resolution - Target.LocalName.Value (" + _sp.ParameterName.Target.LocalName.Value + ") != RefName (" + _sp.ParameterName.RefName + ")")); }
internal static void ValidateFunctionScalarProperty(FunctionScalarProperty sp) { ValidateEFElement(sp); }
public MappingFunctionScalarProperty(EditingContext context, FunctionScalarProperty scalarProperty, MappingEFElement parent) : base(context, scalarProperty, parent) { }
internal override bool ParseSingleElement(ICollection<XName> unprocessedElements, XElement elem) { if (elem.Name.LocalName == FunctionScalarProperty.ElementName) { var prop = new FunctionScalarProperty(this, elem); _properties.Add(prop); prop.Parse(unprocessedElements); } else { return base.ParseSingleElement(unprocessedElements, elem); } return true; }
internal void AddScalarProperty(FunctionScalarProperty prop) { _properties.Add(prop); }
internal void LoadScalarProperties() { if (null == _scalarProperties) { _scalarProperties = new List <MappingFunctionScalarProperty>(); // load children from model // note: have to go to parent to get this as this is a dummy node if (Function != null && MappingFunctionEntityType != null && MappingFunctionEntityType.EntityType != null) { var entityType = MappingFunctionEntityType.EntityType; // loop through all of the 'parameters' in the function foreach (var parm in Function.Parameters()) { FunctionScalarProperty existingScalarProperty = null; // for each column, see if we are already have a scalar property var antiDeps = parm.GetAntiDependenciesOfType <FunctionScalarProperty>(); foreach (var scalarProperty in antiDeps) { // this FunctionScalarProperty could be right under the function, nested inside an AssociationEnd, // or N levels deep inside a complex type hierarchy var spmf = scalarProperty.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction; // if we find one, validate it if (scalarProperty != null && scalarProperty.Name.Status == BindingStatus.Known && spmf != null && ModificationFunction == spmf) { // make sure we are looking at something mapped by the entity type we are mapping if (entityType != spmf.ModificationFunctionMapping.EntityTypeMapping.FirstBoundConceptualEntityType) { continue; } // we are already mapping this existingScalarProperty = scalarProperty; break; } } // if we didn't find one, then create a dummy row with just the column info if (existingScalarProperty == null) { var msp = new MappingFunctionScalarProperty(_context, null, this); msp.StoreParameter = parm; _scalarProperties.Add(msp); } else { var msp = (MappingFunctionScalarProperty) ModelToMappingModelXRef.GetNewOrExisting(_context, existingScalarProperty, this); _scalarProperties.Add(msp); } } } } }
internal override bool ParseSingleElement(ICollection<XName> unprocessedElements, XElement elem) { if (elem.Name.LocalName == FunctionScalarProperty.ElementName) { var prop = new FunctionScalarProperty(this, elem); _scalarProperties.Add(prop); prop.Parse(unprocessedElements); } else if (elem.Name.LocalName == FunctionComplexProperty.ElementName) { var prop = new FunctionComplexProperty(this, elem); _complexProperties.Add(prop); prop.Parse(unprocessedElements); } else if (elem.Name.LocalName == FunctionAssociationEnd.ElementName) { var end = new FunctionAssociationEnd(this, elem); _ends.Add(end); end.Parse(unprocessedElements); } else if (elem.Name.LocalName == ResultBinding.ElementName) { var resultBinding = new ResultBinding(this, elem); _resultBindings.Add(resultBinding); resultBinding.Parse(unprocessedElements); } else { return base.ParseSingleElement(unprocessedElements, elem); } return true; }