public void AddEnumType(EnumType enumType)
 {
     Debug.Assert(_enumTypes.Contains(enumType) == false, "EnumType:" + enumType.DisplayName + " is already added.");
     if (_enumTypes.Contains(enumType) == false)
     {
         _enumTypes.Add(enumType);
     }
 }
        internal ChangeEnumUnderlyingTypeCommand(EnumType enumType, string newType)
        {
            CommandValidation.ValidateEnumType(enumType);
            ValidateString(newType);

            EnumType = enumType;
            NewTypeName = newType;
        }
        internal CreateEnumTypeMemberCommand(EnumType enumType, string name, string value)
            : base(PrereqId)
        {
            ValidateString(name);

            EnumType = enumType;
            Name = name;
            Value = value;
        }
        internal SetEnumTypeFacetCommand(
            EnumType enumType, string enumTypeName, string underlyingType, string externalTypeName, bool isFlag)
        {
            CommandValidation.ValidateEnumType(enumType);

            _enumType = enumType;
            _enumTypeName = enumTypeName;
            _underlyingType = underlyingType;
            _externalTypeName = externalTypeName;
            _isFlag = isFlag;
        }
        /// <summary>
        ///     Change the property type to an enum type.
        /// </summary>
        /// <param name="typeName"></param>
        public void ChangePropertyType(EnumType enumType)
        {
            Debug.Assert(enumType != null, "typeName parameter value is null");
            if (enumType != null)
            {
                ClearEFObject(_typeAttrForPrimitiveType);
                _typeAttrForPrimitiveType = null;

                EnumTypeAttribute.SetRefName(enumType);
                EnumTypeAttribute.Rebind();
            }
        }
        public EnumTypeClipboardFormat(EnumType enumType)
            : base(enumType)
        {
            if (enumType == null)
            {
                throw new ArgumentNullException("enumType");
            }

            _name = enumType.LocalName.Value;
            _underlyingType = enumType.UnderlyingType.Value;
            _isFlag = enumType.IsFlags.Value;
            _externalTypeName = enumType.ExternalTypeName.Value;
            _members = new EnumTypeMembersClipboardFormat(enumType.Members());
        }
        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);
        }
        public EnumTypeViewModel(EnumType enumType)
        {
            Initialize();
            Debug.Assert(enumType != null, "Parameter enum type is null");
            if (enumType != null)
            {
                _enumType = enumType;
                _artifact = enumType.Artifact as EntityDesignArtifact;

                _isFlag = enumType.IsFlags.Value;
                _name = enumType.Name.Value;
                _underlyingType = enumType.UnderlyingType.Value;
                _externalTypeName = enumType.ExternalTypeName.Value;
                _isReferenceExternalType = (String.IsNullOrWhiteSpace(_externalTypeName) == false);

                foreach (var member in enumType.Members())
                {
                    var vm = new EnumTypeMemberViewModel(this, member);
                    vm.PropertyChanged += enumTypeMember_PropertyChanged;
                    Members.Add(vm);
                }
            }
            _isValid = true;
        }
 public ExplorerEnumType(EditingContext context, EnumType enumType, ExplorerEFElement parent)
     : base(context, enumType, parent)
 {
     // do nothing
 }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            var service = cpc.EditingContext.GetEFArtifactService();
            var artifact = service.Artifact;

            // the model that we want to add the entity to
            var model = artifact.ConceptualModel();
            if (model == null)
            {
                throw new CannotLocateParentItemException();
            }

            // check for uniqueness
            if (UniquifyName)
            {
                Name = ModelHelper.GetUniqueName(typeof(EnumType), model, Name);
            }
            else
            {
                string msg = null;
                if (ModelHelper.IsUniqueName(typeof(EnumType), model, Name, true, out msg) == false)
                {
                    throw new CommandValidationFailedException(msg);
                }
            }

            if (String.IsNullOrWhiteSpace(UnderlyingType) == false
                && ModelHelper.UnderlyingEnumTypes.Count(t => String.CompareOrdinal(t.Name, UnderlyingType) == 0) == 0)
            {
                throw new CommandValidationFailedException(
                    String.Format(CultureInfo.CurrentCulture, Resources.Incorrect_Enum_UnderlyingType, UnderlyingType));
            }

            // create the new item in our model
            var enumType = new EnumType(model, null);
            Debug.Assert(enumType != null, "enumType should not be null");
            if (enumType == null)
            {
                throw new ItemCreationFailureException();
            }

            // set the name, add it to the parent item
            enumType.LocalName.Value = Name;

            if (String.IsNullOrWhiteSpace(UnderlyingType) == false
                && String.CompareOrdinal(enumType.UnderlyingType.DefaultValue, UnderlyingType) != 0)
            {
                enumType.UnderlyingType.Value = UnderlyingType;
            }
            if (enumType.IsFlags.DefaultValue != IsFlag)
            {
                enumType.IsFlags.Value = IsFlag;
            }
            if (String.IsNullOrWhiteSpace(ExternalTypeName) == false)
            {
                enumType.ExternalTypeName.Value = ExternalTypeName;
            }

            model.AddEnumType(enumType);

            XmlModelHelper.NormalizeAndResolve(enumType);
            _createdEnumType = enumType;
        }
 /// <summary>
 ///     Deletes the passed in EnumType
 /// </summary>
 /// <param name="complexType"></param>
 internal DeleteEnumTypeCommand(EnumType enumType)
     : base(enumType)
 {
     CommandValidation.ValidateEnumType(enumType);
 }
 internal override bool ParseSingleElement(ICollection<XName> unprocessedElements, XElement elem)
 {
     // Conceptual EntityModel needs to create Conceptual EntityContainer objects
     if (elem.Name.LocalName == BaseEntityContainer.ElementName)
     {
         if (_entityContainers.Count > 0)
         {
             // multiple EntityContainers detected, report an error
             var msg = String.Format(CultureInfo.CurrentCulture, Resources.TOO_MANY_ENTITY_CONTAINER_ELEMENTS, Namespace.Value);
             var error = new ErrorInfo(
                 ErrorInfo.Severity.ERROR, msg, this, ErrorCodes.TOO_MANY_ENTITY_CONTAINER_ELEMENTS, ErrorClass.ParseError);
             Artifact.AddParseErrorForObject(this, error);
         }
         var ec = new ConceptualEntityContainer(this, elem);
         _entityContainers.Add(ec);
         ec.Parse(unprocessedElements);
     }
     else if (elem.Name.LocalName == ComplexType.ElementName)
     {
         var complexType = new ComplexType(this, elem);
         _complexTypes.Add(complexType);
         complexType.Parse(unprocessedElements);
     }
     else if (elem.Name.LocalName == UsingElement.ElementName)
     {
         var use = new UsingElement(this, elem);
         _usings.Add(use);
         use.Parse(unprocessedElements);
     }
     else if (elem.Name.LocalName == EnumType.ElementName)
     {
         // Check if enumType that represents the XElement <see DoParse method>
         var enumType = ModelItemAnnotation.GetModelItem(elem) as EnumType;
         if (enumType == null
             || enumType.IsDisposed)
         {
             enumType = new EnumType(this, elem);
             _enumTypes.Add(enumType);
             enumType.Parse(unprocessedElements);
         }
     }
     else
     {
         return base.ParseSingleElement(unprocessedElements, elem);
     }
     return true;
 }
        protected override void DoParse(ICollection<XName> unprocessedElements)
        {
            // Ensure to parse all enum types before ConceptualProperty/ComplexConceptualProperty are parsed.
            // This is done so that we have enough information to decide which property to create.
            var csdlNamespaceName = SchemaManager.GetCSDLNamespaceName(Artifact.SchemaVersion);
            foreach (var element in XElement.Elements(XName.Get(EnumType.ElementName, csdlNamespaceName)))
            {
                var enumType = new EnumType(this, element);
                _enumTypes.Add(enumType);
                enumType.Parse(unprocessedElements);
            }

            base.DoParse(unprocessedElements);
        }
 internal static void ValidateEnumType(EnumType enumType)
 {
     ValidateEFElement(enumType);
 }
 private ExplorerEnumType AddEnumType(EnumType enumType)
 {
     var explorerEnumType = ModelToExplorerModelXRef.GetNew(_context, enumType, this, typeof(ExplorerEnumType)) as ExplorerEnumType;
     _enumTypes.Insert(explorerEnumType);
     return explorerEnumType;
 }
 internal EnumTypeMember(EnumType enumType, XElement element)
     : base(enumType, element)
 {
 }
 internal SetEnumFlagAttributeCommand(EnumType enumType, bool isFlag)
 {
     CommandValidation.ValidateEnumType(enumType);
     _isFlag = isFlag;
     _enumType = enumType;
 }