Exemple #1
0
 /// <summary>
 /// Verify there is a subscriber before calling the
 /// subscribers with the new event.
 /// </summary>
 private void PublishEnsembleWrite(object sender, WriteEventArgs e)
 {
     if (EnsembleWriteEvent != null)
     {
         EnsembleWriteEvent(sender, e);
     }
 }
Exemple #2
0
 protected virtual void OnBegin(WriteEventArgs args)
 {
     Begin(this, args);
     if (OnOwnLine)
     {
         args.Writer.BeginNewLine(true);
     }
 }
 internal void OnWriteEvent(object sender, WriteEventArgs e)
 {
     if (WriteEvent == null)
     {
         throw new InvalidOperationException($"Command {Name} has no WriteEvent listener attached.");
     }
     WriteEvent.Invoke(sender, e);
 }
        /// <inheritdoc/>
        public override void WriteEvent(WriteEventArgs args)
        {
            //Write to file
            lock (LogFileStream)
            {
                LogFileStream.WriteLine(args.FormattedMessage);

                LogFileStream.Flush();
            }
        }
 /// <inheritdoc/>
 public override void WriteEvent(WriteEventArgs args)
 {
     if (useFastAnsiColoring)
     {
         WriteWithAnsiColorCodes(args);
     }
     else
     {
         WriteWithConsoleColor(args);
     }
 }
Exemple #6
0
 private void _tagger_WriteToDisk(object sender, WriteEventArgs e)
 {
     _writer.OpenWriter();
     foreach (var kvp in SituationIndex.Index)
     {
         foreach (var pair in kvp.Value)
         {
             _writer.WriteSituation(pair.Value, kvp.Key, pair.Key); //was this hard?
         }
     }
     _writer.CloseWriter();
 }
        /// <summary>
        /// Closes the underlying socket
        /// </summary>
        /// <param name="disposing">
        /// If true, the EventArg objects will be disposed instead of being re-added to
        /// the IO pool. This should NEVER be set to true unless we are shutting down the server!
        /// </param>
        private void Dispose(bool disposeEventArgs = false)
        {
            // Set that the socket is being closed once, and properly
            if (SocketClosed)
            {
                return;
            }
            SocketClosed = true;


            ReadEventArgs.Dispose();
            WriteEventArgs.Dispose();
            DisposedEventArgs = true;
            //// Do a shutdown before you close the socket
            //try
            //{
            //    Connection.Shutdown(SocketShutdown.Both);
            //}
            //catch (Exception) { }
            //finally
            //{
            //    // Unregister for vents
            //    ReadEventArgs.Completed -= IOComplete;
            //    WriteEventArgs.Completed -= IOComplete;

            //    // Close the connection
            //    Connection.Close();
            //    Connection = null;
            //}

            //// Call Disconnect Event
            //if (!DisconnectEventCalled && OnDisconnected != null)
            //{
            //    DisconnectEventCalled = true;
            //    OnDisconnected();
            //}

            //// If we need to dispose out EventArgs
            //if (disposeEventArgs)
            //{
            //    ReadEventArgs.Dispose();
            //    WriteEventArgs.Dispose();
            //    DisposedEventArgs = true;
            //}
            //else
            //{
            //    // Finally, release this stream so we can allow a new connection
            //    SocketManager.Release(this);
            //    Released = true;
            //}
        }
        private void WriteWithAnsiColorCodes(WriteEventArgs args)
        {
            // Add colour codes
            string coloredMessage = ansiColours[(int)args.LogType] + args.FormattedMessage + ANSI_RESET_COLOR_CODE;

            // Output
            if (args.LogType == LogType.Error)
            {
                Console.Error.WriteLine(coloredMessage);
            }
            else
            {
                Console.WriteLine(coloredMessage);
            }
        }
        internal void OnWriteProgress(object sender, WriteEventArgs e)
        {
            var progress = new ProgressRecord(0,
                                              String.Format(Properties.Resources.ArchiveCompressing, e.InputFile),
                                              String.Format(Properties.Resources.ArchiveProgress, e.BytesRead, e.TotalBytes))
            {
                CurrentOperation =
                    String.Format(Properties.Resources.ArchiveDestination, e.OutputFile),
                PercentComplete = e.Percent
            };

            if (!Quiet)
            {
                WriteProgress(progress);
            }
        }
Exemple #10
0
        /// <summary>
        /// Closes the underlying socket
        /// </summary>
        /// <param name="DisposeEventArgs">
        /// If true, the EventArg objects will be disposed instead of being re-added to
        /// the IO pool. This should NEVER be set to true unless we are shutting down the server!
        /// </param>
        public void Close(bool DisposeEventArgs = false)
        {
            // Set that the socket is being closed once, and properly
            if (SocketClosed)
            {
                return;
            }
            SocketClosed = true;

            // Do a shutdown before you close the socket
            try
            {
                Connection.Shutdown(SocketShutdown.Both);
            }
            catch (Exception) { }
            finally
            {
                // Unregister for vents
                ReadEventArgs.Completed  -= IOComplete;
                WriteEventArgs.Completed -= IOComplete;

                // Close the connection
                Connection.Close();
                Connection = null;
            }

            // If we need to dispose out EventArgs
            if (DisposeEventArgs)
            {
                ReadEventArgs.Dispose();
                WriteEventArgs.Dispose();
                DisposedEventArgs = true;
            }
            else
            {
                // Finally, release this stream so we can allow a new connection
                SocketManager.Release(this);
                Released = true;
            }

            // Call Disconnect Event
            if (!DisconnectEventCalled && OnDisconnect != null)
            {
                DisconnectEventCalled = true;
                OnDisconnect(this);
            }
        }
        public override void WriteEvent(WriteEventArgs args)
        {
            switch (args.LogType)
            {
            case LogType.Trace:
            case LogType.Info:
                Debug.Log(args.FormattedMessage);
                break;

            case LogType.Warning:
                Debug.LogWarning(args.FormattedMessage);
                break;

            case LogType.Error:
            case LogType.Fatal:
                Debug.LogError(args.FormattedMessage);
                break;
            }
        }
Exemple #12
0
        public override void WriteEvent(WriteEventArgs args)
        {
            switch (args.LogType)
            {
            case LogType.Trace:
            case LogType.Info:
                Main.mod.Logger.Log($"[SERVER] {args.FormattedMessage}");
                break;

            case LogType.Warning:
                Main.mod.Logger.Warning($"[SERVER] {args.FormattedMessage}");
                break;

            case LogType.Error:
            case LogType.Fatal:
                Main.mod.Logger.Error($"[SERVER] {args.FormattedMessage}");
                break;
            }
        }
        private void WriteWithConsoleColor(WriteEventArgs args)
        {
            lock (consoleLock)
            {
                // Set colours
                Console.ForegroundColor = foregroundColours[(int)args.LogType];
                Console.BackgroundColor = backgroundColours[(int)args.LogType];

                // Output
                if (args.LogType == LogType.Error)
                {
                    Console.Error.WriteLine(args.FormattedMessage);
                }
                else
                {
                    Console.WriteLine(args.FormattedMessage);
                }

                Console.ResetColor();
            }
        }
Exemple #14
0
 protected virtual void OnBeginWrite(WriteEventArgs args)
 {
     Begin(this, args);
 }
Exemple #15
0
 protected virtual void OnEndWrite(WriteEventArgs args)
 {
     End.FireInReverse(this, args);
 }
Exemple #16
0
 protected virtual void OnEnd(WriteEventArgs args)
 {
     End(this, args);
 }
Exemple #17
0
        public static void SetPluginLoadData(PluginLoadData pluginLoadData)
        {
            writeEventArgs = new WriteEventArgs("Log", "", LogType.Info, new Exception("Error"), "", DateTime.Now);

            consoleWriter = new ConsoleWriter(pluginLoadData);
        }
 protected void OnOutputEvent(object sender, WriteEventArgs e)
 {
     RootCommand.Console.Output(e);
 }
		internal void OnWriteProgress(object sender, WriteEventArgs e)
		{
			var progress = new ProgressRecord(0, 
                String.Format(Properties.Resources.ArchiveCompressing, e.InputFile),
				String.Format(Properties.Resources.ArchiveProgress, e.BytesRead, e.TotalBytes))
                    {
                        CurrentOperation =
                            String.Format(Properties.Resources.ArchiveDestination, e.OutputFile),
                        PercentComplete = e.Percent
                    };

            if (!Quiet)
            {
                WriteProgress(progress);
            }
		}
Exemple #20
0
        /// <summary>
        /// Sends a message Asynchronously to the client connection
        /// </summary>
        private void ProcessSend()
        {
            // Return if we are closing the socket
            if (SocketClosed)
            {
                return;
            }

            // Bool holder
            bool willRaiseEvent = true;

            // Prevent an connection loss exception
            try
            {
                // Prevent race conditions by locking here.
                // ** Make sure to set WaitingOnAsync Inside the LOCK! **
                lock (_lockObj)
                {
                    // If we are waiting on the IO operation to complete, we exit here
                    if (WaitingOnAsync)
                    {
                        return;
                    }

                    // Get the number of bytes remaining to be sent
                    int NumBytesToSend = SendMessage.Count - SendBytesOffset;

                    // If there are no more bytes to send, then reset
                    if (NumBytesToSend <= 0)
                    {
                        SendMessage.Clear();
                        SendBytesOffset = 0;
                        WaitingOnAsync  = false;
                        return;
                    }

                    // Make sure we arent sending more data then what we have space for
                    BufferDataToken Token = WriteEventArgs.UserToken as BufferDataToken;
                    if (NumBytesToSend > Token.BufferBlockSize)
                    {
                        NumBytesToSend = Token.BufferBlockSize;
                    }

                    // Copy our message to the Write Buffer
                    SendMessage.CopyTo(SendBytesOffset, WriteEventArgs.Buffer, Token.BufferOffset, NumBytesToSend);
                    WriteEventArgs.SetBuffer(Token.BufferOffset, NumBytesToSend);

                    // We have to exit the lock() before we can handle the event manually
                    WaitingOnAsync = true;
                    willRaiseEvent = Connection.SendAsync(WriteEventArgs);
                }
            }
            catch (ObjectDisposedException)
            {
                WaitingOnAsync = false;
                Close();
            }

            // If we wont raise the IO event, that means a connection sent the messsage synchronously
            if (!willRaiseEvent)
            {
                // Remember, if we are here, data was sent synchronously... IOComplete event is not called!
                // First, Check for a closed conenction
                if (WriteEventArgs.BytesTransferred == 0 || WriteEventArgs.SocketError != SocketError.Success)
                {
                    Close();
                    return;
                }
                // Append to the offset
                SendBytesOffset += WriteEventArgs.BytesTransferred;
                WaitingOnAsync   = false;
                ProcessSend();
            }
        }
Exemple #21
0
 /// <inheritdoc/>
 public override void WriteEvent(WriteEventArgs args)
 {
     System.Diagnostics.Debug.WriteLine(args.FormattedMessage);
 }
Exemple #22
0
 public void Write(object sender, WriteEventArgs e)
 {
     Console.WriteLine("PortMonitor::Write");
     e.returnCode = 1;
     e.errorCode  = 0;
 }
Exemple #23
0
 protected virtual void OnBegin(WriteEventArgs e)
 {
     Begin(this, e);
 }
Exemple #24
0
 protected virtual void OnEnd(WriteEventArgs e)
 {
     End(this, e);
 }
 void SLAttributeWriteAll(object sender, WriteEventArgs eventArgs)
 {
     this.WriteAll(eventArgs.Writer);
 }
Exemple #26
0
 /// <summary>
 /// Handles a log event.
 /// </summary>
 public override void WriteEvent(WriteEventArgs args)
 {
     Console.WriteLine(args.FormattedMessage);
 }