public static void internalOutputDebugString(string thisMsg) { try { // The output debug string API seems to be a little strange when it comes to handeling large amounts of // data and does not seem to be able to handle long strings properly. It is likely that it is my code // that is at fault but untill I can get to the bottom of it this listener will chop long strings up // into chunks and send them as separate chunks of 1024 bytes in each. It is then the viewers job // to reassemble them, however in order to help the viewer specialist string truncated identifiers will // be sent as the markers to the extended strings. if (thisMsg.Length > Constants.LIMIT_OUTPUT_DATA_TO) { string[] messageParts = LegacyFlimFlamFormatter.MakeManyStrings(thisMsg, Constants.LIMIT_OUTPUT_DATA_TO); // Truncation identifier is #TNK#[MACHINENAME][TRUNCJOINID]XEX for (int partct = 0; partct < messageParts.Length; partct++) { OutputDebugString(messageParts[partct]); } return; } OutputDebugString(thisMsg); } catch (Exception ex) { InternalUtil.LogInternalError(InternalUtil.InternalErrorCodes.ODSListenerError, "There was an error trying to send data to outputdebugstring. " + ex.Message); throw; } }
/// <summary> /// The TexTCP listeners main dispatcher thread which handles the sending of messages from the Tex component to the TCP stream. /// </summary> private void DispatcherThreadMethod() { Thread.CurrentThread.Name = "TcpListenerDispatcher"; Thread.CurrentThread.IsBackground = true; StringBuilder sb = new StringBuilder(); try { // Put in a wait timeout to ensure that when Tex is destroyed the background thread succesfully terminates. Worst case scenario here // is that it hangs around for quarter of a second while (true) { if (!m_mrse.WaitOne(250, false) && (m_queuedMessages.Count == 0)) { continue; } sb.Length = 0; lock (m_lockqueue) { while (m_queuedMessages.Count > 0) { sb.Append(m_queuedMessages.Dequeue() + Constants.TCPEND_MARKERTAG); } } if (sb.Length > 0) { dispatchOutput(sb.ToString()); } if (!m_mrse.Reset()) { // The Win32Exception constructor provides an error number and message if you dont specify one throw new Win32Exception(); } } } catch (Exception ex) { InternalUtil.LogInternalError(InternalUtil.InternalErrorCodes.TCPListenerError, "Exception in TCPListener Thread:" + ex.Message); throw; } // Destroy resources associated with thread NEVER GETS HERE LOOP IS INFINITE //m_queuedMessages = null; //m_mrse = null; //m_lockqueue = null; }
internal bool AllowedFileIOPermission() { if (cacheFileIOPermissionResult == null) { // If the cache is not yet valid or we are not using it then we populate it. try { FileIOPermission perm = new FileIOPermission(PermissionState.None); perm.AllLocalFiles = (FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery); perm.Demand(); cacheFileIOPermissionResult = true; } catch (SecurityException) { // We are unable to parse stackwalks for file information. InternalUtil.LogInternalError(InternalUtil.InternalErrorCodes.AccessDeniedToSomething, "FileIOPermission denied prior to calling a stackwalk.", TraceLevel.Verbose); cacheFileIOPermissionResult = false; } } return((bool)cacheFileIOPermissionResult); }
/// <summary> /// Method responsible for actual writing of output to tcp stream /// </summary> /// <param name="output">Output string</param> private void dispatchOutput(string output) { // if <60 and errored then waitone return if ((socketCommunicationsDown) && (DateTime.Now - lastSocketException).TotalSeconds < SECONDS_NO_SOCKET_RETRY) { // Ensure that we only retry the socket connection once a minute. m_mrse.Reset(); return; } socketCommunicationsDown = false; Byte[] data = Encoding.ASCII.GetBytes(output); if ((m_tcpClient == null) || (!m_tcpClient.Connected)) { try { m_tcpClient = new TcpClient(m_ipAddress, m_port); m_stream = m_tcpClient.GetStream(); } catch (SocketException sx) { lastSocketException = DateTime.Now; socketCommunicationsDown = true; InternalUtil.LogInternalError(InternalUtil.InternalErrorCodes.TCPListenerError, "Socket Exception : " + sx.Message, TraceLevel.Warning); m_mrse.Reset(); return; } } // Should now have reconnected or at least tried to connect. try { m_stream.Write(data, 0, data.Length); m_stream.Flush(); } catch (IOException iox) { InternalUtil.LogInternalError(InternalUtil.InternalErrorCodes.TCPListenerError, "Socket IO Exception : " + iox.Message, TraceLevel.Warning); m_mrse.Reset(); return; } }