protected override bool Fail(string text) { OnWrite?.Invoke(ELogLevel.Error, text); base.Fail(text); Error(text); return(false); }
protected new bool Error(string text) { OnWrite?.Invoke(ELogLevel.Error, text); WriteLine($"Error: {text}"); base.Error = text; return(false); }
public async Task RunAsync(CancellationToken token = default(CancellationToken)) { var request = CreateRequest(); if (OnWriteAsync != null) { await OnWriteAsync.Invoke(request, token); } else { OnWrite?.Invoke(request); } using (token.Register(() => request.Abort(), false)) using (var response = (HttpWebResponse)await request.GetResponseAsync()) { token.ThrowIfCancellationRequested(); if (OnReadAsync != null) { await OnReadAsync.Invoke(response, token); } else { OnRead?.Invoke(response); } } }
private void WriteFile() { try { while (true) { var logEntry = _data.Take(_isLogging.Token); try { if (!Directory.Exists(_dir)) { Directory.CreateDirectory(_dir); } File.AppendAllText(Path.Combine(_dir, string.Format("{0:yyyy-MM-dd}.txt", DateTime.Now)), logEntry.ToString() + Environment.NewLine); OnWrite?.Invoke(this, logEntry); } catch (Exception ex) { OnError?.Invoke(this, ex.Message); } } } catch (OperationCanceledException) { } catch (Exception ex) { OnError?.Invoke(this, ex.Message); } }
public override void SetAttributes(string path, AssetAttributes attributes) { OnWrite?.Invoke(); var desc = GetDescriptor(path); index[AssetPath.CorrectSlashes(path)] = desc; wasModified = true; }
protected bool WriteLine(ELogLevel log, string text) { OnWrite?.Invoke(log, text); WriteLine($"{log}: {text}"); var failed = log != ELogLevel.Error; return(!failed || Fail(text)); }
public static void Write(LType type, string txt) { OnWrite?.Invoke(type, txt); if (type == LType.HttpInfo) { OutputStream?.WriteS("[{2}][{0}] {1}", type.ToString(), txt, DateTime.Now.ToLongTimeString()); } }
public void WriteLine(char[] buffer, int index, int count) { string value = ""; for (int i = index; i < index + count; i++) { value += buffer[i]; } Console.Print(value, ref this.output); OnWrite?.Invoke(this, new EventArgs()); }
public void Write(char C) { OnWrite?.Invoke(C.ToString()); lock (Clients) foreach (var Cl in Clients) { Cl.Write(C); } }
public override void Write(byte[] buffer, int offset, int count) { if (!CanWrite) { throw new InvalidOperationException("Cannot write to a read-only stream."); } OnWrite?.Invoke(this, buffer, offset, count); baseStream_.Write(buffer, offset, count); }
public void WriteLine(char[] buffer) { string value = ""; foreach (char character in buffer) { value += character; } Console.Print(value, ref this.output); OnWrite?.Invoke(this, new EventArgs()); }
public void InsertLine(string Str) { OnWrite?.Invoke(Str + "\n"); lock (Clients) foreach (var Cl in Clients) { Cl.InsertLine(Str); } }
public void Write(string Str) { OnWrite?.Invoke(Str); lock (Clients) foreach (var Cl in Clients) { Cl.Write(Str); } }
public void Run() { var request = CreateRequest(); OnWrite?.Invoke(request); using (var response = (HttpWebResponse)request.GetResponse()) { OnRead?.Invoke(response); } }
public override void DeleteFile(string path) { OnWrite?.Invoke(); path = AssetPath.CorrectSlashes(path); var desc = GetDescriptor(path); index.Remove(path); trash.Add(desc); wasModified = true; }
public void WriteByte(int address, byte value) { data.Span[address] = value; //base.WriteByte(address, value); OnWrite?.Invoke(this, new BasicRegisterEvent(address, value)); oPL.WriteReg(address, value); }
protected bool WriteLine(string text) { OnWrite?.Invoke(ELogLevel.Info, text); var color = Con.ForegroundColor; Con.ForegroundColor = ConsoleColor.Cyan; //Con.WriteLine(); Con.WriteLine(text); Con.ForegroundColor = color; return(true); }
public override void ImportFileRaw( string path, Stream stream, int reserve, string sourceExtension, DateTime time, AssetAttributes attributes, byte[] cookingRulesSHA1) { OnWrite?.Invoke(); AssetDescriptor d; bool reuseExistingDescriptor = index.TryGetValue(AssetPath.CorrectSlashes(path), out d) && (d.AllocatedSize >= stream.Length) && (d.AllocatedSize <= stream.Length + reserve); if (reuseExistingDescriptor) { d.Length = (int)stream.Length; d.ModificationTime = time; d.CookingRulesSHA1 = cookingRulesSHA1; d.Attributes = attributes; d.SourceExtension = sourceExtension; index[AssetPath.CorrectSlashes(path)] = d; this.stream.Seek(d.Offset, SeekOrigin.Begin); stream.CopyTo(this.stream); reserve = d.AllocatedSize - (int)stream.Length; if (reserve > 0) { byte[] zeroBytes = new byte[reserve]; this.stream.Write(zeroBytes, 0, zeroBytes.Length); } } else { if (FileExists(path)) { DeleteFile(path); } d = new AssetDescriptor(); d.ModificationTime = time; d.CookingRulesSHA1 = cookingRulesSHA1; d.Length = (int)stream.Length; d.Offset = indexOffset; d.AllocatedSize = d.Length + reserve; d.Attributes = attributes; d.SourceExtension = sourceExtension; index[AssetPath.CorrectSlashes(path)] = d; indexOffset += d.AllocatedSize; this.stream.Seek(d.Offset, SeekOrigin.Begin); stream.CopyTo(this.stream); byte[] zeroBytes = new byte[reserve]; this.stream.Write(zeroBytes, 0, zeroBytes.Length); this.stream.Flush(); } wasModified = true; }
public virtual void OnCharacteristicWrite(Android.Bluetooth.BluetoothDevice droidDevice, int requestId, Android.Bluetooth.BluetoothGattCharacteristic characteristic, bool preparedWrite, bool responseNeeded, int offset, byte[] value) { var device = BluetoothManager.BluetoothDeviceWrapper.GetBluetoothDeviceFromDroidDevice((Service.Server as GattServer).BluetoothManager, droidDevice); WriteRequest writeRequest = new WriteRequest { Device = device, Offset = offset, ResponseNeeded = responseNeeded, RequestId = requestId, Value = value }; OnWrite?.Invoke(this, writeRequest); }
public virtual void Write(int address, TValue value) { OnWrite?.Invoke(this, new MemoryWriteEventArgs <TValue>() { Address = address, Value = value }); if (IsReadOnly) { throw new AccessViolationException("Memory area is read only."); } _memory[address] = value; }
public virtual void OnWriteRequest(BluetoothDevice droidDevice, int requestId, bool preparedWrite, bool responseNeeded, int offset, byte[] value) { var bluetoothManager = (Characteristic.Service.Server as GattServer).BluetoothManager; var device = BluetoothManager.BluetoothDeviceWrapper.GetBluetoothDeviceFromDroidDevice(bluetoothManager, droidDevice); IDescriptorWriteRequest writeRequest = new DescriptorWriteRequest { SourceDevice = device, TargetDescriptor = this, Offset = offset, ResponseNeeded = responseNeeded, RequestId = requestId, Value = value }; OnWrite?.Invoke(this, writeRequest); }
public static Run LogColor(string s, Brush b, params object[] formatStrings) { string text = s; if (formatStrings.Length != 0) { text = string.Format(s, formatStrings); } try { File.AppendAllText(logFile, text); } catch { } return(OnWrite?.Invoke(text, b)); }
/// <summary> /// Write a string with specified colors /// </summary> /// <param name="str">the string</param> /// <param name="background">background color</param> /// <param name="foreground">foreground color</param> public static void Write(string str, ConsoleColor?background, ConsoleColor?foreground) { if (foreground.HasValue || background.HasValue) { SetColor(background, foreground); } RealCursorY += (ulong)str.ToCharArray().Where(v => v == '\n').Count(); Console.Write(str); OnWrite?.Invoke(str); if (foreground.HasValue || background.HasValue) { ResetColor(true); } }
public async Task RunAsync() { var request = CreateRequest(); if (OnWriteAsync != null) { await OnWriteAsync.Invoke(request); } else if (OnWrite != null) { OnWrite.Invoke(request); } using (var response = (HttpWebResponse)await request.GetResponseAsync()) { if (OnReadAsync != null) { await OnReadAsync.Invoke(response); } else if (OnRead != null) { OnRead?.Invoke(response); } } }
public void Run() { var request = CreateRequest(); if (OnWrite != null) { OnWrite.Invoke(request); } else { OnWriteAsync?.Invoke(request, CancellationToken.None).GetAwaiter().GetResult(); } using (var response = (HttpWebResponse)request.GetResponse()) { if (OnRead != null) { OnRead?.Invoke(response); } else { OnReadAsync?.Invoke(response, CancellationToken.None).GetAwaiter().GetResult(); } } }
private void RaiseOnWrite(WarnType type, string message, Exception exception) { OnWrite?.Invoke(this, new WarningEventArgs(type, message, exception)); }
/// <summary> /// 强制设置触发事件 /// </summary> /// <param name="value"></param> public void SetValue(short value) { OnWrite?.Invoke(this, value); }
public void Write(string value) { OnWrite?.Invoke(value, null); }
public void Write(object value) { this.Value = value; OnWrite?.Invoke(this.Name, value); }
/// <summary> /// Writes a string to the connector. /// </summary> /// <param name="data">String to write</param> public virtual void WriteString(string data) { OnWrite?.Invoke(new MessageEvent(data)); }