/DemoApp.BusinessModel.ImplCSLA/CSLABusinessObjectsTemplate.tt
Unknown | 1023 lines | 890 code | 133 blank | 0 comment | 0 complexity | b9a01ab11e2a73fda228d99641338723 MD5 | raw file
- <#@ template language="c#" hostspecific="true" debug="true" #>
- <#@ output extension="log" #>
- <#@ assembly name="T4Toolbox.10.0"#>
- <#@ assembly Name="System.Core.dll" #>
- <#@ assembly Name="NetFrameworkExtensions.dll" #>
- <#@ assembly Name="SoftwareEngineering.dll" #>
- <#@ assembly Name="System.ComponentModel.DataAnnotations.dll" #>
- <#@ import namespace="System" #>
- <#@ import namespace="System.IO" #>
- <#@ import namespace="System.Diagnostics" #>
- <#@ import namespace="System.Linq" #>
- <#@ import namespace="System.Collections" #>
- <#@ import namespace="System.Collections.Generic" #>
- <#@ import namespace="NetFrameworkExtensions" #>
- <#@ import namespace="NetFrameworkExtensions.Reflection" #>
- <#@ import namespace="SoftwareEngineering.Modeling" #>
- <#@ import namespace="SoftwareEngineering.Modeling.DataModeling" #>
- <#@ import namespace="System.ComponentModel.DataAnnotations" #>
- <#@ include file="t4toolbox.tt" #>
- <#
- var templateFolder = Path.GetDirectoryName(Host.TemplateFile);
- var modelFileName = File.ReadAllLines(Path.Combine(templateFolder, "ModelLocation.txt"));
- var modelPath = Path.Combine(templateFolder, modelFileName[0]);
- #>
- /* Log file generated on <#= DateTime.Now #>
- * Template file: <#= Path.GetFileName(Host.TemplateFile) #>
- * Model file: <#= Path.GetFullPath(modelPath) #>
- */
-
- Generating Business Object Implementation classes ...
-
- <#
- var model = (DataModel)ModelReader.ReadModel(modelPath);
- var validation = new List<ValidationResult>();
- if (!model.TryValidate(null, validation))
- {#>
-
- Error validating model:
-
- <# foreach (var item in validation)
- { #>
- <#= item.PrintUnlocalized() #>
- <# }
- return this.GenerationEnvironment.ToString();
- }
- #>
- <#
- foreach (var entity in model.EntityTypes)
- {
- var fileName = string.Format("{0}Info.cs", entity.Name);
- #>Generating CSLA Object Info for <#= entity.Name #> on file <#= fileName #> ... <#
- new CslaObjectInfoTemplate(entity).RenderToFile(fileName);
- #>OK!
- <#
- fileName = string.Format("{0}Edit.cs", entity.Name);
- #>Generating CSLA Object Edit for <#= entity.Name #> on file <#= fileName #> ... <#
- new CslaObjectEditTemplate(entity).RenderToFile(fileName);
- #>OK!
- <#
- fileName = string.Format("{0}InfoCollection.cs", entity.Name);
- #>Generating CSLA Object Info Collection for <#= entity.Name #> on file <#= fileName #> ... <#
- new CslaObjectInfoCollectionTemplate(entity).RenderToFile(fileName);
- #>OK!
- <#
- fileName = string.Format("{0}EditCollection.cs", entity.Name);
- #>Generating CSLA Object Edit Collection for <#= entity.Name #> on file <#= fileName #> ... <#
- new CslaObjectEditCollectionTemplate(entity).RenderToFile(fileName);
- #>OK!
- <#
- }
- #>
- <#+
- public class CslaObjectInfoTemplate : T4Toolbox.Template
- {
- public EntityType Model { get; set; }
-
- public CslaObjectInfoTemplate(EntityType model)
- {
- Model = model;
- }
-
- public override string TransformText()
- {
- #>
- using System;
- using System.Collections.Generic;
-
- using Csla;
-
- using EntModApp.EntServices.Business;
-
- using <#= Model.DataModel.Namespace #>.DataAccess;
-
- namespace <#= Model.DataModel.Namespace #>.BusinessLayer
- {
- public partial class Csla<#= Model.Name #>Info :
- <#+ if (Model.BaseEntityTypeRef != null) { #>
- Csla<#= Model.BaseEntityTypeRef.Name #>Info,
- <#+ } else { #>
- ReadOnlyBase<Csla<#= Model.Name #>Info>,
- <#+ } #>
- I<#= Model.Name #>
- {
- #region [ Business Properties ]
-
- <#+ foreach (var prop in Model.PlainProperties) {
- var propType = prop.Type.ToCommonString(prop.AllowNull);
- #>
- public static PropertyInfo<<#= propType #>> <#= prop.Name #>PropertyInfo = RegisterProperty(new PropertyInfo<<#= propType #>>("<#= prop.Name #>"));
- public <#= propType #> <#= prop.Name #>
- {
- get
- {
- return ReadProperty(<#= prop.Name #>PropertyInfo);
- }
- private set
- {
- LoadProperty(<#= prop.Name #>PropertyInfo, value);
- }
- }
-
- <#+ } #>
- <#+ foreach (var prop in Model.References) {
- var propType = string.Format("Csla{0}Info", prop.EntityTypeRef.Name);
- if (prop.IsMultiple) propType = string.Format("Csla{0}InfoCollection", prop.EntityTypeRef.Name);
- #>
- public static PropertyInfo<<#= propType #>> <#= prop.Name #>PropertyInfo = RegisterProperty(new PropertyInfo<<#= propType #>>("<#= prop.Name #>"));
- public <#= propType #> <#= prop.Name #>
- {
- get
- {
- return ReadProperty(<#= prop.Name #>PropertyInfo);
- }
- <#+ if (prop.IsMultiple) { #>private <#+ } #>set
- {
- LoadProperty(<#= prop.Name #>PropertyInfo, value);
- }
- }
-
- <#+ } #>
- #endregion [ Business Properties ]
-
- #region [ Factory Methods ]
- protected internal static Csla<#= Model.Name #>Info Get<#= Model.Name #>Info(<#= Model.Name #> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- if (data == null) throw new ArgumentNullException("data");
- if (loadSettings == null) throw new ArgumentNullException("loadSettings");
- <#+ if (Model.DirectDerivedTypes.Any()) { #>
- Csla<#= Model.Name #>Info result;
- <#+ foreach (var derivedType in Model.DirectDerivedTypes) { #>
- if (data is <#= derivedType.Name #>)
- result = Csla<#= derivedType.Name #>Info.Get<#= derivedType.Name #>Info((<#= derivedType.Name #>)data, <#= derivedType.Name #>LoadSettings.From<#= Model.Name #>LoadSettings(loadSettings));
- else
- <#+ } #>
- {
- result = new Csla<#= Model.Name #>Info();
- result.Fetch<#= Model.Name #>(data, loadSettings);
- }
- <#+ } else { #>
- Csla<#= Model.Name #>Info result = new Csla<#= Model.Name #>Info();
- result.Fetch<#= Model.Name #>(data, loadSettings);
- <#+ } #>
- return result;
- }
-
- private static int ForceInitField = 0;
- protected Csla<#= Model.Name #>Info()
- {
- ForceInitField = 1;
- }
- #endregion [ Factory Methods ]
-
- #region [ Data Access ]
- protected void Fetch<#= Model.Name #>(<#= Model.Name #> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- Fetch<#= Model.Name #>Data(data, loadSettings);
- Fetch<#= Model.Name #>Children(data, loadSettings);
- }
-
- protected void Fetch<#= Model.Name #>Data(<#= Model.Name #> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- <#+ if (Model.BaseEntityTypeRef != null) { #>
- base.Fetch<#= Model.BaseEntityTypeRef.Name #>Data(data, loadSettings);
- <#+ } #>
- <#+ foreach (var prop in Model.PlainProperties) { #>
- this.<#= prop.Name #> = data.<#= prop.Name #>;
- <#+ } #>
- }
-
- protected void Fetch<#= Model.Name #>Children(<#= Model.Name #> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- <#+ if (Model.BaseEntityTypeRef != null) { #>
- base.Fetch<#= Model.BaseEntityTypeRef.Name #>Data(data, loadSettings);
- <#+ } #>
- <#+ foreach (var prop in Model.References) {
- var propType = string.Format("Csla{0}Info", prop.EntityTypeRef.Name);
- if (prop.IsMultiple)
- {
- propType = string.Format("Csla{0}InfoCollection", prop.EntityTypeRef.Name);
- #>
- if (loadSettings.Inclusion.Include<#= prop.Name #>)
- this.<#= prop.Name #> = <#= propType #>.Get<#= prop.EntityTypeRef.Name #>InfoCollection(data.<#= prop.Name #>, loadSettings.Inclusion.Included<#= prop.Name #>Settings);
- <#+ } #>
- <#+ } #>
- }
- #endregion [ Data Access ]
-
- #region [ Explicit I<#= Model.Name #> implementation ]
-
- <#+ foreach (var prop in Model.PlainProperties) {
- var propType = prop.Type.ToCommonString(prop.AllowNull);
- #>
- <#= propType #> I<#= Model.Name #>.<#= prop.Name #>
- {
- get { return this.<#= prop.Name #>; }
- <#+ if (!prop.IsKey) { #>
- set
- {
- throw new NotSupportedException();
- }
- <#+ } #>
- }
-
- <#+ } #>
- <#+ foreach (var prop in Model.References) {
- var propType = string.Format("I{0}", prop.EntityTypeRef.Name);
- if (prop.IsMultiple) propType = string.Format("IBusinessObjectCollection<I{0}>", prop.EntityTypeRef.Name);
- #>
- <#= propType #> I<#= Model.Name #>.<#= prop.Name #>
- {
- get
- {
- return this.<#= prop.Name #>;
- }
- <#+ if (!prop.IsMultiple) { #>
- set
- {
- throw new NotSupportedException();
- }
- <#+ } #>
- }
-
- <#+ } #>
-
- bool IBusinessObject.IsReadonly
- {
- get { return true; }
- }
-
- bool IBusinessObject.IsDirty
- {
- get { return false; }
- }
-
- #endregion [ Explicit I<#= Model.Name #> implementation ]
- }
- }
- <#+
- return this.GenerationEnvironment.ToString();
- }
- }
- #>
- <#+
- public class CslaObjectEditTemplate : T4Toolbox.Template
- {
- public EntityType Model { get; set; }
-
- public CslaObjectEditTemplate(EntityType model)
- {
- Model = model;
- }
-
- public override string TransformText()
- {
- #>
- using System;
- using System.Collections.Generic;
- using System.Linq;
-
- using Csla;
-
- using EntModApp.EntServices.Business;
- using EntModApp.EntServices.IoC;
-
- using <#= Model.DataModel.Namespace #>.DataAccess;
-
- namespace <#= Model.DataModel.Namespace #>.BusinessLayer
- {
- [Serializable]
- public partial class Csla<#= Model.Name #>Edit :
- <#+ if (Model.BaseEntityTypeRef != null) { #>
- Csla<#= Model.BaseEntityTypeRef.Name #>Edit,
- <#+ } else { #>
- BusinessBase<Csla<#= Model.Name #>Edit>,
- <#+ } #>
- I<#= Model.Name #>
- {
- #region [ Business Properties ]
-
- <#+ foreach (var prop in Model.PlainProperties) {
- var propType = prop.Type.ToCommonString(prop.AllowNull);
- #>
- public static PropertyInfo<<#= propType #>> <#= prop.Name #>PropertyInfo = RegisterProperty(new PropertyInfo<<#= propType #>>("<#= prop.Name #>"));
- public <#= propType #> <#= prop.Name #>
- {
- get
- {
- return GetProperty(<#= prop.Name #>PropertyInfo);
- }
- <#+ if (prop.IsKey) { #>private <#+ } #>set
- {
- LoadProperty(<#= prop.Name #>PropertyInfo, value);
- }
- }
-
- <#+ } #>
- <#+ foreach (var prop in Model.References) {
- var propType = string.Format("Csla{0}Edit", prop.EntityTypeRef.Name);
- if (prop.IsMultiple) propType = string.Format("Csla{0}EditCollection", prop.EntityTypeRef.Name);
- #>
- public static PropertyInfo<<#= propType #>> <#= prop.Name #>PropertyInfo = RegisterProperty(new PropertyInfo<<#= propType #>>("<#= prop.Name #>"));
- public <#= propType #> <#= prop.Name #>
- {
- get
- {
- return GetProperty(<#= prop.Name #>PropertyInfo);
- }
- private set
- {
- LoadProperty(<#= prop.Name #>PropertyInfo, value);
- }
- }
-
- <#+ if (!prop.IsMultiple) { #>
- <#+ foreach (var key in prop.ConformKey()) { #>
- public static PropertyInfo<<#= key.KeyType() #>> <#= key.KeyName() #>PropertyInfo = RegisterProperty(new PropertyInfo<<#= key.KeyType() #>>("<#= key.KeyName() #>"));
- public <#= key.KeyType() #> <#= key.KeyName() #>
- {
- get
- {
- return GetProperty(<#= key.KeyName() #>PropertyInfo);
- }
- <#+ if (prop.IsKey) { #>private <#+ } #>set
- {
- LoadProperty(<#= key.KeyName() #>PropertyInfo, value);
- }
- }
-
- <#+ } #>
- <#+ } #>
- <#+ } #>
- #endregion [ Business Properties ]
-
- #region [ Validation Rules ]
- #endregion [ Validation Rules ]
-
- #region [ Authorization Rules ]
- #endregion [ Authorization Rules ]
-
- #region [ Factory Methods ]
-
- #region [ Root Factory Methods ]
- public static Csla<#= Model.Name #>Edit New()
- {
- return DataPortal.Create<Csla<#= Model.Name #>Edit>();
- }
-
- public static void Delete(<#= Model.RootEntityType.Name #>Key key)
- {
- DataPortal.Delete<<#= Model.Name #>>(new SingleCriteria<<#= Model.Name #>, <#= Model.RootEntityType.Name #>Key>(key));
- }
-
- public static void Delete(<#= Model.RootEntityType.ConformKey().ToStringList(", ", k => string.Format("{0} {1}", k.KeyType(), k.KeyName())) #>)
- {
- Delete(new <#= Model.RootEntityType.Name #>Key { <#= Model.RootEntityType.ConformKey().ToStringList(", ", k => string.Format("{0} = {0}", k.KeyName())) #> });
- }
- #endregion [ Root Factory Methods ]
-
- #region [ Child Factory Methods ]
- internal static Csla<#= Model.Name #>Edit NewChild()
- {
- return DataPortal.CreateChild<Csla<#= Model.Name #>Edit>();
- }
-
- internal static Csla<#= Model.Name #>Edit Get<#= Model.Name #>Edit(<#= Model.Name #> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- if (data == null) throw new ArgumentNullException("data");
- if (loadSettings == null) throw new ArgumentNullException("loadSettings");
- <#+ if (Model.DirectDerivedTypes.Any()) { #>
- Csla<#= Model.Name #>Edit result;
- <#+ foreach (var derivedType in Model.DirectDerivedTypes) { #>
- if (data is <#= derivedType.Name #>)
- result = Csla<#= derivedType.Name #>Edit.Get<#= derivedType.Name #>Edit((<#= derivedType.Name #>)data, <#= derivedType.Name #>LoadSettings.From<#= Model.Name #>LoadSettings(loadSettings));
- else
- <#+ } #>
- {
- result = new Csla<#= Model.Name #>Edit();
- result.Fetch<#= Model.Name #>(data, loadSettings);
- }
- <#+ } else { #>
- Csla<#= Model.Name #>Edit result = new Csla<#= Model.Name #>Edit();
- result.Fetch<#= Model.Name #>(data, loadSettings);
- <#+ } #>
- result.MarkAsChild();
- return result;
- }
- #endregion [ Child Factory Methods ]
-
- private static int ForceInitField = 0;
- protected Csla<#= Model.Name #>Edit()
- {
- ForceInitField = 1;
- }
- #endregion [ Factory Methods ]
-
- #region [ Data Access ]
-
- #region [ Root Data Access ]
- protected override void DataPortal_Create()
- {
- base.DataPortal_Create();
- }
-
- [Transactional(TransactionalTypes.TransactionScope)]
- protected override void DataPortal_Insert()
- {
- }
-
- [Transactional(TransactionalTypes.TransactionScope)]
- protected override void DataPortal_Update()
- {
- }
-
- [Transactional(TransactionalTypes.TransactionScope)]
- protected override void DataPortal_DeleteSelf()
- {
- DataPortal_Delete(new SingleCriteria<<#= Model.Name #>, <#= Model.RootEntityType.Name #>Key>(new <#= Model.RootEntityType.Name #>Key { <#= Model.RootEntityType.ConformKey().ToStringList(", ", k => string.Format("{0} = this.{0}", k.KeyName())) #> }));
- }
-
- [Transactional(TransactionalTypes.TransactionScope)]
- private void DataPortal_Delete(SingleCriteria<<#= Model.Name #>, <#= Model.RootEntityType.Name #>Key> criteria)
- {
- }
- #endregion [ Root Data Access ]
-
- #region [ Child Data Access ]
- protected override void Child_Create()
- {
- base.Child_Create();
- }
-
- private void Child_Fetch(object childData)
- {
- }
-
- private void Child_Insert(object parent)
- {
- }
-
- private void Child_Update(object parent)
- {
- }
-
- private void Child_DeleteSelf(object parent)
- {
- }
- #endregion [ Child Data Access ]
-
- protected void Fetch<#= Model.Name #>(<#= Model.Name #> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- Fetch<#= Model.Name #>Data(data, loadSettings);
- Fetch<#= Model.Name #>Children(data, loadSettings);
- }
-
- protected void Fetch<#= Model.Name #>Data(<#= Model.Name #> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- <#+ if (Model.BaseEntityTypeRef != null) { #>
- base.Fetch<#= Model.BaseEntityTypeRef.Name #>Data(data, loadSettings);
- <#+ } #>
- <#+ foreach (var prop in Model.PlainProperties) { #>
- this.<#= prop.Name #> = data.<#= prop.Name #>;
- <#+ } #>
- <#+ foreach (var prop in Model.References) {
- if (!prop.IsMultiple)
- foreach (var key in prop.ConformKey())
- {
- #>
- this.<#= key.KeyName() #> = data.<#= key.KeyName() #>;
- <#+ } #>
- <#+ } #>
- }
-
- protected void Fetch<#= Model.Name #>Children(<#= Model.Name #> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- <#+ if (Model.BaseEntityTypeRef != null) { #>
- base.Fetch<#= Model.BaseEntityTypeRef.Name #>Data(data, loadSettings);
- <#+ } #>
- <#+ foreach (var prop in Model.References) {
- var propType = string.Format("Csla{0}Edit", prop.EntityTypeRef.Name);
- if (prop.IsMultiple)
- {
- propType = string.Format("Csla{0}EditCollection", prop.EntityTypeRef.Name);
- #>
- if (loadSettings.Inclusion.Include<#= prop.Name #>)
- this.<#= prop.Name #> = <#= propType #>.Get<#= prop.EntityTypeRef.Name #>EditCollection(data.<#= prop.Name #>, loadSettings.Inclusion.Included<#= prop.Name #>Settings);
- <#+ } else { #>
- if (loadSettings.Inclusion.Include<#= prop.Name #>)
- this.<#= prop.Name #> = <#= propType #>.Get<#= prop.EntityTypeRef.Name #>Edit(data.<#= prop.Name #>, loadSettings.Inclusion.Included<#= prop.Name #>Settings);
- <#+ } #>
- <#+ } #>
- }
- #endregion [ Data Access ]
-
- #region [ Explicit I<#= Model.Name #> implementation ]
-
- <#+ foreach (var prop in Model.PlainProperties) {
- var propType = prop.Type.ToCommonString(prop.AllowNull);
- #>
- <#= propType #> I<#= Model.Name #>.<#= prop.Name #>
- {
- get { return this.<#= prop.Name #>; }
- <#+ if (!prop.IsKey) { #>
- set
- {
- this.<#= prop.Name #> = value;
- }
- <#+ } #>
- }
-
- <#+ } #>
- <#+ foreach (var prop in Model.References) {
- var propType = string.Format("I{0}", prop.EntityTypeRef.Name);
- if (prop.IsMultiple) propType = string.Format("IBusinessObjectCollection<I{0}>", prop.EntityTypeRef.Name);
- #>
- <#= propType #> I<#= Model.Name #>.<#= prop.Name #>
- {
- get
- {
- return this.<#= prop.Name #>;
- }
- <#+ if (!prop.IsMultiple) { #>
- set
- {
- this.<#= prop.Name #> = (Csla<#= prop.EntityTypeRef.Name #>Edit)value;
- }
- <#+ } #>
- }
-
- <#+ } #>
-
- bool IBusinessObject.IsReadonly
- {
- get { return false; }
- }
-
- bool IBusinessObject.IsDirty
- {
- get { return this.IsDirty; }
- }
-
- #endregion [ Explicit I<#= Model.Name #> implementation ]
- }
- }
- <#+
- return this.GenerationEnvironment.ToString();
- }
- }
- #>
- <#+
- public class CslaObjectInfoCollectionTemplate : T4Toolbox.Template
- {
- public EntityType Model { get; set; }
-
- public CslaObjectInfoCollectionTemplate(EntityType model)
- {
- Model = model;
- }
-
- public override string TransformText()
- {
- #>
- using System;
- using System.Collections.Generic;
- using System.Linq;
-
- using Csla;
-
- using EntModApp.EntServices.Business;
- using EntModApp.EntServices.IoC;
-
- using <#= Model.DataModel.Namespace #>.DataAccess;
-
- namespace <#= Model.DataModel.Namespace #>.BusinessLayer
- {
- [Serializable]
- public partial class Csla<#= Model.Name #>InfoCollection
- : ReadOnlyListBase<Csla<#= Model.Name #>InfoCollection, Csla<#= Model.Name #>Info>,
- IBusinessObjectCollection<I<#= Model.Name #>>
- {
- #region [ Business Properties ]
-
- public int TotalItems { get; private set; }
-
- #endregion [ Business Properties ]
-
- #region [ Factory Methods ]
- public static int GetCount(<#= Model.Name #>LoadSettings loadSettings = null)
- {
- loadSettings = <#= Model.Name #>LoadSettings.From<#= Model.Name #>LoadSettings(loadSettings);
- var cmd = new GetCountCommand { LoadSettings = loadSettings };
- DataPortal.Execute(cmd);
- return cmd.Count;
- }
-
- public static Csla<#= Model.Name #>InfoCollection Get<#= Model.Name #>InfoById(<#= Model.RootEntityType.ConformKey().ToStringList(", ", k => string.Format("{0} {1}", k.KeyType(), k.KeyName())) #>, <#= Model.Name #>LoadSettings loadSettings = null)
- {
- return Get<#= Model.Name #>InfoById(new <#= Model.RootEntityType.Name #>Key { <#= Model.RootEntityType.ConformKey().ToStringList(", ", k => string.Format("{0} = {0}", k.KeyName())) #> }, loadSettings);
- }
-
- public static Csla<#= Model.Name #>InfoCollection Get<#= Model.Name #>InfoById(<#= Model.RootEntityType.Name #>Key key, <#= Model.Name #>LoadSettings loadSettings = null)
- {
- if (key == null) throw new ArgumentNullException("key");
- loadSettings = <#= Model.Name #>LoadSettings.From<#= Model.Name #>LoadSettings(loadSettings);
- loadSettings.Filter.ByKey = key;
- var criteria = new GetAllCriteria
- {
- LoadSettings = loadSettings,
- };
- var result = DataPortal.Fetch<Csla<#= Model.Name #>InfoCollection>(criteria);
- return result;
- }
-
- public static Csla<#= Model.Name #>InfoCollection Get<#= Model.Name #>InfoCollection(<#= Model.Name #>LoadSettings loadSettings = null)
- {
- loadSettings = <#= Model.Name #>LoadSettings.From<#= Model.Name #>LoadSettings(loadSettings);
- var criteria = new GetAllCriteria
- {
- LoadSettings = loadSettings,
- };
- var result = DataPortal.Fetch<Csla<#= Model.Name #>InfoCollection>(criteria);
- return result;
- }
-
- protected internal static Csla<#= Model.Name #>InfoCollection Get<#= Model.Name #>InfoCollection(IEnumerable<<#= Model.Name #>> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- if (data == null) throw new ArgumentNullException("data");
- if (loadSettings == null) throw new ArgumentNullException("loadSettings");
- var result = new Csla<#= Model.Name #>InfoCollection();
- result.FetchAll(data, loadSettings);
- result.TotalItems = result.Count;
- return result;
- }
-
- private static int ForceInit = 0;
- protected Csla<#= Model.Name #>InfoCollection()
- {
- ForceInit = 1;
- }
-
- #region [ Criterias ]
-
- [Serializable]
- class GetAllCriteria : CriteriaBase<GetAllCriteria>//, ICriteriaBase
- {
- public <#= Model.Name #>LoadSettings LoadSettings { get; set; }
- }
- #endregion
-
- #endregion
-
- #region [ Commands ]
- [Serializable]
- class GetCountCommand : CommandBase<GetCountCommand>
- {
- public <#= Model.Name #>LoadSettings LoadSettings { get; set; }
-
- public int Count { get; private set; }
-
- protected override void DataPortal_Execute()
- {
- var dbFactory = ServiceLocator.Current.GetInstance<I<#= Model.DataModel.Name #>DataRepositoryFactory>();
- using (var db = dbFactory.CreateRepository())
- {
- Count = db.<#= Model.EntitySetName #>.Count(LoadSettings);
- }
- }
- }
- #endregion [ Commands ]
-
- #region [ Data Access ]
- private void DataPortal_Fetch(GetAllCriteria criteria)
- {
- var dbFactory = ServiceLocator.Current.GetInstance<I<#= Model.DataModel.Name #>DataRepositoryFactory>();
- IEnumerable<<#= Model.Name #>> data;
- using (var db = dbFactory.CreateRepository())
- {
- int total;
- data = db.<#= Model.RootEntityType.EntitySetName #>.Retrieve(criteria.LoadSettings, out total)<#+ if (Model.BaseEntityTypeRef != null) { #>.Cast<<#= Model.Name #>>()<#+ } #>;
- TotalItems = total;
- }
- FetchAll(data, criteria.LoadSettings);
- }
-
- private void FetchAll(IEnumerable<<#= Model.Name #>> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- var oldIsReadOnly = IsReadOnly;
- var oldRaiseListChangedEvents = RaiseListChangedEvents;
- try
- {
- IsReadOnly = false;
- RaiseListChangedEvents = false;
-
- foreach (var item in data)
- {
- var element = Csla<#= Model.Name #>Info.Get<#= Model.Name #>Info(item, loadSettings);
- this.Add(element);
- }
- }
- finally
- {
- IsReadOnly = oldIsReadOnly;
- RaiseListChangedEvents = oldRaiseListChangedEvents;
- }
- }
- #endregion
-
- #region [ Explicit IBusinessObjectCollection<I<#= Model.Name #>> implementation ]
- void ICollection<I<#= Model.Name #>>.Add(I<#= Model.Name #> item)
- {
- this.Add((Csla<#= Model.Name #>Info)item);
- }
-
- void ICollection<I<#= Model.Name #>>.Clear()
- {
- this.Clear();
- }
-
- bool ICollection<I<#= Model.Name #>>.Contains(I<#= Model.Name #> item)
- {
- return this.Contains((Csla<#= Model.Name #>Info)item);
- }
-
- void ICollection<I<#= Model.Name #>>.CopyTo(I<#= Model.Name #>[] array, int arrayIndex)
- {
- int size = Math.Min(array.Length - arrayIndex, this.Count);
- if (size > 0)
- {
- var a = new Csla<#= Model.Name #>Info[size];
- this.CopyTo(a, 0);
- Array.Copy(a, 0, array, arrayIndex, size);
- }
- }
-
- bool ICollection<I<#= Model.Name #>>.IsReadOnly
- {
- get { return true; }
- }
-
- bool ICollection<I<#= Model.Name #>>.Remove(I<#= Model.Name #> item)
- {
- return this.Remove((Csla<#= Model.Name #>Info)item);
- }
-
- IEnumerator<I<#= Model.Name #>> IEnumerable<I<#= Model.Name #>>.GetEnumerator()
- {
- return this.GetEnumerator();
- }
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return this.GetEnumerator();
- }
-
- bool IBusinessObject.IsReadonly
- {
- get { return true; }
- }
-
- bool IBusinessObject.IsDirty
- {
- get { return false; }
- }
-
- I<#= Model.Name #> IBusinessObjectCollection<I<#= Model.Name #>>.this[int index]
- {
- get
- {
- return this[index];
- }
- set
- {
- this[index] = (Csla<#= Model.Name #>Info)value;
- }
- }
- #endregion [ Explicit IBusinessObjectCollection<I<#= Model.Name #>> implementation ]
- }
- }
- <#+
- return this.GenerationEnvironment.ToString();
- }
- }
- #>
- <#+
- public class CslaObjectEditCollectionTemplate : T4Toolbox.Template
- {
- public EntityType Model { get; set; }
-
- public CslaObjectEditCollectionTemplate(EntityType model)
- {
- Model = model;
- }
-
- public override string TransformText()
- {
- #>
- using System;
- using System.Collections.Generic;
- using System.Linq;
-
- using Csla;
-
- using EntModApp.EntServices.Business;
- using EntModApp.EntServices.IoC;
-
- using <#= Model.DataModel.Namespace #>.DataAccess;
-
- namespace <#= Model.DataModel.Namespace #>.BusinessLayer
- {
- [Serializable]
- public partial class Csla<#= Model.Name #>EditCollection
- : BusinessListBase<Csla<#= Model.Name #>EditCollection, Csla<#= Model.Name #>Edit>,
- IBusinessObjectCollection<I<#= Model.Name #>>
- {
- #region [ Business Properties ]
-
- public int TotalItems { get; private set; }
-
- #endregion [ Business Properties ]
-
- #region [ Factory Methods ]
-
- #region [ Root Factory Methods ]
- public static Csla<#= Model.Name #>EditCollection New()
- {
- return DataPortal.Create<Csla<#= Model.Name #>EditCollection>();
- }
-
- public static Csla<#= Model.Name #>EditCollection Get<#= Model.Name #>EditById(<#= Model.RootEntityType.ConformKey().ToStringList(", ", k => string.Format("{0} {1}", k.KeyType(), k.KeyName())) #>, <#= Model.Name #>LoadSettings loadSettings = null)
- {
- return Get<#= Model.Name #>EditById(new <#= Model.RootEntityType.Name #>Key { <#= Model.RootEntityType.ConformKey().ToStringList(", ", k => string.Format("{0} = {0}", k.KeyName())) #> }, loadSettings);
- }
-
- public static Csla<#= Model.Name #>EditCollection Get<#= Model.Name #>EditById(<#= Model.RootEntityType.Name #>Key key, <#= Model.Name #>LoadSettings loadSettings = null)
- {
- if (key == null) throw new ArgumentNullException("key");
- loadSettings = <#= Model.Name #>LoadSettings.From<#= Model.Name #>LoadSettings(loadSettings);
- loadSettings.Filter.ByKey = key;
- var criteria = new GetAllCriteria
- {
- LoadSettings = loadSettings,
- };
- var result = DataPortal.Fetch<Csla<#= Model.Name #>EditCollection>(criteria);
- return result;
- }
-
- public static Csla<#= Model.Name #>EditCollection Get<#= Model.Name #>EditCollection(<#= Model.Name #>LoadSettings loadSettings = null)
- {
- loadSettings = <#= Model.Name #>LoadSettings.From<#= Model.Name #>LoadSettings(loadSettings);
- var criteria = new GetAllCriteria
- {
- LoadSettings = loadSettings,
- };
- var result = DataPortal.Fetch<Csla<#= Model.Name #>EditCollection>(criteria);
- return result;
- }
- #endregion [ Root Factory Methods ]
-
- #region [ Child Factory Methods ]
- internal static Csla<#= Model.Name #>EditCollection Get<#= Model.Name #>EditCollection(IEnumerable<<#= Model.Name #>> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- if (data == null) throw new ArgumentNullException("data");
- if (loadSettings == null) throw new ArgumentNullException("loadSettings");
- var result = new Csla<#= Model.Name #>EditCollection();
- result.MarkAsChild();
- result.FetchAll(data, loadSettings);
- result.TotalItems = result.Count;
- return result;
- }
- #endregion [ Child Factory Methods ]
-
- private static int ForceInit = 0;
- protected Csla<#= Model.Name #>EditCollection()
- {
- ForceInit = 1;
- }
-
- #region [ Criterias ]
- [Serializable]
- class GetAllCriteria : CriteriaBase<GetAllCriteria>
- {
- public <#= Model.Name #>LoadSettings LoadSettings { get; set; }
- }
- #endregion
-
- #endregion
-
- #region [ Data Access ]
- private void DataPortal_Fetch(GetAllCriteria criteria)
- {
- var dbFactory = ServiceLocator.Current.GetInstance<I<#= Model.DataModel.Name #>DataRepositoryFactory>();
- IEnumerable<<#= Model.Name #>> data;
- using (var db = dbFactory.CreateRepository())
- {
- int total;
- data = db.<#= Model.RootEntityType.EntitySetName #>.Retrieve(criteria.LoadSettings, out total)<#+ if (Model.BaseEntityTypeRef != null) { #>.Cast<<#= Model.Name #>>()<#+ } #>;
- TotalItems = total;
- }
- FetchAll(data, criteria.LoadSettings);
- }
-
- private void FetchAll(IEnumerable<<#= Model.Name #>> data, <#= Model.Name #>LoadSettings loadSettings)
- {
- var oldRaiseListChangedEvents = RaiseListChangedEvents;
- try
- {
- RaiseListChangedEvents = false;
-
- foreach (var item in data)
- {
- var element = Csla<#= Model.Name #>Edit.Get<#= Model.Name #>Edit(item, loadSettings);
- this.Add(element);
- }
- }
- finally
- {
- RaiseListChangedEvents = oldRaiseListChangedEvents;
- }
- }
- #endregion
-
- #region [ Explicit IBusinessObjectCollection<I<#= Model.Name #>> implementation ]
-
- void ICollection<I<#= Model.Name #>>.Add(I<#= Model.Name #> item)
- {
- this.Add((Csla<#= Model.Name #>Edit)item);
- }
-
- void ICollection<I<#= Model.Name #>>.Clear()
- {
- this.Clear();
- }
-
- bool ICollection<I<#= Model.Name #>>.Contains(I<#= Model.Name #> item)
- {
- return this.Contains((Csla<#= Model.Name #>Edit)item);
- }
-
- void ICollection<I<#= Model.Name #>>.CopyTo(I<#= Model.Name #>[] array, int arrayIndex)
- {
- int size = Math.Min(array.Length - arrayIndex, this.Count);
- if (size > 0)
- {
- var a = new Csla<#= Model.Name #>Edit[size];
- this.CopyTo(a, 0);
- Array.Copy(a, 0, array, arrayIndex, size);
- }
- }
-
- int ICollection<I<#= Model.Name #>>.Count
- {
- get { return this.Count; }
- }
-
- bool ICollection<I<#= Model.Name #>>.IsReadOnly
- {
- get { return false; }
- }
-
- bool ICollection<I<#= Model.Name #>>.Remove(I<#= Model.Name #> item)
- {
- return this.Remove((Csla<#= Model.Name #>Edit)item);
- }
-
- IEnumerator<I<#= Model.Name #>> IEnumerable<I<#= Model.Name #>>.GetEnumerator()
- {
- return this.GetEnumerator();
- }
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return this.GetEnumerator();
- }
-
- bool IBusinessObject.IsReadonly
- {
- get { return false; }
- }
-
- bool IBusinessObject.IsDirty
- {
- get { return this.IsDirty; }
- }
-
- I<#= Model.Name #> IBusinessObjectCollection<I<#= Model.Name #>>.this[int index]
- {
- get
- {
- return this[index];
- }
- set
- {
- this[index] = (Csla<#= Model.Name #>Edit)value;
- }
- }
-
- #endregion [ Explicit IBusinessObjectCollection<I<#= Model.Name #>> implementation ]
- }
- }
- <#+
- return this.GenerationEnvironment.ToString();
- }
- }
- #>