internal CreateEnumTypeMemberCommand(CreateEnumTypeCommand cmd, string name, string value) : base(PrereqId) { ValidateString(name); EnumType = null; Name = name; Value = value; AddPreReqCommand(cmd); }
protected override void InvokeInternal(CommandProcessorContext cpc) { // create copy of the EnumType var cmd = new CreateEnumTypeCommand( _clipboardEnumType.Name, _clipboardEnumType.UnderlyingType, _clipboardEnumType.ExternalTypeName, _clipboardEnumType.IsFlag, true); CommandProcessor.InvokeSingleCommand(cpc, cmd); // Copy the members foreach (var member in _clipboardEnumType.Members.ClipboardMembers) { CommandProcessor.InvokeSingleCommand(cpc, new CreateEnumTypeMemberCommand(cmd, member.MemberName, member.MemberValue)); } _createdEnumType = cmd.EnumType; AddAnnotations(_clipboardEnumType, _createdEnumType); }
/// <summary> /// This helper function will create an Enum type using default name. /// NOTE: If the cpc already has an active transaction, these changes will be in that transaction /// and the caller of this helper method must commit it to see these changes committed. /// </summary> /// <param name="cpc"></param> /// <returns>The new EnumType</returns> public static EnumType CreateEnumTypeWithDefaultName(CommandProcessorContext cpc) { var service = cpc.EditingContext.GetEFArtifactService(); var artifact = service.Artifact; // the model that we want to add the complex type to var model = artifact.ConceptualModel(); if (model == null) { throw new CannotLocateParentItemException(); } var enumTypeName = ModelHelper.GetUniqueNameWithNumber(typeof(EnumType), model, Resources.Model_DefaultEnumTypeName); // go create it var cp = new CommandProcessor(cpc); var cmd = new CreateEnumTypeCommand(enumTypeName, null); cp.EnqueueCommand(cmd); cp.Invoke(); return(cmd.EnumType); }
/// <summary> /// This helper function will create an Enum type using default name. /// NOTE: If the cpc already has an active transaction, these changes will be in that transaction /// and the caller of this helper method must commit it to see these changes committed. /// </summary> /// <param name="cpc"></param> /// <returns>The new EnumType</returns> public static EnumType CreateEnumTypeWithDefaultName(CommandProcessorContext cpc) { var service = cpc.EditingContext.GetEFArtifactService(); var artifact = service.Artifact; // the model that we want to add the complex type to var model = artifact.ConceptualModel(); if (model == null) { throw new CannotLocateParentItemException(); } var enumTypeName = ModelHelper.GetUniqueNameWithNumber(typeof(EnumType), model, Resources.Model_DefaultEnumTypeName); // go create it var cp = new CommandProcessor(cpc); var cmd = new CreateEnumTypeCommand(enumTypeName, null); cp.EnqueueCommand(cmd); cp.Invoke(); return cmd.EnumType; }
// <summary> // Show the dialog to create a new enum type. // </summary> public static EnumType AddNewEnumType( string selectedUnderlyingType, EditingContext editingContext, string originatingId, EventHandler onDialogActivated = null) { if (editingContext == null) { throw new ArgumentNullException("editingContext"); } var artifactService = editingContext.GetEFArtifactService(); var entityDesignArtifact = artifactService.Artifact as EntityDesignArtifact; Debug.Assert( entityDesignArtifact != null, typeof(EntityDesignViewModelHelper).Name + ".AddEnumType: Unable to find Entity Design Artifact from the passed in editing context."); if (entityDesignArtifact != null) { var vm = new EnumTypeViewModel(entityDesignArtifact, selectedUnderlyingType); var result = ShowEnumTypeDialog(vm, onDialogActivated); if (result == true && vm.IsValid) { var cp = new CommandProcessor(editingContext, originatingId, Resources.Tx_CreateEnumType); var createEnumTypeCommand = new CreateEnumTypeCommand( vm.Name, vm.SelectedUnderlyingType , (vm.IsReferenceExternalType ? vm.ExternalTypeName : String.Empty), vm.IsFlag, false); cp.EnqueueCommand(createEnumTypeCommand); foreach (var member in vm.Members) { if (String.IsNullOrWhiteSpace(member.Name) == false) { cp.EnqueueCommand(new CreateEnumTypeMemberCommand(createEnumTypeCommand, member.Name, member.Value)); } } cp.Invoke(); return createEnumTypeCommand.EnumType; } } return null; }