public static void SetValue(XElement _parent, PropertyExtensionContext _context, XName xName, bool value) { bool propertyValue = value; // Make changes to the .edmx document in an EntityDesignerChangeScope to enable undo/redo of changes. using (EntityDesignerChangeScope scope = _context.CreateChangeScope("Set EDMXFileTools")) { if (_parent.HasElements) { XElement lastChild = _parent.Elements().Where<XElement>(element => element != null && element.Name == xName).LastOrDefault(); if (lastChild != null) { // Property element already exists under the EntityType element, so update its value. lastChild.SetValue(propertyValue.ToString()); } else { // Property 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.ToString())); } } else { // The element has no child elements so create a new MyNewProperty element as its first child. _parent.Add(new XElement(xName, propertyValue.ToString())); } // 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 static void SetValue(XElement _parent, PropertyExtensionContext _context, XName xName, string value) { string propertyValue; if (value != null) propertyValue = value.Trim(); else propertyValue = string.Empty; using (EntityDesignerChangeScope scope = _context.CreateChangeScope("Set EDMXFileTools")) { 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 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(); } } }
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(); } }
/// <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 MyNewProperty(element, context); }
public MyNewPropertyProperty(XElement parent, PropertyExtensionContext context) { _context = context; _parent = parent; }
public RefreshOnSaveEnabledProperty(XElement parent, PropertyExtensionContext context) { _context = context; _parent = parent; }
public MyNewDesignSurfaceProperty(XElement parent, PropertyExtensionContext context) { _context = context; _parent = parent; }
public MultiFileEDMXEnabledProperty(XElement parent, PropertyExtensionContext context) { _context = context; _parent = parent; }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <param name="context"></param> /// <returns></returns> public object CreateProperty(XElement element, PropertyExtensionContext context) { return new RefreshOnSaveEnabledProperty(element, context); }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <param name="context"></param> /// <returns></returns> public object CreateProperty(XElement element, PropertyExtensionContext context) { return new EdmxAutomationEnabledProperty(element, context); }
public EdmxAutomationEnabledProperty(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); }