354 lines
14 KiB
Text
354 lines
14 KiB
Text
template GenerateBaseClasses()
|
|
abstract class MetaElementBase : IMetaDataBase
|
|
{
|
|
readonly string _id;
|
|
readonly Guid _guid;
|
|
readonly TagedValueCollection _tagedValues;
|
|
|
|
public string ID { get { return _id; } }
|
|
|
|
public Guid GUID { get { return _guid; } }
|
|
|
|
public TagedValueCollection TagedValues { get { return _tagedValues; } }
|
|
|
|
public string Name { get; set; }
|
|
|
|
public string Description { get; set; }
|
|
|
|
protected MetaElementBase(int id, string guid)
|
|
{
|
|
_id = id.ToString(CultureInfo.InvariantCulture);
|
|
_guid = new Guid(guid);
|
|
_tagedValues = new TagedValueCollection();
|
|
Name = Description = "";
|
|
}
|
|
}
|
|
|
|
sealed class MetaPaletteLink : IMetaPaletteLink
|
|
{
|
|
public string Name { get; private set; }
|
|
|
|
public MetaPaletteCollection PartnerPalettes { get; private set; }
|
|
|
|
public IMetaPalette OwnerPalette { get; private set; }
|
|
|
|
public IMetaPaletteAssociation Association { get; private set; }
|
|
|
|
void SelectChildPalettes(IMetaPalette curentPalette)
|
|
{
|
|
foreach (IMetaPalette child in curentPalette.InheritedMetaPalettes.Values)
|
|
{
|
|
PartnerPalettes.Add(child.Name, child);
|
|
SelectChildPalettes(child);
|
|
}
|
|
}
|
|
|
|
public MetaPaletteLink(IMetaPaletteRole targetRole, IMetaPalette ownerPalette)
|
|
{
|
|
OwnerPalette = ownerPalette;
|
|
Association = targetRole.Association;
|
|
IMetaPalette endMetaPalette = targetRole.OwnerMetaPalette;
|
|
IMetaPalette startMetaPalette = targetRole.Association.AssociatedRoles.Values
|
|
.First(startRole => startRole.ID != targetRole.ID)
|
|
.OwnerMetaPalette;
|
|
// név beállítása
|
|
if (startMetaPalette == OwnerPalette) // sima link, megyezik az asszociációval
|
|
{
|
|
Name = string.IsNullOrEmpty(targetRole.Name) ?
|
|
endMetaPalette.Name : // nincs role definiálva
|
|
targetRole.Name; // van role definiálva
|
|
}
|
|
else // ez a link egy asszociációs osztály szemszögéből látja az asszociációt
|
|
{
|
|
Name = string.IsNullOrEmpty(targetRole.Name) ?
|
|
endMetaPalette.Name + OwnerPalette.Name : // nincs role definiálva
|
|
targetRole.Name + OwnerPalette.Name; // van role definiálva
|
|
}
|
|
// elkészítem a partner paletták listáját
|
|
PartnerPalettes = new MetaPaletteCollection { { targetRole.OwnerMetaPalette.Name, targetRole.OwnerMetaPalette } };
|
|
SelectChildPalettes(targetRole.OwnerMetaPalette);
|
|
// normál asszociációs link
|
|
if( OwnerPalette != startMetaPalette || Association.AssociationMetaPalette == null )
|
|
{
|
|
return;
|
|
}
|
|
PartnerPalettes.Add(Association.AssociationMetaPalette.Name, Association.AssociationMetaPalette);
|
|
SelectChildPalettes(Association.AssociationMetaPalette);
|
|
}
|
|
}
|
|
|
|
sealed class MetaPalette : MetaElementBase, IMetaPalette
|
|
{
|
|
public string DBTableName { get; set; }
|
|
|
|
// ReSharper disable once MemberCanBePrivate.Local
|
|
internal string BaseMetaPaletteName { get; set; }
|
|
|
|
readonly Lazy<IMetaPalette> _baseMetaPalette;
|
|
|
|
IMetaPalette GetBaseMetaPalette()
|
|
{
|
|
IMetaPalette baseMetaPalette;
|
|
if (BaseMetaPaletteName != null &&
|
|
_palettes.TryGetValue(BaseMetaPaletteName, out baseMetaPalette))
|
|
{
|
|
return baseMetaPalette;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public IMetaPalette BaseMetaPalette { get { return BaseMetaPaletteName == null ? null : _baseMetaPalette.Value; } }
|
|
|
|
// ReSharper disable once MemberCanBePrivate.Local
|
|
internal string AssociationID { get; set; }
|
|
|
|
readonly Lazy<IMetaPaletteAssociation> _association;
|
|
|
|
IMetaPaletteAssociation GetAssociation()
|
|
{
|
|
IMetaPaletteAssociation association;
|
|
if (AssociationID != null &&
|
|
_associations.TryGetValue(AssociationID, out association))
|
|
{
|
|
return association;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public IMetaPaletteAssociation Association { get { return AssociationID == null ? null : _association.Value; } }
|
|
|
|
readonly Lazy<MetaPaletteCollection> _inheritedMetaPalettes;
|
|
|
|
MetaPaletteCollection GetInheritedMetaPalettes()
|
|
{
|
|
var inheritedMetaPalettes = new MetaPaletteCollection();
|
|
foreach (IMetaPalette palette in
|
|
_palettes.Values
|
|
.Where(p => p.BaseMetaPalette == this))
|
|
{
|
|
inheritedMetaPalettes.Add(palette.Name, palette);
|
|
}
|
|
return inheritedMetaPalettes;
|
|
}
|
|
|
|
public MetaPaletteCollection InheritedMetaPalettes { get { return _inheritedMetaPalettes.Value; } }
|
|
|
|
readonly Lazy<MetaPaletteFieldCollection> _fields;
|
|
|
|
MetaPaletteFieldCollection GetAttributes()
|
|
{
|
|
var fields = new MetaPaletteFieldCollection();
|
|
foreach (IMetaPaletteField field in
|
|
_attributes.Values
|
|
.Where(f => f.OwnerMetaPalette == this))
|
|
{
|
|
fields.Add(field.Name, field);
|
|
}
|
|
return fields;
|
|
}
|
|
|
|
public MetaPaletteFieldCollection Attributes { get { return _fields.Value; } }
|
|
|
|
readonly Lazy<MetaPaletteFieldCollection> _allFields;
|
|
|
|
MetaPaletteFieldCollection GetAllAttributes()
|
|
{
|
|
var allFields = new MetaPaletteFieldCollection();
|
|
for (IMetaPalette current = this; current != null; current = current.BaseMetaPalette)
|
|
{
|
|
foreach (IMetaPaletteField field in current.Attributes.Values)
|
|
{
|
|
allFields.Add(field.Name, field);
|
|
}
|
|
}
|
|
return allFields;
|
|
}
|
|
|
|
public MetaPaletteFieldCollection AllAttributes { get { return _allFields.Value; } }
|
|
|
|
readonly Lazy<MetaPaletteLinkCollection> _links;
|
|
|
|
MetaPaletteLinkCollection GetLinks()
|
|
{
|
|
var links = new MetaPaletteLinkCollection();
|
|
for (IMetaPalette current = this; current != null; current = current.BaseMetaPalette)
|
|
{
|
|
// ReSharper disable once AccessToModifiedClosure
|
|
foreach (MetaPaletteLink mpl in
|
|
current.Roles.Values
|
|
.Select(startRole => new MetaPaletteLink(
|
|
startRole.Association.AssociatedRoles.Values.First(endRole => startRole.ID != endRole.ID),
|
|
current)))
|
|
{
|
|
links.Add(mpl.Name, mpl);
|
|
}
|
|
if (current.Association == null)
|
|
{
|
|
continue;
|
|
}
|
|
// ReSharper disable once AccessToModifiedClosure
|
|
foreach (MetaPaletteLink mpl in
|
|
current.Association.AssociatedRoles.Values
|
|
.Select(role => new MetaPaletteLink(role, current)))
|
|
{
|
|
links.Add(mpl.Name, mpl);
|
|
}
|
|
}
|
|
return links;
|
|
}
|
|
|
|
public MetaPaletteLinkCollection Links { get { return _links.Value; } }
|
|
|
|
readonly Lazy<MetaPaletteRoleCollection> _connectedRoles;
|
|
|
|
MetaPaletteRoleCollection GetRoles()
|
|
{
|
|
var connectedRoles = new MetaPaletteRoleCollection();
|
|
foreach (IMetaPaletteRole role in
|
|
_roles.Values
|
|
.Where(r => r.OwnerMetaPalette == this))
|
|
{
|
|
connectedRoles.Add(role.ID, role);
|
|
}
|
|
return connectedRoles;
|
|
}
|
|
|
|
// ReSharper disable once MemberHidesStaticFromOuterClass
|
|
public MetaPaletteRoleCollection Roles { get { return _connectedRoles.Value; } }
|
|
|
|
public MetaPalette(int id, string guid)
|
|
: base(id, guid)
|
|
{
|
|
_baseMetaPalette = new Lazy<IMetaPalette>(GetBaseMetaPalette);
|
|
_association = new Lazy<IMetaPaletteAssociation>(GetAssociation);
|
|
_inheritedMetaPalettes = new Lazy<MetaPaletteCollection>(GetInheritedMetaPalettes);
|
|
_fields = new Lazy<MetaPaletteFieldCollection>(GetAttributes);
|
|
_allFields = new Lazy<MetaPaletteFieldCollection>(GetAllAttributes);
|
|
_links = new Lazy<MetaPaletteLinkCollection>(GetLinks);
|
|
_connectedRoles = new Lazy<MetaPaletteRoleCollection>(GetRoles);
|
|
}
|
|
}
|
|
|
|
sealed class MetaPaletteField : MetaElementBase, IMetaPaletteField
|
|
{
|
|
public AttributeType Type { get; set; }
|
|
|
|
public string DBFieldName { get; set; }
|
|
|
|
// ReSharper disable once MemberCanBePrivate.Local
|
|
internal string OwnerMetaPaletteName { get; set; }
|
|
|
|
readonly Lazy<IMetaPalette> _ownerMetaPalette;
|
|
|
|
IMetaPalette GetOwnerMetaPalette()
|
|
{
|
|
IMetaPalette ownerMetaPalette;
|
|
if (OwnerMetaPaletteName != null &&
|
|
_palettes.TryGetValue(OwnerMetaPaletteName, out ownerMetaPalette))
|
|
{
|
|
return ownerMetaPalette;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public IMetaPalette OwnerMetaPalette { get { return OwnerMetaPaletteName == null ? null : _ownerMetaPalette.Value; } }
|
|
|
|
public MetaPaletteField(int id, string guid)
|
|
: base(id, guid)
|
|
{
|
|
_ownerMetaPalette = new Lazy<IMetaPalette>(GetOwnerMetaPalette);
|
|
}
|
|
}
|
|
|
|
sealed class MetaPaletteRole : MetaElementBase, IMetaPaletteRole
|
|
{
|
|
public string Multiplicity { get; set; }
|
|
|
|
// ReSharper disable once MemberCanBePrivate.Local
|
|
internal string OwnerMetaPaletteName { get; set; }
|
|
|
|
readonly Lazy<IMetaPalette> _ownerMetaPalette;
|
|
|
|
IMetaPalette GetOwnerMetaPalette()
|
|
{
|
|
IMetaPalette ownerMetaPalette;
|
|
if (OwnerMetaPaletteName != null &&
|
|
_palettes.TryGetValue(OwnerMetaPaletteName, out ownerMetaPalette))
|
|
{
|
|
return ownerMetaPalette;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public IMetaPalette OwnerMetaPalette { get { return OwnerMetaPaletteName == null ? null : _ownerMetaPalette.Value; } }
|
|
|
|
// ReSharper disable once MemberCanBePrivate.Local
|
|
internal string MetaPaletteAssociationName { get; set; }
|
|
|
|
readonly Lazy<IMetaPaletteAssociation> _association;
|
|
|
|
IMetaPaletteAssociation GetAssociation()
|
|
{
|
|
IMetaPaletteAssociation association;
|
|
if (MetaPaletteAssociationName != null &&
|
|
_associations.TryGetValue(MetaPaletteAssociationName, out association))
|
|
{
|
|
return association;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public IMetaPaletteAssociation Association { get { return MetaPaletteAssociationName == null ? null : _association.Value; } }
|
|
|
|
public MetaPaletteRole(int id, string guid)
|
|
: base(id, guid)
|
|
{
|
|
_ownerMetaPalette = new Lazy<IMetaPalette>(GetOwnerMetaPalette);
|
|
_association = new Lazy<IMetaPaletteAssociation>(GetAssociation);
|
|
}
|
|
}
|
|
|
|
sealed class MetaPaletteAssociation : MetaElementBase, IMetaPaletteAssociation
|
|
{
|
|
// ReSharper disable once MemberCanBePrivate.Local
|
|
internal string AssociationMetaPaletteName { get; set; }
|
|
|
|
readonly Lazy<IMetaPalette> _associationMetaPalette;
|
|
|
|
IMetaPalette GetAssociationMetaPalette()
|
|
{
|
|
IMetaPalette associationMetaPalette;
|
|
if (AssociationMetaPaletteName != null &&
|
|
_palettes.TryGetValue(AssociationMetaPaletteName, out associationMetaPalette))
|
|
{
|
|
return associationMetaPalette;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public IMetaPalette AssociationMetaPalette { get { return AssociationMetaPaletteName == null ? null : _associationMetaPalette.Value; } }
|
|
|
|
readonly Lazy<MetaPaletteRoleCollection> _associatedMetaPaletteRoles;
|
|
|
|
MetaPaletteRoleCollection GetAssociatedRoles()
|
|
{
|
|
var associatedMetaPaletteRoles = new MetaPaletteRoleCollection();
|
|
foreach (IMetaPaletteRole role in
|
|
_roles.Values
|
|
.Where(r => r.Association == this))
|
|
{
|
|
associatedMetaPaletteRoles.Add(role.ID, role);
|
|
}
|
|
return associatedMetaPaletteRoles;
|
|
}
|
|
|
|
public MetaPaletteRoleCollection AssociatedRoles { get { return _associatedMetaPaletteRoles.Value; } }
|
|
|
|
public MetaPaletteAssociation(int id, string guid)
|
|
: base(id, guid)
|
|
{
|
|
_associationMetaPalette = new Lazy<IMetaPalette>(GetAssociationMetaPalette);
|
|
_associatedMetaPaletteRoles = new Lazy<MetaPaletteRoleCollection>(GetAssociatedRoles);
|
|
}
|
|
}
|
|
end template
|