コード例 #1
0
 public static void RegisterWith(IPluginRegistry registry)
 {
     if (AlreadyRegisteredWith(registry))
     {
         return;
     }
 }
コード例 #2
0
 /// <summary>
 /// Initializes the provided <see cref="IPluginRegistry"/> with
 /// the information provided within the Windows registry.
 /// </summary>
 /// <param name="registry">The <see cref="IPluginRegistry"/> to
 /// initialize.</param>
 public void Initialize(IPluginRegistry registry)
 {
     foreach (Assembly assembly in _assemblies)
     {
         registry.Initialize(assembly);
     }
 }
コード例 #3
0
 public Program(IOutputFormatterRegistry outputFormatterRegistry, IProcessorRegistry processorRegistry,
                IPluginRegistry pluginRegistry, ILogger <Program> logger)
 {
     OutputFormatterRegistry = outputFormatterRegistry;
     ProcessorRegistry       = processorRegistry;
     PluginRegistry          = pluginRegistry;
     Logger = logger;
 }
コード例 #4
0
 public CoreApp(IPluginRegistry pluginRegistry, FunctionsEngine functionsEngine, ILoggerFactory loggerFactory, DeviceConfigurationProvider configurationProvider)
 {
     _pluginRegistry        = pluginRegistry;
     _functionsEngine       = functionsEngine;
     _log                   = loggerFactory.CreateLogger <CoreApp>();
     _configurationProvider = configurationProvider;
     _loggerFactory         = loggerFactory;
 }
コード例 #5
0
        public PlugableMigrationsAssembly(IPluginRegistry registry, Type contextType)
        {
            this.migrations = registry.GetRegisteredPlugins()
                              .SelectMany(plugin =>
            {
                return(plugin.GetType().Assembly.GetExportedTypes()
                       .Where(t => t.GetCustomAttribute <MigrationAttribute>() != null)
                       .Select(t => t.GetTypeInfo()));
            });

            this.contextType = contextType;
        }
コード例 #6
0
        private static bool AlreadyRegisteredWith(IPluginRegistry registry)
        {
            string key = typeof(GeneratedPluginRegistrant).Name;

            if (registry.HasPlugin(key))
            {
                return(true);
            }
            else
            {
                registry.RegistrarFor(key);
                return(false);
            }
        }
コード例 #7
0
    public static ParsedRecord ResolveAliases(this ParsedRecord parsedRecord, IPluginRegistry registry)
    {
        var current  = parsedRecord.PluginDescriptor;
        var proposed = current.ResolveAliases(registry);

        if (current != proposed && proposed != PluginDescriptor.NoPlugin)
        {
            var adjusted = parsedRecord with
            {
                PluginDescriptor = proposed
            };
            return(adjusted);
        }
        ;

        return(parsedRecord);
    }
コード例 #8
0
        public void Execute(IDictionary <string, object> state)
        {
            IPluginRegistry pluginRegistry = container.Resolve <IPluginRegistry>();
            IPluginService  pluginService  = container.Resolve <IPluginService>();

            pluginRegistry.Clear();

            foreach (IPlugin plugin in pluginService.GetPlugins())
            {
                Assembly assembly    = Assembly.LoadFrom(string.Format(@"{0}\{1}\{2}\bin\{2}.dll", container.Resolve <string>("PluginsFolder"), plugin.Category, plugin.Name));
                Type     programType = assembly.GetExportedTypes().Where(t => t.Name == "Program").FirstOrDefault();

                if (programType != null)
                {
                    container.RegisterType(programType);

                    object program = container.Resolve(programType);

                    MethodInfo registerMethod = program.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance).Where(m => m.Name == "Register").FirstOrDefault();

                    if (registerMethod != null)
                    {
                        ParameterInfo[] parameters = registerMethod.GetParameters();

                        if (parameters.Length == 1 && parameters[0].ParameterType == typeof(IPluginContext))
                        {
                            IPluginContext context = new PluginContext(plugin, container);

                            registerMethod.Invoke(program, new object[] { context });

                            context.Merge(plugin);

                            pluginService.Save(plugin);

                            pluginRegistry.Add(plugin);
                        }
                    }
                }
            }

            container.RegisterInstance(pluginRegistry);
        }
コード例 #9
0
        public async Task ShutdownAsync()
        {
            _log.LogTrace("Stop timers");
            if (_everyMinuteTimer != null)
            {
                _everyMinuteTimer.Dispose();
                _everyMinuteTimer = null;
            }

            StopWebserver();

            if (_functionsEngine != null)
            {
                _functionsEngine.Shutdown();
                _functionsEngine = null;
            }

            if (_pluginRegistry != null)
            {
                await _pluginRegistry.TeardownPluginsAsync();

                _pluginRegistry = null;
            }
        }
コード例 #10
0
    public static PluginDescriptor ResolveAliases(this PluginDescriptor pluginDescriptor, IPluginRegistry registry)
    {
        // Let's see if we find an alias registered under just the name
        var alias      = pluginDescriptor.Name;
        var registered = registry[alias];

        // ...if not, see if one is registered under the full name
        if (registered == PluginDescriptor.NoPlugin)
        {
            alias      = pluginDescriptor.FullName;
            registered = registry[alias];
        }

        if (registered != PluginDescriptor.NoPlugin)
        {
            var proposedName         = registered.Name;
            var proposedManufacturer = registered.Manufacturer;
            if (pluginDescriptor.Name != proposedName || pluginDescriptor.Manufacturer != proposedManufacturer)
            {
                var adjusted = pluginDescriptor with
                {
                    Name         = proposedName,
                    Manufacturer = proposedManufacturer
                };
                return(adjusted);
            }
            ;
        }

        return(pluginDescriptor);
    }
コード例 #11
0
 public static IEnumerable <PluginDescriptor> ResolveAliases(this IEnumerable <PluginDescriptor> pluginDescriptors,
                                                             IPluginRegistry registry)
 {
     return(pluginDescriptors.Select(pi => pi.ResolveAliases(registry)));
 }
コード例 #12
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            // This deferral should have an instance reference, if it doesn't... the GC will
            // come some day, see that this method is not active anymore and the local variable
            // should be removed. Which results in the application being closed.
            _deferral              = taskInstance.GetDeferral();
            taskInstance.Canceled += TaskInstance_Canceled;

            // this is one way to handle unobserved task exceptions but not the best
            TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;

            // configure logging first

            // init IoC
            // see: http://intellitect.com/net-core-dependency-injection/#ActivatorUtilities
            // and https://stackify.com/net-core-dependency-injection/
            // and http://derpturkey.com/vnext-dependency-injection-overview/
            var container = new ServiceCollection();

            // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging?tabs=aspnetcore2x#tabpanel_J929VbWwYc_aspnetcore2x
            container.AddLogging(builder =>
            {
                builder.AddDebug();
                builder.AddRest();
                builder.SetMinimumLevel(LogLevel.Trace);
                //builder.AddFilter<DebugLoggerProvider>("Default", LogLevel.Trace);
                //builder.AddFilter("IoTHs.Plugin.AzureIoTHub", LogLevel.Debug);
            });

            container.AddSingleton <IPluginRegistry, PluginRegistry>();

            container.AddSingleton <IMessageQueue>(new MessageQueue());
            container.AddSingleton <ChannelValueCache>();
            container.AddSingleton <DeviceConfigurationProvider>();
            container.AddTransient <CoreApp>();
            container.AddSingleton <FunctionsEngine>();
            container.AddSingleton <IApiAuthenticationService, ApiAuthenticationService>();

            container.AddSingleton <IAzureIoTHubPlugin, AzureIoTHubPlugin>();
#if ABUS
            container.AddTransient <SecVestPlugin>();
#endif
            container.AddTransient <EtaTouchPlugin>();
#if TWILIO
            container.AddTransient <TwilioPlugin>();
#endif
            container.AddTransient <HomeMaticPlugin>();
#if MQTTBROKER
            container.AddTransient <MqttBrokerPlugin>();
#endif

            // container available globally
            var locator = container.BuildServiceProvider();
            ServiceLocator.SetLocatorProvider(() => locator);

            // init device registry and add devices
            _pluginRegistry = locator.GetService <IPluginRegistry>();
            _pluginRegistry.RegisterPluginType <IAzureIoTHubPlugin>();
#if ABUS
            _pluginRegistry.RegisterPluginType <SecVestPlugin>();
#endif
            _pluginRegistry.RegisterPluginType <EtaTouchPlugin>();
#if TWILIO
            _pluginRegistry.RegisterPluginType <TwilioPlugin>();
#endif
            _pluginRegistry.RegisterPluginType <HomeMaticPlugin>();
#if MQTTBROKER
            _pluginRegistry.RegisterPluginType <MqttBrokerPlugin>();
#endif

            _log = locator.GetService <ILoggerFactory>().CreateLogger <StartupTask>();
            _log.LogInformation("Starting");
            // send package version to iot hub for tracking device software version
            var package   = Windows.ApplicationModel.Package.Current;
            var packageId = package.Id;
            var version   = packageId.Version;
            _log.LogInformation("Package version: " + version.Major + "." + version.Minor + "." + version.Build);

            _log.LogTrace("Launching CoreApp");
            _log.LogTrace("Local data folder: " + Windows.Storage.ApplicationData.Current.LocalFolder.Path);

            try
            {
                _coreApp = locator.GetService <CoreApp>();
                await _coreApp.RunAsync();
            }
            catch (Exception ex)
            {
                _log.LogError(ex, "CoreApp Run crashed");
                throw;
            }

            // The message Loop Worker runs in the background and checks for specific messages
            // which tell the CoreApp to either reboot the device or exit the app, which should
            // restart of the app
            _log.LogTrace("Launching MessageLoopWorker");
            MessageLoopWorker();

            // Dont release deferral, otherwise app will stop
        }
コード例 #13
0
 public static IEnumerable <ParsedRecord> ResolveAliases(this IEnumerable <ParsedRecord> parsedRecords,
                                                         IPluginRegistry registry)
 {
     return(parsedRecords.Select(rd => rd.ResolveAliases(registry)));
 }