src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/DomainClasses/EntityDesignerViewModel.cs
/// <summary>
///     Invokes the ModelChanges within the ModelChangeContext that is typically wrapped within a
///     DSL transaction. This will mutate our model composed of EFObjects and will also push changes
///     down to the XLinq tree in the XML Model.
/// </summary>
Invokes the ModelChanges within the ModelChangeContext that is typically wrapped within a
DSL transaction. This will mutate our model composed of EFObjects and will also push changes
down to the XLinq tree in the XML Model.
Invokes the ModelChanges within the ModelChangeContext that is typically wrapped within a DSL transaction . This will mutate our model composed of EFObjects and will also push changes down to the XLinq tree in the XML Model .
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        private void ProcessViewModelChanges(string name, IList<ViewModelChange> viewModelChanges)
        {
            if (viewModelChanges != null
                && viewModelChanges.Count > 0)
            {
                var context = new EfiTransactionContext();
                var containsDiagramChanges = viewModelChanges.Any(vmc => vmc.IsDiagramChange);
                context.Add(
                    EfiTransactionOriginator.TransactionOriginatorDiagramId,
                    new ModelDesigner.DiagramContextItem(DiagramId, containsDiagramChanges));
                var cpc = new CommandProcessorContext(
                    EditingContext, EfiTransactionOriginator.EntityDesignerOriginatorId, name, null, context);
                var cp = new CommandProcessor(cpc);
                if (Store.PropertyBag.ContainsKey(DeleteUnmappedStorageEntitySetsProperty))
                {
                    var unmappedMasterList =
                        Store.PropertyBag[DeleteUnmappedStorageEntitySetsProperty] as List<ICollection<StorageEntitySet>>;
                    Store.PropertyBag.Remove(DeleteUnmappedStorageEntitySetsProperty);
                    if (unmappedMasterList != null)
                    {
                        foreach (var unmappedEntitySets in unmappedMasterList)
                        {
                            var duse = new DeleteUnmappedStorageEntitySetsCommand(unmappedEntitySets);
                            cp.EnqueueCommand(duse);
                        }
                    }
                }
                var setParentUndoUnit = false;
                try
                {
                    if (cpc.EditingContext.ParentUndoUnitStarted == false)
                    {
                        cpc.EditingContext.ParentUndoUnitStarted = true;
                        cpc.Artifact.XmlModelProvider.BeginUndoScope(name);
                        setParentUndoUnit = true;
                    }
                    var cmd = new DelegateCommand(
                        () =>
                            {
                                foreach (var change in viewModelChanges)
                                {
                                    change.Invoke(cpc);
                                }
                            });
                    cp.EnqueueCommand(cmd);
                    cp.Invoke();
                }
                catch (Exception e)
                {
                    if (!(e is CommandValidationFailedException || e is FileNotEditableException))
                    {
                        Debug.Fail("Exception thrown while committing change to Model. " + e.Message);
                    }
                    throw;
                }
                finally
                {
                    if (setParentUndoUnit)
                    {
                        cpc.EditingContext.ParentUndoUnitStarted = false;
                        cpc.Artifact.XmlModelProvider.EndUndoScope();
                    }
                }
            }
        }
[ SuppressMessage ( " " , " " ) ] private void ProcessViewModelChanges ( string name , IList < ViewModelChange > viewModelChanges ) { if ( viewModelChanges != null && viewModelChanges . Count > 0 ) { var context = new EfiTransactionContext ( ) ; var containsDiagramChanges = viewModelChanges . Any ( vmc => vmc . IsDiagramChange ) ; context . Add ( EfiTransactionOriginator . TransactionOriginatorDiagramId , new ModelDesigner . DiagramContextItem ( DiagramId , containsDiagramChanges ) ) ; var cpc = new CommandProcessorContext ( EditingContext , EfiTransactionOriginator . EntityDesignerOriginatorId , name , null , context ) ; var cp = new CommandProcessor ( cpc ) ; if ( Store . PropertyBag . ContainsKey ( DeleteUnmappedStorageEntitySetsProperty ) ) { var unmappedMasterList = Store . PropertyBag [ DeleteUnmappedStorageEntitySetsProperty ] as List < ICollection < StorageEntitySet > > ; Store . PropertyBag . Remove ( DeleteUnmappedStorageEntitySetsProperty ) ; if ( unmappedMasterList != null ) { foreach ( var unmappedEntitySets in unmappedMasterList ) { var duse = new DeleteUnmappedStorageEntitySetsCommand ( unmappedEntitySets ) ; cp . EnqueueCommand ( duse ) ; } } } var setParentUndoUnit = false ; try { if ( cpc . EditingContext . ParentUndoUnitStarted == false ) { cpc . EditingContext . ParentUndoUnitStarted = true ; cpc . Artifact . XmlModelProvider . BeginUndoScope ( name ) ; setParentUndoUnit = true ; } var cmd = new DelegateCommand ( ( ) => { foreach ( var change in viewModelChanges ) { change . Invoke ( cpc ) ; } } ) ; cp . EnqueueCommand ( cmd ) ; cp . Invoke ( ) ; } catch ( Exception e ) { if ( ! ( e is CommandValidationFailedException || e is FileNotEditableException ) ) { Debug . Fail ( " " + e . Message ) ; } throw ; } finally { if ( setParentUndoUnit ) { cpc . EditingContext . ParentUndoUnitStarted = false ; cpc . Artifact . XmlModelProvider . EndUndoScope ( ) ; } } } }
Invokes the ModelChanges within the ModelChangeContext that is typically wrapped within a
DSL transaction.
Invokes the ModelChanges within the ModelChangeContext that is typically wrapped within a DSL transaction .
// check if the DeleteUnmappedStorageEntitySetsProperty property is set // if the property is set then unset it and add a // command to remove these for each item in the master list
name
string
viewModelChanges
IList<ViewModelChange>