internal static void ConfigureDependencies(TinyIoCContainer container, MessageViewerConfiguration config) { var messageStore = new MsSqlMessageStore( new MsSqlMessageStoreConfiguration("Server=.;Database=brighterMessageStore;Trusted_Connection=True", "messages", MsSqlMessageStoreConfiguration.DatabaseType.MsSqlServer)); container.Register(messageStore); container.Register(typeof (IMessageStoreConfigProvider), typeof (MessageStoreConfigProvider)); container.Register(typeof (IMessageStoreViewerFactory), typeof (MessageStoreViewerFactory)); container.Register(typeof(IHandleCommand<RepostCommand>), typeof (RepostCommandHandler)); container.Register(typeof (IAmAMessageRecoverer), typeof (MessageRecoverer)); container.Register<MessageViewerConfiguration>(config); var factory = new HandlerFactory(); factory.Add(container.Resolve<RepostCommandHandler>()); container.Register<IHandlerFactory>(factory); }
internal static void ConfigureDependencies(TinyIoCContainer container) { var logger = LogProvider.GetLogger("MainNancyModule"); logger.Log(LogLevel.Debug, () => "GET on messages"); var messageStore = new MsSqlMessageStore( new MsSqlMessageStoreConfiguration("Server=.;Database=brighterMessageStore;Trusted_Connection=True", "messages", MsSqlMessageStoreConfiguration.DatabaseType.MsSqlServer), logger); container.Register(messageStore); container.Register(typeof (IMessageStoreActivationStateProvider), typeof (MessageStoreActivationStateProvider)); container.Register(typeof (IMessageStoreViewerFactory), typeof (MessageStoreViewerFactory)); container.Register(typeof(IHandleCommand<RepostCommand>), typeof (RepostCommandHandler)); var factory= new HandlerFactory(); factory.Add(container.Resolve<RepostCommandHandler>()); container.Register<IHandlerFactory>(factory); }
public SimpleInjectorHandlerConfig(Container container) { _container = container; _handlerFactory = new HandlerFactory(container); }
/// <summary> /// Gets an instance of the provided type from the handler factory. /// </summary> /// <param name="factory">The handler factory.</param> /// <typeparam name="T">The requested type.</typeparam> /// <returns>An instance of the provided type.</returns> public static T GetInstance <T>(this HandlerFactory factory) => (T)factory(typeof(T));
public IHandlerConfiguration Build() { var factory = new HandlerFactory(_container); return(new HandlerConfiguration(_handlerRegistry, factory)); }
public HandlerConfiguration(IQueryHandlerRegistry handlerRegistry, HandlerFactory factory) { HandlerRegistry = handlerRegistry; HandlerFactory = factory; DecoratorFactory = factory; }
public HandlerConfig(MessageMapperFactory mappers, HandlerFactory handlers) { _mappers = mappers; _handlers = handlers; }
public void InsertProduct(Product p) { var handler = HandlerFactory <Product> .GetHandler(); handler.Insert(p); }
public IpEndpointListener(IPEndPoint endpoint, HandlerFactory handlerFactory, int backlog = DefaultBacklogSize) { tcpListener = new TcpListener(endpoint); this.backlog = backlog; }
protected TQuery GetQueryHandler <TQuery>(HandlerFactory factory) { return((TQuery)factory(typeof(TQuery))); }
public AspNetDependencyInjectionHandlerConfig(IServiceCollection services) { _services = services; _handlerFactory = new HandlerFactory(services); }
public abstract IObservable <Unit> Handle(IRequest notification, HandlerFactory handlerFactory, Func <IEnumerable <Func <IRequest, IObservable <Unit> > >, IRequest, Unit> publish);
public CloudSyncFile(FileItem fileItem, HandlerFactory handlerFactory) { _fileItem = fileItem; _handlerFactory = handlerFactory; }
public void it_should_return_instance() { HandlerFactory.CreateInstance <object>(typeof(object)).ShouldBeTypeOf <object>(); }
public abstract Task <TResult> Invoke(IQuery <TResult> query, HandlerFactory factory, CancellationToken token = default(CancellationToken));
/// <summary> /// Gets instance of the provided type from the handler factory. /// </summary> /// <param name="factory">The handler factory.</param> /// <typeparam name="T">The requested type.</typeparam> /// <returns>An instance of the provided type.</returns> public static IEnumerable <T> GetInstances <T>(this HandlerFactory factory) => (IEnumerable <T>)factory(typeof(IEnumerable <T>));
public override void ProcessMessage(Connection connection, NetworkMessage inboundMessage) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } if (inboundMessage == null) { throw new ArgumentNullException(nameof(inboundMessage)); } byte packetType; if (!connection.IsAuthenticated || connection.XTeaKey.Sum(b => b) == 0) { // this is a new connection... packetType = inboundMessage.GetByte(); if (packetType != (byte)GameIncomingPacketType.PlayerLoginRequest) { // but this is not the packet we were expecting for a new connection. connection.Close(); return; } //if (ServiceConfiguration.GetConfiguration().ReceivedClientVersionInt > 770) { var os = inboundMessage.GetUInt16(); ServiceConfiguration.GetConfiguration().ReceivedClientVersionInt = inboundMessage.GetUInt16(); //} var gameConfig = ServiceConfiguration.GetConfiguration(); // Make a copy of the message in case we fail to decrypt using the first set of keys. var messageCopy = NetworkMessage.Copy(inboundMessage); inboundMessage.RsaDecrypt(useRsa2: true); if (inboundMessage.GetByte() != 0) { // means the RSA decrypt was unsuccessful, lets try with the other set of RSA keys... inboundMessage = messageCopy; inboundMessage.RsaDecrypt(useCipKeys: gameConfig.UsingCipsoftRsaKeys); if (inboundMessage.GetByte() != 0) { // means the RSA decrypt was unsuccessful, lets try with the other set of RSA keys... inboundMessage = messageCopy; inboundMessage.RsaDecrypt(useCipKeys: !gameConfig.UsingCipsoftRsaKeys); if (inboundMessage.GetByte() != 0) { // These RSA keys are also usuccessful... so give up. connection.Close(); return; } } } } else { // Decrypt message using XTea inboundMessage.XteaDecrypt(connection.XTeaKey); inboundMessage.GetUInt16(); packetType = inboundMessage.GetByte(); } var handler = HandlerFactory.CreateIncommingForType(packetType); handler?.HandleMessageContents(inboundMessage, connection); if (handler?.ResponsePackets != null && handler.ResponsePackets.Any()) { // Send any responses prepared for var message = new NetworkMessage(4); foreach (var outPacket in handler.ResponsePackets) { message.AddPacket(outPacket); } connection.Send(message); } }
static void Main() { var cookieToken = new AntiForgeryToken() { // SecurityToken will be populated automatically. IsSessionToken = true }; // Console.WriteLine(cookieToken.SecurityToken); byte[] newByte = new byte[] { 1, 36, 255, 6, 166, 145, 62, 221, 232, 38, 102, 166, 8, 143, 125, 165, 243, 0, 0, 0, 0, }; string[] _purposes = new string[] { "System.Web.Helpers.AntiXsrf.AntiForgeryToken.v1" }; var test1 = MachineKey.Protect(newByte, _purposes); var test2 = MachineKey.Protect(newByte, _purposes); Console.WriteLine(AreByteArraysEqual(test1, test2));; var x1 = HttpServerUtility.UrlTokenEncode(MachineKey.Protect(newByte, _purposes)); var x2 = HttpServerUtility.UrlTokenEncode(MachineKey.Protect(newByte, _purposes)); Console.WriteLine(x1); Console.WriteLine(x2); var x3 = MachineKey.Unprotect(HttpServerUtility.UrlTokenDecode(x1), _purposes); var x4 = MachineKey.Unprotect(HttpServerUtility.UrlTokenDecode(x2), _purposes); Console.WriteLine(x3); Console.WriteLine(x4); Console.WriteLine(AreByteArraysEqual(x3, x4));; return; AntiForgeryToken formToken = new AntiForgeryToken() { SecurityToken = cookieToken.SecurityToken, IsSessionToken = false }; AntiForgeryTokenSerializer serializer = new AntiForgeryTokenSerializer(new MachineKey45CryptoSystem()); var formVal1 = serializer.Serialize(formToken); Console.WriteLine(formVal1); //Console.WriteLine(formToken.ClaimUid); serializer.Deserialize(formVal1).SecurityToken.GetData().OutputByteArray(); Console.WriteLine(); Console.WriteLine(); var formVal2 = serializer.Serialize(formToken); Console.WriteLine(formVal2); // Console.WriteLine(formToken.ClaimUid); serializer.Deserialize(formVal2).SecurityToken.GetData().OutputByteArray(); Console.WriteLine(); Console.WriteLine(); var cookieVal = serializer.Serialize(cookieToken); Console.WriteLine(cookieVal); serializer.Deserialize(cookieVal).SecurityToken.GetData().OutputByteArray(); var cookieVal2 = serializer.Serialize(cookieToken); Console.WriteLine(cookieVal2); serializer.Deserialize(cookieVal2).SecurityToken.GetData().OutputByteArray(); return; //string cookieValue = "emTIesw2uxjqSIp8y67CHsMc_cxMxEJMO-CVy3tQLnJQPD2Fjywsi8k1hppsm8XkM5T0ZU8q0WUP4dgk7IngZl3jzDZuBt97n0a5-PUENqk1"; //string fromValue1 = ""; //string fromValue2 = ""; ////var cookieToken = serializer.Deserialize(cookieValue); ////var formToken2 = serializer.Deserialize("ZgFqPlKwjNHB1imWLFWOhfxo-MXpLk4hr2J1yhmPt12dPsEgyREn3VO1IMjqUcZ4gkHV6dORMDMkORxsGhaB_yGU_iJ8-ozRyGnNHtwRHLYEtpTi0"); //var formToken = serializer.Deserialize("UMTdP94vuMVKtLnzzxrGVLt7lVM_51-psWSI79cGa6gGn1KDRwCDJ8j9Z-O4am9i6pD06jQX5fALSxxqsQB-3L4DHwYudWoQoOApexREUz6P_nOECzbdgQlK5-kX9Xkd0"); //Console.WriteLine(formToken.SecurityToken); ////Console.WriteLine(formToken2.SecurityToken); ////Console.WriteLine(cookieToken.SecurityToken); //return; var builderx = new ContainerBuilder(); builderx.RegisterType <ConsoleOutput> ().As <IOutput> ().InstancePerLifetimeScope(); var containerx = builderx.Build(); using (var scope1 = containerx.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag)) { var outputer = scope1.Resolve <IOutput>(); outputer.Write("hello"); } return; var str = "[quote=(yuan)]123123"; str = Regex.Replace(str, @"\[quote=(.+?)\]", String.Empty, RegexOptions.Compiled | RegexOptions.IgnoreCase); Console.WriteLine(str); str = "[quote=(yuan)]123123"; Console.WriteLine(Regex.Matches(str, @"\[quote=(.+?)\]").Count); foreach (Match item in Regex.Matches(str, @"\[quote=(.+?)\]")) { Console.WriteLine(item.Groups.Count); } return; string sentence = "the quick brown fox jumps over the lazy dog"; // Split the string into individual words. string[] words = sentence.Split(' '); // Prepend each word to the beginning of the // new sentence to reverse the word order. string reversed = words.Aggregate((workingSentence, next) => { Console.WriteLine("current: " + workingSentence + "\t" + next); return(next + " " + workingSentence); }); Console.WriteLine(reversed); //Mapper.Configuration.AssertConfigurationIsValid(); return; // Lambda expression as executable code. Func <int, bool> deleg = i => i < 5; // Invoke the delegate and display the output. Console.WriteLine("deleg(4) = {0}", deleg(4)); // Lambda expression as data in the form of an expression tree. System.Linq.Expressions.Expression <Func <int, bool> > expr = i => i < 5; // Compile the expression tree into executable code. Func <int, bool> deleg2 = expr.Compile(); // Invoke the method and print the output. Console.WriteLine("deleg2(4) = {0}", deleg2(4)); return; var routeValues = new RouteValueDictionary { { "Namespaces", "Nop.Plugin.Widgets.NivoSlider.Controllers" }, { "area", null }, { "widgetZone", "home_top" } }; var props = TypeDescriptor.GetProperties(routeValues); foreach (PropertyDescriptor item in props) { Console.WriteLine(item.Name + " " + item.GetValue(routeValues).ToString()); } Console.WriteLine(); Console.WriteLine(); var props2 = routeValues.GetType().GetProperties(); foreach (var item in props2) { Console.WriteLine(item.Name + " " + item.GetValue(routeValues).ToString()); } return; var builder = new ContainerBuilder(); builder.RegisterType <ConsoleOutput>().AsSelf().As <IOutput>().InstancePerRequest(); builder.RegisterType <TodayWriter>().As <IDateWriter>().InstancePerMatchingLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag);; builder.Register(c => new FakeHttpContext("~")).As <HttpContextBase>().InstancePerLifetimeScope(); //builder.RegisterSource(new AutofacDemo.Features.AnyConcreteTypeNotAlreadyRegisteredSource()); builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_per_request").InstancePerLifetimeScope(); builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("nop_cache_static").SingleInstance(); var container = builder.Build(); using (var scopeContainer = container.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag)) { //var myComponent = scopeContainer.Resolve<MyComponent>(); var myComponent = scopeContainer.Resolve <ConsoleOutput>(); var pets = scopeContainer.Resolve <Pet>(); pets.Output(); // test for cache var iCache = scopeContainer.Resolve <ICacheManager>(); Console.WriteLine(iCache.GetType()); iCache = scopeContainer.ResolveNamed <ICacheManager>("nop_cache_static"); Console.WriteLine(iCache.GetType()); try { iCache = scopeContainer.ResolveNamed <ICacheManager>("nop_cache_static11"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return; HandlerFactory hf = new HandlerFactory(); var method = typeof(HandlerFactory).GetMethod("GetHandler"); Console.WriteLine(method); method = method.MakeGenericMethod(typeof(int)); Console.WriteLine(method.ToString()); Console.WriteLine(method); int x = 3; var result = method.Invoke(hf, null); Console.WriteLine(method.IsGenericMethod); return; }
public void it_should_return_instance() { HandlerFactory.CreateInstance <IRequestHandler>(typeof(TestRequestHandler)).ShouldBeTypeOf <TestRequestHandler>(); }
public static void Main(string[] args) { var builder = new ConfigurationBuilder() .AddEnvironmentVariables(); var configuration = builder.Build(); Log.Logger = new LoggerConfiguration() .WriteTo.LiterateConsole() .CreateLogger(); var container = new Container(); var handlerFactory = new HandlerFactory(container); var messageMapperFactory = new MessageMapperFactory(container); container.Register <IHandleRequests <GreetingEvent>, GreetingEventHandler>(); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <GreetingEvent, GreetingEventHandler>(); //create policies var retryPolicy = Policy .Handle <Exception>() .WaitAndRetry(new[] { TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(150) }); var circuitBreakerPolicy = Policy .Handle <Exception>() .CircuitBreaker(1, TimeSpan.FromMilliseconds(500)); var policyRegistry = new PolicyRegistry { { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy } }; //create message mappers var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory) { { typeof(GreetingEvent), typeof(GreetingEventMessageMapper) } }; var amqpUri = configuration["BABEL_BROKER"]; //create the gateway var rmqConnnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri(amqpUri)), //AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange"), }; var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnnection); var dispatcher = DispatchBuilder.With() .CommandProcessor(CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()) .Build()) .MessageMappers(messageMapperRegistry) .DefaultChannelFactory(new InputChannelFactory(rmqMessageConsumerFactory, null)) .Connections(new Connection[] { new Connection <GreetingEvent>( new ConnectionName("paramore.example.greeting"), new ChannelName("greeting.event"), new RoutingKey("greeting.event"), timeoutInMilliseconds: 200) }).Build(); dispatcher.Receive(); Console.WriteLine("Press Enter to stop ..."); Console.ReadLine(); dispatcher.End().Wait(); }
public ListenerService(TcpListener server, TcpClient client, HandlerFactory handlerFactory) { _server = server; _client = client; _handlerFactory = handlerFactory; }