private void OnConnectionChanged(Codes code, Exception error, string text)
		{
			try
			{
				Message message;

				if (error == null)
				{
					switch (code)
					{
						case Codes.DllConnected:
						case Codes.QuikConnected:
							try
							{
								bool isAlive;

								try
								{
									isAlive = IsConnectionAlive();
								}
								catch
								{
									isAlive = false;
								}

								GetTerminal().AssignProcess();

								message = new ConnectMessage
								{
									Error = isAlive ? null : new ApiException(code, LocalizedStrings.Str1837)
								};
							}
							catch (Exception ex)
							{
								message = new ConnectMessage { Error = ex };
							}
							break;
						case Codes.DllDisconnected:
							message = new DisconnectMessage();
							break;
						case Codes.QuikDisconnected:
							message = new ConnectMessage { Error = new ApiException(code, text) };
							break;
						default:
							message = new ConnectMessage
							{
								Error = new InvalidOperationException(LocalizedStrings.Str1838Params.Put(code))
							};
							break;
					}
				}
				else
				{
					message = new ConnectMessage { Error = error };
				}

				SendOutMessage(message);
			}
			catch (Exception ex)
			{
				SendOutError(ex);
			}
		}