/// <summary>Constructs the see <see cref="WpfUITimer"/>.</summary>
		/// 
		/// <param name="interval">The interval for the timer.</param>
		/// <param name="normalPriority">True if the timer runs at normal priority.</param>
		/// <param name="callback">The callback on the timer tick event.</param>
		/// <param name="start">True if the timer should start running.</param>
		public WpfUITimer(TimeSpan interval, bool normalPriority, Action callback, bool start) {
			this.callback = callback ?? throw new ArgumentNullException(nameof(callback));
			handlerCallback = (o, s) => callback();
			dispatcherTimer = new DispatcherTimer(
				interval,
				WpfUIService.GetPriority(normalPriority),
				handlerCallback,
				Application.Current.Dispatcher);
			if (!start)
				dispatcherTimer.Stop();
		}
示例#2
0
        public async ValueTask Run(ILifetimeScope scope)
        {
            foreach (var type in LoadedTypes)
            {
                LoadedTypeDescriptors.Add(type, type.GetCustomAttribute <EmberPluginAttribute>().ToString());
            }
            if (WpfUIService != null)
            {
                Logger.LogInformation($"Preparing UI service...");
                foreach (var(type, pluginDesciptor) in LoadedTypeDescriptors)
                {
                    if (scope.TryResolveNamed(pluginDesciptor, type, out var instnace) && instnace is ICoreWpfPlugin plugin)
                    {
                        WpfUIService.RegisterWpfPlugin(plugin);
                    }
                }
                Logger.LogInformation($"Starting UI Application...");
                await WpfUIService.StartWpfUIService();

                Logger.LogInformation($"Wpf UI Application started.");
            }

            foreach (var(type, pluginDesciptor) in LoadedTypeDescriptors)
            {
                Logger.LogInformation($"Preparing plugin {pluginDesciptor}...");
                try
                {
                    Logger.LogInformation($"Resolving plugin {pluginDesciptor}...");
                    if (scope.TryResolveNamed(pluginDesciptor, type, out var instnace) && instnace is IPlugin plugin)
                    {
                        await Load(plugin);

                        Logger.LogInformation($"Loaded plugin {pluginDesciptor}");
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError(e, $"Error while load {pluginDesciptor}");
                }
            }
            await InitializeAllPlugins();
        }