private void OnConnectionFailedInvoked(ConnectionError error) { isConnected = false; if (OnConnectionFailed != null) { OnConnectionFailed(error); } }
// // Write a object instance to data output stream // public override void TightMarshal2(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut, BooleanStream bs) { base.TightMarshal2(wireFormat, o, dataOut, bs); ConnectionError info = (ConnectionError)o; TightMarshalBrokerError2(wireFormat, info.Exception, dataOut, bs); TightMarshalNestedObject2(wireFormat, (DataStructure)info.ConnectionId, dataOut, bs); }
// // Un-marshal an object instance from the data input stream // public override void LooseUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn) { base.LooseUnmarshal(wireFormat, o, dataIn); ConnectionError info = (ConnectionError)o; info.Exception = LooseUnmarshalBrokerError(wireFormat, dataIn); info.ConnectionId = (ConnectionId)LooseUnmarshalNestedObject(wireFormat, dataIn); }
// // Un-marshal an object instance from the data input stream // public override void TightUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn, BooleanStream bs) { base.TightUnmarshal(wireFormat, o, dataIn, bs); ConnectionError info = (ConnectionError)o; info.Exception = TightUnmarshalBrokerError(wireFormat, dataIn, bs); info.ConnectionId = (ConnectionId)TightUnmarshalNestedObject(wireFormat, dataIn, bs); }
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\ #region --Constructors-- /// <summary> /// Basic Constructor /// </summary> /// <history> /// 05/05/2018 Created [Fabian Sauter] /// </history> public TCPConnection2(XMPPAccount account) : base(account) { this.lastConnectionError = null; this.connectingCTS = null; this.dataReader = null; this.dataWriter = null; this.socket = null; this.readingCTS = null; }
public void StartTracking() { if (_tracker != null) { _tracker.GazeDataReceived += Tracker_GazeDataReceived; } else { ConnectionError?.Invoke(this, "Tracker not found"); } }
// // Write the booleans that this object uses to a BooleanStream // public override int TightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) { ConnectionError info = (ConnectionError)o; int rc = base.TightMarshal1(wireFormat, o, bs); rc += TightMarshalBrokerError1(wireFormat, info.Exception, bs); rc += TightMarshalNestedObject1(wireFormat, (DataStructure)info.ConnectionId, bs); return(rc + 0); }
private Task OnConnectionError(ConnectionErrorCode errorcode) { if (ConnectionError != null) { return(ConnectionError.InvokeAllAsync(this, new ConnectionErrorEventArgs(errorcode))); } else { return(Task.CompletedTask); } }
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\ #region --Constructors-- /// <summary> /// Basic Constructor /// </summary> /// <history> /// 05/05/2018 Created [Fabian Sauter] /// </history> public TCPConnection2(XMPPAccount account) : base(account) { lastConnectionError = null; connectingCTS = null; dataReader = null; dataWriter = null; socket = null; readingCTS = null; disableTcpTimeout = false; disableTlsTimeout = false; }
internal static string GetCallbackMessage(IMessageTask callback, ConnectionError connectionError) { string message = $"Protocol error ({callback.Method}): {connectionError.Message}"; if (!string.IsNullOrEmpty(connectionError.Data)) { message += $" {connectionError.Data}"; } return(!string.IsNullOrEmpty(connectionError.Message) ? RewriteErrorMeesage(message) : string.Empty); }
private void OnConnectionError() { if (!Connected) { return; } Connected = false; cancelToken.Cancel(); ConnectionError?.Invoke(this, null); }
protected override void execute() { TnSServer server = new TnSServer(socket, new TnSProtocol()); server.OnRequestReceived += (ToAccept request) => { if (RequestReceived != null) { return(RequestReceived(request)); } return(request); }; server.JobInitialized += (Job job) => { JobsList.Receiving.push(job); this.job = job; }; try { server.transfer(); } catch (SocketException e) { // Trigger the event of conncetion error ConnectionError?.Invoke(job); } catch (System.IO.IOException e) { String sourceName = null; //if (job != null) { // job.Status = Job.JobStatus.ConnectionError; // // Trigger the event of Path error // sourceName = job.Task.Info[0].Name; // if (job.Task.Info.Count > 1) // for (int i = 1; i > job.Task.Info.Count; i++) // sourceName += ", " + job.Task.Info[i].Name; //} PathError?.Invoke(e, job); } catch (ObjectDisposedException e) { ConnectionError?.Invoke(job); // NOTE: 'ObjectDisposedException' and 'SocketException' make the same management as the generale 'Exception'. // However they have their own catch because they are very common exceptions in this point of the code, and // in this way they are marked and clearely visible. // This separation is not neede, but it's really useful to remark this concept. } catch (Exception e) { ConnectionError?.Invoke(job); } finally { // Remove the job (if any) from the list if (job != null) { JobsList.Receiving.remove(job.Id); } // Close the socket socket.Close(); } }
private void commDataSender_ConnectionError(System.Net.Sockets.SocketException ex) { if (this.InvokeRequired) { this.Invoke(new Sender.ConnectionErrorHandler(commDataSender_ConnectionError), ex); return; } ConnectionError?.Invoke(this, ex); showError(ex); DisableEnableItems(true); SetStatus("<Connection Error>"); }
// 关闭连接 (不会自动情况发送队列, 但是清空接受数据缓冲) public void Close() { if (_state == ConnectionState.Closed) { return; } _state = ConnectionState.Closed; if (_sendThread != null) { // _sendThread.Abort(); _sendThread = null; } if (_recvThread != null) { // _recvThread.Abort(); _recvThread = null; } if (_sock != null) { if (_sock.Connected) { try { if (_sock.ProtocolType == ProtocolType.Tcp) { _sock.Shutdown(SocketShutdown.Both); } // _sock.Disconnect(false); } catch (Exception exception) { Debug.LogError(exception); } } _sock.Close(); _sock = null; } do { var buffer = _recvQueue.Pop(); if (buffer == null) { break; } buffer.Release(); } while (true); _recvQueue.Clear(); if (Closed != null) { Closed(); } _error = ConnectionError.None; }
/// <summary> /// To call the event <see cref="ConnectionError"/>. /// </summary> /// <param name="exception">Error connection.</param> private void RaiseConnectionError(Exception exception) { if (exception == null) { throw new ArgumentNullException(nameof(exception)); } ConnectionState = ConnectionStates.Failed; ConnectionError?.Invoke(exception); this.AddErrorLog(exception); }
internal static void ThrowConnectionException(int errno, string message = "") { ConnectionError _error = (ConnectionError)errno; Log.Debug(Globals.LogTag, "ThrowConnectionException " + _error); switch (_error) { case ConnectionError.AddressFamilyNotSupported: throw new InvalidOperationException("Address Family Not Supported"); case ConnectionError.AlreadyExists: throw new InvalidOperationException("Already Exists"); case ConnectionError.DhcpFailed: throw new InvalidOperationException("DHCP Failed"); case ConnectionError.EndOfIteration: throw new InvalidOperationException("End Of Iteration"); case ConnectionError.InvalidKey: throw new InvalidOperationException("Invalid Key"); case ConnectionError.InvalidOperation: throw new InvalidOperationException("Invalid Operation " + message); case ConnectionError.InvalidParameter: throw new ArgumentException("Invalid Parameter"); case ConnectionError.NoConnection: throw new InvalidOperationException("No Connection"); case ConnectionError.NoReply: throw new InvalidOperationException("No Reply"); case ConnectionError.NotSupported: throw new NotSupportedException("Unsupported feature " + message); case ConnectionError.NowInProgress: throw new InvalidOperationException("Now In Progress"); case ConnectionError.OperationAborted: throw new InvalidOperationException("Operation Aborted"); case ConnectionError.OperationFailed: throw new InvalidOperationException("Operation Failed"); case ConnectionError.OutOfMemoryError: throw new OutOfMemoryException("Out Of Memory Error"); case ConnectionError.PermissionDenied: throw new UnauthorizedAccessException("Permission Denied " + message); } }
public VideoStreamerDevice(FFmpegStreamer streamer, IVideoStreamerConfiguration configuration) { _config = configuration; _recordingConfig = new VideoStreamerRecordingConfiguration(configuration); _streamer = streamer; _streamer.ProcessExited += (_, __) => ConnectionError?.Invoke(this, new ConnectionException("Webcam video process exited.")); Code = DeviceCode.Create(this, DeviceType.Streaming.WEBCAM_VIDEO) .RunsOnMainThread(false) .ConnectionType(DeviceConnectionType.Process) .Build(); }
protected void SendConnectionError() { if (!IsConnected) { return; } Disconnect(); if (ConnectionError != null) { ConnectionError.Raise(this, new EventArgs()); } }
public ScreenCastStreamerDevice(FFmpegStreamer streamer, IScreenCastStreamerConfiguration configuration) { _config = configuration; _recordingConfig = new VideoStreamerRecordingConfiguration(configuration); _streamer = streamer; _streamer.ProcessExited += (_, e) => ConnectionError?.Invoke(this, new ConnectionException("Screencast process exited.")); Code = DeviceCode.Create(this, DeviceType.Streaming.SCREENCAST) .RunsOnMainThread(false) .ConnectionType(DeviceConnectionType.Process) .Build(); }
protected virtual void FinalizeSend(IAsyncResult ar) { try { var handler = (Socket)ar.AsyncState; var bytesSent = handler.EndSend(ar); } catch (Exception e) { ConnectionError.PrintUnexpectedConnectionErrorDetails(e); throw; } }
/// <summary> /// Handle incoming commands /// </summary> /// <param name="commandTransport">An ITransport</param> /// <param name="command">A Command</param> protected void OnCommand(ITransport commandTransport, Command command) { if (command is MessageDispatch) { DispatchMessage((MessageDispatch)command); } else if (command is KeepAliveInfo) { OnKeepAliveCommand(commandTransport, (KeepAliveInfo)command); } else if (command is WireFormatInfo) { this.brokerWireFormatInfo = (WireFormatInfo)command; } else if (command is BrokerInfo) { this.brokerInfo = (BrokerInfo)command; } else if (command is ShutdownInfo) { if (!closing && !closed) { OnException(commandTransport, new NMSException("Broker closed this connection.")); } } else if (command is ConnectionError) { if (!closing && !closed) { ConnectionError connectionError = (ConnectionError)command; BrokerError brokerError = connectionError.Exception; string message = "Broker connection error."; string cause = ""; if (null != brokerError) { message = brokerError.Message; if (null != brokerError.Cause) { cause = brokerError.Cause.Message; } } OnException(commandTransport, new NMSConnectionException(message, cause)); } } else { Tracer.Error("Unknown command: " + command); } }
public bool ConnectToDevice() { try { Log?.Invoke(this, new Core.LogMessage(Core.LogLevel.Info, LogTags.Connection, "Searching for an eye tracker...")); using (CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))) { var tracker = _browser.SearchAsync(cts.Token) .ConfigureAwait(false) .GetAwaiter() .GetResult(); if (tracker != null) { string name = tracker.Name ?? String.Empty; string productId = tracker.ProductId ?? String.Empty; string familyName = tracker.FamilyName ?? String.Empty; Log?.Invoke(this, new Core.LogMessage(Core.LogLevel.Info, LogTags.Connection, $"Eye tracker found: {familyName} - {name} ({productId}). Connecting...")); AttachEventHandlers(tracker); tracker.Connect(); DeviceInfo.Name = name; DeviceInfo.FamilyName = familyName; DeviceInfo.ProductId = productId; _connectedTracker = tracker; Log?.Invoke(this, new Core.LogMessage(Core.LogLevel.Info, LogTags.Connection, "Connection successful")); OnCanCalibrateChanged(); return(true); } } Log?.Invoke(this, new Core.LogMessage(Core.LogLevel.Error, LogTags.Connection, "No eye tracker found.")); } catch (OperationCanceledException) { Log?.Invoke(this, new Core.LogMessage(Core.LogLevel.Error, LogTags.Connection, "Failed to find an eye tracker within the time limit.")); } catch (Exception ex) { Log?.Invoke(this, new Core.LogMessage(Core.LogLevel.Error, LogTags.Connection, "Failed to connect to an eye tracker.", ex)); ConnectionError?.Invoke(this, new ConnectionException("Failed to connect to an eye tracker, see inner exception for details.", ex)); } return(false); }
protected override void execute() { if (Settings.Instance.Network == null) { return; } NetworkInterface nic = Settings.Instance.Network.Nic; IPAddress addr = null; foreach (UnicastIPAddressInformation ip in nic.GetIPProperties().UnicastAddresses) { if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { addr = ip.Address; } } //IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, Settings.Instance.SERV_ACCEPTING_PORT); IPEndPoint localEndPoint = new IPEndPoint(addr, Settings.Instance.SERV_ACCEPTING_PORT); listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { listener.Bind(localEndPoint); listener.Listen(50); while (true) { Console.WriteLine("Waiting for a connection..."); Socket handler = listener.Accept(); ReceptionExecutor receiver = new ReceptionExecutor(handler); receiver.RequestReceived += (ToAccept request) => { if (RequestReceived != null) { return(RequestReceived(request)); } return(request); }; receiver.ConnectionError += (Job j) => { ConnectionError?.Invoke(j); }; receiver.PathError += (System.IO.IOException e, Job job) => { PathError?.Invoke(e, job); }; RegisterChild(receiver); receiver.run(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public void Connect() { Dispatcher.OnRequestThreadAsync(() => { try { Connection.Connect(); } catch (Exception e) { ConnectionError.SafeInvoke(e); } }); }
public bool ConnectToDevice() { try { _hook = Hook.GlobalEvents(); return(true); } catch (Exception ex) { Log?.Invoke(this, new Core.LogMessage(Core.LogLevel.Error, LogTags.Connection, "Failed to connect to device", ex)); ConnectionError?.Invoke(this, ex); } return(false); }
public void Send(IMessage message) { _connectFinalized.WaitOne(); var byteData = Encoding.ASCII.GetBytes(message.SerializeToXml() + Constants.EtbByte); try { _tcpConnection.Send(byteData); } catch (Exception e) { ConnectionError.PrintUnexpectedConnectionErrorDetails(e); throw; } }
private void StartReading() { while (true) { try { _tcpConnection.Receive(); } catch (Exception e) { ConnectionError.PrintUnexpectedConnectionErrorDetails(e); throw; } } }
/// <summary> Построить VM для данной страницы </summary> public override void SetupViewModel() { base.SetupViewModel(); if (_forecastObjectProvider == null) { throw new NullReferenceException("Не задана бизнеслогика страницы"); } var dialogElement = new ConnectionError(); DialogController = new DialogController(dialogElement); ViewModel = new ForecastsObjectsViewModel(_forecastObjectProvider, DialogController); }
/// <summary> /// To call the event <see cref="Connector.ConnectionError"/>. /// </summary> /// <param name="exception">Error connection.</param> private void RaiseConnectionError(Exception exception) { if (exception == null) { throw new ArgumentNullException("exception"); } // адаптеры маркет-данных сами должны оповещать коннектор //if (!IsMarketDataIndependent) // RaiseExportError(exception); ConnectionState = ConnectionStates.Failed; ConnectionError.SafeInvoke(exception); this.AddErrorLog(exception); }
protected virtual void OnConnected() { _error = ConnectionError.None; _state = ConnectionState.Running; _RECV_BUFFER = new byte[_sock.ReceiveBufferSize]; _sendThread = new Thread(new ThreadStart(_SendThreadEntry)); _recvThread = new Thread(new ThreadStart(_RecvThreadEntry)); _sendThread.Start(); _recvThread.Start(); // Debug.Log("Connection.SetRunning"); if (Connected != null) { Connected(); } }
public void Show(ConnectionError error) { base.Show(); switch(error) { case ConnectionError.InvalidNameLength: Label.text = Strings.Login.NameCharacterLimit; break; case ConnectionError.MatchesExistingName: Label.text = Strings.Login.NameMatchesExisting; break; case ConnectionError.ProtocolMismatch: Label.text = Strings.Login.ProtocolMismatch; break; } }
private static string errorToString(ConnectionError error) { string errorDescription = ""; switch (error) { case ConnectionError.OpenError: errorDescription = "Failed to open connection"; break; case ConnectionError.NoReply: errorDescription = "Communication error - no reply from Brick"; break; case ConnectionError.ReadError: errorDescription = "Error reading Brick reply"; break; case ConnectionError.WriteError: errorDescription = "Error sending Brick command"; break; default: errorDescription = "Unknown communication error"; break; } return errorDescription; }
public SendConnectionError(ConnectionError error) { Error = error; }
public void setActivityParameters(ApplicationID _appID, int _difficulty, int _languageArea, string _userID, int _evaluation_mode, string _challenge, Mode _mode) { appID = _appID; LevelParameters param = new LevelParameters(_challenge); number_words = param.batchSize; languageArea = _languageArea; difficulty = _difficulty; level = _challenge; mode = _mode; userID = _userID; //challenge = _challenge; evaluation_mode = _evaluation_mode; loading_status = new ConnectionError("Loading of words have to be invoked",RoutineStatus.IDLE); }
public void ConnectionExited(ConnectionError e) { Console.WriteLine(e.ToString()); if (_connection != null) { _connection.Close(); _connection = null; } switch (e) { case ConnectionError.LISTENING_SOCKET_IN_USE: this._gameState = GameState.MENU; break; case ConnectionError.REJECTED_BY_HOST: this._gameState = GameState.MENU; break; case ConnectionError.CONNECTION_EXITED: this._gameState = GameState.MENU; break; default: this._gameState = GameState.MENU; break; } GenerateBalls(); }
public ConnectionFailedEventArgs(ConnectionError error, string message) { Error = error; Message = message; }
void Update() { if (loading_status.status()==RoutineStatus.ERROR){ Debug.LogError(loading_status.getError()); return; } switch(state){ case 0://Loading user details state = loadingUserDetails(); break; case 1: Debug.Log("Request user profile"); profile_query = server.requestUserProfile(userID); state = 2; break; case 2: if(profile_query.status()== RoutineStatus.READY){ Debug.Log("Get user profile"); userProfile = server.getUserProfile(); if (Application.platform == RuntimePlatform.Android){ tts = gameObject.AddComponent<TTS_android>(); }else{ tts = gameObject.AddComponent<TTS_googletranslate>(); } tts.init(9,9,language.ToString()); Debug.Log("Request save logs"); saved_data_query = server.requestSavefile(); state = 3; break; }else if(profile_query.status()== RoutineStatus.ERROR){ Debug.LogError(profile_query.getError()); state = 1; //userProfile = new PackagedUserProfile(); break; }else{ break; } case 3: if(saved_data_query.status() == RoutineStatus.READY){ PackagedUserLogs pul = server.getSaveFiles(); //OLD//PackagedUserLogs pul = server.getUserLogs(); int number_pages = pul.getTotalPages(); Debug.Log("Get save logs: "+pul.page+"/"+number_pages); if (number_pages>0){ /*saved_data_query = server.requestUserLogs( null, null, number_pages, new string[]{Tag.SAVEFILE.ToString()} , ApplicationID.GAME_WORLD.ToString(), null);//Request last page */ game_state = processSaveFile(pul.getLogs()); loading_status = new ConnectionError("Savefile loaded",RoutineStatus.READY); state = 5; }else{ game_state = ""; loading_status = new ConnectionError("New savefile",RoutineStatus.READY); state = 5; } }else if(saved_data_query.status() == RoutineStatus.ERROR){ loading_status = new ConnectionError("Couldn't load first page of save file. "+saved_data_query.getError(),RoutineStatus.ERROR); //state = -1; state = 5; Debug.Log("Safenet?"); loading_status = new ConnectionError("Could not load first page",RoutineStatus.READY); } break; } if (saveRoutine!=null){ if(saveRoutine.status()==RoutineStatus.READY){ List<int> result = ((GetRoutine<List<int>>)saveRoutine).getPackage(); string output = "Flush success!"; foreach(int a in result) output+=", "+a; Debug.Log(output); }else if(saveRoutine.status()==RoutineStatus.ERROR){ Debug.Log("Flush error!"); saveRoutine = null; } } }
/// <summary> /// Initializes a new instance of <see cref="MonoBrick.ConnectionException"/> /// </summary> /// <param name='error'> /// A connection error /// </param> /// <param name='inner'> /// Inner exception /// </param> public ConnectionException(ConnectionError error, Exception inner) : base(errorToString(error), inner, (byte)error) { }
void PrintClass_OnConnectionError() { try { if (this.InvokeRequired) { ConnectionError del = new ConnectionError(PrintClass_OnConnectionError); this.Invoke(del); } else { if (WorkMode.ProductsScan == _mode) { using (BTConnectionErrorForm frm = new BTConnectionErrorForm()) { if (frm.ShowDialog() == DialogResult.Yes) { BTPrintClass.PrintClass.Reconnect(); } } } } } catch (ObjectDisposedException) { } }
static internal Exception InternalConnectionError(ConnectionError internalError) { return InvalidOperation(Res.GetString(Res.ADP_InternalConnectionError, (int)internalError)); }
internal static Exception InternalConnectionError(ConnectionError internalError) { return InvalidOperation(System.Data.Res.GetString("ADP_InternalConnectionError", new object[] { (int) internalError })); }
public void SendConnectionError(ConnectionError connectionError) { var message = new ServerMessage.SendConnectionError(connectionError); Socket.Send(message.AsJson()); }