|
using System;
using System.Drawing;
using System.Windows.Forms;
using Codebasement.DomainDrivenDesign.Basement.Basement;
using Codebasement.DomainDrivenDesign.Basement.EventArguments;
using Codebasement.DomainDrivenDesign.Model.ModelClasses;
using Codebasement.DomainDrivenDesign.Model.Utilities;
namespace Codebasement.DomainDrivenDesign.Model.Factory
{
/// <summary>
///
/// </summary>
public static class ModelFactory
{
/// <summary>
/// Creates the object.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="parentObject">The parent object.</param>
/// <returns></returns>
public static BasementObject CreateObject(
Type type,
BasementObject parentObject)
{
BasementObject newObject =
Activator.CreateInstance(type) as BasementObject;
if (newObject != null)
{
newObject.ObjectIdentifier = Guid.NewGuid();
newObject.OnBasementObjectCreated(new BasementObjectEventArgs(newObject));
}
if (parentObject != null)
{
if (parentObject.Relatables.Contains(type))
parentObject.Relations.Add(newObject);
else
throw new InvalidOperationException(
String.Format("Type {0} not relatable to object {1}",
type, parentObject));
}
return newObject;
}
/// <summary>
/// Removes the object.
/// </summary>
/// <param name="basementObject">The basement object.</param>
/// <param name="parentObject">The parent object.</param>
public static void RemoveObject(BasementObject basementObject, BasementObject parentObject)
{
if (!(parentObject != null &
basementObject != null)) return;
parentObject.Relations.Remove(basementObject);
basementObject.OnBasementObjectRemoved(new BasementObjectEventArgs(basementObject));
}
/// <summary>
/// New container.
/// </summary>
/// <returns></returns>
public static BasementObject NewContainer()
{
BasementObject basementObject =
CreateObject(typeof (InformationContainer), null);
InformationContainer container =
basementObject as InformationContainer;
if (container != null)
container.Name = "Root";
Customers customers =
CreateObject(typeof(Customers), container) as Customers;
Servers servers =
CreateObject(typeof (Servers), container) as Servers;
Server server =
CreateObject(typeof (Server), servers) as Server;
Users users =
CreateObject(typeof(Users), container) as Users;
return basementObject;
}
/// <summary>
/// Gets the index of the image.
/// </summary>
/// <param name="type">The type.</param>
/// <returns></returns>
public static int GetImageIndex(Type type)
{
return ModelImages.GetImageIndex(type);
}
/// <summary>
/// Gets the image.
/// </summary>
/// <param name="type">The type.</param>
/// <returns></returns>
public static Image GetImage(Type type)
{
return ModelImages.GetImage(type);
}
/// <summary>
/// Gets the image list.
/// </summary>
/// <returns></returns>
public static ImageList GetImageList()
{
return ModelImages.GetImageList();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.