3 using System
.Threading
;
4 using System
.Collections
.Generic
;
13 public class MainControl
: IMainControl
15 Thread presentationThread
;
16 bool disposed
= false;
18 IList
<ConnectionControl
> connControls
= new List
<ConnectionControl
>();
22 ConnectionFactory factory
;
26 IrcConnection
.ConnectionCreated
+= ConnectionCreatedHandler
;
27 StartTheWholeThingUp();
38 System
.GC
.SuppressFinalize(this);
41 protected void Dispose(bool managedRes
)
46 foreach (ConnectionControl ctrl
in connControls
)
47 ctrl
.Connection
.Dispose();
52 void StartTheWholeThingUp()
54 Logger
.Debug("MainControl fetching Frontend & Backend");
55 frontend
= AcquireFrontend(Options
.Frontend
);
56 backend
= AcquireBackend(Options
.Backend
);
58 if (frontend
== null || backend
== null)
59 System
.Console
.WriteLine("Fuck : {0} {1}", frontend
== null, backend
== null);
61 GuiFactory
.Factory
= frontend
.ToolkitFactory
;
63 Logger
.Debug("Frontend & Backend fetched");
64 InitializePresentation();
69 presentationThread
.Join();
72 public void ConnectNewServer(ConnectionInfo ci
)
75 1) Type typeOfGenericClass = System.Type.GetType("MyGenericClass`1")
76 2) Type typeParameters = typeof(myGenericTypeToCreate)
77 3) Type genericType = typeOfGenericClass.MakeGericType(typeparameters)
78 4) ConstructorInfo ci = genericType.GetConstrucors()[0]
81 factory
= backend
.GetConnectionFactory();
82 factory
.RequestConnection(ci
);
85 /*public void JoinChan(string serverName, string chan)
87 foreach(ConnectionControl ctrl in connControls) {
88 if (ctrl.Connection.Server == serverName)
89 ctrl.Connection.JoinChannel(chan);
93 public void WaitForInit()
95 while (!frontend
.IsInitialized
)
98 System
.Threading
.Thread
.Sleep(500);
101 public IConnectionControl
GetConnectionControl(string serverName
)
103 IConnectionControl temp
= null;
105 foreach (IConnectionControl ctrl
in connControls
) {
106 if (ctrl
.ServerName
== serverName
) {
115 void InitializePresentation()
117 Logger
.Debug("Initializing Presentation layer");
118 presentationThread
= new Thread(delegate() { frontend.StartPresentation(this); }
);
119 presentationThread
.IsBackground
= false;
120 presentationThread
.Name
= "PresentationThreadChannel";
121 presentationThread
.Start();
124 void ConnectionCreatedHandler(object sender
, EventArgs e
)
126 this.connControls
.Add(new ConnectionControl((IrcConnection
)sender
, this));
129 IFrontend
AcquireFrontend(string id
)
131 foreach (TypeExtensionNode node
in AddinManager
.GetExtensionNodes("/Circ/Frontends")) {
133 return (IFrontend
)node
.CreateInstance();
139 IBackend
AcquireBackend(string id
)
142 foreach (TypeExtensionNode node
in AddinManager
.GetExtensionNodes("/Circ/Backends")) {
144 return (IBackend
)node
.CreateInstance();
150 internal IFrontend Frontend
{
156 internal IBackend Backend
{