source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/IHS BMX Framework/IndianHealthService.BMXNet/Net/BMXNetSocketBroker.cs@ 1769

Last change on this file since 1769 was 1146, checked in by Sam Habiel, 13 years ago

Initial Import of BMX4

File size: 6.7 KB
Line 
1using System;
2using System.Diagnostics;
3using System.Text;
4using System.IO;
5using System.Net.Sockets;
6using System.Net;
7using System.Security.Cryptography;
8using System.Security.Permissions;
9using System.Security.Principal;
10using System.Threading;
11using System.Timers;
12using IndianHealthService.BMXNet.Services;
13using IndianHealthService.BMXNet.Model;
14
15namespace IndianHealthService.BMXNet.Net
16{
17 /// <summary>
18 /// BMXNetBroker implements low-level socket connectivity to RPMS databases.
19 /// The VA RPC Broker must be running on the RPMS server in order for
20 /// BMXNetBroker to connect.
21 /// </summary>
22
23 [DnsPermission(SecurityAction.Assert, Unrestricted = true)]
24 internal class BMXNetSocketBroker : BMXNetBroker, BMXNetSessionConnectionSource
25 {
26 public BMXNetSocketBroker()
27 {
28 }
29
30 private BMXRemoteSessionPool _sessionPool = null;
31
32 internal BMXRemoteSessionPool SessionPool
33 {
34 get { return _sessionPool; }
35 set { _sessionPool = value; }
36 }
37
38 public override RemoteSessionPool RemoteSessionPool
39 {
40 get { return this.SessionPool; }
41 }
42
43 public override void Close()
44 {
45 if (this.SessionPool != null)
46 {
47 this.SessionPool.Close();
48 this.SessionPool = null;
49 }
50 }
51
52 public User FriendUser
53 {
54 set
55 {
56 this.User = value;
57 }
58 }
59
60 private bool _loggedInWithWindowsIdentity = false;
61
62 public bool LoggedInWithWindowsIdentity
63 {
64 get { return _loggedInWithWindowsIdentity; }
65 set { _loggedInWithWindowsIdentity = value; }
66 }
67
68 private BMXNetSocketConnectionSpec _connectionSpec = null;
69
70 public BMXNetSocketConnectionSpec ConnectionSpec
71 {
72 get { return _connectionSpec; }
73 set { _connectionSpec = value; }
74 }
75
76
77 public override bool IsConnected
78 {
79 get
80 {
81 return this.PrimarySession != null && this.PrimarySession.SessionConnection.IsConnected;
82 }
83 }
84
85
86 public override RemoteSession PrimaryRemoteSession
87 {
88 get
89 {
90 return (RemoteSession)this.PrimarySession;
91 }
92 }
93
94 private BMXNetRemoteSession _primarySession = null;
95
96 internal BMXNetRemoteSession PrimarySession
97 {
98 get { return _primarySession; }
99 set { _primarySession = value; }
100 }
101
102
103 void BMXNetSessionConnectionSource.CloseConnection(BMXNetSessionConnection aConnection)
104 {
105 if (aConnection == null)
106 {
107 return;
108 }
109
110 this.Log.Log("BMX NET", "Debug", "Closing Socket Session Connection");
111
112 aConnection.Close();
113 }
114
115
116 BMXNetSessionConnection BMXNetSessionConnectionSource.OpenConnection()
117 {
118 this.Log.Log("BMX NET", "Debug", "Opening Socket Session Connection");
119 BMXNetSessionSocketConnection connection = new BMXNetSessionSocketConnection(this);
120
121 connection.OpenConnection(this.ConnectionSpec);
122
123 return connection.IsConnected ? connection : null;
124 }
125
126
127 public override bool Open(string aServer, int aPort, string aNameSpace, string anAccessCode, string aVerifyCode,int sendTimeout,int receiveTimeout)
128 {
129 BMXNetSocketConnectionSpec spec = new BMXNetSocketConnectionSpec();
130 spec.SendTimeout = sendTimeout;
131 spec.ReceiveTimeout = receiveTimeout;
132 spec.Server = aServer;
133 spec.Port = aPort;
134 spec.NameSpace = aNameSpace;
135 spec.EncryptedAccessVerifyCode = new BMXNetSessionSocketConnection(this).EncryptAccessVerifyCode(anAccessCode, aVerifyCode);
136
137 this.ConnectionSpec = spec;
138
139 return this.Open(spec);
140 }
141
142
143 public override bool Open(string aServer, int aPort, string aNameSpace, WindowsIdentity windowsIdentity, int sendTimeout, int receiveTimeout)
144 {
145 BMXNetSocketConnectionSpec spec = new BMXNetSocketConnectionSpec();
146 spec.SendTimeout = sendTimeout;
147 spec.ReceiveTimeout = receiveTimeout;
148 spec.Server = aServer;
149 spec.Port = aPort;
150 spec.NameSpace = aNameSpace;
151 spec.WindowsIdentity = windowsIdentity;
152
153 this.ConnectionSpec = spec;
154
155 return this.Open(spec);
156 }
157
158
159 private bool Open(BMXNetSocketConnectionSpec aSpec)
160 {
161 this.ConnectionSpec = aSpec;
162 this.SessionPool = new BMXRemoteSessionPool();
163 this.SessionPool.Log = this.Log;
164 this.SessionPool.Begin(this);
165 this.PrimarySession = (BMXNetRemoteSession)this.SessionPool.OpenSession();
166
167 return this.PrimarySession != null;
168 }
169
170 public override String RegisterWindowsIdentityForWindowsAuthenication(WindowsIdentity aWindowsIdentity)
171 {
172 if (this.PrimarySession.IsConnected)
173 {
174 if (aWindowsIdentity.IsAuthenticated)
175 {
176 return this.PrimarySession.TransmitRPC("BMXNetSetUser", aWindowsIdentity.Name);
177 }
178 else
179 {
180 throw new BMXNetException("Current Windows User is not authenticated");
181 }
182 }
183 else
184 {
185 throw new BMXNetException("Connection disconnected immediately after login.");
186 }
187 }
188
189
190 }
191
192 /*
1931 ;;1;Signons not currently allowed on this processor.
1942 ;;1;Maximum number of users already signed on to this processor.
1953 ;;1;This device has not been defined to the system -- contact system manager.
1964 ;;0;Not a valid Windows Identity map value.
1975 ;;0;No Access Allowed for this User.
1986 ;;0;Invalid device password.
1997 ;;0;Device locked due to too many invalid sign-on attempts.
2008 ;;1;This device is out of service.
2019 ;;0;*** MULTIPLE SIGN-ONS NOT ALLOWED ***
20210 ;;1;You don't have access to this device!
20311 ;;0;Your access code has been terminated. Please see your site manager!
20412 ;;0;VERIFY CODE MUST be changed before continued use.
20513 ;;1;This device may only be used outside of this time frame |
20614 ;;0;'|' is not a valid UCI!
20715 ;;0;'|' is not a valid program name!
20816 ;;0;No PRIMARY MENU assigned to user or User is missing KEY to menu!
20917 ;;0;Your access to the system is prohibited from |.
21018 ;;0;Windows Integrated Security Not Allowed on this port.*/
211
212
213}
Note: See TracBrowser for help on using the repository browser.