public static void BuidFluentValidation(this IServiceCollection service)//services nesenmizi yarattık startup'taki gibi. { service.Configure <ApiBehaviorOptions>(options => { options.InvalidModelStateResponseFactory = (context) => { var errors = context.ModelState.Values.SelectMany(x => x.Errors.Select(p => p.ErrorMessage)).Reverse().ToList(); var result = new KernelResponse { IsSuceess = false, Messages = errors }; return(new BadRequestObjectResult(result)); }; }); }
/// <summary> /// Sends a kernel response to a specific application /// </summary> /// <param name="response">Kernel response</param> /// <param name="senderGuid">Guid of the sender application</param> public static void Send(KernelResponse response, string senderGuid) { try { RegistryKey rk = Registry.LocalMachine.CreateSubKey(Core.REGISTRY_REGISTERED_APPLICATIONS_PATH + "\\{" + senderGuid + "}"); rk.SetValue("Message", response.ToString(), RegistryValueKind.String); rk.SetValue("Param", "", RegistryValueKind.String); rk.Close(); NamedEvents namedEvent = new NamedEvents(); namedEvent.Send(senderGuid+"-"+response.ToString()); } catch (Exception e) { Logger.Error("Booter.cs:Send: " + e.ToString()); } }
/// <summary> /// Broadcast a kernel response to a specific application /// </summary> /// <param name="response">Kernel response</param> public static void Broadcast(KernelResponse response) { NamedEvents namedEvent = new NamedEvents(); namedEvent.Send(Core.BROADCAST_EVENT_PREFIX + response.ToString()); }
/// <summary> /// Fires events based on kernel response events to subscribed event handlers that are provided by applications /// </summary> /// <param name="rsp">A kernel response</param> private static void FireEvent(KernelResponse rsp) { if (subscribed[(int)rsp]) delegates[(int)rsp](rsp); }
/// <summary> /// Allows applications to unsubscribe to kernel events /// </summary> /// <param name="type">The kernel event to subscribe to</param> public static void UnsubscribeEvent(KernelResponse type) { subscribed[(int)type] = false; }
/// <summary> /// Allows applications to subscribe to specific kernel events /// </summary> /// <param name="type">The kernel event to subscribe to</param> /// <param name="handler">The event handler to be invoked once the event is fired</param> public static void SubscribeEvent(KernelResponse type, KernelResponseHandler handler) { subscribed[(int)type] = true; delegates[(int)type] = handler; Thread t = new Thread(EventListener); threads.Add(t.ManagedThreadId, t); events.Add(t.ManagedThreadId, type); t.Start(); }