Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Console/Console.cs @ 357

Last change on this file since 357 was 357, checked in by gkronber, 16 years ago

worked on ticket #187. code is a mess. work-in-progress.

File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using System.Xml;
7using System.ServiceModel;
8using System.ServiceModel.Description;
9using HeuristicLab.CEDMA.DB.Interfaces;
10
11namespace 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}
Note: See TracBrowser for help on using the repository browser.