1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using System.Xml;
|
---|
28 | using System.ServiceModel;
|
---|
29 | using System.ServiceModel.Description;
|
---|
30 | using HeuristicLab.CEDMA.DB.Interfaces;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.CEDMA.Core {
|
---|
33 | public class Console : ItemBase, IEditable {
|
---|
34 | private AgentList agentList;
|
---|
35 | private ResultList resultsList;
|
---|
36 | private DatabaseOperatorLibrary operatorLibary;
|
---|
37 | private ChannelFactory<IDatabase> factory;
|
---|
38 | private IDatabase database;
|
---|
39 | private string serverUri;
|
---|
40 | public string ServerUri {
|
---|
41 | get { return serverUri; }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public IAgentList AgentList {
|
---|
45 | get { return agentList; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public ResultList ResultsList {
|
---|
49 | get { return resultsList; }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public IOperatorLibrary OperatorLibrary {
|
---|
53 | get { return operatorLibary; }
|
---|
54 | }
|
---|
55 |
|
---|
56 | public Console()
|
---|
57 | : base() {
|
---|
58 | agentList = new AgentList();
|
---|
59 | resultsList = new ResultList();
|
---|
60 | operatorLibary = new DatabaseOperatorLibrary();
|
---|
61 | }
|
---|
62 |
|
---|
63 | public IEditor CreateEditor() {
|
---|
64 | return new ConsoleEditor(this);
|
---|
65 | }
|
---|
66 |
|
---|
67 | public override IView CreateView() {
|
---|
68 | return new ConsoleEditor(this);
|
---|
69 | }
|
---|
70 |
|
---|
71 | #region serialization
|
---|
72 | public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
|
---|
73 | XmlNode node = base.GetXmlNode(name, document, persistedObjects);
|
---|
74 | XmlAttribute uriAttribute = document.CreateAttribute("ServerURI");
|
---|
75 | uriAttribute.Value = serverUri;
|
---|
76 | node.Attributes.Append(uriAttribute);
|
---|
77 | return node;
|
---|
78 | }
|
---|
79 |
|
---|
80 | public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
|
---|
81 | base.Populate(node, restoredObjects);
|
---|
82 | serverUri = node.Attributes["ServerURI"].Value;
|
---|
83 | }
|
---|
84 | #endregion
|
---|
85 |
|
---|
86 | #region WCF
|
---|
87 | private void ResetConnection() {
|
---|
88 | NetTcpBinding binding = new NetTcpBinding();
|
---|
89 | binding.MaxReceivedMessageSize = 100000000; // 100Mbytes
|
---|
90 | binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars
|
---|
91 | binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements;
|
---|
92 | binding.Security.Mode = SecurityMode.None;
|
---|
93 | factory = new ChannelFactory<IDatabase>(binding);
|
---|
94 | database = factory.CreateChannel(new EndpointAddress(serverUri));
|
---|
95 | agentList.Database = database;
|
---|
96 | operatorLibary.Database = database;
|
---|
97 |
|
---|
98 | ChannelFactory<IStore> storeFactory = new ChannelFactory<IStore>(binding);
|
---|
99 | IStore store = storeFactory.CreateChannel(new EndpointAddress(serverUri + "/RdfStore"));
|
---|
100 | resultsList.Store = store;
|
---|
101 | }
|
---|
102 | #endregion
|
---|
103 |
|
---|
104 | internal void Connect(string serverUri) {
|
---|
105 | this.serverUri = serverUri;
|
---|
106 | ResetConnection();
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|