private void On(WriteEvent e) { if (e.Type == WriteType.ChattingTooFast) { this._warning = true; } }
/// <summary> /// Sends the specified message. /// </summary> /// <param name="Message">The message.</param> internal void Send(Message Message) { if (Message.Device.Connected) { SocketAsyncEventArgs WriteEvent = this.WritePool.Dequeue(); if (WriteEvent == null) { WriteEvent = new SocketAsyncEventArgs { DisconnectReuseSocket = false }; } WriteEvent.SetBuffer(Message.ToBytes, Message.Offset, Message.Length + 7 - Message.Offset); WriteEvent.AcceptSocket = Message.Device.Socket; WriteEvent.RemoteEndPoint = Message.Device.Socket.RemoteEndPoint; WriteEvent.UserToken = Message.Device.Token; if (!Message.Device.Socket.SendAsync(WriteEvent)) { this.ProcessSend(Message, WriteEvent); } } else { this.Disconnect(Message.Device?.Token?.Args); } }
public override void Write(char c) { if (c != '\r') { WriteEvent?.Invoke(c.ToString()); } }
private void On(WriteEvent e) { const string pmPrefix = "* "; const string pmSuffix = " > you"; const string pmSendPrefix = "* you > "; if (e.Title.StartsWith(pmPrefix) && e.Title.EndsWith(pmSuffix)) { var username = e.Title.Substring(pmPrefix.Length, e.Title.Length - pmPrefix.Length - pmSuffix.Length); var message = e.Text.Substring(0, e.Text.Length - 1); // Bug ingame, space after each private message new PrivateMessageEvent(username, message) .RaiseIn(this.BotBits); } else if (e.Title.StartsWith(pmSendPrefix)) { var username = e.Title.Substring(pmSendPrefix.Length); var message = e.Text.Substring(0, e.Text.Length - 1); // Bug ingame, space after each private message var channel = this.GetChatChannel(username); if (channel.LastSent == message) { channel.LastReceived = message; } } else if (e.Title == "* SYSTEM" && e.Text == "You are trying to chat too fast, spamming the chat room is not nice!") { this._warning = true; this.InitTimer(); } }
private void On(WriteEvent e) { if (e.Type == WriteType.ReceivedPrivateMessage) { var username = e.GetUser(); var message = e.Text.TrimEnd(' '); // Bug ingame, space after each private message new PrivateMessageEvent(username, message) .RaiseIn(this.BotBits); } else if (e.Type == WriteType.SentPrivateMessage) { var username = e.GetUser(); var message = $"/pm {username} {e.Text.TrimEnd(' ')}"; // Bug ingame, space after each private message var channel = this.GetChatChannel(username); if (channel.LastSent == message) { channel.LastReceived = message; } } else if (e.Type == WriteType.ChattingTooFast) { this._warning = true; } }
/// <summary> /// Sends the specified byte array. /// </summary> /// <param name="Message">The array.</param> internal void Send(Device Device, byte[] Message) { if (Device.Connected) { SocketAsyncEventArgs WriteEvent = this.WritePool.Dequeue(); if (WriteEvent == null) { WriteEvent = new SocketAsyncEventArgs { DisconnectReuseSocket = false }; } WriteEvent.SetBuffer(Message, 0, Message.Length); WriteEvent.AcceptSocket = Device.Socket; WriteEvent.RemoteEndPoint = Device.Socket.RemoteEndPoint; WriteEvent.UserToken = Device.Token; if (!Device.Socket.SendAsync(WriteEvent)) { this.ProcessSend(Device, Message, 0, WriteEvent); } } else { this.Disconnect(Device.Token.Args); } }
private static void Write(string type, string message, params object[] args) { if (!Enable) { return; } string s; if (args == null) { s = String.Format("{0:MMddyy HH:mm:ss}: {1} {2}", DateTime.Now, type, message); } else { s = String.Format("{0:MMddyy HH:mm:ss}: {1} {2} {3}", DateTime.Now, type, message, args); } Console.WriteLine(s); using (StreamWriter streamWriter = new StreamWriter(FilePath, true)) { streamWriter.WriteLine(s); streamWriter.Close(); } WriteEvent?.Invoke(s, EventArgs.Empty); }
internal void OnWriteEvent(object sender, WriteEventArgs e) { if (WriteEvent == null) { throw new InvalidOperationException($"Command {Name} has no WriteEvent listener attached."); } WriteEvent.Invoke(sender, e); }
protected override void Write(LogEventInfo logEvent) { var args = new LoggerEventArgs(logEvent) { RenderLayout = Layout.Render(logEvent) }; WriteEvent?.Invoke(null, args); }
private static void On(WriteEvent e) { var text = e.Text.ToLower(); var title = e.Title.ToLower(); if (!ContainsIgnoreMessages(title, text)) { Write(e.Text, e.Title + ":"); } }
public static void Write(string message, LogLevel logLevel = LogLevel.Info) { var globalLogLevel = Settings.Default.IsVerboseLogEnabled ? LogLevel.Debug : LogLevel.Info; if (globalLogLevel > logLevel) { return; } WriteEvent?.Invoke(Instance, new WriteEventArgs(message, logLevel)); Instance._contents.AppendLine(message); switch (logLevel) { case LogLevel.Debug: if (_log.IsDebugEnabled) { _log.Debug(message); } break; case LogLevel.Info: if (_log.IsInfoEnabled) { _log.Info(message); } break; case LogLevel.Warn: if (_log.IsWarnEnabled) { _log.Warn(message); } break; case LogLevel.Error: if (_log.IsErrorEnabled) { _log.Error(message); } break; case LogLevel.Fatal: if (_log.IsFatalEnabled) { _log.Fatal(message); } break; default: throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null); } }
/// <summary> /// Запись сообщения в лог /// </summary> private static void WriteToTrace(string message, TraceMessageKind traceMessageKind, string category) { // Если уровень логирование недопустимый, то пропускаем запись if (!levels.Contains(TraceMessageKind.All) && !levels.Contains(traceMessageKind)) { return; } foreach (Writer writer in writers) { writer.Write(message, traceMessageKind, category); } WriteEvent?.Invoke(new WriteEventArgs { Message = message, Kind = traceMessageKind }); }
private void OnWrite(WriteEvent e) { const string pmPrefix = "* "; const string pmSuffix = " > you"; if (e.Title.StartsWith(pmPrefix) && e.Title.EndsWith(pmSuffix)) { var username = e.Title.Substring(pmPrefix.Length, e.Title.Length - pmPrefix.Length - pmSuffix.Length); var message = e.Text.Substring(0, e.Text.Length - 1); // Bug ingame, space after each private message new PrivateMessageEvent(username, message) .RaiseIn(this.BotBits); } else if (e.Title == "SYSTEM" && e.Text == "You are trying to chat too fast, spamming the chat is not nice!") { _warning = true; } }
/// <summary> /// Sends the specified message. /// </summary> /// <param name="Buffer">The buffer.</param> /// <param name="Token">The token.</param> public static void Send(byte[] Buffer, NetworkToken Token) { if (Buffer == null) { throw new ArgumentNullException(nameof(Message), "Buffer == null at Send(Buffer, Token)."); } if (Token == null) { throw new ArgumentNullException(nameof(Token), "Token == null at Send(Buffer, Token)."); } if (Token.IsConnected) { SocketAsyncEventArgs WriteEvent = NetworkTcp.WritePool.Dequeue(); if (WriteEvent == null) { WriteEvent = new SocketAsyncEventArgs { DisconnectReuseSocket = false }; } WriteEvent.SetBuffer(Buffer, 0, Buffer.Length); WriteEvent.AcceptSocket = Token.Socket; WriteEvent.RemoteEndPoint = Token.Socket.RemoteEndPoint; WriteEvent.UserToken = Token; if (!Token.Socket.SendAsync(WriteEvent)) { NetworkTcp.ProcessSend(WriteEvent); } } else { NetworkTcp.Disconnect(Token.AsyncEvent); } }
public override void WriteLine(string value) { WriteEvent?.Invoke(this, new ConsoleWriterEventArgs("(ex)" + value + "(/ex)\n")); base.Write(value); }
public static void Write() { WriteEvent?.Invoke("", null); }
public static void Write(string format, params object[] arg) { WriteEvent?.Invoke(format, arg); }
public override void WriteLine(string value) { WriteEvent?.Invoke(value + NewLine); }
//Write Event is delegate public execute(WriteEvent writeFx) { //Crawl writeFx("message"); }
/// <summary> /// Raise the <see cref="WriteEvent" /> event. /// </summary> /// <param name="entry"> /// The entry written to event log. /// </param> protected void OnWriteEvent(EventLogEntry entry) { WriteEvent?.Invoke(this, new EventLogWriteEventArgs(entry)); }
public override void Write(string value) { WriteEvent?.Invoke(this, new ConsoleWriterEventArgs(value)); }
/// <summary> /// Trace event /// </summary> public void WriteLine(string ControlTypeName, string EventName) { WriteEvent?.Invoke(true, ControlTypeName, EventName, ""); }
private TypeSymbol ExecuteListOfInstructions(BaseInstruction linst) { while (linst != null) { if (linst.Ins is CallInstruction) { CallInstruction callaux = linst.Ins as CallInstruction; UL = ExecuteCall(callaux); if (UL == TypeSymbol.U_Return) { // warning but I condiered it as error; GetRuntimeError(RuntimeMessagesError.ReturnInProcedure); } if (UL == TypeSymbol.U_Halt) { return(UL); } } else if (linst.Ins is IfInstruction) { IfInstruction ifaux = linst.Ins as IfInstruction; UL = ExecuteListOfInstructions((EvaluateCondition(ifaux.Cond)) ? ifaux.Ins : ifaux.InsElse); if (UL == TypeSymbol.U_Halt || UL == TypeSymbol.U_Break || UL == TypeSymbol.U_Return || UL == TypeSymbol.U_Exit) { return(UL); } } else if (linst.Ins is WhileInstruction) { WhileInstruction whileaux = linst.Ins as WhileInstruction; while (EvaluateCondition(whileaux.Cond)) { UL = ExecuteListOfInstructions(whileaux.Ins); if (UL == TypeSymbol.U_Halt || UL == TypeSymbol.U_Return || UL == TypeSymbol.U_Exit) { return(UL); } if (UL == TypeSymbol.U_Break) { break; } } } else if (linst.Ins is ForInstruction) { ForInstruction foraux = linst.Ins as ForInstruction; TExpression expB = EvaluateInteger(foraux.ExpBegin); TExpression expE = EvaluateInteger(foraux.ExpEnd); TExpression step = EvaluateInteger(foraux.ExpStep); if (!foraux.IsDown) { Assign(foraux.V, 0, expB); while (expB.ValNB <= expE.ValNB) { UL = ExecuteListOfInstructions(foraux.Ins); if (UL == TypeSymbol.U_Halt || UL == TypeSymbol.U_Return || UL == TypeSymbol.U_Exit) { return(UL); } if (UL == TypeSymbol.U_Break) { break; } // expB.ValNB = expB.ValNB + 1; expB.ValNB = expB.ValNB + step.ValNB; Assign(foraux.V, 0, expB); } } else { Assign(foraux.V, 0, expB); while (expB.ValNB >= expE.ValNB) { UL = ExecuteListOfInstructions(foraux.Ins); if (UL == TypeSymbol.U_Halt || UL == TypeSymbol.U_Return || UL == TypeSymbol.U_Exit) { return(UL); } if (UL == TypeSymbol.U_Break) { break; } // expB.ValNB = expB.ValNB + 1; expB.ValNB = expB.ValNB - step.ValNB; Assign(foraux.V, 0, expB); } } Free(ref expB); Free(ref expE); Free(ref step); } else if (linst.Ins is DoWhileInstruction) { #if doc DoWhileInstruction doaux = linst.Ins as DoWhileInstruction; do { UL = ExecuteListOfInstructions(doaux.Ins); if (UL == TypeSymbol.U_Halt || UL == TypeSymbol.U_Return || UL == TypeSymbol.U_Exit) { return(UL); } if (UL == TypeSymbol.U_Break) { break; } } while (EvaluateCondition(doaux.Cond)); #else //ExecuteOneTimeLoopAtLeast(linst.Ins as TConditionBase, true); #endif } else if (linst.Ins is RepeatUntilInstruction) { #if doc RepeatUntilInstruction repeataux = linst.Ins as RepeatUntilInstruction; do { UL = ExecuteListOfInstructions(repeataux.Ins); if (UL == TypeSymbol.U_Halt || UL == TypeSymbol.U_Return || UL == TypeSymbol.U_Exit) { return(UL); } if (UL == TypeSymbol.U_Break) { break; } } while (!EvaluateCondition(repeataux.Cond)); #else ExecuteOneTimeLoopAtLeast(linst.Ins as TConditionBase, false) #endif } else if (linst.Ins is BreakInstruction) { return((linst.Ins as BreakInstruction).UL); } else if (linst.Ins is ReturnInstruction) { ReturnInstruction returnaux = linst.Ins as ReturnInstruction; GReturn = returnaux; return(TypeSymbol.U_Return); } else if (linst.Ins is AssignInstruction) { AssignInstruction assignaux = linst.Ins as AssignInstruction; Func <TExpression, TExpression, TExpression> a = (expValue, op) => { expValue.Next = op; op.Prev = expValue; TExpression varExpression = new TExpression { UL = TypeSymbol.U_Var }; varExpression.ValVar = assignaux.Var; varExpression.Index = TExpression.CopyExpression(assignaux.index); varExpression.Next = expValue; expValue.Prev = varExpression; return(EvaluateExpression(varExpression)); }; TExpression exp0; TExpression expOperator; if (assignaux.Exp != null) // = , += , -= , *= , /=, ^= , %= { exp0 = EvaluateExpression(assignaux.Exp); if (assignaux.UL != TypeSymbol.U_Assignment) // += , -= , *= , /=, ^= , %= { TypeSymbol ulAux; if (assignaux.UL == TypeSymbol.U_PluseAssigment) { ulAux = TypeSymbol.U_Pluse; } else if (assignaux.UL == TypeSymbol.U_MinusAssigment) { ulAux = TypeSymbol.U_Minus; } else if (assignaux.UL == TypeSymbol.U_MultiplyAssigment) { ulAux = TypeSymbol.U_Multiply; } else if (assignaux.UL == TypeSymbol.U_DivisionAssigment) { ulAux = TypeSymbol.U_Division; } else if (assignaux.UL == TypeSymbol.U_PowAssigment) { ulAux = TypeSymbol.U_Pow; } else //if (assignaux.UL == TypeSymbol.U_ModAssigment) { ulAux = TypeSymbol.U_Mod; } expOperator = new TExpression { UL = ulAux }; exp0 = EvaluateExpression(assignaux.Exp); if ((exp0.Next != null) || (exp0.Prev != null)) { throw new ArgumentException("This is notification for me hakam"); } expOperator = new TExpression { UL = ulAux }; exp0 = EvaluateExpression(assignaux.Exp); if ((exp0.Next != null) || (exp0.Prev != null)) { throw new ArgumentException("This is notification for me hakam"); } exp0 = a(exp0, expOperator); } } else // ++ , -- { exp0 = new TExpression { UL = TypeSymbol.U_Cst_Int, ValNB = 1 }; if (assignaux.UL == TypeSymbol.U_PlusePluse) { expOperator = new TExpression { UL = TypeSymbol.U_Pluse }; } else { expOperator = new TExpression { UL = TypeSymbol.U_Minus }; } exp0 = a(exp0, expOperator); } if (assignaux.index == null) { Assign(assignaux.Var, 0, exp0); } else { TExpression iexp = EvaluateInteger(assignaux.index); Assign(assignaux.Var, GiveIntWithRuntimeError(Math.Truncate(iexp.ValNB)), exp0); Free(ref iexp); } Free(ref exp0); } else if (linst.Ins is TWrite) { TWrite writeAux = linst.Ins as TWrite; TExpression exp = EvaluateExpression(writeAux.exp); string output = ""; while (exp != null) { if (exp.UL == TypeSymbol.U_True) { output += true.ToString(); } else if (exp.UL == TypeSymbol.U_False) { output += false.ToString(); } else if (exp.UL == TypeSymbol.U_Cst_Str) { output += exp.ValStr; } else if (exp.UL == TypeSymbol.U_Cst_Real || exp.UL == TypeSymbol.U_Cst_Int) { output += exp.ValNB.ToString(); } exp = exp.Next; } WriteEvent?.Invoke(this, new WriteEventArgs(writeAux.isLn, output, false)); Free(ref exp); } else if (linst.Ins is ReadInstruction) { ReadInstruction readAux = linst.Ins as ReadInstruction; InputForm inputRead = new InputForm(); inputRead.ShowDialog(); string result = inputRead.Input; TExpression expAux = new TExpression { UL = TypeSymbol.U_Cst_Str, ValStr = result }; try { expAux.ValNB = Convert.ToDouble(result); expAux.UL = IsIntMethod(expAux.ValNB); expAux.ValStr = ""; } catch (FormatException) { } try { expAux.UL = (Convert.ToBoolean(result) ? TypeSymbol.U_True : TypeSymbol.U_False); expAux.ValStr = ""; } catch (FormatException) { } int index = 0; if (readAux.index != null) { TExpression temp = EvaluateInteger(readAux.index); index = GiveIntWithRuntimeError(Math.Truncate(temp.ValNB)); Free(ref temp); } Assign(readAux.V, index, expAux); } else { GetRuntimeError(RuntimeMessagesError.UnknownInstruction); } linst = linst.Next; } return(TypeSymbol.U_EOF); }
/// <summary> /// Trace event and some event related information /// </summary> public void WriteLine(string ControlTypeName, string EventName, string Parameters, params Object[] ParameterArgs) { WriteEvent?.Invoke(true, ControlTypeName, EventName, Parameters, ParameterArgs); }
private Log() { InitializeComponent(); Write = new WriteEvent(addLogItem); }