private void DisposeJobs(IEnumerable <string> jobsToDispose, bool isDueToSettingsChange) { AssertNotDisposed(); foreach (IJob job in _jobs.Where(item => jobsToDispose.Contains(ExportedTypeLibrary.GetExportAlias(item.GetType()))).ToList()) { if (isDueToSettingsChange) { Logger.Instance.LogFormat(LogType.Trace, this, Resources.SettingsJobDisabled, job.GetType().Name); } try { job.Dispose(); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Warning, this, Resources.JobManagerDisposeJobFailed, job.GetType().Name); Logger.Instance.LogException(this, ex); } finally { _jobs.Remove(job); } } }
internal IEnumerable <ILayoutPanelElement> GetInitializedViews() { IEnumerable <string> enabledWidgets = GetEnabledWidgets(); foreach (ExportedType export in ExportedTypeLibrary.GetExports(typeof(IUIWidget)).Where(j => enabledWidgets.Contains(j.Attribute.Alias))) { IUIWidget widget = export.CreateInstance <IUIWidget>(); string widgetName = widget.GetType().Name; Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.BeginInitialization, widgetName); try { if (!widget.Initialize()) { Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.InitializationFailure, widgetName); continue; } LayoutAnchorablePane pane = CreatePaneFromWidget(widget); _panelElements.Add(pane); Widgets.Add(widget); Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.InitializationSuccess, widgetName); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.InitializationError, widgetName); Logger.Instance.LogException(this, ex); } } return(_panelElements); }
private void InitializeSettings() { _faxPath = new DirectoryInfo(_configuration.FaxPath); _archivePath = new DirectoryInfo(_configuration.ArchivePath); _analysisPath = new DirectoryInfo(_configuration.AnalysisPath); string ocrPath = null; if (_configuration.OCRSoftware == OcrSoftware.Tesseract) { if (string.IsNullOrWhiteSpace(_configuration.OCRSoftwarePath)) { ocrPath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\tesseract"; } } else { if (string.IsNullOrWhiteSpace(_configuration.OCRSoftwarePath)) { ocrPath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\cuneiform"; } } _ocrPath = new DirectoryInfo(ocrPath); if (!_ocrPath.Exists) { throw new DirectoryNotFoundException(string.Format("The OCR software '{0}' was suggested to be found in path '{1}', which doesn't exist!", _configuration.OCRSoftware, _ocrPath.FullName)); } // Import parser with the given name/alias _parser = ExportedTypeLibrary.Import <IParser>(_configuration.AlarmFaxParserAlias); Logger.Instance.LogFormat(LogType.Info, this, "Using parser '{0}'.", _parser.GetType().FullName); }
/// <summary> /// Prevents a default instance of the <see cref="AddressBook"/> class from being created. /// </summary> private AddressBook() { _entries = new List <AddressBookEntry>(); _addressProviders = new List <IAddressProvider>(); _addressProviders.AddRange(ExportedTypeLibrary.ImportAll <IAddressProvider>()); }
private void InitializeJobs() { foreach (var export in ExportedTypeLibrary.GetExports(typeof(IUIJob)).Where(j => App.GetApp().Configuration.EnabledJobs.Contains(j.Attribute.Alias))) { IUIJob job = export.CreateInstance <IUIJob>(); string jobName = job.GetType().Name; Logger.Instance.LogFormat(LogType.Info, this, "Initializing UI-job type '{0}'...", jobName); try { if (!job.Initialize()) { Logger.Instance.LogFormat(LogType.Warning, this, "UI-Job type '{0}' initialization failed. The UI-job will not be executed.", jobName); continue; } _uiJobs.Add(job); Logger.Instance.LogFormat(LogType.Info, this, "UI-Job type '{0}' initialization successful.", jobName); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Error, this, "An error occurred while initializing UI-job type '{0}'. The error message was: {1}", jobName, ex.Message); } } }
private void InitializeOcrSoftware() { AssertCustomOcrPathExist(); _ocrSoftware = ExportedTypeLibrary.Import <IOcrSoftware>(_configuration.OCRSoftware); Logger.Instance.LogFormat(LogType.Info, this, Properties.Resources.InitializeUsingOcrSoftware, _configuration.OCRSoftware); }
void IAlarmSource.Initialize(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _configuration = new MailConfiguration(serviceProvider); _mailParser = ExportedTypeLibrary.Import <IParser>(_configuration.ParserAlias); }
static CustomDataEditorCache() { TypeEditors = new List <Type>(); foreach (var export in ExportedTypeLibrary.GetExports(typeof(ICustomDataEditor))) { TypeEditors.Add(export.Type); } }
bool IJob.Initialize(IServiceProvider serviceProvider) { _settings = serviceProvider.GetService <ISettingsServiceInternal>(); _addressing = serviceProvider.GetService <IAddressingServiceInternal>(); _provider = ExportedTypeLibrary.Import <ISmsProvider>(_settings.GetSetting(SettingKeys.Provider).GetValue <string>()); return(true); }
bool IJob.Initialize(IServiceProvider serviceProvider) { _settings = serviceProvider.GetService <ISettingsServiceInternal>(); _addressing = serviceProvider.GetService <IAddressingServiceInternal>(); _userName = _settings.GetSetting("SMSJob", "UserName").GetValue <string>(); _password = _settings.GetSetting("SMSJob", "Password").GetValue <string>(); _provider = ExportedTypeLibrary.Import <ISmsProvider>(_settings.GetSetting("SMSJob", "Provider").GetValue <string>()); return(true); }
static void Main(string[] args) { Console.WriteLine("".PadRight(16, '*')); Console.WriteLine($"{Environment.NewLine}This tool is only for test purpose!{Environment.NewLine}It generates a 'test operation' and uses the the default printer for printing the template located under 'Resources\\OperationPrintTemplate_NonStatic.htm'{Environment.NewLine}{Environment.NewLine}"); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($" --> Press 'enter' to continue. <-- {Environment.NewLine}"); Console.ResetColor(); Console.WriteLine("".PadRight(16, '*')); ConsoleKeyInfo key = Console.ReadKey(false); if (key.Key != ConsoleKey.Enter) { return; } Console.WriteLine($"Please be patient...{Environment.NewLine}Job is getting executed! It can take a few seconds until something happens."); IJob job = ExportedTypeLibrary.GetExports(typeof(IJob)).SingleOrDefault(x => x.Attribute.Alias == "OperationPrinterJob").CreateInstance <IJob>(); job.Initialize(new FakeSettingsService()); FakeContext c = new FakeContext { Phase = JobPhase.AfterOperationStored }; job.Execute(c, new Operation { Comment = "Testeinsatz für die Feuerwehr Musterstadt", Picture = "Brand Einfamilienhaus", Einsatzort = new PropertyLocation { Street = "Karlstraße", StreetNumber = "5", City = "München", ZipCode = "80335", GeoLatitude = 48.142792, GeoLongitude = 11.567208 }, Messenger = "Donald Duck", OperationNumber = "B 1.0 123456 1234", Timestamp = DateTime.Now, TimestampIncome = DateTime.Now, OperationPlan = "Plan 42", Priority = "Prio 1", Resources = { new OperationResource { FullName = "Entenhausen 11/1" }, new OperationResource { FullName = "Musterstadt 40/1", RequestedEquipment = { "Geräteträger" }, Timestamp = DateTime.Now.ToString("HH:mm:ss") } }, Keywords = new OperationKeywords { B = "B3", Keyword = "Brand Wohnhaus", EmergencyKeyword = "Brand Person in Gefahr" } }); Thread.Sleep(1000); }
bool IJob.Initialize(IServiceProvider serviceProvider) { _settings = serviceProvider.GetService <ISettingsServiceInternal>(); _provider = ExportedTypeLibrary.Import <IGeoCoder>(_settings.GetSetting("Geocoding", "Provider").GetValue <string>()); if (_provider.ApiKeyRequired) { string apikey = _settings.GetSetting("Geocoding", "ApiKey").GetValue <string>(); _provider.ApiKey = apikey; } return(true); }
private void InitializeAlarmSources() { foreach (var export in ExportedTypeLibrary.GetExports(typeof(IAlarmSource)).Where(j => _configuration.EnabledAlarmSources.Contains(j.Attribute.Alias))) { Logger.Instance.LogFormat(LogType.Info, this, Resources.AlarmSourceEnabling, export.Type.Name); IAlarmSource alarmSource = export.CreateInstance <IAlarmSource>(); _alarmSources.Add(alarmSource); Logger.Instance.LogFormat(LogType.Info, this, Resources.AlarmSourceEnabled, export.Type.Name); } }
private void InitializeAndAddJobs(IEnumerable <string> jobsToInitialize) { AssertNotDisposed(); foreach (var export in ExportedTypeLibrary.GetExports(typeof(IJob)).Where(j => jobsToInitialize.Contains(j.Attribute.Alias))) { IJob job = export.CreateInstance <IJob>(); if (InitializeJob(job)) { _jobs.Add(job); } } }
void IAlarmSource.Initialize(IServiceProvider serviceProvider) { _settings = serviceProvider.GetService <ISettingsServiceInternal>(); string smsParserAlias = _settings.GetSetting(SmsSettingKeys.SmsParser).GetValue <string>(); _parser = ExportedTypeLibrary.Import <IParser>(smsParserAlias); if (_parser == null) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.SmsParserNotFoundError, smsParserAlias); _parser = new DefaultSMSParser(); } }
private void RefreshSpecifiedAddressFiltersSync() { lock (SyncRoot) { _addressFilter = new List <IAddressFilter>(); IList <string> exports = SettingsService.GetSetting(SettingKeys.FiltersConfigurationKey).GetValue <ExportConfiguration>().GetEnabledExports(); foreach (var export in ExportedTypeLibrary.GetExports(typeof(IAddressFilter)).Where(j => exports.Contains(j.Attribute.Alias))) { _addressFilter.Add(export.CreateInstance <IAddressFilter>()); } } }
bool IJob.Initialize(IServiceProvider serviceProvider) { _settings = serviceProvider.GetService <ISettingsServiceInternal>(); _provider = ExportedTypeLibrary.Import <IGeoCoder>(_settings.GetSetting(SettingKeysJob.Provider).GetValue <string>()); if (_provider.IsApiKeyRequired) { _provider.ApiKey = _settings.GetSetting(SettingKeysJob.ApiKey).GetValue <string>(); } return(true); }
private void InitializeJobs() { foreach (var export in ExportedTypeLibrary.GetExports(typeof(IUIJob)).Where(j => App.GetApp().Configuration.EnabledJobs.Contains(j.Attribute.Alias))) { IUIJob job = export.CreateInstance <IUIJob>(); string jobName = job.GetType().Name; Logger.Instance.LogFormat(LogType.Info, this, Resources.JobInitializeBegin, jobName); try { if (!job.Initialize()) { Logger.Instance.LogFormat(LogType.Warning, this, Resources.JobInitializeError, jobName); continue; } _uiJobs.Add(job); Logger.Instance.LogFormat(LogType.Info, this, Resources.JobInitializeSuccess, jobName); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Error, this, Resources.JobGenericError, jobName, ex.Message); Logger.Instance.LogException(this, ex); } } foreach (var export in ExportedTypeLibrary.GetExports(typeof(IIdleUIJob)).Where(j => App.GetApp().Configuration.EnabledIdleJobs.Contains(j.Attribute.Alias))) { IIdleUIJob job = export.CreateInstance <IIdleUIJob>(); string jobName = job.GetType().Name; Logger.Instance.LogFormat(LogType.Info, this, Resources.JobInitializeBegin, jobName); try { if (!job.Initialize()) { Logger.Instance.LogFormat(LogType.Warning, this, Resources.JobInitializeError, jobName); continue; } _idleUiJobs.Add(job); Logger.Instance.LogFormat(LogType.Info, this, Resources.JobInitializeSuccess, jobName); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Error, this, Resources.JobGenericError, jobName, ex.Message); Logger.Instance.LogException(this, ex); } } }
void IAlarmSource.Initialize(IServiceProvider serviceProvider) { _configuration = new FaxConfiguration(serviceProvider); _faxPath = new DirectoryInfo(_configuration.FaxPath); _archivePath = new DirectoryInfo(_configuration.ArchivePath); _analysisPath = new DirectoryInfo(_configuration.AnalysisPath); InitializeOcrSoftware(); // Import parser with the given name/alias _parser = ExportedTypeLibrary.Import <IParser>(_configuration.AlarmFaxParserAlias); Logger.Instance.LogFormat(LogType.Info, this, "Using parser '{0}'.", _parser.GetType().FullName); }
private void InitializeOperationViewer() { string operationViewerAlias = App.GetApp().Configuration.OperationViewer; _operationViewer = ExportedTypeLibrary.Import <IOperationViewer>(operationViewerAlias); if (_operationViewer == null) { Logger.Instance.LogFormat(LogType.Warning, this, Resources.DesiredOperationViewerNotFound, operationViewerAlias); _operationViewer = new Views.DummyOperationViewer(); } _busyTemplate = new Lazy <FrameworkElement>(() => _operationViewer.Visual); }
void ITypeEditor.Initialize(string editorParameter) { if (!string.IsNullOrWhiteSpace(editorParameter)) { Type type = Type.GetType(editorParameter); if (type != null) { var exports = ExportedTypeLibrary.GetExports(type).Select(e => GetEntryViewModel(e)).OrderBy(e => e.DisplayName); _viewModel.Exports.AddRange(exports); return; } } throw new InvalidOperationException(string.Format(Properties.Resources.ExportEditorsTypeRequired, editorParameter)); }
private void InitializeOperationViewer() { string operationViewerAlias = App.GetApp().Configuration.OperationViewer; _operationViewer = ExportedTypeLibrary.Import <IOperationViewer>(operationViewerAlias); // If there is no operation viewer defined or it could not be found, use the default one and log it if (_operationViewer == null) { Logger.Instance.LogFormat(LogType.Warning, this, "Could not find operation viewer with alias '{0}'. Using the default one. Please check the configuration file!", operationViewerAlias); _operationViewer = new Views.DefaultOperationView(); } _controlTemplate = new Lazy <FrameworkElement>(() => { return(_operationViewer.Visual); }); }
private void InitializeOperationViewer() { string operationViewerAlias = App.GetApp().Configuration.OperationViewer; _operationViewer = ExportedTypeLibrary.Import <IOperationViewer>(operationViewerAlias); // If there is no operation viewer defined or it could not be found, use the default one and log it if (_operationViewer == null) { Logger.Instance.LogFormat(LogType.Warning, this, Resources.DesiredOperationViewerNotFound, operationViewerAlias); _operationViewer = new Views.DummyOperationViewer(); } _busyTemplate = new Lazy <FrameworkElement>(() => { return(_operationViewer.Visual); }); }
static TypeEditorCache() { TypeEditors = new Dictionary <string, Type>(); TypeEditors[""] = typeof(TypeEditors.DefaultTypeEditor); foreach (ExportedType export in ExportedTypeLibrary.GetExports(typeof(ITypeEditor))) { RegisterTypeEditor(export.Attribute.Alias, export.Type); foreach (ConfigurationTypeEditorAttribute attribute in export.Type.GetCustomAttributes(typeof(ConfigurationTypeEditorAttribute), false)) { RegisterTypeEditor(attribute.SourceType.FullName, export.Type); } } // TODO: Better editors! // TODO: 'SimpleXmlTextEditor' still needed? RegisterTypeEditor("SimpleXmlTextEditor", typeof(TypeEditors.StringArrayTypeEditor)); }
private void InitializeProvider() { var providerName = _settings.GetSetting(SettingKeysJob.Provider).GetValue <string>(); _provider = ExportedTypeLibrary.Import <IGeoCoder>(providerName); Logger.Instance.LogFormat(LogType.Debug, this, Properties.Resources.UsingProviderTrace, providerName); if (_provider.IsApiKeyRequired) { _provider.ApiKey = _settings.GetSetting(SettingKeysJob.ApiKey).GetValue <string>(); if (string.IsNullOrEmpty(_provider.ApiKey)) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.NoKeyForGeocodingService, providerName); } } }
static TypeEditorCache() { TypeEditors = new Dictionary <string, Type>(); TypeEditors[""] = typeof(TypeEditors.DefaultTypeEditor); foreach (var export in ExportedTypeLibrary.GetExports(typeof(ITypeEditor))) { // 1. Use alias. TypeEditors[export.Attribute.Alias] = export.Type; // 2. Use attribute if available. ConfigurationTypeEditorAttribute attribute = (ConfigurationTypeEditorAttribute)export.Type.GetCustomAttributes(typeof(ConfigurationTypeEditorAttribute), false).FirstOrDefault(); if (attribute != null) { TypeEditors[attribute.SourceType.FullName] = export.Type; } } // TODO: Better editors! TypeEditors["SimpleXmlTextEditor"] = typeof(TypeEditors.StringArrayTypeEditor); }
void ITypeEditor.Initialize(string editorParameter) { if (string.IsNullOrWhiteSpace(editorParameter)) { return; } // Find out the type - if the type could not be found, make the combobox editable Type type = Type.GetType(editorParameter); if (type == null) { cboExport.IsEditable = true; return; } // Otherwise list all exports foreach (ExportedType export in ExportedTypeLibrary.GetExports(type).OrderBy(et => et.Attribute.Alias)) { cboExport.Items.Add(export.Attribute.Alias); } }
internal List <ILayoutPanelElement> InitializeViews() { ReadOnlyCollection <string> enabledWidgets = GetEnabledWidgets(); foreach (ExportedType export in ExportedTypeLibrary.GetExports(typeof(IUIWidget)).Where(j => enabledWidgets.Contains(j.Attribute.Alias))) { var iuiWidget = export.CreateInstance <IUIWidget>(); string iuiWidgetName = iuiWidget.GetType().Name; Logger.Instance.LogFormat(LogType.Info, this, Properties.Resources.Init, iuiWidgetName); try { if (!iuiWidget.Initialize()) { Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.InitFailed, iuiWidgetName); continue; } var pane = new LayoutAnchorablePane(new LayoutAnchorable { Content = iuiWidget.UIElement, ContentId = iuiWidget.ContentGuid, Title = iuiWidget.Title, CanClose = false, CanHide = false }); _panelElements.Add(pane); _widgets.Add(iuiWidget); Logger.Instance.LogFormat(LogType.Info, this, Properties.Resources.InitSuccessful, iuiWidgetName); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.InitError, iuiWidgetName, ex.Message); } } return(_panelElements); }
bool IJob.Initialize() { // Get export configuration ExportConfiguration exports = SettingsManager.Instance.GetSetting("GrowlJob", "GrowlSender").GetValue <ExportConfiguration>(); // Add each export to the list, if initialization succeeded foreach (string exportAlias in exports.GetEnabledExports()) { try { IGrowlSender growlSender = ExportedTypeLibrary.Import <IGrowlSender>(exportAlias); // This one has passed! _growlSender.Add(growlSender); Logger.Instance.LogFormat(LogType.Info, this, "Added growl sender '{0}'.", exportAlias); } catch { Logger.Instance.LogFormat(LogType.Warning, this, "An error occurred while initialization plug-in '{0}'. Ignoring plug-in.", exportAlias); } } return(true); }
private void InitializeParser() { _parser = ExportedTypeLibrary.Import <IParser>(_configuration.AlarmFaxParserAlias); Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.UsingParserTrace, _parser.GetType().FullName); }