public MainWindowViewModel() { ToolboxViewModel = new ToolboxViewModel(); ErrorsListViewModel = new ErrorsListViewModel(); PropertyInspectorViewModel = new PropertyInspectorViewModel(); DebugViewModel = new DebugViewModel(); OutputViewModel = new OutputViewModel(); WorkflowOutlineViewModel = new WorkflowOutlineViewModel(); StatusViewModel.SetText("Ready"); syncCtx = SynchronizationContext.Current; ToolboxViewModel.IsVisible = true; PropertyInspectorViewModel.IsVisible = true; OutputViewModel.IsVisible = true; ErrorsListViewModel.IsVisible = true; DebugViewModel.IsVisible = true; WorkflowOutlineViewModel.IsVisible = true; MessengerInstance.Register <RequestCloseProgramMessage>(this, OnRequestCloseProgramMessage); }
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(); }