1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using System.Xml;
|
---|
7 | using System.ServiceModel;
|
---|
8 | using System.ServiceModel.Description;
|
---|
9 | using HeuristicLab.CEDMA.DB.Interfaces;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.CEDMA.Console {
|
---|
12 | public class Console : ItemBase, IEditable {
|
---|
13 | private AgentList agentList;
|
---|
14 | private ChannelFactory<IDatabase> factory;
|
---|
15 | private IDatabase database;
|
---|
16 | private string serverUri;
|
---|
17 | public string ServerUri {
|
---|
18 | get { return serverUri; }
|
---|
19 | set {
|
---|
20 | serverUri = value;
|
---|
21 | ResetConnection();
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | public IAgentList AgentList {
|
---|
26 | get { return agentList; }
|
---|
27 | }
|
---|
28 |
|
---|
29 | public Console()
|
---|
30 | : base() {
|
---|
31 | agentList = new AgentList();
|
---|
32 | }
|
---|
33 |
|
---|
34 | public IEditor CreateEditor() {
|
---|
35 | return new ConsoleEditor(this);
|
---|
36 | }
|
---|
37 |
|
---|
38 | public IView CreateView() {
|
---|
39 | return new ConsoleEditor(this);
|
---|
40 | }
|
---|
41 |
|
---|
42 | #region serialization
|
---|
43 | public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
|
---|
44 | XmlNode node = base.GetXmlNode(name, document, persistedObjects);
|
---|
45 | XmlAttribute uriAttribute = document.CreateAttribute("ServerURI");
|
---|
46 | uriAttribute.Value = serverUri;
|
---|
47 | node.Attributes.Append(uriAttribute);
|
---|
48 | return node;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
|
---|
52 | base.Populate(node, restoredObjects);
|
---|
53 | ServerUri = node.Attributes["ServerURI"].Value;
|
---|
54 | }
|
---|
55 | #endregion
|
---|
56 |
|
---|
57 | #region WCF
|
---|
58 | private void ResetConnection() {
|
---|
59 | NetTcpBinding binding = new NetTcpBinding();
|
---|
60 | binding.MaxReceivedMessageSize = 10000000; // 10Mbytes
|
---|
61 | binding.ReaderQuotas.MaxStringContentLength = 10000000; // also 10M chars
|
---|
62 | binding.ReaderQuotas.MaxArrayLength = 10000000; // also 10M elements;
|
---|
63 | binding.Security.Mode = SecurityMode.None;
|
---|
64 | factory = new ChannelFactory<IDatabase>(binding);
|
---|
65 | database = factory.CreateChannel(new EndpointAddress(serverUri));
|
---|
66 | agentList.Database = database;
|
---|
67 | }
|
---|
68 | #endregion
|
---|
69 | }
|
---|
70 | }
|
---|