private int _elevationMeters; // -1000 to 10000 public Airport(string code, string city, double lat, double lng, int elevM) { Code = code; City = city; Latitude = lat; Longitude = lng; ElevationMeters = elevM; if (Logger != null) { Logger.Invoke("New Airport created. "); } }
/// <summary> /// Socket读取 /// </summary> /// <param name="socket">socket</param> /// <param name="receiveCount">读取长度</param> /// <param name="warningLog">日记委托记录</param> /// <returns>读到的数据,如果内部出现异常则返回null</returns> protected byte[] SocketTryRead(Socket socket, int receiveCount, LoggerDelegate warningLog = null) { byte[] receiveBytes = new byte[receiveCount]; int receiveFinish = 0; while (receiveFinish < receiveCount) { // 分批读取 int receiveLength = (receiveCount - receiveFinish) >= BufferSize ? BufferSize : (receiveCount - receiveFinish); try { var readLeng = socket.Receive(receiveBytes, receiveFinish, receiveLength, SocketFlags.None); if (readLeng == 0) { return(null); } receiveFinish += readLeng; } catch (SocketException ex) { warningLog?.Invoke(ex.Message, ex); return(null); } } return(receiveBytes); }
/// <summary> /// Logs the specified text with as specified type to the viewport and any method assigned to the GUI.Logger /// </summary> /// <param name="textToLog"></param> /// <param name="type"></param> public static void Log(string textToLog, LogItemType type) { while (m_ViewPort == null || m_ViewPort.IsHandleCreated == false || m_ViewPort.Visible == false) { Thread.Sleep(15); } m_ViewPort.AppendToLog(textToLog, type); if (GUI.Logger != null) { Logger.Invoke(textToLog, type); } }
/// <summary> /// Logs the specified text with as specified type to the viewport and any method assigned to the GUI.Logger /// </summary> /// <param name="textToLog"></param> /// <param name="type"></param> public static void Log(string textToLog, LogItemType type) { if (m_threadViewPort == null) { m_threadViewPort = new Thread(new ThreadStart(DisplayViewPort)); m_threadViewPort.SetApartmentState(ApartmentState.STA); m_threadViewPort.IsBackground = true; m_threadViewPort.Name = "ViewPort"; m_threadViewPort.Start(); } while (m_ViewPort == null || m_ViewPort.IsHandleCreated == false || m_ViewPort.Visible == false) { Thread.Sleep(15); } m_ViewPort.AppendToLog(textToLog, type); if (GUI.Logger != null) { Logger.Invoke(textToLog, type); } }
static void Main(string[] args) { try { LoggerDelegate logger = null; logger = LogToScreen; logger += LogFancy; logger += LogToFile; // these two lines are equivalent logger?.Invoke("Something happened"); // nullable expression if (logger != null) { logger("Something happened"); // if null } } finally { Console.WriteLine("Press any key to finish"); Console.ReadKey(); } }
internal virtual bool ApplyCommandImpl(SMUCmdConstant cmd, uint val, Func <uint, string> msgFunc) { if (ApplySMUCommand(cmd, val, mSmu.SMU_PCI_ADDR) != SMU.Status.OK) { mLogger.Invoke($"Socket 1 apply cmd error: {cmd}"); return(false); } mLogger.Invoke($"Socket 1: {msgFunc.Invoke(val)}"); if (mIsDualSocket) { if (ApplySMUCommand(cmd, val, mSmu.SMU_PCI_ADDR_2) != SMU.Status.OK) { mLogger.Invoke($"Socket 2 apply cmd error: {cmd}"); return(false); } mLogger.Invoke($"Socket 2: {msgFunc.Invoke(val)}"); } return(true); }
/// <summary> /// Method logging events are sent to. /// </summary> /// <param name="message">The message <c>String</c> to log.</param> /// <param name="level">The <c>LogLevel</c> of your message.</param> public static void WriteEntry(string message, LogLevel level) { Delegate?.Invoke(message, level); }