1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
7
using System.Collections.ObjectModel;
9
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.CSDL;
10
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.CSDL.Function;
11
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.CSDL.Type;
12
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.Designer.Common;
13
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.Designer.CSDL.Association;
14
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.Designer.CSDL.Property;
15
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.Designer.CSDL.Type;
16
using ICSharpCode.Data.EDMDesigner.Core.EDMObjects.Common;
20
namespace ICSharpCode.Data.EDMDesigner.Core.EDMObjects.Designer.CSDL
24
private IndexableUIBusinessTypeObservableCollection<EntityType, UIEntityType> _entityTypes;
25
private UIEntityType _hierarchyType;
26
private ObservableCollection<UIEntityType> _hierarchyTypes;
27
private IndexableUIBusinessTypeObservableCollection<ComplexType, UIComplexType> _complexTypes;
29
public EDMView EDMView { get; internal set; }
30
public CSDLContainer CSDL { get; internal set; }
33
public IndexableUIBusinessTypeObservableCollection<EntityType, UIEntityType> EntityTypes
37
if (_entityTypes == null)
39
_entityTypes = new IndexableUIBusinessTypeObservableCollection<EntityType, UIEntityType>(CSDL.EntityTypes.Select(et => new UIEntityType(this, et)));
40
CSDL.EntityTypes.ItemAdded += newEntityType => _entityTypes.GetAndAddIfNotExist(newEntityType, net => new UIEntityType(this, net));
41
CSDL.EntityTypes.ItemRemoved += oldEntityType => _entityTypes.Remove(_entityTypes[oldEntityType]);
47
internal void EntityTypesPropertyChanged()
49
EntityTypes.Refresh();
52
public UIEntityType HierarchyType
54
get { return _hierarchyType; }
57
_hierarchyType = value;
58
HierarchyTypes.Clear();
63
while ((baseType = value.BusinessInstance.BaseType) != null)
64
value = new UIEntityType(this, baseType, value);
65
HierarchyTypes.Add(value);
69
public ObservableCollection<UIEntityType> HierarchyTypes
73
if (_hierarchyTypes == null)
74
_hierarchyTypes = new ObservableCollection<UIEntityType>();
75
return _hierarchyTypes;
78
#endregion Entity Types
81
public IndexableUIBusinessTypeObservableCollection<ComplexType, UIComplexType> ComplexTypes
85
if (_complexTypes == null)
87
_complexTypes = new IndexableUIBusinessTypeObservableCollection<ComplexType, UIComplexType>(CSDL.ComplexTypes.Select(ct => new UIComplexType(this, ct)));
88
CSDL.ComplexTypes.ItemAdded += newComplexType => _complexTypes.GetAndAddIfNotExist(newComplexType, nct => new UIComplexType(this, nct));
89
CSDL.ComplexTypes.ItemRemoved += oldComplexType => _complexTypes.Remove(_complexTypes[oldComplexType]);
94
#endregion Complex Types
96
#region CSDL Functions
97
public ObservableCollection<Function> Functions
101
return CSDL.Functions;
104
#endregion CSDL Functions
106
public UIAssociation AddAssociation(string associationName, string navigationProperty1Name, UIEntityType navigationProperty1EntityType, Cardinality navigationProperty1Cardinality, string navigationProperty2Name, UIEntityType navigationProperty2EntityType, Cardinality navigationProperty2Cardinality)
108
var association = CSDL.AddAssociation(associationName, navigationProperty1Name, navigationProperty1EntityType.BusinessInstance, navigationProperty1Cardinality, navigationProperty2Name, navigationProperty2EntityType.BusinessInstance, navigationProperty2Cardinality);
109
return new UIAssociation { NavigationProperty1 = navigationProperty1EntityType.Properties[association.PropertyEnd1] as UIRelatedProperty, NavigationProperty2 = navigationProperty2EntityType.Properties[association.PropertyEnd2] as UIRelatedProperty };
112
public UIEntityType AddEntityType(string entityTypeName, UIEntityType baseType)
114
return EntityTypes[CSDL.AddEntityType(entityTypeName, baseType != null ? null : string.Concat(entityTypeName, "Set"), baseType == null ? null : baseType.BusinessInstance)];
117
public UIComplexType AddComplexType(string complexTypeName)
119
return ComplexTypes[CSDL.AddComplexType(complexTypeName)];
122
public void DeleteType(IUIType uiType)
124
var entityType = uiType.BusinessInstance as EntityType;
125
if (entityType != null)
126
CSDL.EntityTypes.Remove(entityType);
127
var complexType = uiType.BusinessInstance as ComplexType;
128
if (complexType != null)
129
CSDL.ComplexTypes.Remove(complexType);
130
OnTypeDeleted(uiType);
133
protected virtual void OnTypeDeleted(IUIType uiType)
135
if (TypeDeleted != null)
139
public event Action<IUIType> TypeDeleted;