public async Task <ITcpServer> CreateServer(IServerConnection serverConnection) { if (await _serverCache.ContainsKeyAsync(serverConnection.Name)) { return(await _serverCache.GetItemAsync(serverConnection.Name)); } var server = _resolver.Resolve <ITcpServer>(); server.ServerConnection = serverConnection; server.PacketFormatter = new EndOfTransmissionPacketFormatter(); server.Log = _resolver.Resolve <ILogFactory>() .CreateLog(new Dictionary <string, string> { { "ApplicationName", GetType().FullName }, { "Category", "TcpServerFactory" }, { "TcpServerName", server.ServerConnection.Name }, { "TcpServerInstance", server.GetHashCode().ToString() } }); await _serverCache.SetItemAsync(serverConnection.Name, server); return(server); }
public ILog CreateLog(IDictionary <string, string> properties = null) { var log = _resolver.ResolveAllInstances <ILog>(); var bLogger = new BroadcastLogger(log, _resolver); if (_resolver.IsRegistered <Dictionary <string, string> >("LoggingContext")) { var defaultProperties = _resolver.Resolve <Dictionary <string, string> >("LoggingContext"); bLogger.AddToContext(defaultProperties); } bLogger.AddToContext(properties); return(bLogger); }
public byte[] Hash(byte[] input, HashProviders provider = HashProviders.Default) { IHashProvider p = null; if (provider == HashProviders.UserAccountSecurity) { p = _resolver.Resolve <IHashProvider>("MURMUR3"); } else { p = _resolver.Resolve <IHashProvider>(); } return(p.Hash(input)); }
public object CreateInstance(IResolve resolvingContext) { ConstructorInfo[] ctors = _targetType.GetConstructors(); if (ctors.Length > 1) { throw new Exception($"type {_targetType} has more than 1 constructor"); } object instance; if (ctors.Length == 0) { instance = Activator.CreateInstance(_targetType); } else { ParameterInfo[] parameters = ctors[0].GetParameters(); object[] instances = new object[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { instances[i] = resolvingContext.Resolve(parameters[i].ParameterType); } ; instance = Activator.CreateInstance(_targetType, instances); } return(instance); }
public UserActor(ILogFactory logFactory, ICommandToEventAdapter commandToEventAdapter, IResolve resolver) { _user = resolver.Resolve <IUser>(); _commandToEventAdapter = commandToEventAdapter; _resolver = resolver; _logger = logFactory.CreateLog(); Receive <IUpdateUserActorStateCommand>(cmd => { _user = cmd.UpdatedUser; Sender.Tell(_commandToEventAdapter.Adapt <IUpdateUserActorStateCommand, IUserUpdatedEvent>(cmd)); }); Receive <IRequestTrackUserCommand>(trackuserCommand => { if (string.IsNullOrEmpty(_user.Id)) { _user.Id = trackuserCommand.UserId; } var response = _commandToEventAdapter.Adapt <IRequestTrackUserCommand, IRespondActorStateEvent>(trackuserCommand); response.User = _user; Sender.Tell(response); //Sender.Tell(_commandToEventAdapter.Adapt<IRequestTrackUserCommand, IUserTrackingEvent>(trackuserCommand)); }); }
public TOut Adapt <TIn, TOut>(TIn input) where TIn : IMessage where TOut : IMessage { var updatedEvent = _resolver.Resolve <TOut>(); updatedEvent.MessageId = input.MessageId; return(updatedEvent); }
public static void Main(string[] args) { try { var resolveUrOptions = ConsoleArgsResolveUR.Resolve(args); resolveUrOptions.MsBuilderPath = MsBuildResolveUR.FindMsBuildPath(resolveUrOptions.Platform); _resolveur = ResolveURFactory.GetResolver( resolveUrOptions, resolveur_HasBuildErrorsEvent, resolveur_ProjectResolveCompleteEvent); _resolveur.Resolve(); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } catch (FileNotFoundException fnfe) { Console.WriteLine(fnfe.Message); } catch (InvalidDataException ide) { Console.WriteLine(ide.Message); } catch (NotSupportedException nse) { Console.WriteLine(nse.Message); } }
public ITcpClient CreateClient(IServerConnection serverConnection) { var client = _resolver.Resolve <ITcpClient>(); client.ServerConnection = serverConnection; client.PacketFormatter = new EndOfTransmissionPacketFormatter(); return(client); }
public void IResolveTest(IResolve resolver) { // Act var value = resolver.Resolve(ref Context); // Validate Assert.IsNotNull(value); Assert.AreSame(StringConst, value); }
public async Task <IUser> Get(string id) { var msg = _resolver.Resolve <IRequestTrackUserCommand>(); msg.UserId = id; var result = await _userManagerActorRef.Ask <IRespondActorStateEvent>(msg); return(result?.User); }
public IServerConnection GetConnection(ClientTransports transport, string host, int port) { var connection = _resolver.Resolve <IServerConnection>(); connection.Host = host; connection.Port = port; connection.Transport = transport; return(connection); }
public IStatusReport AssembleReport(string provider, int instanceId, StatusTypes statusType, IDictionary <string, double> status, IDictionary <string, string> properties = null) { var report = _resolver.Resolve <IStatusReport>(); report.Provider = provider; report.InstanceId = instanceId; report.StatusType = statusType; report.Metrics = status; report.Properties = properties; return(report); }
public void Compile() { var items = new Dictionary <string, ISpecificCultureTranslations>(); foreach (var culture in SupportedCultures) { var diKey = "culture_" + culture.LCID; var instance = _resolver.Resolve <ISpecificCultureTranslations>("DEFAULT"); instance.CultureInfo = culture; instance.LCID = culture.LCID; instance.Translations = new Dictionary <string, string>(); items.Add(diKey, instance); _register.RegisterInstance(instance, diKey); } foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { if (asm.FullName.Contains("NeonTetra")) { try { foreach (var resourceName in asm.GetManifestResourceNames()) { try { var name = resourceName; if (name.EndsWith(".resources", StringComparison.InvariantCultureIgnoreCase)) { name = name.Substring(0, name.Length - ".resources".Length); } var rm = new ResourceManager(name, asm); foreach (var culture in SupportedCultures) { var diKey = "culture_" + culture.LCID; var languageSpecificTranslation = items[diKey]; LoadCacheFromResourceManager(rm, culture, languageSpecificTranslation); } rm.ReleaseAllResources(); } catch (Exception /*e1*/) { } } } catch (Exception /*e*/) { } } } }
static void Main(string[] args) { ConcreteClass abstractFactory = new Factory(); IResolve mapA = abstractFactory.Get("Hi"); MyObject resolverA = mapA.Resolve(); Console.WriteLine(resolverA.ToString()); IResolve mapB = abstractFactory.Get("Bye"); MyObject resolverB = mapB.Resolve(); Console.WriteLine(resolverB); Console.ReadLine(); }
public BroadcastLogger(IEnumerable <ILog> logs, IResolve resolver) { _loggers = (from l in logs where l.GetType() != typeof(BroadcastLogger) select l).ToImmutableArray(); _enabled = _loggers.Any(); if (resolver.IsRegistered <IConfiguration>()) { var config = resolver.Resolve <IConfiguration>(); if (config.IsReady) { var levels = config.GetValueOrDefault("Logging:Levels", "NONE"); if (levels.IndexOf("DEBUG", StringComparison.InvariantCultureIgnoreCase) >= 0) { debugEnabled = true; } if (levels.IndexOf("INFO", StringComparison.InvariantCultureIgnoreCase) >= 0) { informationEnabled = true; } if (levels.IndexOf("EVENT", StringComparison.InvariantCultureIgnoreCase) >= 0) { eventEnabled = true; } if (levels.IndexOf("ERROR", StringComparison.InvariantCultureIgnoreCase) >= 0) { errorEnabled = true; } if (levels.IndexOf("FATAL", StringComparison.InvariantCultureIgnoreCase) >= 0) { fatalEnabled = true; } if (levels.IndexOf("ALL", StringComparison.InvariantCultureIgnoreCase) >= 0) { debugEnabled = true; informationEnabled = true; eventEnabled = true; errorEnabled = true; fatalEnabled = true; } } } }
public SerilogLogger(IResolve resolver) { var loggerConfiguration = new LoggerConfiguration(); if (resolver.IsRegistered <IConfiguration>()) { _configuration = resolver.Resolve <IConfiguration>(); if (_configuration.DebugMode) { loggerConfiguration.WriteTo.Debug(); WriteToDebug = true; } //if (resolver.IsRegistered<IAzureServicesConfiguration>()) //{ // var azureConfig = resolver.Resolve<IAzureServicesConfiguration>(); // if (azureConfig != null && azureConfig.ApplicationInsights != null && // azureConfig.ApplicationInsights.Enabled && // !string.IsNullOrEmpty(azureConfig.ApplicationInsights.Key)) // { // loggerConfiguration.WriteTo.ApplicationInsights(azureConfig.ApplicationInsights.Key, // LogEventToTelemetryConverter); // TelemetryDebugWriter.IsTracingDisabled = true; // WriteToAppInsights = true; // } //} if (System.Diagnostics.Debugger.IsAttached) { try { loggerConfiguration.WriteTo.ColoredConsole(); WriteToColoredConsole = true; } catch (Exception) { //optional, swallow if failes } } var levelMap = new Dictionary <string, LogEventLevel>(StringComparer.InvariantCultureIgnoreCase) { { "DEBUG", LogEventLevel.Debug }, { "INFO", LogEventLevel.Information }, { "EVENT", LogEventLevel.Information }, { "ERROR", LogEventLevel.Error }, { "FATAL", LogEventLevel.Fatal }, { "ALL", LogEventLevel.Verbose } }; var levels = _configuration.GetValueOrDefault("Logging:Levels", "NONE"); if (levelMap.TryGetValue(levels, out var logEventLevel)) { loggerConfiguration.MinimumLevel.Is(logEventLevel); } } _logger = loggerConfiguration.CreateLogger(); _contextProperties = new ConcurrentDictionary <string, string>(); }
public AkkaUserManager(IResolve resolver) { _resolver = resolver; _userManagerActorRef = _resolver.Resolve <IActorRef>("UserManagerActor"); }
public static T Resolve <T>(this IResolve resolver) { return((T)resolver.Resolve(typeof(T))); }