Example #1
0
 public MappingModificationFunctionMapping(EditingContext context, ModificationFunction functionMapping, MappingEFElement parent)
     : base(context, functionMapping, parent)
 {
     if (functionMapping != null)
     {
         _functionType   = functionMapping.FunctionType;
         _properties     = new MappingFunctionScalarProperties(context, functionMapping, this);
         _resultBindings = new MappingResultBindings(context, functionMapping, this);
     }
 }
 public MappingModificationFunctionMapping(EditingContext context, ModificationFunction functionMapping, MappingEFElement parent)
     : base(context, functionMapping, parent)
 {
     if (functionMapping != null)
     {
         _functionType = functionMapping.FunctionType;
         _properties = new MappingFunctionScalarProperties(context, functionMapping, this);
         _resultBindings = new MappingResultBindings(context, functionMapping, this);
     }
 }
        public override bool Initialize(object component, TreeGridDesignerColumnDescriptor[] columns)
        {
            if (!base.Initialize(component, columns))
            {
                return false;
            }

            var mappingFunctionScalarProperties = component as MappingFunctionScalarProperties;
            if (mappingFunctionScalarProperties != null)
            {
                _mappingFunctionScalarProperties = mappingFunctionScalarProperties;
            }

            return true;
        }
Example #4
0
        private void ClearChildren()
        {
            if (_children != null)
            {
                _children.Clear();
            }

            if (_properties != null)
            {
                _properties.Dispose();
                _properties = null;
            }

            if (_resultBindings != null)
            {
                _resultBindings.Dispose();
                _resultBindings = null;
            }
        }
Example #5
0
        internal override void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
        {
            Debug.Assert(context != null, "null context");

            Debug.Assert(Function == null, "Don't call this method if we already have a ModelItem");
            Debug.Assert(MappingFunctionEntityType.EntityType != null, "The parent item isn't set up correctly");

            Debug.Assert(underlyingModelItem != null, "null underlyingModelItem");

            var function = underlyingModelItem as Function;

            Debug.Assert(
                function != null, "underlyingModelItem must be of type Function, actual type = " + underlyingModelItem.GetType().FullName);
            Debug.Assert(!function.EntityModel.IsCSDL, "The function must be in the SSDL");

            Context = context;

            // create a context if we weren't passed one
            if (cpc == null)
            {
                cpc = new CommandProcessorContext(
                    Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_CreateFunctionMapping);
            }

            // create the commands
            var cmd = new CreateFunctionMappingCommand(MappingFunctionEntityType.EntityType, function, null, _functionType);

            // set up our post event to fix up the view model
            cmd.PostInvokeEvent += (o, eventsArgs) =>
            {
                var mf = cmd.ModificationFunction;
                Debug.Assert(mf != null, "null ModificationFunction");

                // fix up our view model
                ModelItem = mf;
                // The parent item for the function mapping view model always has 3 children; insert, update and delete items.  If there isn�t
                // a function mapped for any of these, then there is still a view model item since we want to display the �creator node� text.
                // Calling this.Parent.AddChild(this) here would make the parent think it had a new child instead of updating the existing one -
                // so it is correct to _not_ call it here.
            };

            var cmd2 = new DelegateCommand(
                () =>
            {
                var mf = ModificationFunction;
                Debug.Assert(
                    mf != null,
                    "Null ModificationFunction when trying to create view-model dummy nodes in MappingModificationFunctionMapping.CreateModelItem()");

                if (mf != null)
                {
                    //set up _properties and _resultBindings here as they are dummy ViewModel nodes
                    // (i.e. don't correspond to any underlying ModelItem)
                    _properties     = new MappingFunctionScalarProperties(context, mf, this);
                    _resultBindings = new MappingResultBindings(context, mf, this);
                    _properties.Parent.AddChild(_properties);
                    _resultBindings.Parent.AddChild(_resultBindings);

                    // now ensure _properties scalar properties children have been calculated
                    // (this creates scalar properties with just the column info
                    // since this ModificationFunction has not yet been mapped)
                    _properties.LoadScalarProperties();

                    // now try and do some match ups between the function and the entity
                    var mappedEntityType = MappingFunctionEntityType.EntityType as ConceptualEntityType;

                    Debug.Assert(
                        MappingFunctionEntityType.EntityType == null || mappedEntityType != null,
                        "EntityType is not ConceptualEntityType");

                    if (mappedEntityType != null)
                    {
                        foreach (var mfsp in _properties.ScalarProperties)
                        {
                            // Try to do some auto-matching of the sproc's parameters to the EntityType's properties.
                            // Search for a property in the mapped EntityType's inheritance hierarchy that matches the
                            // parameter's name. First search this EntityType (both its scalar and complex properties),
                            // then search its parents scalar and complex properties and so on up the hierarchy
                            var propNameToSearchFor = mfsp.StoreParameter.LocalName.Value;
                            var propList            = new List <Property>();
                            var entityTypeToSearch  = mappedEntityType;
                            // reset this back to the mapped EntityType each time through the loop
                            while (entityTypeToSearch != null &&
                                   false
                                   == ModelHelper.FindScalarPropertyPathByLocalName(
                                       entityTypeToSearch, propNameToSearchFor, out propList))
                            {
                                if (entityTypeToSearch.BaseType == null)
                                {
                                    // safety code - this should not happen but will prevent an infinite loop if it does
                                    entityTypeToSearch = null;
                                }
                                else
                                {
                                    entityTypeToSearch = entityTypeToSearch.BaseType.Target;
                                }
                            }

                            // if propList is still empty that means we did not find a match - so leave the parameter unmapped
                            if (propList.Count > 0)
                            {
                                mfsp.CreateModelItem(cpc, _context, propList);
                            }
                        }
                    }
                }
            });

            try
            {
                // now make the change
                var cp = new CommandProcessor(cpc);
                cp.EnqueueCommand(cmd);
                cp.EnqueueCommand(cmd2);
                cp.Invoke();
            }
            catch
            {
                ModelItem = null;
                ClearChildren();

                throw;
            }
        }
 internal ParameterBranch(
     MappingFunctionScalarProperties mappingFunctionScalarProperties, TreeGridDesignerColumnDescriptor[] columns)
     : base(mappingFunctionScalarProperties, columns)
 {
     _mappingFunctionScalarProperties = mappingFunctionScalarProperties;
 }
        private void ClearChildren()
        {
            if (_children != null)
            {
                _children.Clear();
            }

            if (_properties != null)
            {
                _properties.Dispose();
                _properties = null;
            }

            if (_resultBindings != null)
            {
                _resultBindings.Dispose();
                _resultBindings = null;
            }
        }
        internal override void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
        {
            Debug.Assert(context != null, "null context");

            Debug.Assert(Function == null, "Don't call this method if we already have a ModelItem");
            Debug.Assert(MappingFunctionEntityType.EntityType != null, "The parent item isn't set up correctly");

            Debug.Assert(underlyingModelItem != null, "null underlyingModelItem");

            var function = underlyingModelItem as Function;
            Debug.Assert(
                function != null, "underlyingModelItem must be of type Function, actual type = " + underlyingModelItem.GetType().FullName);
            Debug.Assert(!function.EntityModel.IsCSDL, "The function must be in the SSDL");

            Context = context;

            // create a context if we weren't passed one
            if (cpc == null)
            {
                cpc = new CommandProcessorContext(
                    Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_CreateFunctionMapping);
            }

            // create the commands
            var cmd = new CreateFunctionMappingCommand(MappingFunctionEntityType.EntityType, function, null, _functionType);
            // set up our post event to fix up the view model
            cmd.PostInvokeEvent += (o, eventsArgs) =>
                {
                    var mf = cmd.ModificationFunction;
                    Debug.Assert(mf != null, "null ModificationFunction");

                    // fix up our view model
                    ModelItem = mf;
                    // The parent item for the function mapping view model always has 3 children; insert, update and delete items.  If there isn’t 
                    // a function mapped for any of these, then there is still a view model item since we want to display the ‘creator node’ text.
                    // Calling this.Parent.AddChild(this) here would make the parent think it had a new child instead of updating the existing one - 
                    // so it is correct to _not_ call it here.
                };

            var cmd2 = new DelegateCommand(
                () =>
                    {
                        var mf = ModificationFunction;
                        Debug.Assert(
                            mf != null,
                            "Null ModificationFunction when trying to create view-model dummy nodes in MappingModificationFunctionMapping.CreateModelItem()");

                        if (mf != null)
                        {
                            //set up _properties and _resultBindings here as they are dummy ViewModel nodes
                            // (i.e. don't correspond to any underlying ModelItem)
                            _properties = new MappingFunctionScalarProperties(context, mf, this);
                            _resultBindings = new MappingResultBindings(context, mf, this);
                            _properties.Parent.AddChild(_properties);
                            _resultBindings.Parent.AddChild(_resultBindings);

                            // now ensure _properties scalar properties children have been calculated
                            // (this creates scalar properties with just the column info 
                            // since this ModificationFunction has not yet been mapped)
                            _properties.LoadScalarProperties();

                            // now try and do some match ups between the function and the entity
                            var mappedEntityType = MappingFunctionEntityType.EntityType as ConceptualEntityType;

                            Debug.Assert(
                                MappingFunctionEntityType.EntityType == null || mappedEntityType != null,
                                "EntityType is not ConceptualEntityType");

                            if (mappedEntityType != null)
                            {
                                foreach (var mfsp in _properties.ScalarProperties)
                                {
                                    // Try to do some auto-matching of the sproc's parameters to the EntityType's properties.
                                    // Search for a property in the mapped EntityType's inheritance hierarchy that matches the
                                    // parameter's name. First search this EntityType (both its scalar and complex properties),
                                    // then search its parents scalar and complex properties and so on up the hierarchy
                                    var propNameToSearchFor = mfsp.StoreParameter.LocalName.Value;
                                    var propList = new List<Property>();
                                    var entityTypeToSearch = mappedEntityType;
                                    // reset this back to the mapped EntityType each time through the loop
                                    while (entityTypeToSearch != null
                                           && false
                                           == ModelHelper.FindScalarPropertyPathByLocalName(
                                               entityTypeToSearch, propNameToSearchFor, out propList))
                                    {
                                        if (entityTypeToSearch.BaseType == null)
                                        {
                                            // safety code - this should not happen but will prevent an infinite loop if it does
                                            entityTypeToSearch = null;
                                        }
                                        else
                                        {
                                            entityTypeToSearch = entityTypeToSearch.BaseType.Target;
                                        }
                                    }

                                    // if propList is still empty that means we did not find a match - so leave the parameter unmapped
                                    if (propList.Count > 0)
                                    {
                                        mfsp.CreateModelItem(cpc, _context, propList);
                                    }
                                }
                            }
                        }
                    });

            try
            {
                // now make the change
                var cp = new CommandProcessor(cpc);
                cp.EnqueueCommand(cmd);
                cp.EnqueueCommand(cmd2);
                cp.Invoke();
            }
            catch
            {
                ModelItem = null;
                ClearChildren();

                throw;
            }
        }