static void Main(string[] args) { PluginActivator activator = new PluginActivator(); IPlugin plugin1 = new Plugin <IEmployee>(1, "TerrariumGame", "Say", BindingFlags.NonPublic | BindingFlags.Instance, 1, new string[] { "Plugin 1" }); IPlugin plugin2 = new Plugin <IEmployee>(3, "TerrariumGame", "Say", BindingFlags.NonPublic | BindingFlags.Instance, 1, new string[] { "Plugin 2" }); activator.AddPlugin(plugin2); activator.AddPlugin(plugin1); //activator.RemovePlugin(plugin); foreach (var plugins in activator.Activate()) { foreach (var plugin in plugins) { foreach (var result in plugin.Action()) { if (result != null) { Console.WriteLine(result.ToString()); } } } } Console.ReadKey(true); }
public static IServiceCollection AddAutomationAuth(this IServiceCollection services, IConfiguration authenticationSection, IConfiguration authorizationSection) { var authorizationOptions = authorizationSection.Get <GitAutomation.Auth.AuthorizationOptions>(); foreach (var plugin in authorizationOptions.Types.Select(PluginActivator.GetPluginOrNull <IRegisterPrincipalValidation>)) { plugin?.RegisterPrincipalValidation(services, authorizationSection); } var authBuilder = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.Events = new CookieAuthenticationEvents { OnValidatePrincipal = async(context) => { var principalValidation = context.HttpContext.RequestServices.GetServices <IPrincipalValidation>(); var currentPrincipal = context.Principal; foreach (var entry in principalValidation) { currentPrincipal = await entry.OnValidatePrincipal(context.HttpContext, currentPrincipal); if (currentPrincipal == null) { context.RejectPrincipal(); break; } } if (currentPrincipal != null) { context.ReplacePrincipal(currentPrincipal); } } }; }); var authenticationOptions = authenticationSection.Get <AuthenticationOptions>(); services.Configure <AuthenticationOptions>(authenticationSection); PluginActivator.GetPlugin <IRegisterAuthentication>( typeName: authenticationOptions.Type, errorMessage: $"Unknown git service api registry: {authenticationOptions.Type}. Specify a .Net type.`" ).RegisterAuthentication(services, authBuilder, authenticationSection); services.AddAuthorization(options => { options.AddGitAutomationPolicies(); }); return(services); }
public static IServiceCollection AddGitUtilities(this IServiceCollection services, IConfiguration persistenceConfiguration, IConfiguration repositoryConfiguration, IConfiguration appConfiguration) { services.AddSingleton <IRepositoryMediator, RepositoryMediator>(); services.AddSingleton <GitAutomation.Processes.IReactiveProcessFactory, GitAutomation.Processes.ReactiveProcessFactory>(); services.AddSingleton <IRepositoryOrchestration, RepositoryOrchestration>(); services.AddSingleton <IOrchestrationActions, OrchestrationActions>(); services.AddSingleton <IRepositoryStateDriver, RepositoryStateDriver>(); services.AddSingleton <IRemoteRepositoryState, RemoteRepositoryState>(); services.AddSingleton <ILocalRepositoryState, LocalRepositoryState>(); services.AddSingleton <IGitCli>(sp => sp.GetRequiredService <ILocalRepositoryState>().Cli); services.AddSingleton <Func <HttpClient> >(() => new HttpClient()); services.AddTransient <GitAutomation.Orchestration.Actions.IntegrateBranchesOrchestration>(); services.AddSingleton <GitAutomation.Work.IUnitOfWorkFactory, GitAutomation.Work.UnitOfWorkFactory>(); services.AddSingleton <IBranchSettingsNotifiers, BranchSettingsNotifiers>(); services.AddSingleton(appConfiguration.Get <AppOptions>() ?? new AppOptions()); var persistenceOptions = persistenceConfiguration.Get <PersistenceOptions>(); PluginActivator.GetPlugin <IRegisterBranchSettings>( typeName: persistenceOptions.Type, errorMessage: $"Unknown persistence registry: {persistenceOptions.Type}. Specify a .Net type." ).RegisterBranchSettings(services, persistenceConfiguration); var repositoryOptions = repositoryConfiguration.Get <GitRepositoryOptions>(); PluginActivator.GetPlugin <IRegisterGitServiceApi>( typeName: repositoryOptions.ApiType, errorMessage: $"Unknown git service api registry: {repositoryOptions.ApiType}. Specify a .Net type, such as `{typeof(RegisterMemory).FullName}`" ).RegisterGitServiceApi(services, repositoryConfiguration); services.AddIntegrationNamingConvention(repositoryOptions); services.AddTransient <NormalMergeStrategy>(); services.AddTransient <MergeNextIterationMergeStrategy>(); services.AddTransient <ForceFreshMergeStrategy>(); services.AddTransient <IMergeStrategyManager, MergeStrategyManager>(); return(services); }
private void Initialize(string ipAddress, int port) { /// set culture to US Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); /// register configuration & worker ObjectPool.Instance.Register <IServer>().ImplementedBy(this); ObjectPool.Instance.Register <GSMServer.Configuration.IConfiguration>().ImplementedBy(new ApplicationSettings()); ObjectPool.Instance.Register <Worker.IPipeline>().ImplementedBy(new DefaultPipeline(new ActionInvokerLookup(this))); /// register logging IInternalLogging ObjectPool.Instance.Register <IInternalLogging>().ImplementedBy(new BaseInternalLogging()); ObjectPool.Instance.Register <ISMSLogging>().ImplementedBy(new ArchiveSMSLogging()); /// initialize database InitializeDatabase(); GSMServer.Configuration.IConfiguration settings = ObjectPool.Instance.Resolve <GSMServer.Configuration.IConfiguration>(); portColletion = new RandomConnectionProvider(); workerPoolManager = new WorkerPoolManager(); workerPoolManager.AddPool(new DatabaseWorkerPool()); workerPoolManager.AddPool(new MemoryWorkerPool()); pluginMap = new PluginObserver(); string countryCode = ((ApplicationSettings)settings).General.CountryCode; string IsNullintervalProcessQueue = ((ApplicationSettings)settings).General.IntervalWorkerQueue.ToString(); string IsNullintervalReadMessage = ((ApplicationSettings)settings).General.IntervalReadMessage.ToString(); int intervalProcessQueue; int intervalReadMessage = TimeConstant.READ_TIMEOUT; if (string.IsNullOrEmpty(IsNullintervalProcessQueue)) { throw new System.Configuration.ConfigurationErrorsException("Interval Queue cannot be null or zero."); } else { intervalProcessQueue = Convert.ToInt32(IsNullintervalProcessQueue); if (intervalProcessQueue < 1000) { throw new InvalidOperationException("Interval Queue may cause invalid operation while sending SMS because value is to fast."); } } BasicInformation connection; StringBuilder portname, sparity, sstop, shand; StringBuilder serviceCenter = new StringBuilder(); bool pduMode = false; int baudrate, databits; Parity parity; StopBits stopBits; Handshake handshake; /// for comparison is the configuration in accordance with the detected serial ports by OS? string[] ports = System.IO.Ports.SerialPort.GetPortNames(); foreach (GSMServer.Configuration.SerialPort node in ((ApplicationSettings)settings).SerialPorts.Items) { portname = new StringBuilder(node.PortName); pduMode = false; pduMode = node.PDUMode; if (!string.IsNullOrEmpty(node.ServiceCenter)) { serviceCenter = new StringBuilder(countryCode + node.ServiceCenter.Substring(1, node.ServiceCenter.Length - 1)); } baudrate = Convert.ToInt32(node.BaudRate); databits = Convert.ToInt32(node.DataBits); parity = new Parity(); sparity = new StringBuilder(node.Parity.ToLower()); if (sparity.ToString() == "even") { parity = Parity.Even; } else if (sparity.ToString() == "mark") { parity = Parity.Mark; } else if (sparity.ToString() == "none") { parity = Parity.None; } else if (sparity.ToString() == "odd") { parity = Parity.Odd; } else if (sparity.ToString() == "space") { parity = Parity.Space; } stopBits = new StopBits(); sstop = new StringBuilder(node.StopBits.ToLower()); if (sstop.ToString() == "none") { stopBits = StopBits.None; } else if (sstop.ToString() == "one") { stopBits = StopBits.One; } else if (sstop.ToString() == "onepointfive") { stopBits = StopBits.OnePointFive; } else if (sstop.ToString() == "two") { stopBits = StopBits.Two; } handshake = new Handshake(); shand = new StringBuilder(node.Handshake.ToLower()); if (shand.ToString() == "none") { handshake = Handshake.None; } else if (shand.ToString() == "requesttosend") { handshake = Handshake.RequestToSend; } else if (shand.ToString() == "RequestToSendXOnXOff") { handshake = Handshake.RequestToSendXOnXOff; } else if (shand.ToString() == "xonxoff") { handshake = Handshake.XOnXOff; } /// check whether port there is in collection? if (ports.Where(b => b.ToLower().Equals(portname.ToString().ToLower())).SingleOrDefault() != null) { connection = new BasicInformation(portname.ToString(), baudrate, parity, stopBits, databits, handshake, serviceCenter.ToString(), pduMode); InitSerialPort(connection); } } GSMServer.Plugin.Plugin plugin; foreach (PluginElement pluginElement in ((ApplicationSettings)settings).Plugins.Items) { plugin = PluginActivator.Create(pluginElement.AssemblyFile, pluginElement.Type); if (plugin != null) { pluginMap.Add(pluginElement.AssemblyFile, plugin); } } availableConnections = portColletion.ToList(); if (portColletion.Count > 0) { intervalProcessQueue = (intervalProcessQueue / portColletion.Count) + TimeConstant.DEFAULT_INTERVAL_QUEUE; } else { intervalProcessQueue = (intervalProcessQueue) + TimeConstant.DEFAULT_INTERVAL_QUEUE; } timerReadQueue = new System.Timers.Timer(intervalReadMessage); timerReadQueue.Elapsed += timerReadQueue_Elapsed; timerProcessRequestQueue = new System.Timers.Timer(intervalProcessQueue); timerProcessRequestQueue.Elapsed += TimerProcessingRequest_Elapsed; if (portColletion.Count > 0) { if (!this.Active) { this.BeginAcceptClient(); } } base.PacketReceived += OnPacketReceived; base.Connected += OnClientConnected; base.Disconnected += OnClientDisconnect; base.Closed += OnClosed; base.Open += OnOpen; }