1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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 HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
25 | using System;
|
---|
26 | using System.Threading;
|
---|
27 | using System.Threading.Tasks;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Optimization.Networks {
|
---|
30 | [Item("ServicePort", "A service port of an optimization network node.")]
|
---|
31 | [StorableClass]
|
---|
32 | public class ServicePort : ClientServicePort, IServicePort {
|
---|
33 | [StorableConstructor]
|
---|
34 | protected ServicePort(bool deserializing) : base(deserializing) { }
|
---|
35 | protected ServicePort(ServicePort original, Cloner cloner) : base(original, cloner) { }
|
---|
36 | public ServicePort() : base("ServicePort") { }
|
---|
37 | public ServicePort(string name) : base(name) { }
|
---|
38 | public ServicePort(string name, string description) : base(name, description) { }
|
---|
39 |
|
---|
40 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
41 | return new ServicePort(this, cloner);
|
---|
42 | }
|
---|
43 |
|
---|
44 | public ServiceParameterCollection Process(ServiceParameterCollection parameters) {
|
---|
45 | return Process(parameters, CancellationToken.None);
|
---|
46 | }
|
---|
47 | public ServiceParameterCollection Process(ServiceParameterCollection parameters, CancellationToken token) {
|
---|
48 | return OnProcessParameters(parameters, token);
|
---|
49 | }
|
---|
50 | public async Task<ServiceParameterCollection> ProcessAsync(ServiceParameterCollection parameters) {
|
---|
51 | return await ProcessAsync(parameters, CancellationToken.None);
|
---|
52 | }
|
---|
53 | public async Task<ServiceParameterCollection> ProcessAsync(ServiceParameterCollection parameters, CancellationToken token) {
|
---|
54 | return await Task.Run(() => { return Process(parameters, token); }, token);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public event EventHandler<EventArgs<ServiceParameterCollection, CancellationToken>> ProcessParameters;
|
---|
58 | protected virtual ServiceParameterCollection OnProcessParameters(ServiceParameterCollection parameters, CancellationToken token) {
|
---|
59 | var handler = ProcessParameters;
|
---|
60 | if (handler != null) handler(this, new EventArgs<ServiceParameterCollection, CancellationToken>(parameters, token));
|
---|
61 | return parameters;
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|