private void DisconnectNow() { lock (objlock) { try { if (_client != null) { try { if (_speakHost != null) { _speakHost = null; } _client.Disconnect(); _client.Dispose(); } catch (Exception) { } } } catch (Exception) { } } }
private void Connect(object sender, RoutedEventArgs e) { if (ScsClient != null) { ScsClient.Disconnect(); } ScsClient = ScsServiceClientBuilder.CreateClient <IInformerService>( new ScsTcpEndPoint(ServerIp.Text, 23232), Client); ScsClient.Timeout = 1000; ScsClient.ConnectTimeout = 2000; ScsClient.Connected += OnScsConnnected; ScsClient.Disconnected += OnScsDisconnected; Log("Try connect..."); ThreadPool.QueueUserWorkItem( o => { try { ScsClient.Connect(); } catch { Log("Can't connect to server."); } }); }
public bool Auth(string authKey) { bool isAuthed = authKey == _authKey; if (!isAuthed) { _authedClient.Disconnect(); } return(authKey == _authKey); }
void IDriverPresenter.OnUnregisterDriver() { if (_scsClient != null) { _server.UnregisterDriver(_driverId); _scsClient.Disconnect(); _scsClient = null; _view.OnDisconnected(); } }
/// <summary> /// Disconnects from server if it is connected. /// </summary> public void Disconnect() { if (_scsClient != null && _scsClient.CommunicationState == CommunicationStates.Connected) { try { _scsClient.Disconnect(); } catch { } _scsClient = null; } }
private void DisconnectNow() { if (_client == null) { return; } try { SpeechHost = null; _client.Disconnect(); _client.Disconnected -= OnClientDisconnect; _client.Connected -= OnClientConnect; _client.Dispose(); } catch (Exception exception) { Console.WriteLine($"Error while disconnecting speaker client : {exception.Message}"); } }
private void OnMainFormClosing(Object sender , FormClosingEventArgs e) { Timer.Stop(); if (m_ChangeNotificationObject != null) { TransactionObject transactionObject = m_RemoteAccessClient.ServiceProxy.BeginTransaction(); m_RemoteAccessClient.ServiceProxy.UnregisterForProfileChanges(transactionObject, m_ChangeNotificationObject, true); m_ChangeNotificationObject = null; } if (m_RemoteAccessClient != null) { m_RemoteAccessClient.Disconnect(); m_RemoteAccessClient.Dispose(); m_RemoteAccessClient = null; } }
private static void connectionJunction() { // create the user object that is the real plugin, accessed from the pluginAPI wrapper Util.callback = callback; Util.hs = host; plugin.OurInstanceFriendlyName = Util.Instance; // connect to HS so it can register a callback to us host.Connect(Util.IFACE_NAME, Util.Instance); Console.WriteLine("Connected, waiting to be initialized..."); do { System.Threading.Thread.Sleep(10); } while (client.CommunicationState == HSCF.Communication.Scs.Communication.CommunicationStates.Connected & !HSPI.bShutDown & !HSPI.timedReset); if (!HSPI.bShutDown) { connectionJunction(); // Attempt to reconnect, the disconnection was not intentional } else { Console.WriteLine("Connection lost, exiting"); // disconnect from server for good here client.Disconnect(); clientCallback.Disconnect(); wait(2); if (HSPI.timedReset) { reset = true; } else { reset = false; } } }
public static void Main(string[] args) { string serverIp = "127.0.0.1"; string serverCmd = null; foreach (string serverCmd_loopVariable in args) { serverCmd = serverCmd_loopVariable; string[] ch = new string[1]; ch[0] = "="; string[] parts = serverCmd.Split(ch, StringSplitOptions.None); switch (parts[0].ToLower()) { case "server": serverIp = parts[1]; break; case "instance": try { Util.Instance = parts[1]; } catch (Exception) { Util.Instance = ""; } break; } } Console.WriteLine("Plugin: " + Util.IFACE_NAME + " Instance: " + Util.Instance + " starting..."); Console.WriteLine("Connecting to server at " + serverIp + "..."); client = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(serverIp, 10400), plugin); clientCallback = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(serverIp, 10400), plugin); int Attempts = 1; TryAgain: try { client.Connect(); clientCallback.Connect(); double APIVersion = 0; try { host = client.ServiceProxy; APIVersion = host.APIVersion; // will cause an error if not really connected Console.WriteLine("Host API Version: " + APIVersion.ToString()); } catch (Exception ex) { Console.WriteLine("Error getting API version from host object: " + ex.Message + "->" + ex.StackTrace); //Return } try { callback = clientCallback.ServiceProxy; APIVersion = callback.APIVersion; // will cause an error if not really connected } catch (Exception ex) { Console.WriteLine("Error getting API version from callback object: " + ex.Message + "->" + ex.StackTrace); return; } } catch (Exception ex) { Console.WriteLine("Cannot connect attempt " + Attempts.ToString() + ": " + ex.Message); if (ex.Message.ToLower().Contains("timeout occurred.")) { Attempts += 1; if (Attempts < 6) { goto TryAgain; } } if (client != null) { client.Dispose(); client = null; } if (clientCallback != null) { clientCallback.Dispose(); clientCallback = null; } wait(4); return; } try { // create the user object that is the real plugin, accessed from the pluginAPI wrapper Util.callback = callback; Util.hs = host; plugin.OurInstanceFriendlyName = Util.Instance; // connect to HS so it can register a callback to us host.Connect(Util.IFACE_NAME, Util.Instance); Console.WriteLine("Connected, waiting to be initialized..."); do { System.Threading.Thread.Sleep(10); } while (client.CommunicationState == HSCF.Communication.Scs.Communication.CommunicationStates.Connected & !HSPI.bShutDown); Console.WriteLine("Connection lost, exiting"); // disconnect from server for good here client.Disconnect(); clientCallback.Disconnect(); wait(2); System.Environment.Exit(0); } catch (Exception ex) { Console.WriteLine("Cannot connect(2): " + ex.Message); wait(2); System.Environment.Exit(0); return; } }
public void run() { string[] cmdArgs = Environment.GetCommandLineArgs(); Console.WriteLine("Manager::run() - arguments are {0}", Environment.CommandLine); String paramServer = "127.0.0.1"; String paramInstance = ""; foreach (string arg in cmdArgs) { Console.WriteLine(" - arg: {0}", arg); if (arg.Contains("=")) { String[] ArgS = arg.Split('='); Console.WriteLine(" -- {0}=>{1}", ArgS[0], ArgS[1]); switch (ArgS[0]) { case "server": paramServer = ArgS[1]; break; case "instance": paramInstance = ArgS[1]; break; default: Console.WriteLine("Unhandled param: {0}", ArgS[0]); break; } } } pluginInst = new HSPI(paramInstance); //Environment.CommandLine. client = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); clientCB = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); try { client.Connect(); clientCB.Connect(); hsHost = client.ServiceProxy; double ApiVer = hsHost.APIVersion; Console.WriteLine("Host ApiVersion : {0}", ApiVer); hsHostCB = clientCB.ServiceProxy; ApiVer = hsHostCB.APIVersion; Console.WriteLine("Host CB ApiVersion : {0}", ApiVer); } catch (Exception e) { Console.WriteLine("Cannot start instance because of : {0}", e.Message); return; } Console.WriteLine("Connection to HS succeeded!"); try { pluginInst.hsHost = hsHost; pluginInst.hsHostCB = hsHostCB; hsHost.Connect(pluginInst.Name, ""); Console.WriteLine("Connected, waiting to be initialized..."); do { Thread.Sleep(500); } while (client.CommunicationState == CommunicationStates.Connected && pluginInst.Running); Console.WriteLine("Connection lost, exiting"); pluginInst.Running = false; client.Disconnect(); clientCB.Disconnect(); } catch (Exception e) { Console.WriteLine("Failed to host connect: {0}", e.Message); return; } Console.WriteLine("Exiting!!!"); }
private void submitExamBtn_Click(object sender, EventArgs e) { string errMsg = ""; bool error = false; string remainingTime = remainingtimeLbl.Text; ExamLog.Add($"[{DateTime.Now}] [Student Tried to Submit SUBMIT EXAM] [Remaing time: {remainingTime}]"); foreach (var q in anExam.QuestionsList) { if (q.StudentAnswer == string.Empty || q.StudentAnswer == null) { error = true; errMsg = errMsg + $" Q{q.QuestionNumber}. "; } } if (error) { MessageBox.Show("Please provide answers for the following questions before you submit the exam" + errMsg); return; } bool saved = false; anExam.RequiredStudentDetails.SequenceNumber = (long.Parse(anExam.RequiredStudentDetails.SequenceNumber) + 1).ToString(); while (!saved) { try { if (MessageBox.Show("(Recommended) Please save file to disk before submitting on network.", "Important Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { SaveFileDialog adialog = new SaveFileDialog(); adialog.Filter = "FCT Exam File (*.FCTANS)|*.FCTANS"; adialog.DefaultExt = "FCTANS"; adialog.FileName = $"{DateTime.Now.Day}-{DateTime.Now.Month}-{DateTime.Now.Year}-Submission-{studentIDTxtBox.Text}"; adialog.AddExtension = true; if (adialog.ShowDialog() == DialogResult.OK) { ExamLog.Add($"[{DateTime.Now}] [Student Saved Exam On Disk] [File Location: ({adialog.FileName})]"); anExam.ExamLog = ExamLog; //anExam.RequiredStudentDetails = requiredDetails; ExamHelper.SaveExamToFile(anExam, examKeyTxtBox.Text, adialog.FileName); aLogger.LogMessage($"[Student Saved Exam On Disk] [File Location: ({adialog.FileName})]", LogMsgType.Verbose); } } else { ExamLog.Add($"[{DateTime.Now}] [Student Did not Select To Save File To Disk]"); } saved = true; } catch (Exception ex) { ExamLog.Add($"[{DateTime.Now}] [Student Saved Exam On Disk (Process Failed) (exception: {ex.Message}] "); MessageBox.Show("File Did Not Save Correctly, please retry!"); } } var reqDetailsEnc = anExam.RequiredStudentDetails; reqDetailsEnc.EncryptDetails(); aLogger.LogMessage("Submitting Exam Through Network ... (Started)", LogMsgType.Verbose); anExam.ExamLog = ExamLog; // anExam.RequiredStudentDetails = requiredDetails; if (client.ServiceProxy.SubmitExamEncryptedZipped(ExamHelper.GetExamFileWithoutSave(anExam, examKeyTxtBox.Text, sharedKeyISTxtBox.Text, (highSecChkBox.Checked ? Security.FilterationSecurityLevel.High : Security.FilterationSecurityLevel.Moderate)), reqDetailsEnc)) { aLogger.LogMessage("Submitting Exam Through Network ... (Done Succesfully.)", LogMsgType.Verbose); MessageBox.Show("Exam Submitted Correctly. Closing..."); client.Disconnect(); aLogger.LogMessage("Disconnected from server", LogMsgType.Verbose); this.Close(); } else { aLogger.LogMessage("Submitting Exam Through Network ... (Process Failed)", LogMsgType.Verbose); MessageBox.Show("ERROR: Submission Failed. "); } }
public void run() { string[] cmdArgs = Environment.GetCommandLineArgs(); Console.WriteLine("Manager::run() - arguments are {0}", Environment.CommandLine); String paramServer = "127.0.0.1"; String paramInstance = ""; foreach (string arg in cmdArgs) { Console.WriteLine(" - arg: {0}", arg); if (arg.Contains("=")) { String[] ArgS = arg.Split('='); Console.WriteLine(" -- {0}=>{1}", ArgS[0], ArgS[1]); switch (ArgS[0]) { case "server": paramServer = ArgS[1]; break; case "instance": paramInstance = ArgS[1]; break; default: Console.WriteLine("Unhandled param: {0}", ArgS[0]); break; } } } pluginInst = new HSPI(paramInstance); //Environment.CommandLine. client = ScsServiceClientBuilder.CreateClient<IHSApplication>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); clientCB = ScsServiceClientBuilder.CreateClient<IAppCallbackAPI>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); try { client.Connect(); clientCB.Connect(); hsHost = client.ServiceProxy; double ApiVer = hsHost.APIVersion; Console.WriteLine("Host ApiVersion : {0}", ApiVer); hsHostCB = clientCB.ServiceProxy; ApiVer = hsHostCB.APIVersion; Console.WriteLine("Host CB ApiVersion : {0}", ApiVer); } catch (Exception e) { Console.WriteLine("Cannot start instance because of : {0}", e.Message); return; } Console.WriteLine("Connection to HS succeeded!"); try { pluginInst.hsHost = hsHost; pluginInst.hsHostCB = hsHostCB; hsHost.Connect(pluginInst.Name, ""); Console.WriteLine("Connected, waiting to be initialized..."); do { Thread.Sleep(500); } while (client.CommunicationState == CommunicationStates.Connected && pluginInst.Running); Console.WriteLine("Connection lost, exiting"); pluginInst.Running = false; client.Disconnect(); clientCB.Disconnect(); } catch (Exception e) { Console.WriteLine("Failed to host connect: {0}", e.Message); return; } Console.WriteLine("Exiting!!!"); }