/// <summary> /// Helper method to update the DefaultableValue if and only if the value has changed /// </summary> /// <param name="existingValue"> /// existing value of attribute (StringOrNone.NoneValue indicates attribute /// currently does not exist) /// </param> /// <param name="newValue"> /// new value of attribute passed into setter (null indicates user did not select /// anything on the drop-down and so no setting should take place, StringOrNone.NoneValue indicates user /// selected '(None)' on the drop-down and so attribute should be removed if present) /// </param> /// <param name="defaultableValueToUpdate"></param> internal static void UpdateDefaultableValueIfValuesDiffer( StringOrNone existingValue, StringOrNone newValue, DefaultableValue <StringOrNone> defaultableValueToUpdate) { if (null == newValue) { // user exited drop-down without selecting anything return; } if (existingValue.Equals(newValue)) { // no change in value - so just return return; } else { // existingValue and valueToSet are different - so update the DefaultableValue // if newValue is NoneValue then set valueToSet to null which will remove the attribute // otherwise use newValue as is var valueToSet = (StringOrNone.NoneValue.Equals(newValue) ? null : newValue); var cmd = new UpdateDefaultableValueCommand <StringOrNone>(defaultableValueToUpdate, valueToSet); var cpc = PropertyWindowViewModelHelper.GetCommandProcessorContext(); CommandProcessor.InvokeSingleCommand(cpc, cmd); } }
protected override void InvokeInternal(CommandProcessorContext cpc) { // if the DesignerInfoPropertySet doesn't exist then we need to create it. if (_designerInfo.PropertySet == null) { _designerInfo.PropertySet = new DesignerInfoPropertySet(_designerInfo, null); } // if the DesignerProperty doesn't exist then we need to create it. DesignerProperty designerProperty; if (!_designerInfo.PropertySet.TryGetDesignerProperty(_name, out designerProperty)) { designerProperty = new DesignerProperty(_designerInfo.PropertySet, null); designerProperty.LocalName.Value = _name; _designerInfo.PropertySet.AddDesignerProperty(_name, designerProperty); } // First let's check make sure any non-valid values are caught up the stack if (!designerProperty.ValueAttr.IsValidValue(_value)) { throw new CommandValidationFailedException( String.Format(CultureInfo.CurrentCulture, Resources.NonValidDesignerProperty, _value, _name)); } // now we update the value of the designer property var cmdUpdateDefaultableValue = new UpdateDefaultableValueCommand<string>(designerProperty.ValueAttr, _value); CommandProcessor.InvokeSingleCommand(cpc, cmdUpdateDefaultableValue); // normalize and resolve the entire DesignerInfo XmlModelHelper.NormalizeAndResolve(_designerInfo); }
protected override void InvokeInternal(CommandProcessorContext cpc) { var cmd = new UpdateDefaultableValueCommand<string>(_typeAccess, _newValue); CommandProcessor.InvokeSingleCommand(cpc, cmd); if (ModelConstants.CodeGenerationAccessInternal.Equals(_newValue, StringComparison.Ordinal)) { var cet = _typeAccess.GetParentOfType(typeof(ConceptualEntityType)) as ConceptualEntityType; Debug.Assert(null != cet, "parent of _typeAccess should be of type " + typeof(ConceptualEntityType).FullName); if (null != cet) { // Note: it is valid for the EntitySet to be null var ces = cet.EntitySet as ConceptualEntitySet; if (null != ces) { var entitySetGetterAccess = ces.GetterAccess.Value; if (ModelConstants.CodeGenerationAccessPublic.Equals(entitySetGetterAccess) || ModelConstants.CodeGenerationAccessProtected.Equals(entitySetGetterAccess)) { // new value is Internal and EntitySet's existing value is Public or Protected // so need to also update the GetterAccess attribute on the EntitySet // (otherwise will get runtime error 6036) var cmd2 = new UpdateDefaultableValueCommand<string>(ces.GetterAccess, _newValue); CommandProcessor.InvokeSingleCommand(cpc, cmd2); } } } } }
protected override void InvokeInternal(CommandProcessorContext cpc) { // safety check, this should never be hit Debug.Assert(Property != null, "InvokeInternal is called when Property is null."); if (Property == null) { throw new InvalidOperationException("InvokeInternal is called when Property is null."); } var cmd = new UpdateDefaultableValueCommand<string>(Property.StoreGeneratedPattern, SgpValue); CommandProcessor.InvokeSingleCommand(cpc, cmd); // ensure view keys are propagated from C-side to S-side var cet = Property.EntityType as ConceptualEntityType; if (cet != null) { PropagateViewKeysToStorageModel.AddRule(cpc, cet); } // ensure StoreGeneratedPattern is propagated from C-side to S-side // unless we are part of an Update Model txn in which case there is no need // as the whole artifact has this integrity check applied by UpdateModelFromDatabaseCommand if (EfiTransactionOriginator.UpdateModelFromDatabaseId != cpc.OriginatorId) { var cProp = Property as ConceptualProperty; Debug.Assert(cProp != null, "expected Property of type ConceptualProperty, instead got type " + Property.GetType().FullName); if (cProp != null) { PropagateStoreGeneratedPatternToStorageModel.AddRule(cpc, cProp, true); } } }
/// <summary> /// Helper method to update the DefaultableValue if and only if the value has changed /// </summary> /// <param name="existingValue"> /// existing value of attribute (StringOrNone.NoneValue indicates attribute /// currently does not exist) /// </param> /// <param name="newValue"> /// new value of attribute passed into setter (null indicates user did not select /// anything on the drop-down and so no setting should take place, StringOrNone.NoneValue indicates user /// selected '(None)' on the drop-down and so attribute should be removed if present) /// </param> /// <param name="defaultableValueToUpdate"></param> internal static void UpdateDefaultableValueIfValuesDiffer( StringOrNone existingValue, StringOrNone newValue, DefaultableValue<StringOrNone> defaultableValueToUpdate) { if (null == newValue) { // user exited drop-down without selecting anything return; } if (existingValue.Equals(newValue)) { // no change in value - so just return return; } else { // existingValue and valueToSet are different - so update the DefaultableValue // if newValue is NoneValue then set valueToSet to null which will remove the attribute // otherwise use newValue as is var valueToSet = (StringOrNone.NoneValue.Equals(newValue) ? null : newValue); var cmd = new UpdateDefaultableValueCommand<StringOrNone>(defaultableValueToUpdate, valueToSet); var cpc = PropertyWindowViewModelHelper.GetCommandProcessorContext(); CommandProcessor.InvokeSingleCommand(cpc, cmd); } }
internal static void StaticInvoke(CommandProcessorContext cpc, EntityTypeShape entityTypeShape, Guid domainPropertyId) { var viewModel = entityTypeShape.GetRootViewModel(); Debug.Assert(viewModel != null, "Unable to find root view model from entity type shape:" + entityTypeShape.AccessibleName); if (viewModel != null) { var modelEntityShape = viewModel.ModelXRef.GetExisting(entityTypeShape) as Model.Designer.EntityTypeShape; // If ModelXRef does not contain about model EntityTypeShape,try to get the information through DSL Model Element if (modelEntityShape == null) { var modelDiagram = viewModel.ModelXRef.GetExisting(viewModel.GetDiagram()) as Diagram; var entityType = viewModel.ModelXRef.GetExisting(entityTypeShape.ModelElement) as EntityType; Debug.Assert(modelDiagram != null, "Why Escher Diagram is null?"); Debug.Assert(entityType != null, "Why there is no XRef between Escher EntityType and DSL EntityT?"); if (modelDiagram != null && entityType != null) { modelEntityShape = entityType.GetAntiDependenciesOfType <Model.Designer.EntityTypeShape>() .FirstOrDefault(ets => ets.Diagram.Id == modelDiagram.Id.Value); } if (modelEntityShape != null) { viewModel.ModelXRef.Add(modelEntityShape, entityTypeShape, cpc.EditingContext); } } // if modelentityshape is still null, create one if (modelEntityShape == null) { EntityTypeShapeAdd.StaticInvoke(cpc, entityTypeShape); modelEntityShape = viewModel.ModelXRef.GetExisting(entityTypeShape) as Model.Designer.EntityTypeShape; } Debug.Assert(modelEntityShape != null); if (modelEntityShape != null) { if (domainPropertyId == NodeShape.AbsoluteBoundsDomainPropertyId) { var cp = new CommandProcessor(cpc); cp.EnqueueCommand( new UpdateDefaultableValueCommand <double>(modelEntityShape.PointX, entityTypeShape.AbsoluteBounds.X)); cp.EnqueueCommand( new UpdateDefaultableValueCommand <double>(modelEntityShape.PointY, entityTypeShape.AbsoluteBounds.Y)); cp.EnqueueCommand( new UpdateDefaultableValueCommand <double>(modelEntityShape.Width, entityTypeShape.AbsoluteBounds.Width)); cp.Invoke(); } else if (domainPropertyId == NodeShape.IsExpandedDomainPropertyId) { var cmd = new UpdateDefaultableValueCommand <bool>(modelEntityShape.IsExpanded, entityTypeShape.IsExpanded); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } } }
internal static void StaticInvoke(CommandProcessorContext cpc, EntityTypeShape entityTypeShape, Guid domainPropertyId) { var viewModel = entityTypeShape.GetRootViewModel(); Debug.Assert(viewModel != null, "Unable to find root view model from entity type shape:" + entityTypeShape.AccessibleName); if (viewModel != null) { var modelEntityShape = viewModel.ModelXRef.GetExisting(entityTypeShape) as Model.Designer.EntityTypeShape; // If ModelXRef does not contain about model EntityTypeShape,try to get the information through DSL Model Element if (modelEntityShape == null) { var modelDiagram = viewModel.ModelXRef.GetExisting(viewModel.GetDiagram()) as Diagram; var entityType = viewModel.ModelXRef.GetExisting(entityTypeShape.ModelElement) as EntityType; Debug.Assert(modelDiagram != null, "Why Escher Diagram is null?"); Debug.Assert(entityType != null, "Why there is no XRef between Escher EntityType and DSL EntityT?"); if (modelDiagram != null && entityType != null) { modelEntityShape = entityType.GetAntiDependenciesOfType<Model.Designer.EntityTypeShape>() .FirstOrDefault(ets => ets.Diagram.Id == modelDiagram.Id.Value); } if (modelEntityShape != null) { viewModel.ModelXRef.Add(modelEntityShape, entityTypeShape, cpc.EditingContext); } } // if modelentityshape is still null, create one if (modelEntityShape == null) { EntityTypeShapeAdd.StaticInvoke(cpc, entityTypeShape); modelEntityShape = viewModel.ModelXRef.GetExisting(entityTypeShape) as Model.Designer.EntityTypeShape; } Debug.Assert(modelEntityShape != null); if (modelEntityShape != null) { if (domainPropertyId == NodeShape.AbsoluteBoundsDomainPropertyId) { var cp = new CommandProcessor(cpc); cp.EnqueueCommand( new UpdateDefaultableValueCommand<double>(modelEntityShape.PointX, entityTypeShape.AbsoluteBounds.X)); cp.EnqueueCommand( new UpdateDefaultableValueCommand<double>(modelEntityShape.PointY, entityTypeShape.AbsoluteBounds.Y)); cp.EnqueueCommand( new UpdateDefaultableValueCommand<double>(modelEntityShape.Width, entityTypeShape.AbsoluteBounds.Width)); cp.Invoke(); } else if (domainPropertyId == NodeShape.IsExpandedDomainPropertyId) { var cmd = new UpdateDefaultableValueCommand<bool>(modelEntityShape.IsExpanded, entityTypeShape.IsExpanded); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } } }
internal static void StaticInvoke(CommandProcessorContext cpc, AssociationConnector associationConnector, Guid domainPropertyId) { var viewModel = associationConnector.GetRootViewModel(); Debug.Assert(viewModel != null, "Unable to find root view model from AssociationConnector: " + associationConnector); if (viewModel != null) { Connector modelAssociationConnector = viewModel.ModelXRef.GetExisting(associationConnector) as Model.Designer.AssociationConnector; if (modelAssociationConnector == null) { AssociationConnectorAdd.StaticInvoke(cpc, associationConnector); modelAssociationConnector = viewModel.ModelXRef.GetExisting(associationConnector) as Model.Designer.AssociationConnector; } Debug.Assert(modelAssociationConnector != null); if (modelAssociationConnector != null) { if (domainPropertyId == LinkShape.EdgePointsDomainPropertyId) { List <KeyValuePair <double, double> > points = null; if (associationConnector.ManuallyRouted && associationConnector.EdgePoints.Count > 0) { points = new List <KeyValuePair <double, double> >(associationConnector.EdgePoints.Count); foreach (EdgePoint point in associationConnector.EdgePoints) { points.Add(new KeyValuePair <double, double>(point.Point.X, point.Point.Y)); } } if (points != null) { var cmd = new SetConnectorPointsCommand(modelAssociationConnector, points); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } else if (domainPropertyId == LinkShape.ManuallyRoutedDomainPropertyId) { // if the connectors are not manually routed, we need to clean up all the connector points in the association connectors. if (associationConnector.ManuallyRouted == false && modelAssociationConnector.ConnectorPoints != null && modelAssociationConnector.ConnectorPoints.Count > 0) { var points = new List <KeyValuePair <double, double> >(); var setConnectorPointCmd = new SetConnectorPointsCommand(modelAssociationConnector, points); CommandProcessor.InvokeSingleCommand(cpc, setConnectorPointCmd); } var cmd = new UpdateDefaultableValueCommand <bool>( modelAssociationConnector.ManuallyRouted, associationConnector.ManuallyRouted); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } } }
private void LoadDesignerInfoAndDescriptors(EditingContext editingContext, EFArtifact artifact) { if (artifact != null && artifact.DesignerInfo() != null) { DesignerInfo connectionDesignerInfo = null; DesignerInfo optionsDesignerInfo = null; var foundConnectionDesignerInfo = artifact.DesignerInfo() .TryGetDesignerInfo(ConnectionDesignerInfo.ElementName, out connectionDesignerInfo); if (foundConnectionDesignerInfo) { var connectionDesigner = connectionDesignerInfo as ConnectionDesignerInfo; Debug.Assert(connectionDesigner != null, "DesignerInfo with element name 'Connection' must be a ConnectionDesignerInfo"); if (connectionDesigner != null) { // if the owner of the edmx file is a website, then we can // only have one possible value (EmbedInOutputAssembly) for metadata artifact processing // however the item template just adds CopyToOutputDirectory, so we need to fix it var project = VSHelpers.GetProjectForDocument(artifact.Uri.LocalPath, PackageManager.Package); if (project != null) { var appType = VsUtils.GetApplicationType(Services.ServiceProvider, project); if (appType == VisualStudioProjectSystem.Website) { var mapDefault = ConnectionManager.GetMetadataArtifactProcessingDefault(); if (connectionDesigner.MetadataArtifactProcessingProperty != null && connectionDesigner.MetadataArtifactProcessingProperty.ValueAttr.Value != mapDefault) { var cpc = new CommandProcessorContext( editingContext, EfiTransactionOriginator.PropertyWindowOriginatorId, Resources.Tx_ChangeMetadataArtifactProcessing); var cmd = new UpdateDefaultableValueCommand <string>( connectionDesigner.MetadataArtifactProcessingProperty.ValueAttr, mapDefault); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } } _EFConnectionDesignerInfoDescriptor = new EFConnectionDesignerInfoDescriptor(); _EFConnectionDesignerInfoDescriptor.Initialize(connectionDesigner, editingContext); } } var foundOptionsDesignerInfo = artifact.DesignerInfo() .TryGetDesignerInfo(OptionsDesignerInfo.ElementName, out optionsDesignerInfo); if (foundOptionsDesignerInfo) { _EFOptionsDesignerInfoDescriptor = new EFOptionsDesignerInfoDescriptor(); _EFOptionsDesignerInfoDescriptor.Initialize(optionsDesignerInfo as OptionsDesignerInfo, editingContext); } } }
internal static void StaticInvoke(CommandProcessorContext cpc, AssociationConnector associationConnector, Guid domainPropertyId) { var viewModel = associationConnector.GetRootViewModel(); Debug.Assert(viewModel != null, "Unable to find root view model from AssociationConnector: " + associationConnector); if (viewModel != null) { Connector modelAssociationConnector = viewModel.ModelXRef.GetExisting(associationConnector) as Model.Designer.AssociationConnector; if (modelAssociationConnector == null) { AssociationConnectorAdd.StaticInvoke(cpc, associationConnector); modelAssociationConnector = viewModel.ModelXRef.GetExisting(associationConnector) as Model.Designer.AssociationConnector; } Debug.Assert(modelAssociationConnector != null); if (modelAssociationConnector != null) { if (domainPropertyId == LinkShape.EdgePointsDomainPropertyId) { List<KeyValuePair<double, double>> points = null; if (associationConnector.ManuallyRouted && associationConnector.EdgePoints.Count > 0) { points = new List<KeyValuePair<double, double>>(associationConnector.EdgePoints.Count); foreach (EdgePoint point in associationConnector.EdgePoints) { points.Add(new KeyValuePair<double, double>(point.Point.X, point.Point.Y)); } } if (points != null) { var cmd = new SetConnectorPointsCommand(modelAssociationConnector, points); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } else if (domainPropertyId == LinkShape.ManuallyRoutedDomainPropertyId) { // if the connectors are not manually routed, we need to clean up all the connector points in the association connectors. if (associationConnector.ManuallyRouted == false && modelAssociationConnector.ConnectorPoints != null && modelAssociationConnector.ConnectorPoints.Count > 0) { var points = new List<KeyValuePair<double, double>>(); var setConnectorPointCmd = new SetConnectorPointsCommand(modelAssociationConnector, points); CommandProcessor.InvokeSingleCommand(cpc, setConnectorPointCmd); } var cmd = new UpdateDefaultableValueCommand<bool>( modelAssociationConnector.ManuallyRouted, associationConnector.ManuallyRouted); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } } }
internal void PersistDisplayType() { var modelDiagram = ModelElement.ModelXRef.GetExisting(this) as ModelDiagram; Debug.Assert(modelDiagram != null, "Model Diagram should be present"); if (modelDiagram != null) { if (modelDiagram.DisplayType.Value != DisplayNameAndType) { var cpc = new CommandProcessorContext( ModelElement.EditingContext, EfiTransactionOriginator.EntityDesignerOriginatorId, EntityDesignerResources.Tx_SetMemberFormatValue); var cmd = new UpdateDefaultableValueCommand<bool>(modelDiagram.DisplayType, DisplayNameAndType); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } }
/// <summary> /// Update function import IsComposable attribute if changed. /// </summary> private void UpdateFunctionImportIsComposable(CommandProcessorContext cpc) { var previousValue = FunctionImport.IsComposable.Value; if (FunctionImportIsComposable != previousValue) { Command updateComposableCommand = new UpdateDefaultableValueCommand<BoolOrNone>( FunctionImport.IsComposable, FunctionImportIsComposable); CommandProcessor.InvokeSingleCommand(cpc, updateComposableCommand); } }
private void PropagateConceptualSGPToStorageProperty(StorageProperty sProp) { if (null == sProp) { Debug.Fail("null StorageProperty"); return; } if (sProp.IsDisposed) { // this StorageProperty was deleted after this integrity check was created but // before it was invoked - not an error - just ignore this property return; } if (sProp.IsKeyProperty) { if (IsStorageForNonRootEntityType(sProp)) { // this StorageProperty is for a key column on a table which acts as storage for a non-root EntityType // (e.g. in a TPT hierarchy). So do not set SGP - it should be set only on the root column. return; } if (IsDependentSidePropertyInAssociation(sProp)) { // this StorageProperty is used in the dependent side of an Association. // So do not set SGP - it should be set only on the principal side. return; } } // loop over ConceptualProperties mapped to this StorageProperty foreach (var sp in sProp.GetAntiDependenciesOfType<ScalarProperty>()) { // only use ScalarProperty elements inside an EntitySetMapping or EntityTypeMapping // (MappingFragment is only used by those types of mappings) if (null != sp.GetParentOfType(typeof(MappingFragment))) { // only propagate values from non-key C-side properties var cProp = sp.Name.Target as ConceptualProperty; if (cProp != null) { var cSideSGPValue = cProp.StoreGeneratedPattern.Value; if (_propagateNoneSGP || false == ModelConstants.StoreGeneratedPattern_None.Equals(cSideSGPValue, StringComparison.Ordinal)) { // have found a C-side property whose SGP value should be propagated if (false == cSideSGPValue.Equals(sProp.StoreGeneratedPattern.Value, StringComparison.Ordinal)) { var cmd = new UpdateDefaultableValueCommand<string>(sProp.StoreGeneratedPattern, cSideSGPValue); CommandProcessor.InvokeSingleCommand(_cpc, cmd); } return; } // Otherwise have found a C-side SGP but it has value "None" and have been told not to propagate "None" values // (will apply to where SGP is absent too since "None" is the default value). // So loop round looking for the next C-side SGP to see if it applies. } } } }
internal static void StaticInvoke(CommandProcessorContext cpc, InheritanceConnector inheritanceConnector, Guid domainPropertyId) { // The situation where inheritanceConnector.IsDeleted to be true is when the user is trying to create circular inheritance. // In that case, the inheritance connector creation is aborted but this rule could still be fired. if (inheritanceConnector.IsDeleted || inheritanceConnector.IsDeleting) { return; } Connector modelInheritanceConnector = null; var viewModel = inheritanceConnector.GetRootViewModel(); Debug.Assert(viewModel != null, "Unable to find root view model from inheritance connector: " + viewModel); if (viewModel != null) { modelInheritanceConnector = viewModel.ModelXRef.GetExisting(inheritanceConnector) as Model.Designer.InheritanceConnector; if (modelInheritanceConnector == null) { InheritanceConnectorAdd.StaticInvoke(cpc, inheritanceConnector); modelInheritanceConnector = viewModel.ModelXRef.GetExisting(inheritanceConnector) as Model.Designer.InheritanceConnector; } } // we should have a connector unless its been deleted due to circular inheritance checks Debug.Assert( modelInheritanceConnector != null || (modelInheritanceConnector == null && inheritanceConnector.IsDeleted), "We could not locate an underlying model item to change for this Inheritance connector"); if (modelInheritanceConnector != null) { if (domainPropertyId == LinkShape.EdgePointsDomainPropertyId) { List<KeyValuePair<double, double>> points = null; if (inheritanceConnector.ManuallyRouted && inheritanceConnector.EdgePoints.Count > 0) { points = new List<KeyValuePair<double, double>>(inheritanceConnector.EdgePoints.Count); foreach (EdgePoint point in inheritanceConnector.EdgePoints) { points.Add(new KeyValuePair<double, double>(point.Point.X, point.Point.Y)); } } if (points != null) { var cmd = new SetConnectorPointsCommand(modelInheritanceConnector, points); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } else if (domainPropertyId == LinkShape.ManuallyRoutedDomainPropertyId) { // if the connectors are not manually routed (the connectors are auto layout), we need to clear our the layout information in our model. if (inheritanceConnector.ManuallyRouted == false && modelInheritanceConnector.ConnectorPoints != null && modelInheritanceConnector.ConnectorPoints.Count > 0) { var points = new List<KeyValuePair<double, double>>(); var setConnectorPointscmd = new SetConnectorPointsCommand(modelInheritanceConnector, points); CommandProcessor.InvokeSingleCommand(cpc, setConnectorPointscmd); } var cmd = new UpdateDefaultableValueCommand<bool>( modelInheritanceConnector.ManuallyRouted, inheritanceConnector.ManuallyRouted); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } }
private void PropagateConceptualSGPToStorageProperty(StorageProperty sProp) { if (null == sProp) { Debug.Fail("null StorageProperty"); return; } if (sProp.IsDisposed) { // this StorageProperty was deleted after this integrity check was created but // before it was invoked - not an error - just ignore this property return; } if (sProp.IsKeyProperty) { if (IsStorageForNonRootEntityType(sProp)) { // this StorageProperty is for a key column on a table which acts as storage for a non-root EntityType // (e.g. in a TPT hierarchy). So do not set SGP - it should be set only on the root column. return; } if (IsDependentSidePropertyInAssociation(sProp)) { // this StorageProperty is used in the dependent side of an Association. // So do not set SGP - it should be set only on the principal side. return; } } // loop over ConceptualProperties mapped to this StorageProperty foreach (var sp in sProp.GetAntiDependenciesOfType <ScalarProperty>()) { // only use ScalarProperty elements inside an EntitySetMapping or EntityTypeMapping // (MappingFragment is only used by those types of mappings) if (null != sp.GetParentOfType(typeof(MappingFragment))) { // only propagate values from non-key C-side properties var cProp = sp.Name.Target as ConceptualProperty; if (cProp != null) { var cSideSGPValue = cProp.StoreGeneratedPattern.Value; if (_propagateNoneSGP || false == ModelConstants.StoreGeneratedPattern_None.Equals(cSideSGPValue, StringComparison.Ordinal)) { // have found a C-side property whose SGP value should be propagated if (false == cSideSGPValue.Equals(sProp.StoreGeneratedPattern.Value, StringComparison.Ordinal)) { var cmd = new UpdateDefaultableValueCommand <string>(sProp.StoreGeneratedPattern, cSideSGPValue); CommandProcessor.InvokeSingleCommand(_cpc, cmd); } return; } // Otherwise have found a C-side SGP but it has value "None" and have been told not to propagate "None" values // (will apply to where SGP is absent too since "None" is the default value). // So loop round looking for the next C-side SGP to see if it applies. } } } }
internal void PersistZoomLevel() { // make sure that we have ActiveDiagramView to get the current ZoomLevel from if (ActiveDiagramView != null && !ModelUtils.IsSerializing(Store)) { var modelDiagram = ModelElement.ModelXRef.GetExisting(this) as ModelDiagram; Debug.Assert(modelDiagram != null, "Model Diagram should be present"); if (modelDiagram != null) { if (undefinedZoomLevel != ZoomLevel && modelDiagram.ZoomLevel.Value != ZoomLevel) { var cpc = new CommandProcessorContext( ModelElement.EditingContext, EfiTransactionOriginator.EntityDesignerOriginatorId, EntityDesignerResources.Tx_SetZoom); var cmd = new UpdateDefaultableValueCommand<int>(modelDiagram.ZoomLevel, ZoomLevel); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } } }
internal static void StaticInvoke(CommandProcessorContext cpc, InheritanceConnector inheritanceConnector, Guid domainPropertyId) { // The situation where inheritanceConnector.IsDeleted to be true is when the user is trying to create circular inheritance. // In that case, the inheritance connector creation is aborted but this rule could still be fired. if (inheritanceConnector.IsDeleted || inheritanceConnector.IsDeleting) { return; } Connector modelInheritanceConnector = null; var viewModel = inheritanceConnector.GetRootViewModel(); Debug.Assert(viewModel != null, "Unable to find root view model from inheritance connector: " + viewModel); if (viewModel != null) { modelInheritanceConnector = viewModel.ModelXRef.GetExisting(inheritanceConnector) as Model.Designer.InheritanceConnector; if (modelInheritanceConnector == null) { InheritanceConnectorAdd.StaticInvoke(cpc, inheritanceConnector); modelInheritanceConnector = viewModel.ModelXRef.GetExisting(inheritanceConnector) as Model.Designer.InheritanceConnector; } } // we should have a connector unless its been deleted due to circular inheritance checks Debug.Assert( modelInheritanceConnector != null || (modelInheritanceConnector == null && inheritanceConnector.IsDeleted), "We could not locate an underlying model item to change for this Inheritance connector"); if (modelInheritanceConnector != null) { if (domainPropertyId == LinkShape.EdgePointsDomainPropertyId) { List <KeyValuePair <double, double> > points = null; if (inheritanceConnector.ManuallyRouted && inheritanceConnector.EdgePoints.Count > 0) { points = new List <KeyValuePair <double, double> >(inheritanceConnector.EdgePoints.Count); foreach (EdgePoint point in inheritanceConnector.EdgePoints) { points.Add(new KeyValuePair <double, double>(point.Point.X, point.Point.Y)); } } if (points != null) { var cmd = new SetConnectorPointsCommand(modelInheritanceConnector, points); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } else if (domainPropertyId == LinkShape.ManuallyRoutedDomainPropertyId) { // if the connectors are not manually routed (the connectors are auto layout), we need to clear our the layout information in our model. if (inheritanceConnector.ManuallyRouted == false && modelInheritanceConnector.ConnectorPoints != null && modelInheritanceConnector.ConnectorPoints.Count > 0) { var points = new List <KeyValuePair <double, double> >(); var setConnectorPointsCmd = new SetConnectorPointsCommand(modelInheritanceConnector, points); CommandProcessor.InvokeSingleCommand(cpc, setConnectorPointsCmd); } var cmd = new UpdateDefaultableValueCommand <bool>( modelInheritanceConnector.ManuallyRouted, inheritanceConnector.ManuallyRouted); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } }
internal void PersistSnapToGrid() { var modelDiagram = ModelElement.ModelXRef.GetExisting(this) as ModelDiagram; Debug.Assert(modelDiagram != null, "Model Diagram should be present"); if (modelDiagram != null) { if (modelDiagram.SnapToGrid.Value != SnapToGrid) { var cpc = new CommandProcessorContext( ModelElement.EditingContext, EfiTransactionOriginator.EntityDesignerOriginatorId, EntityDesignerResources.Tx_SetSnapToGrid); var cmd = new UpdateDefaultableValueCommand<bool>(modelDiagram.SnapToGrid, SnapToGrid); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } }
// helper method which compares values and synchronizes the C-side facet to the S-side value if they differ private void SynchronizeFacet <T>( string sSidePropertyType, DefaultableValue <T> sSideDefaultableValue, string cSidePropertyType, DefaultableValue <T> cSideDefaultableValue) where T : class { if (null == sSidePropertyType) { Debug.Fail("sSidePropertyType cannot be null"); return; } if (null == sSideDefaultableValue) { Debug.Fail("sSideDefaultableValue cannot be null"); return; } if (null == cSidePropertyType) { Debug.Fail("cSidePropertyType cannot be null"); return; } if (null == cSideDefaultableValue) { Debug.Fail("cSideDefaultableValue cannot be null"); return; } if (false == ConceptualFacetExists(cSidePropertyType, cSideDefaultableValue.AttributeName)) { // this facet does not apply to a C-side property of this type - so do not attempt to propagate the S-side value // (this can happen e.g. if an S-side property is mapped to a C-side property with an inconsistent type) return; } // get values that S- and C-side DefaultableValues will assume at runtime if they are absent // (Note: this is different from DefaultableValue.DefaultValue which returns what // to show in the Designer as the default - usually "(None)") var sSideDefaultableValueDefaultValue = GetStorageFacetDefault(sSidePropertyType, sSideDefaultableValue); var sSideValueToPropagate = sSideDefaultableValue.Value; var preExistingCSideValue = cSideDefaultableValue.Value; T valueToSet; if (sSideDefaultableValue.IsDefaulted || null == sSideValueToPropagate || sSideValueToPropagate.Equals(sSideDefaultableValueDefaultValue)) { // sometimes the default value for a facet on the C-side is the same as that for the same // facet on the S-side, but sometimes they are different. Here the S-side has been defaulted // so we need to do different things dependent on whether these default values are the same. var cSideDefaultableValueDefaultValue = GetConceptualFacetDefault(cSidePropertyType, cSideDefaultableValue); if ((null == sSideDefaultableValueDefaultValue && null == cSideDefaultableValueDefaultValue) || (null != sSideDefaultableValueDefaultValue && sSideDefaultableValueDefaultValue.Equals(cSideDefaultableValueDefaultValue))) { // default value for C-side facet is the same as the default value for the S-side facet if (cSideDefaultableValue.IsDefaulted || null == preExistingCSideValue || preExistingCSideValue.Equals(cSideDefaultableValueDefaultValue)) { // the attribute on both sides is either absent or explicitly set to the default value // (note: the null case is when the default value itself is null)- so no need to update the C-side. // This prevents "absent" on the S-side causing an update when the pre-existing C-side value is // the default value and vice versa. return; } // if absent on the S-side, set valueToSet to null which will cause the C-side attribute to be removed, // otherwise use the S-side's explicit value. valueToSet = (sSideDefaultableValue.IsDefaulted ? null : sSideValueToPropagate); } else if (sSideDefaultableValue.IsDefaulted && null == sSideDefaultableValueDefaultValue) { // S-side is defaulted but we have no default value to propagate Debug.Fail( "S-side DefaultableValue is defaulted but default value of S-side DefaultableValue is null, so defaulting C-side DefaultableValue would cause it to assume different default value: " + cSideDefaultableValueDefaultValue); return; } else { // default value for C-side facet is different from the default value for the S-side facet // so need to explictly set the C-side. Only reason for not updating is if the value is // already what we would set it to. if (false == cSideDefaultableValue.IsDefaulted && sSideDefaultableValueDefaultValue.Equals(preExistingCSideValue)) { return; } valueToSet = (sSideDefaultableValue.IsDefaulted ? sSideDefaultableValueDefaultValue : sSideValueToPropagate); } } else { // we are synchronizing an explicit (i.e. non-default) value from the S-side to the C-side - // only reason for not updating is if the value is already what we would set it to. if (sSideValueToPropagate.Equals(preExistingCSideValue)) { // values are the same - so no need to update return; } valueToSet = sSideValueToPropagate; } // now update the C-side facet var cmd = new UpdateDefaultableValueCommand <T>(cSideDefaultableValue, valueToSet); CommandProcessor.InvokeSingleCommand(_cpc, cmd); }
private static void UpdateOnDeleteAction(CommandProcessorContext cpc, AssociationEnd newAssocEnd, AssociationEnd tempArtifactAssocEnd) { Debug.Assert(newAssocEnd != null, "newAssoc should not be null"); Debug.Assert(tempArtifactAssocEnd != null, "tempArtifactAssocEnd should not be null"); if (newAssocEnd == null || tempArtifactAssocEnd == null) { return; } // ensure the OnDeleteAction for the existing artifact is the same as that for the temp artifact if (null == tempArtifactAssocEnd.OnDeleteAction && null != newAssocEnd.OnDeleteAction) { // temp artifact has no OnDeleteAction - so delete the one in the existing artifact newAssocEnd.OnDeleteAction.Delete(); } else if (null != tempArtifactAssocEnd.OnDeleteAction && null != tempArtifactAssocEnd.OnDeleteAction.Action) { var tempArtifactOnDeleteAction = tempArtifactAssocEnd.OnDeleteAction.Action.Value; if (null == newAssocEnd.OnDeleteAction) { // existing artifact has no OnDeleteAction - so create a new one and assign the value from the temp artifact var cmd = new CreateOnDeleteActionCommand(newAssocEnd, tempArtifactOnDeleteAction); CommandProcessor.InvokeSingleCommand(cpc, cmd); } // use ordinal comparison as possible values for this attribute are fixed regardless of locale else if (false == newAssocEnd.OnDeleteAction.Action.Value.Equals(tempArtifactOnDeleteAction, StringComparison.Ordinal)) { // existing artifact has an OnDeleteAction but the value does not match - so assign the value from the temp artifact var cmd = new UpdateDefaultableValueCommand<string>(newAssocEnd.OnDeleteAction.Action, tempArtifactOnDeleteAction); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } }