example
unknown
csharp
3 years ago
5.0 kB
14
Indexable
private bool loadElement()
{
DenResourceFilesHandler resourceHandler = new DenResourceFilesHandler(Session);
//Fetch the portals dll etc. from the database
EpcResourceFilesIdentity resourceId = new EpcResourceFilesIdentity() { Cotstd_Stdid = currentElement.Dashboard_Stdid, Id = currentElement.Resource_Id, Seqno = 0 };
Assembly assembly = null;
if (!resourceHandler.IsBuiltinResource(resourceId.Id))
{
string filename = resourceHandler.GetResource(resourceId);
if (!String.IsNullOrEmpty(filename))
{
//Load it
assembly = resourceHandler.LoadAssembly(filename);
}
}
else
{
assembly = resourceHandler.GetLoadedAssembly(resourceId.Id == "USERINTERFACE" ? "xxx.dll" : "xxxxx.dll");
}
if (assembly != null)
{
// Walk through each type in the assembly
foreach (Type type in assembly.GetTypes())
{
// Check if type is a class and its name matches currentElement's class name
if (type.IsClass && type.Name.Equals(currentElement.Classname))
{
// Array of constructors' required parameter types
Type[] constructorParamTypes = new Type[]
{
typeof(IdesSession),
typeof(EpcDashboardElements),
typeof(decimal?)
};
object o = null;
ConstructorInfo ci = type.GetConstructor(constructorParamTypes);
// Check if the constructor with required parameter types exists
if (ci != null)
{
// Invoke constructor with provided parameters
o = ci.Invoke(new object[] { Session, currentElement, currentContext });
}
else
{
// Check if default constructor exists
ci = type.GetConstructor(Type.EmptyTypes);
if (ci != null)
{
// Invoke default constructor
o = ci.Invoke(null);
}
}
// If object implements IIdesDashboardElement interface, set session
if (o is IDenDashboardElement)
{
(o as IDenDashboardElement).SetSession(Session);
}
// Convert object to Control type
currentControl = o as Control;
if (currentControl != null)
{
// Set dock style to fill
currentControl.Dock = DockStyle.Fill;
}
}
// Pick up a class
if (type.IsClass == true && type.Name.Equals(currentElement.Classname))
{
Type[] citypes = new Type[3];
citypes[0] = typeof(DenSession);
citypes[1] = typeof(EpcDashboardElements);
citypes[2] = typeof(decimal?);
object o = null;
ConstructorInfo ci = type.GetConstructor(citypes);
if (ci != null)
{
o = ci.Invoke(new object[] { Session, currentElement, currentContext });
}
else
{
ci = type.GetConstructor(Type.EmptyTypes);
if (ci != null)
o = ci.Invoke(null);
}
if (o is IDensDashboardElement)
{
(o as IDensDashboardElement).SetSession(Session);
}
currentControl = o as Control;
if (currentControl != null)
{
currentControl.Dock = DockStyle.Fill;
}
}
}
if (currentControl != null)
{
initGridViews(currentControl);
this.Controls.Add(currentControl);
}
}
return true;
}Editor is loading...