/// <summary> /// Set new <see cref="LoggerCallback"/>s for this logger. /// </summary> /// <param name="types">The logger types to change/add.</param> /// <param name="callback">The callback used to log those types.</param> public void SetCallbacks(LogCallbackTypes types, LoggerCallback callback) { if (callback == null) { throw new ArgumentNullException(nameof(callback), "The callback must not be null."); } if (types.HasFlag(LogCallbackTypes.Info)) { this._InfoCallback = callback; } if (types.HasFlag(LogCallbackTypes.Warning)) { this._WarningCallback = callback; _WarningSet = true; } if (types.HasFlag(LogCallbackTypes.Error)) { this._ErrorCallback = callback; _ErrorSet = true; } if (types.HasFlag(LogCallbackTypes.Exception)) { this._ExceptionCallback = callback; _ExceptionSet = true; } }
public AnalyticsPlugin(LoggerCallback logger, string fileName) { this.logger = logger; this.FileName = fileName; this.LoadAnalyticsData(); this.RequestBackgroundThread(); }
public void SetCallbacks(LogCallbackTypes types, LoggerCallback callback) { if (callback == null) { throw new ArgumentNullException(nameof(callback), "The callback must be set."); } if (types.HasFlag(LogCallbackTypes.Info)) { this.LogInfoCallback = callback; } if (types.HasFlag(LogCallbackTypes.Warning)) { this.LogWarningCallback = callback; WarningCallbackSet = true; } if (types.HasFlag(LogCallbackTypes.Error)) { this.LogErrorCallback = callback; ErrorCallbackSet = true; } if (types.HasFlag(LogCallbackTypes.Exception)) { this.LogExceptionCallback = callback; ExceptionCallbackSet = true; } }
public WebSocket(Func <MemoryStream> recycledStreamFactory, Stream stream, int keepAliveInterval, string secWebSocketExtensions, bool includeExceptionInCloseResponse, bool isClient, string subProtocol, int maxBufferSize, LoggerCallback logger) { _receiveBuffer = new ArraySegment <byte>(new byte[maxBufferSize]); _recycledStreamFactory = recycledStreamFactory; _stream = stream; _logger = logger; _isClient = isClient; _subProtocol = subProtocol; _state = WebSocketState.Open; if (secWebSocketExtensions?.IndexOf("permessage-deflate") >= 0) { _usePerMessageDeflate = true; } logger(LogLevel.Info, "using websocket compression: " + _usePerMessageDeflate); KeepAliveInterval = keepAliveInterval; _includeExceptionInCloseResponse = includeExceptionInCloseResponse; if (keepAliveInterval <= 0) { throw new InvalidOperationException("KeepAliveInterval must be positive"); } LastPingPong = DateTime.UtcNow; NeedsPing = true; _pingCounter = (int)LastPingPong.Ticks; }
public RPCServer(NexusAPI api, string endPoint, int port, LoggerCallback logger = null) { if (string.IsNullOrEmpty(endPoint)) { endPoint = "/"; } Port = port; EndPoint = endPoint; API = api; var settings = new ServerSettings() { Environment = ServerEnvironment.Prod, Port = port, MaxPostSizeInBytes = 1024 * 128, Compression = false }; _server = new HTTPServer(settings, logger); var rpc = new RPCPlugin(_server, endPoint); foreach (var entry in api.Methods) { var methodName = char.ToLower(entry.Name[0]) + entry.Name.Substring(1); var apiMethod = entry; rpc.RegisterHandler(methodName, (paramNode) => { var args = new object[apiMethod.Parameters.Count]; for (int i = 0; i < args.Length; i++) { if (i < paramNode.ChildCount) { args[i] = paramNode.GetNodeByIndex(i).Value; } else if (apiMethod.Parameters[i].HasDefaultValue) { args[i] = apiMethod.Parameters[i].DefaultValue; } else { throw new RPCException("missing argument: " + apiMethod.Parameters[i].Name); } } IAPIResult result; try { result = api.Execute(apiMethod.Name, args); } catch (APIException e) { throw new RPCException(e.Message); } CheckForError(result); return(APIUtils.FromAPIResult(result)); }); } }
public static void Subscribe(LoggerCallback subscriber) { lock (entries) { callback = subscriber; callback?.OnAll(entries.Select(ToEntry).ToArray()); } }
public static void Report(IRequest request, bool found) { LoggerCallback handler = ReportEvent; if (handler != null) { handler(request, found); } }
internal void InvokeLoggerCallback( object sender, LoggerCallbackEventArgs e) { lock (_lockObj) { LoggerCallback?.Invoke(sender, e); } }
public HTTPServer(ServerSettings settings, LoggerCallback log = null, SessionStorage sessionStorage = null) { this.SessionStorage = sessionStorage != null ? sessionStorage : new MemorySessionStorage(); this.Logger = log != null ? log : (_, __) => {}; this.StartTime = DateTime.Now; _bufferPool = new BufferPool(); _bufferFactory = _bufferPool.GetBuffer; this._router = new Router(); this.Settings = settings; SessionStorage.Restore(); var fullPath = settings.Path; this.OnNotFound = (request) => { return(HTTPResponse.FromString("Not found...", HTTPCode.NotFound)); }; this.OnException = (exception) => { return(HTTPResponse.FromString("Exception: " + exception.Message, HTTPCode.InternalServerError)); }; Logger(LogLevel.Info, $"~LUNAR SERVER~ [{settings.Environment} mode] using port: {settings.Port}"); if (fullPath != null) { fullPath = fullPath.Replace("\\", "/"); if (!fullPath.EndsWith("/")) { fullPath += "/"; } Logger(LogLevel.Info, $"Root path: {fullPath}"); this._assetCache = new AssetCache(Logger, fullPath); } else { Logger(LogLevel.Warning, $"No root path specified."); this._assetCache = null; } // Create a TCP/IP socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listener.Blocking = true; listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); }
public OauthConnection(LoggerCallback log, string app_url, string client_id, string client_secret, string localPath) { if (!app_url.StartsWith("http://")) { app_url = "http://" + app_url; } this.logger = log; this.app_url = app_url; this.client_id = client_id; this.client_secret = client_secret; this.localPath = localPath; }
private Logger(TextWriter outputWriter , LoggerCallback onInformationCallback , LoggerCallback onWarningCallback , LoggerCallback onErrorCallback , LoggerCallback onCriticalCallback) { OutputWriter = outputWriter; var callbackLevel = 0; LoggerCallbacks = GetRange(onInformationCallback, onWarningCallback, onErrorCallback, onCriticalCallback) .ToDictionary(_ => callbackLevel++, x => x); }
public OauthConnection Create(OauthKind kind, LoggerCallback logger, string client_id, string client_secret, string redirect_uri, string token = null) { var app_url = this.Server.Settings.Host; if (!app_url.StartsWith("http://")) { app_url = "http://" + app_url; } switch (kind) { case OauthKind.Facebook: return(new FacebookAuth(logger, app_url, client_id, client_secret, redirect_uri)); case OauthKind.LinkedIn: return(new LinkedInAuth(logger, app_url, client_id, client_secret, redirect_uri)); default: return(null); } }
public void UnsetCallbacks(LogCallbackTypes callbacks) { if (callbacks.HasFlag(LogCallbackTypes.Warning)) { this.LogWarningCallback = null; WarningCallbackSet = false; } if (callbacks.HasFlag(LogCallbackTypes.Error)) { this.LogErrorCallback = null; ErrorCallbackSet = false; } if (callbacks.HasFlag(LogCallbackTypes.Exception)) { this.LogExceptionCallback = null; ExceptionCallbackSet = false; } }
/// <summary> /// Remove a one or multiple callbacks from this logger. /// </summary> /// <param name="callbacks">The set or callbacks to remove.</param> public void UnsetCallbacks(LogCallbackTypes callbacks) { if (callbacks.HasFlag(LogCallbackTypes.Warning)) { this._WarningCallback = null; _WarningSet = false; } if (callbacks.HasFlag(LogCallbackTypes.Error)) { this._ErrorCallback = null; _ErrorSet = false; } if (callbacks.HasFlag(LogCallbackTypes.Exception)) { this._ExceptionCallback = null; _ExceptionSet = false; } }
public void LogMessage(string message, LoggerCallback callback = null, int time = 2000) { if (!Active) { return; } m_cache.Append(DateTime.Now.ToString("[HH:mm:ss.fff] ")); for (int x = 0; x < IndentLevel; x++) { m_cache.Append(" "); } m_cache.AppendFormat("{0}{1}", message, (m_logger != null ? m_logger.NewLine : "\r\n")); if (callback != null) { callback(message, time); // Callback to pass message to another logger (ie. ShowNotification) } if (m_init) { if (m_logger == null) { try { m_logger = Sandbox.ModAPI.MyAPIGateway.Utilities.WriteFileInLocalStorage(Filename + ".log", typeof(Logger)); } catch { return; } } //Sandbox.ModAPI.MyAPIGateway.Utilities.ShowNotification("writing: " + message); m_logger.Write(m_cache); m_logger.Flush(); m_cache.Clear(); } }
/// <summary> /// Allows custom logging callbacks for Info/Verbose, Warnings, Errors and Exceptions. Mostly used by <see cref="Debug"/>. /// </summary> /// <param name="informationCallback">The Info/Verbose callback, must be set.</param> /// <param name="warningCallback">The Warning callback, can be null.</param> /// <param name="errorCallback">The Error callback, can be null.</param> /// <param name="exceptionCallback">The Exception callback, can be null.</param> /// <exception cref="ArgumentNullException"></exception> public Logger( LoggerCallback informationCallback, LoggerCallback warningCallback = null, LoggerCallback errorCallback = null, LoggerCallback exceptionCallback = null) { this._InfoCallback = informationCallback ?? throw new ArgumentNullException(nameof(informationCallback), "At least the information callback must be set."); if (warningCallback != null) { this._WarningCallback = warningCallback; this._WarningSet = true; } if (errorCallback != null) { this._ErrorCallback = errorCallback; this._ErrorSet = true; } if (exceptionCallback != null) { this._ExceptionCallback = exceptionCallback; this._ExceptionSet = true; } }
// ReSharper disable once UseDeconstructionOnParameter this is why we are here to Deconstruct /// <summary> /// Deconstructs the <see cref="KeyValuePair{TKey,TValue}"/>. /// </summary> /// <param name="pair"></param> /// <param name="level"></param> /// <param name="callback"></param> /// <remarks>Should be able to use deconstruction "naturally", /// but for whatever reason this is necessary.</remarks> public static void Deconstruct(this KeyValuePair <int, LoggerCallback> pair, out int level , out LoggerCallback callback) { level = pair.Key; callback = pair.Value; }
private void StartServer() { LoggerCallback logger = new LoggerCallback (this.UpdateLogThreaded); try { server = new Server(int.Parse(txtServerPort.Text)); user = new UserBase(); //server.BindSigninNotify(new GenericCallback(this.UpdateSignin)); //server.BindSignoutNotify(new GenericCallback(this.UpdateSignout)); server.BindUserBase(user); server.BindDebugObject(logger); user.BindDebugObject(logger); server.StartServer(); user.Connect(); } catch (Exception ex) { UpdateLog("Port address is incorrect or already in use. " + ex.Message); } }
public static void CreateLogger(LoggerCallback callback) { new Logger(callback); }
public static extern void SetLogger(int LogLevel, LoggerCallback callback);
private Logger(LoggerCallback callback) { ReportEvent += callback; }
protected void WriteLog(string log) { LoggerCallback?.Invoke(log); }
public void BindDebugObject(LoggerCallback l) { logNotify = l; }
public FacebookAuth(LoggerCallback log, string app_url, string client_id, string client_secret, string localPath) : base(log, app_url, client_id, client_secret, localPath) { }
public FileCache(LoggerCallback logger, string filePath) { this.logger = logger; this.filePath = filePath + "public/"; }
public void BindDebugObject(LoggerCallback l) { updateFunction = l; }
private static extern void subscribeAsLoggerListener(LoggerCallback callback);
public LinkedInAuth(LoggerCallback log, string app_url, string client_id, string client_secret, string redirect_uri) : base(log, app_url, client_id, client_secret, redirect_uri) { }
public AssetCache(LoggerCallback logger, string filePath) : base(logger, filePath) { BuildAssetCache("js", "application/javascript", x => JSMinifier.Compress(x)); BuildAssetCache("css", "text/css", x => CSSMinifier.Compress(x)); }
public RESTServer(NexusAPI api, string endPoint, int port, LoggerCallback logger = null) { if (string.IsNullOrEmpty(endPoint)) { endPoint = "/"; } if (!endPoint.EndsWith("/")) { endPoint += "/"; } Port = port; EndPoint = endPoint; API = api; var settings = new ServerSettings() { Environment = ServerEnvironment.Prod, Port = port, MaxPostSizeInBytes = 1024 * 128 }; _server = new HTTPServer(settings, logger); var apiMap = DataNode.CreateObject(); foreach (var entry in api.Methods) { var methodName = char.ToLower(entry.Name[0]) + entry.Name.Substring(1); var apiMethod = entry; var path = endPoint + methodName; var paths = new List <string>(); var mapEntry = DataNode.CreateObject(methodName); apiMap.AddNode(mapEntry); var argMap = DataNode.CreateArray("args"); mapEntry.AddNode(argMap); paths.Add(path); foreach (var arg in apiMethod.Parameters) { var argEntry = DataNode.CreateObject(); argEntry.AddField("name", arg.Name); argEntry.AddField("type", arg.Type.Name); argEntry.AddField("required", arg.DefaultValue == null); argEntry.AddField("description", arg.Description); argMap.AddNode(argEntry); path += "/{" + arg.Name + "}"; paths.Add(path); } foreach (var url in paths) { _server.Get(url, (request) => { var args = new object[apiMethod.Parameters.Count]; IAPIResult result; try { for (int i = 0; i < args.Length; i++) { var name = apiMethod.Parameters[i].Name; if (request.args.ContainsKey(name)) { args[i] = request.args[name]; } else if (apiMethod.Parameters[i].DefaultValue != null) { args[i] = apiMethod.Parameters[i].DefaultValue; } else { throw new APIException("missing argument: " + apiMethod.Parameters[i].Name); } } result = api.Execute(apiMethod.Name, args); } catch (APIException e) { result = new ErrorResult() { error = e.Message }; } if (result is ErrorResult) { var temp = (ErrorResult)result; var error = DataNode.CreateObject(); error.AddField("error", temp.error); return(error); } return(APIUtils.FromAPIResult(result)); }); } _server.Get(endPoint, (request) => { return(apiMap); }); } }
/// <summary> /// Set the logger function to CCycles. /// </summary> /// <param name="clientId">ID of client</param> /// <param name="loggerCb">The logger callback function.</param> public static void set_logger(uint clientId, LoggerCallback loggerCb) { var intptr_delegate = Marshal.GetFunctionPointerForDelegate(loggerCb); cycles_set_logger(clientId, intptr_delegate); }
internal static extern bool RegisterLoggerCallback(LoggerCallback callback);