B
BennyEz
I'm attempting to create an object based system where custom business
objects are inherited by a custom Shape object which implements a
custom shape interface exposing a Render method along with other
possible methods.
For example:
public interface ICustomShape
{
double Width { get;set; }
double Height { get;set; }
double StartX { get;set; }
double StartY { get;set; }
string Text { get;set; }
void PreRender(Visio.Window vsoWin);
void Render(Visio.Window vsoWin);
void PostRender(Visio.Window vsoWin);
}
--------------------
class Building
{
private string _Name;
private string _Address;
public List<Room> Rooms = new List<Room>();
public string Name
{
get
{
return _Name.ToString();
}
set
{
_Name = value.ToString();
}
}
public string Address
{
get
{
return _Address.ToString();
}
set
{
_Address = value.ToString();
}
}
}
----------------------------------------------------------------------------
class Room
{
private string _RoomCode;
public string RoomCode
{
get
{
return _RoomCode.ToString();
}
set
{
_RoomCode= value.ToString();
}
}
}
------------------------------------------------------------------------------
class BuildingShape : Building, ICustomShape
{
//Here you would implement the public properties Width, Height,
StartX, StartY, and Text.
//Here you would also implement the Render methods.
}
------------------------------------------------------------------------------
ok, I also have a Diagram interface which represents an overall visio
diagram.
public interface IDiagram
{
double Width { get;set; }
double Height { get;set; }
void PreRender(Visio.Window vsoWin);
void Render(Visio.Window vsoWin);
void PostRender(Visio.Window vsoWin);
}
-------------------------------------------------------------------------------
Next there is also a base Diagram class which implements the above
interface and lets you implement the render methods as you wish as
well as add new functionality.
So now we can have different types of diagrams. I could create a new
interface that passes in a Word Doc instead of a Visio.Window. This
allows you to reuse drawing and sizing function where possible and
still extend what you have.
The Diagram class I currently have has a public list you can add
shapes to. So you can create a bunch of building shapes and inside of
these place Room Shapes and then place all these room shapes into the
Shapes List:
public List<object> Shapes = new List<object>();
I then implement the Render method of the Diagram.cs like so:
public void Render(Microsoft.Office.Interop.Visio.Window
vsoWin)
{
Type FoundInterface;
Type shpType;
TestBed.Interfaces.ICustomShape shpObj;
foreach (object shp in this.Shapes)
{
shpType = shp.GetType();
FoundInterface = shpType.GetInterface("ICustomShape");
if (FoundInterface != null)
{
shpObj = (TestBed.Interfaces.ICustomShape)shp;
shpObj.Render(vsoWin);
}
}
}
-------------------------------------
So for each of the shapes you place in the list it will call the
shapes's render method regardless of what it's base type is. That
shape can then have a collection it iterates through and call the
render method of all of the shapes found in there.
With this you could create self drawing diagrams with much potential
for re-use. Let's say for example that we are not drawing to scale but
rather only making a building large enough to show the rooms, and each
room only large enough to list student names. That means we'd have to
figure out the number of rooms and the size of those rooms before we
could figure out the size of the building. I picture using the pre-
render methods to help out with that.
There are a lot of options. Problem is, I feel like there has to be
something like this out there. Even for all it's "possible" up-sides
it still feels very cubmbersome when trying to do certain things. Am I
re-creating the wheel here or does anyone see a better approach to
what I am trying to do?
Here is a real world example of what it is being used for:
We have business object that represent infrastructure, DataCenters,
Servers, Apps, Firewalls, Routers, Switches, etc. etc....
We want to plot these on a number of different diagrams. Say one is a
global map. We set the diagram to open the global map as a template.
Then set the X and Y of each DataCenter to Long and Lat however now
these data centers must Look at all the servers within, then within
each of these servers look at how many apps are running on that
server. You need room to list the apps and therefore the shape
representing the server will be as big as needed to list all the apps.
Add all those servers together with margins between them and this
represents the data center size. I also want flags being able to tell
the Datacenters to perhaps not draw the apps inside the servers. This
would reduce the size of the DataCenter because the servers would not
need room for the apps. So on and So on..
Any ideas would be appreciated. Thanks
objects are inherited by a custom Shape object which implements a
custom shape interface exposing a Render method along with other
possible methods.
For example:
public interface ICustomShape
{
double Width { get;set; }
double Height { get;set; }
double StartX { get;set; }
double StartY { get;set; }
string Text { get;set; }
void PreRender(Visio.Window vsoWin);
void Render(Visio.Window vsoWin);
void PostRender(Visio.Window vsoWin);
}
--------------------
class Building
{
private string _Name;
private string _Address;
public List<Room> Rooms = new List<Room>();
public string Name
{
get
{
return _Name.ToString();
}
set
{
_Name = value.ToString();
}
}
public string Address
{
get
{
return _Address.ToString();
}
set
{
_Address = value.ToString();
}
}
}
----------------------------------------------------------------------------
class Room
{
private string _RoomCode;
public string RoomCode
{
get
{
return _RoomCode.ToString();
}
set
{
_RoomCode= value.ToString();
}
}
}
------------------------------------------------------------------------------
class BuildingShape : Building, ICustomShape
{
//Here you would implement the public properties Width, Height,
StartX, StartY, and Text.
//Here you would also implement the Render methods.
}
------------------------------------------------------------------------------
ok, I also have a Diagram interface which represents an overall visio
diagram.
public interface IDiagram
{
double Width { get;set; }
double Height { get;set; }
void PreRender(Visio.Window vsoWin);
void Render(Visio.Window vsoWin);
void PostRender(Visio.Window vsoWin);
}
-------------------------------------------------------------------------------
Next there is also a base Diagram class which implements the above
interface and lets you implement the render methods as you wish as
well as add new functionality.
So now we can have different types of diagrams. I could create a new
interface that passes in a Word Doc instead of a Visio.Window. This
allows you to reuse drawing and sizing function where possible and
still extend what you have.
The Diagram class I currently have has a public list you can add
shapes to. So you can create a bunch of building shapes and inside of
these place Room Shapes and then place all these room shapes into the
Shapes List:
public List<object> Shapes = new List<object>();
I then implement the Render method of the Diagram.cs like so:
public void Render(Microsoft.Office.Interop.Visio.Window
vsoWin)
{
Type FoundInterface;
Type shpType;
TestBed.Interfaces.ICustomShape shpObj;
foreach (object shp in this.Shapes)
{
shpType = shp.GetType();
FoundInterface = shpType.GetInterface("ICustomShape");
if (FoundInterface != null)
{
shpObj = (TestBed.Interfaces.ICustomShape)shp;
shpObj.Render(vsoWin);
}
}
}
-------------------------------------
So for each of the shapes you place in the list it will call the
shapes's render method regardless of what it's base type is. That
shape can then have a collection it iterates through and call the
render method of all of the shapes found in there.
With this you could create self drawing diagrams with much potential
for re-use. Let's say for example that we are not drawing to scale but
rather only making a building large enough to show the rooms, and each
room only large enough to list student names. That means we'd have to
figure out the number of rooms and the size of those rooms before we
could figure out the size of the building. I picture using the pre-
render methods to help out with that.
There are a lot of options. Problem is, I feel like there has to be
something like this out there. Even for all it's "possible" up-sides
it still feels very cubmbersome when trying to do certain things. Am I
re-creating the wheel here or does anyone see a better approach to
what I am trying to do?
Here is a real world example of what it is being used for:
We have business object that represent infrastructure, DataCenters,
Servers, Apps, Firewalls, Routers, Switches, etc. etc....
We want to plot these on a number of different diagrams. Say one is a
global map. We set the diagram to open the global map as a template.
Then set the X and Y of each DataCenter to Long and Lat however now
these data centers must Look at all the servers within, then within
each of these servers look at how many apps are running on that
server. You need room to list the apps and therefore the shape
representing the server will be as big as needed to list all the apps.
Add all those servers together with margins between them and this
represents the data center size. I also want flags being able to tell
the Datacenters to perhaps not draw the apps inside the servers. This
would reduce the size of the DataCenter because the servers would not
need room for the apps. So on and So on..
Any ideas would be appreciated. Thanks