public static void SetValue(XElement _parent, PropertyExtensionContext _context, XName xName, string value)
        {
            string propertyValue = string.Empty;

            if (value != null)
            {
                propertyValue = value.Trim();
            }
            using (EntityDesignerChangeScope scope = _context.CreateChangeScope("Set StarterKit Property"))
            {
                if (_parent.HasElements)
                {
                    XElement lastChild = _parent.Elements().Where <XElement>(element => element != null && element.Name == xName).LastOrDefault();
                    if (lastChild != null)
                    {
                        lastChild.SetValue(propertyValue);
                    }
                    else
                    {
                        // MyNewProperty element does not exist, so create a new one as the last
                        // child of the EntityType element.
                        _parent.Elements().Last().AddAfterSelf(new XElement(xName, propertyValue));
                    }
                }
                else
                {
                    // The EntityType element has no child elements so create a new MyNewProperty
                    // element as its first child.
                    _parent.Add(new XElement(xName, propertyValue));
                }

                // Commit the changes.
                scope.Complete();
            }
        }
 public IdentityEntityProperties(XElement parent, PropertyExtensionContext context)
 {
     this.propertyManager = new PropertyManager(parent.GetDefaultNamespace());
     this.context         = context;
     this.parent          = parent;
     this.parent.Changed += parentChanged;
 }
        public void SetValue(XElement parent, PropertyExtensionContext context, XName name, XElement value)
        {
            if (value == null)
            {
                foreach (var element in GetEntityTypesWithIdentityElement(parent, name))
                {
                    element.Element(name).Remove();
                }
                return;
            }

            var otherElements = (from element in value.Elements()
                                 let otherName = element.Name
                                                 where propertyNames.Contains(otherName) && otherName != name
                                                 select element).ToList();

            if (otherElements.Any())
            {
                DialogResult result = DialogResult.OK;
                if (GetEntityTypesWithIdentityElement(parent, otherName).Count() == 1)
                {
                    string nameString      = name.LocalName.Substring(name.LocalName.Length - 5, 4);
                    string otherNameString = otherName.LocalName.Substring(otherName.LocalName.Length - 5, 4);
                    string message         = string.Format("Selected entity type is already used as a {0} identity. Would you like to set it as a {1} identity? A {0} identity will be unset.", otherName, name);
                    string caption         = string.Format("Entity is already in use as {0} identity!", otherName);
                    result = MessageBox.Show(message, caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    value.Element(otherName).Remove();
                }
            }

            using (EntityDesignerChangeScope scope = context.CreateChangeScope("Set ASP.NET Identity Property"))
            {
                foreach (var element in GetEntityTypesWithIdentityElement(parent, name))
                {
                    if (element != value)
                    {
                        element.Element(name).Remove();
                    }
                }

                if (value.Elements(name).Count() < 1)
                {
                    value.FirstNode.AddBeforeSelf(new XElement(name));
                }

                // Commit the changes.
                scope.Complete();
            }
        }
Beispiel #4
0
        public object CreateProperty(XElement element, PropertyExtensionContext context)
        {
            var edmXName = XName.Get("Key", "http://schemas.microsoft.com/ado/2008/09/edm");
            var keys     = element.Parent.Element(edmXName).Elements().Select(e => e.Attribute("Name").Value);

            if (keys.Contains(element.Attribute("Name").Value))
            {
                return(new InsertWhenValue(element, context));
            }
            return(null);
        }
Beispiel #5
0
 public MyNewPropertyProperty(XElement parent, PropertyExtensionContext context)
 {
     _context = context;
     _parent  = parent;
 }
 /// <summary>
 /// Called when the selected object in the Entity Data Model Designer changes and the new selection matches the object specified by the EntityDesignerExtendedProperty attribute.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public object CreateProperty(XElement element, PropertyExtensionContext context)
 {
     return(new MyNewPropertyProperty(element, context));
 }
 public InsertWhenValue(XElement property, PropertyExtensionContext context)
 {
     _context  = context;
     _property = property;
 }
 public MyNewDesignSurfaceLayerProperty(XElement parent, PropertyExtensionContext context)
 {
     _context = context;
     _parent  = parent;
 }
 /// <summary>
 /// Called when the selected object in the Entity Data Model Designer
 /// changes and the new selection matches the object specified by the
 /// EntityDesignerExtendedProperty attribute.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public object CreateProperty(XElement element, PropertyExtensionContext context)
 {
     return(new IdentityEntityProperties(element, context));
 }
Beispiel #10
0
        public void SetValue(XElement parent, PropertyExtensionContext context, string entityName, string identityType)
        {
            if (entityName == null)
            {
                using (EntityDesignerChangeScope scope = context.CreateChangeScope("Set ASP.NET Identity Property"))
                {
                    RemoveIdentityAttributeOfType(parent, identityType);
                    scope.Complete();
                    return;
                }
            }

            XElement set = GetEntitySetsByEntityName(parent, entityName).FirstOrDefault();

            if (set == null)
            {
                throw new ArgumentException(string.Format("Entity Model does not contain any entity with name \"{0}\".", entityName));
            }

            var identityTypeAttribute = set.Attributes(Constants.aspNetIdentityAttributeName).FirstOrDefault();

            if (identityTypeAttribute != null)
            {
                if (identityTypeAttribute.Value == identityType)
                {
                    return;
                }

                DialogResult result    = DialogResult.OK;
                string       otherType = identityTypeAttribute.Value;
                string       message   = string.Format("Selected entity type is already used as a {0} identity. Would you like to set it as a {1} identity? A {0} identity will be unset.", otherType, identityType);
                string       caption   = string.Format("Entity is already in use as {0} identity!", otherType);
                result = MessageBox.Show(message, caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    using (EntityDesignerChangeScope scope = context.CreateChangeScope("Set ASP.NET Identity Property"))
                    {
                        RemoveIdentityAttributeOfType(parent, identityType);
                        identityTypeAttribute.Value = identityType;
                        scope.Complete();
                    }
                }
            }
            else
            {
                using (EntityDesignerChangeScope scope = context.CreateChangeScope("Set ASP.NET Identity Property"))
                {
                    if (!parent.Attributes(aspNetIdentityXmlnsAttributeName).Any())
                    {
                        parent.Add(new XAttribute(aspNetIdentityXmlnsAttributeName, Constants.AspNetIdentityNamespace));
                    }

                    identityTypeAttribute = new XAttribute(Constants.aspNetIdentityAttributeName, identityType);
                    set.Add(identityTypeAttribute);
                    scope.Complete();
                }
            }
        }
 /// <summary>
 /// Called when the selected object in the Entity Data Model Designer changes and the new selection matches the object specified by the EntityDesignerExtendedProperty attribute.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public object CreateProperty(XElement element, PropertyExtensionContext context)
 {
     return(new DomainDrivenDesignProperty(element, context));
 }
 public AuditableValue(XElement property, PropertyExtensionContext context)
 {
     _context  = context;
     _property = property;
 }
Beispiel #13
0
 public Property(XElement parent, PropertyExtensionContext context, string xmlNamespace)
 {
     Context   = context;
     Parent    = parent;
     Namespace = xmlNamespace;
 }
Beispiel #14
0
 public DomainDrivenDesignProperty(XElement parent, PropertyExtensionContext context)
     : base(parent, context, Namespace)
 {
 }
 public object CreateProperty(XElement element, PropertyExtensionContext context)
 {
     return(new AuditableValue(element, context));
 }
 /// <summary>
 /// Called when the selected object in the Entity Data Model Designer
 /// changes and the new selection matches the object specified by the
 /// EntityDesignerExtendedProperty attribute.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public object CreateProperty(XElement element, PropertyExtensionContext context)
 {
     return(new MyNewDesignSurfaceLayerProperty(element, context));
 }