public static Boolean Update(Student s) { Boolean results = true; String commareaStr = String.Empty; Boolean result = false; EciRequest eciReq; using (GatewayConnection gwyConnection = new GatewayConnection(gwyHostName, gwyPort)) { //Prepare the EciRequest eciReq = new EciRequest(); eciReq.ServerName = StudentDB.cicsServer; eciReq.Program = ProgramName; eciReq.ExtendMode = EciExtendMode.EciNoExtend; String commareaString = String.Format("{0} {1}", "M", s.ToString()); commareaString = commareaString.PadRight(CommareaLength); //eciReq.SetCommareaData(new byte[CommareaLength]); eciReq.SetCommareaData(ASCIIEncoding.ASCII.GetBytes(commareaString)); eciReq.UserId = "CICSUSER"; eciReq.Password = ""; Console.WriteLine("ASCII: {0}", commareaStr); //Flow the request if (FlowRequest(gwyConnection, eciReq)) { byte[] commarea = eciReq.GetCommareaData(); commareaStr = Encoding.ASCII.GetString(commarea); result = true; Console.WriteLine("Message: {0}", commareaStr.Substring(commareaStr.Length - 40, 40)); } } return(results); }
public void Connect() { try { InsertLog.AddLog("MirasysVCAInterfaceService Connect(): Start"); if (_connection != null) { _connection.ConnectionEvent -= new EventHandler <ConnectionEventArgs>(OnConnectionEvent); _connection.Dispose(); _connection = null; } _connection = new GatewayConnection(MirasysHostIP, Convert.ToInt32(MirasysHostPort), MirasysHostUserName, MirasysHostPassword, TestSDKApplicationCode); _connection.ConnectionEvent += new EventHandler <ConnectionEventArgs>(OnConnectionEvent); session = _connection.SessionContext; session.ErrorHandler.SessionExceptionThrown += new EventHandler <Mirasys.Clients.Gateway.SDK.Events.ExceptionEventArgs>(OnExceptionThrown);;//ErrorHandler_SessionExceptionThrown; session.RequestValidation += new EventHandler <RequestValidationEventArgs>(OnRequestValidation); session.ProfileService.ProfileEventReceived += new EventHandler <ProfileEventArgs>(OnProfileEventReceived); session.ProfileService.UserStatusChanged += new EventHandler <AuthenticationEventArgs>(OnUserStatusChanged); //session.RecorderEventService.RecorderEventReceived += new EventHandler<RecorderEventArgs>(OnRecorderEventReceived); _connection.Connect(); } catch (Exception ex) { InsertLog.AddLog("MirasysVCAInterfaceService Connect(): Exception " + ex.Message); } }
public GatewayConnection Add(GatewayConnection gatewayConnection) { var res = db.GatewayConnections.Add(gatewayConnection); db.SaveChanges(); return(res); }
public GatewayShard(DiscordOptions configuration, IServiceProvider provider, int shardId = 0) { ShardId = shardId; _packetHandler = provider.GetRequiredService <IDiscordPacketHandler>(); _logger = provider.GetRequiredService <ILogger <GatewayShard> >(); _tokenSource = new CancellationTokenSource(); _connection = new GatewayConnection(configuration, provider, ShardId); }
private void OnConnectionEvent(System.Object aSource, ConnectionEventArgs aArgs) { try { InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): start"); GatewayConnection connection = (GatewayConnection)aSource; // ConsoleWriteLine("Connection event: " + connection.Status.ToString()); var connStatus = connection.Status; if (connection.Status == ConnectionStatus.Connected) { //Log Connected try { InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): Connected "); System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { string strResult = "Connected"; MainWindow.txtResult.AppendText(strResult + "\n"); if (MainWindow.txtResult.LineCount > 20) { MainWindow.txtResult.Clear(); } })); //_connection.SessionContext.AlarmService //_AlarmEvents = new AlarmEvents(_connection.SessionContext.AlarmService); InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): Connected 1 ");// + _connection.SessionContext.); } catch (Exception ex) { InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): Exception " + ex.Message); } } else { if (connection.Status == ConnectionStatus.ConnectionFailed) { InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): ConnectionFailed "); System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { string strResult = "ConnectionFailed"; MainWindow.txtResult.AppendText(strResult + "\n"); if (MainWindow.txtResult.LineCount > 20) { MainWindow.txtResult.Clear(); } })); //Program.ShowErrorMessageBox(this, "Error occured when connection to Gateway was attempted.", "Connection failed"); } } } catch (Exception ex) { InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): Exception 1 " + ex.Message); } }
public GatewayShard(GatewayProperties configuration) { tokenSource = new CancellationTokenSource(); connection = new GatewayConnection(configuration); if (configuration.UseGatewayEvents) { eventHandler = new GatewayEventHandler( PacketReceived, configuration.SerializerOptions); } }
public async Task TestStateModificationAsync() { var mockWebsocketClient = new MockWebsocketClient(); var gateway = new GatewayConnection( new GatewayProperties { Token = "cannot be null", WebSocketFactory = () => mockWebsocketClient, }); await gateway.StartAsync(default);
public void EciConnect(String host, Int32 port, String login, String password, String serverName) { if (host == null) { throw new ArgumentNullException(nameof(host)); } if (login == null) { throw new ArgumentNullException(nameof(login)); } if (password == null) { throw new ArgumentNullException(nameof(password)); } if (serverName == null) { throw new ArgumentNullException(nameof(serverName)); } var account = new Account( () => new DnsEndPoint(host, port), () => new User(login, password), () => serverName); try { using (var connection = new GatewayConnection(account.Hostname.Host, account.Hostname.Port)) { var request = new EciRequest(); request.UserId = account.User.Login; request.Password = account.User.Password; request.ServerName = account.ServerName; //request.ExtendMode = EciExtendMode.EciNoExtend; string commarea = "L" + new string(' ', 43); request.Program = "program"; //connection.Flow(request); } } catch (GatewayException ge) { Console.WriteLine("ERROR: {0}", ge.Message); } catch (SocketException se) { Console.WriteLine("ERROR: {0}", se.Message); } }
private static bool FlowRequest(GatewayConnection gwyConnection, EciRequest eciReq) { int attempts = 0; while (attempts < MaxFlowAttempts) { //Flow throws a System.Net.SocketException if a connection //failure occurs, or an IBM.CTG.GatewayException if an error //occurs in the Gateway daemon gwyConnection.Flow(eciReq); //Test return code switch (eciReq.EciReturnCode) { case EciReturnCode.EciNoError: //Flow succeeded return(true); case EciReturnCode.EciErrSecurityError: //Security error, prompt for CICS logon credentials Console.Write("Enter CICS user id : "); //eciReq.UserId = Console.ReadLine(); eciReq.UserId = "CICSUSER"; Console.Write("Enter CICS password: "******"The transaction abended: {0}", eciReq.AbendCode); return(false); case EciReturnCode.EciErrNoCics: //CICS server not found Console.WriteLine("CICS server not found"); return(false); default: //Other error return code Console.WriteLine("ECI return code: {0} ({1})", eciReq.EciReturnCode.ToString(), (int)eciReq.EciReturnCode); return(false); } //Increment number of attempts attempts++; } //Number of attempts exceeded MaxFlowAttempts return(false); }
public void Disconnect() { try { InsertLog.AddLog("MirasysVCAInterfaceService Disconnect(): start "); if (_connection != null) { _connection.ConnectionEvent -= new EventHandler <ConnectionEventArgs>(OnConnectionEvent); _connection.Disconnect(); _connection.Dispose(); _connection = null; } } catch (Exception ex) { InsertLog.AddLog("MirasysVCAInterfaceService Disconnect(): Exception " + ex.Message); } }
public void EciConnect(DnsEndPoint server, User info, String serverName) { if (server == null) { throw new ArgumentNullException(nameof(server)); } if (serverName == null) { throw new ArgumentNullException(nameof(serverName)); } var account = new Account( () => new DnsEndPoint(server.Host, server.Port), () => new User(info.Login, info.Password), () => serverName); try { using (var connection = new GatewayConnection(account.Hostname.Host, account.Hostname.Port)) { var request = new EciRequest(); request.UserId = account.User.Login; request.Password = account.User.Password; request.ServerName = account.ServerName; } } catch (GatewayException ge) { Console.WriteLine("ERROR: {0}", ge.Message); } catch (SocketException se) { Console.WriteLine("ERROR: {0}", se.Message); } }
public static Student[] List(Student s) { Boolean results = true; String commareaStr = String.Empty; Boolean result = false; EciRequest eciReq; byte[] commarea = null; Student[] students = null; List <Student> list = null; using (GatewayConnection gwyConnection = new GatewayConnection(gwyHostName, gwyPort)) { //Prepare the EciRequest eciReq = new EciRequest(); eciReq.ServerName = StudentDB.cicsServer; eciReq.Program = ProgramName; eciReq.ExtendMode = EciExtendMode.EciNoExtend; String commareaString = String.Format("{0} {1}", "L", s.ToString()); commareaString = commareaString.PadRight(CommareaLength); Console.WriteLine("ASCII: {0}", commareaStr); //eciReq.SetCommareaData(new byte[CommareaLength]); eciReq.SetCommareaData(ASCIIEncoding.ASCII.GetBytes(commareaString)); eciReq.UserId = "CICSUSER"; eciReq.Password = ""; //Flow the request if (FlowRequest(gwyConnection, eciReq)) { commarea = eciReq.GetCommareaData(); for (int i = 3; i < commarea.Length; i++) { if (commarea[i] == 0) { commarea[i] = 32; } } commareaStr = Encoding.ASCII.GetString(commarea); setResponse(commareaStr); result = true; Console.WriteLine("ASCII: {0}", commareaStr); Console.WriteLine("Message: {0}", commareaStr.Substring(commareaStr.Length - 40, 40)); } list = new List <Student>(); int count = (int)commarea[2]; for (int i = 0; i < count; i++) { list.Add(new Student(commareaStr.Substring(3 + (115 * i), 115))); } } if (list.Count > 0) { students = list.ToArray <Student>(); } return(students); }
public static Student Inquire(String STUD_ID) { EciRequest eciReq; //Open the Gateway connection with an infinite timeout period //The 'using' C# construct ensures the GatewayConnection is closed //when it goes out of scope, even if an exception is thrown //A System.Net.SocketException will be thrown if the connection //attempt fails, and an IBM.CTG.GatewayException will be thrown if //an error occurs in the Gateway daemon using (GatewayConnection gwyConnection = new GatewayConnection(gwyHostName, gwyPort)) { //Prepare the EciRequest eciReq = new EciRequest(); eciReq.ServerName = cicsServer; eciReq.Program = ProgramName; eciReq.ExtendMode = EciExtendMode.EciNoExtend; //String commareaString = "L 999999999"; String commareaString = String.Format("{0} {1}", "I", STUD_ID); commareaString = commareaString.PadRight(CommareaLength); //eciReq.SetCommareaData(new byte[CommareaLength]); eciReq.SetCommareaData(ASCIIEncoding.ASCII.GetBytes(commareaString)); //Flow the request if (FlowRequest(gwyConnection, eciReq)) { //Display returned COMMAREA byte[] commarea = eciReq.GetCommareaData(); //Display as hex // Console.Write(" HEX: "); // for (int i = 0; i < commarea.Length; i++) { // Console.Write("{0:x2}", commarea[i]); // } //Convert the byte data into a string, treating the data //as ASCII encoded characters. This relies on the CICS program //returning ASCII text in the COMMAREA for (int i = 3; i < commarea.Length; i++) { if (commarea[i] == 0) { commarea[i] = 32; } } commareaStr = Encoding.ASCII.GetString(commarea); Console.WriteLine("ASCII: {0}", commareaStr); Console.WriteLine("Message: {0}", commareaStr.Substring(commareaStr.Length - 40, 40)); } } Student s = new Student(); IntPtr pBuf = Marshal.StringToBSTR(commareaStr.Substring(3, Student.Size)); s = (Student)Marshal.PtrToStructure(pBuf, typeof(Student)); Marshal.FreeBSTR(pBuf); return(s); }