private void OnSelectActivitiesTypesMessage(SelectActivitiesTypesMessage selectActivitiesTypesMessage) { var addDlg = new AddActivitiesWindow(selectActivitiesTypesMessage.AvailableActivitiesTypes) { Owner = this }; selectActivitiesTypesMessage.Execute(addDlg.ShowDialog().GetValueOrDefault() ? new SelectActivitiesTypesResult(addDlg.SelectedActivitiesTypes) : SelectActivitiesTypesResult.DoNothing); }
public void AddReference() { var worker = new BackgroundWorker { WorkerReportsProgress = true }; worker.ProgressChanged += (sender, args) => StatusViewModel.SetProgressValue(args.ProgressPercentage, 100); worker.DoWork += (sender, args) => { StatusViewModel.SetProgressText("Searching activities on references directories"); var directories = Settings.Default.ReferencesPaths; var actitiesTypes = new List<Type>(); if (directories != null) { for (var i = 0; i < directories.Count; i++) { worker.ReportProgress(i * 100 / directories.Count); var directory = directories[i]; var fileNames = Directory.GetFiles(directory, "*.dll", SearchOption.TopDirectoryOnly); foreach (var fileName in fileNames) { try { var assembly = Assembly.LoadFile(fileName); actitiesTypes.AddRange(assembly.GetExportedTypes().Where(IsValidActivityType)); } catch (BadImageFormatException) { } catch (ReflectionTypeLoadException) { } catch (TypeLoadException) { } } } args.Result = actitiesTypes; } }; worker.RunWorkerCompleted += (o, eventArgs) => { var activitiesTypes = eventArgs.Result as IEnumerable<Type>; var selectMsg = new SelectActivitiesTypesMessage( activitiesTypes, this, null, result => { if (result.PerformAdd) { foreach (var activityType in result.SelectedActivitiesTypes) { AddActivity(activityType); } } }); StatusViewModel.HideProgress(); MessengerInstance.Send(selectMsg); }; worker.RunWorkerAsync(); }
public void AddReference() { var worker = new BackgroundWorker { WorkerReportsProgress = true }; worker.ProgressChanged += (sender, args) => StatusViewModel.SetProgressValue(args.ProgressPercentage, 100); worker.DoWork += (sender, args) => { StatusViewModel.SetProgressText("Searching activities on references directories"); var directories = Settings.Default.ReferencesPaths; var actitiesTypes = new List <Type>(); if (directories != null) { for (var i = 0; i < directories.Count; i++) { worker.ReportProgress(i * 100 / directories.Count); var directory = directories[i]; var fileNames = Directory.GetFiles(directory, "*.dll", SearchOption.TopDirectoryOnly); foreach (var fileName in fileNames) { try { var assembly = Assembly.LoadFile(fileName); actitiesTypes.AddRange(assembly.GetExportedTypes().Where(IsValidActivityType)); } catch (BadImageFormatException) { } catch (ReflectionTypeLoadException) { } catch (TypeLoadException) { } } } args.Result = actitiesTypes; } }; worker.RunWorkerCompleted += (o, eventArgs) => { var activitiesTypes = eventArgs.Result as IEnumerable <Type>; var selectMsg = new SelectActivitiesTypesMessage( activitiesTypes, this, null, result => { if (result.PerformAdd) { foreach (var activityType in result.SelectedActivitiesTypes) { AddActivity(activityType); } } }); StatusViewModel.HideProgress(); MessengerInstance.Send(selectMsg); }; worker.RunWorkerAsync(); }