|
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Remoting;
using System.Runtime.Versioning;
using Harlinn.CIMTool.Types;
using System.Text;
namespace Harlinn.CIMTool.CodeGenerator
{
public class Namespace : NamedElement
{
string rootNamespaceName;
CodeProvider codeProvider;
ManagementScopeWrapper scope;
NamespaceClassFactory namespaceClassFactory;
Dictionary<string, NamedElement> elements;
CodeNamespace managementCodeNamespace;
bool enablePrefix;
public Namespace(CodeProvider theCodeProvider, ManagementScopeWrapper theScope)
{
if (theCodeProvider == null)
{
throw new ArgumentNullException("theCodeProvider");
}
if (theScope == null)
{
throw new ArgumentNullException("theScope");
}
codeProvider = theCodeProvider;
scope = theScope;
rootNamespaceName = theCodeProvider.GeneratorOptions.RootManagementNamespace;
elements = new Dictionary<string, NamedElement>();
if (string.IsNullOrWhiteSpace(theCodeProvider.GeneratorOptions.ManagementNamespace))
{
Key = theScope.Name;
Name = AddName(Key);
}
else
{
Key = theScope.Name;
Name = AddName(theCodeProvider.GeneratorOptions.ManagementNamespace);
}
enablePrefix = true;
BindingListEx<ManagementClassWrapper> classes = theScope.Classes;
/*
BaseElementClass baseElementClass = new BaseElementClass(this);
string baseElementClassName = PrefixName("BaseElement");
baseElementClass.Key = "BaseElement";
baseElementClass.Name = baseElementClassName;
Names.Add(baseElementClass.Key, baseElementClassName);
elements.Add(baseElementClass.Key, baseElementClass);
*/
foreach (ManagementClassWrapper mc in classes)
{
string name = AddName(mc.Name);
Class theClass = new Class(this, mc);
theClass.Key = mc.Name;
theClass.Name = name;
elements.Add(mc.Name, theClass);
}
foreach (NamedElement ne in elements.Values)
{
ne.ResolveReferences();
}
foreach (NamedElement ne in elements.Values)
{
ne.ResolveDuplicates();
}
namespaceClassFactory = new NamespaceClassFactory(this);
namespaceClassFactory.Key = Name + "ClassFactory"; // typeof(NamespaceClassFactory).Name;
namespaceClassFactory.Name = AddName(namespaceClassFactory.Key);
elements.Add(namespaceClassFactory.Key, namespaceClassFactory);
}
public NamespaceClassFactory NamespaceClassFactory
{
get
{
return namespaceClassFactory;
}
}
public CodeNamespace ManagementCodeNamespace
{
get
{
if (managementCodeNamespace == null)
{
managementCodeNamespace = new CodeNamespace(rootNamespaceName+"."+Name);
}
return managementCodeNamespace;
}
}
public override string PrefixName(string theName)
{
if (enablePrefix)
{
return CodeProvider.PrefixName(theName);
}
return theName;
}
public override void GenerateManagementCode()
{
CodeNamespace cn = ManagementCodeNamespace;
cn.Imports.Add(new CodeNamespaceImport("System"));
cn.Imports.Add(new CodeNamespaceImport("System.ComponentModel"));
cn.Imports.Add(new CodeNamespaceImport("System.Management"));
cn.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));
cn.Imports.Add(new CodeNamespaceImport("Harlinn.CIMTool.Mgmt"));
if (CodeProvider.Language == CodeLanguage.VB)
{
cn.Imports.Add(new CodeNamespaceImport("Microsoft.VisualBasic"));
}
// Elements["BaseElement"].GenerateManagementCode();
List<Class> classes = new List<Class>();
foreach (NamedElement ne in Elements.Values)
{
if (ne is Class)
{
Class theClass = (Class)ne;
classes.Add(theClass);
}
}
classes.Sort(new ClassComparer());
foreach (Class c in classes)
{
c.GenerateManagementCode();
}
namespaceClassFactory.GenerateManagementCode();
}
public Dictionary<string, NamedElement> Elements
{
get
{
return elements;
}
}
public override CodeProvider CodeProvider
{
get
{
return codeProvider;
}
}
}
}
|
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.
Chief Architect - Sea Surveillance AS.
Specializing in integrated operations and high performance computing solutions.
I’ve been fooling around with computers since the early eighties, I’ve even done work on CP/M and MP/M.
Wrote my first “real” program on a BBC micro model B based on a series in a magazine at that time. It was fun and I got hooked on this thing called programming ...
A few Highlights:
- High performance application server development
- Model Driven Architecture and Code generators
- Real-Time Distributed Solutions
- C, C++, C#, Java, TSQL, PL/SQL, Delphi, ActionScript, Perl, Rexx
- Microsoft SQL Server, Oracle RDBMS, IBM DB2, PostGreSQL
- AMQP, Apache qpid, RabbitMQ, Microsoft Message Queuing, IBM WebSphereMQ, Oracle TuxidoMQ
- Oracle WebLogic, IBM WebSphere
- Corba, COM, DCE, WCF
- AspenTech InfoPlus.21(IP21), OsiSoft PI
More information about what I do for a living can be found at:
harlinn.com or
LinkedIn
You can contact me at
espen@harlinn.no