-
Notifications
You must be signed in to change notification settings - Fork 0
/
SAPIDocReceiveConfiguration.cs
176 lines (129 loc) · 6.82 KB
/
SAPIDocReceiveConfiguration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using SAP.Middleware;
using SAP.Middleware.Connector;
namespace Clarks.SAP.Connector
{
/// <summary>
/// Encapsulates connection functionality using NCO 3.
/// </summary>
public class SAPIDocReceiveConfiguration : IServerConfiguration
{
// holds all server configurations
Dictionary<string, RfcConfigParameters> availableDestinations = null;
RfcConfigParameters _parameters = new RfcConfigParameters();
// event fired when configuration is changed
public event RfcServerManager.ConfigurationChangeHandler ConfigurationChanged;
/// <summary>
/// Constructor
/// </summary>
/// <param name="locationConfigDom">Configuration connection parameters</param>
public SAPIDocReceiveConfiguration(string serverName,string destinationName,XmlDocument locationConfigDom)
{
if (availableDestinations==null)
availableDestinations = new Dictionary<string, RfcConfigParameters>();
UpdateParameters(serverName, destinationName,locationConfigDom);
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="locationConfigDom">Configuration connection parameters</param>
public SAPIDocReceiveConfiguration(string serverName,string destinationName,string progId)
{
if (availableDestinations == null)
availableDestinations = new Dictionary<string, RfcConfigParameters>();
AddParameters(serverName, progId);
}
/// <summary>
/// Implemented from IDestinationConfiguration,returns populated
/// Rfc parameters collection to RFC destination manager
/// </summary>
/// <param name="destinationName">The destination name used in repositiry</param>
/// <returns>The collection of RFC parameters</returns>
public RfcConfigParameters GetParameters(string serverName)
{
RfcConfigParameters foundDestination;
if (availableDestinations != null)
{
availableDestinations.TryGetValue(serverName, out foundDestination);
if (foundDestination==null)
throw new ApplicationException(string.Format("Server:{0} parameters do not exist in repository", serverName));
}
else
{
throw new ApplicationException(string.Format("Server:{0} parameters do not exist in repository",serverName));
}
//return foundDestination;
RfcConfigParameters rfcConfigParameters = availableDestinations[serverName];
return rfcConfigParameters;
}
/// <summary>
/// Called from constructor
/// </summary>
/// <param name="locationConfigDom">Xml containing parameters, passed by BizTalk</param>
public void UpdateParameters(string serverName, string destinationName, XmlDocument configDOM)
{
RfcConfigParameters parameters = new RfcConfigParameters();
parameters.Add(RfcConfigParameters.RepositoryDestination, destinationName);
parameters.Add(RfcConfigParameters.Name, serverName);
parameters.Add(RfcConfigParameters.GatewayHost, SAPIDocUtils.Extract(configDOM, "/Config/gatewayHost").ToString());
parameters.Add(RfcConfigParameters.GatewayService, SAPIDocUtils.Extract(configDOM, "/Config/gatewayService").ToString());
parameters.Add(RfcConfigParameters.ProgramID, SAPIDocUtils.Extract(configDOM, "/Config/programID").ToString());
parameters.Add(RfcConfigParameters.RegistrationCount, SAPIDocUtils.Extract(configDOM, "/Config/registrationCount").ToString());
parameters.Add(RfcConfigParameters.Trace,SAPIDocUtils.ExtractUInt(configDOM, "/Config/rfcTrace").ToString());
RfcConfigParameters existingConfiguration;
//if a destination of that name existed before, we need to fire a change event
if (availableDestinations.TryGetValue(serverName, out existingConfiguration))
{
availableDestinations[serverName] = parameters;
RfcConfigurationEventArgs eventArgs = new RfcConfigurationEventArgs(RfcConfigParameters.EventType.CHANGED, parameters);
System.Diagnostics.Trace.WriteLine("Fire change event " + eventArgs.ToString() + " for destination " + serverName);
// fire changed event
if (ConfigurationChanged != null)
ConfigurationChanged(serverName, eventArgs);
}
else
{
availableDestinations[serverName] = parameters;
}
}
/// <summary>
/// Called by constructor
/// </summary>
/// <param name="serverName"></param>
public void AddParameters(string serverName,string progId)//, string destinationName)
{
// temp hard-coded for prototyping
string destinationName = "SAP_IDOC_DESTINATION_CONFIG";
RfcConfigParameters parameters = new RfcConfigParameters();
parameters.Add(RfcConfigParameters.Name, serverName);
parameters.Add(RfcConfigParameters.RepositoryDestination, destinationName);
parameters.Add(RfcConfigParameters.GatewayHost, "10.2.17.78");
parameters.Add(RfcConfigParameters.GatewayService, "3300");
parameters.Add(RfcConfigParameters.ProgramID, progId);
parameters.Add(RfcConfigParameters.RegistrationCount, "1");
RfcConfigParameters existingConfiguration;
//if a destination of that name existed before, we need to fire a change event
if (availableDestinations.TryGetValue(serverName, out existingConfiguration))
{
availableDestinations[serverName] = parameters;
RfcConfigurationEventArgs eventArgs= new RfcConfigurationEventArgs(RfcConfigParameters.EventType.CHANGED, _parameters);
System.Diagnostics.Trace.WriteLine("Fire change event " + eventArgs.ToString() + " for destination " + serverName);
// fire changed event
if (ConfigurationChanged != null)
ConfigurationChanged(serverName, eventArgs);
}
else
{
availableDestinations[serverName] = parameters;
}
}
// The following code is not used in this example
public bool ChangeEventsSupported()
{
return true;
}
}
}