// This supports loading objects instead of xaml into the designer public void Load(object instance) { if (isLoaded) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WorkflowDesignerLoadShouldBeCalledOnlyOnce)); } isLoaded = true; if (instance == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("instance")); } DesignerConfigurationService configurationService = this.context.Services.GetService <DesignerConfigurationService>(); configurationService.ApplyDefaultPreference(); // Because we want AutoConnect/AutoSplit to be on even in Dev10 if PU1 is installed. // But we cannot know whether PU1 is installed or not, we decide to enable these 2 features for all Dev10. if (configurationService.WorkflowDesignerHostId == WorkflowDesignerHostId.Dev10) { configurationService.AutoConnectEnabled = true; configurationService.AutoSplitEnabled = true; } configurationService.IsWorkflowLoaded = true; configurationService.Validate(); if (this.PreviewLoad != null) { this.PreviewLoad(this, new PreviewLoadEventArgs(instance, this.context)); } if (configurationService.TargetFrameworkName.IsLessThan45()) { TargetFrameworkPropertyFilter.FilterOut45Properties(); } modelTreeManager = new ModelTreeManager(this.context); modelTreeManager.Load(instance); this.context.Services.Publish(typeof(ModelTreeManager), modelTreeManager); viewManager = GetViewManager(this.modelTreeManager.Root); this.context.Services.Publish <ModelSearchService>(this.ModelSearchService); view.Children.Add((UIElement)viewManager.View); modelTreeManager.EditingScopeCompleted += new EventHandler <EditingScopeEventArgs>(OnEditingScopeCompleted); this.view.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => { this.perfEventProvider.WorkflowDesignerApplicationIdleAfterLoad(); })); //Subscribe to the ViewStateChanged event of ViewStateService to show document dirty. It would be published in the call to GetViewManager(). WorkflowViewStateService wfViewStateService = this.Context.Services.GetService(typeof(ViewStateService)) as WorkflowViewStateService; if (wfViewStateService != null) { wfViewStateService.UndoableViewStateChanged += new ViewStateChangedEventHandler(OnViewStateChanged); } this.isModelChanged = false; }
private static List <object> GetFromClipboard(out List <object> metaData, EditingContext editingContext) { Fx.Assert(editingContext != null, "editingContext should not be null"); MultiTargetingSupportService multiTargetingService = editingContext.Services.GetService <IMultiTargetingSupportService>() as MultiTargetingSupportService; DesignerConfigurationService config = editingContext.Services.GetService <DesignerConfigurationService>(); DataObject dataObject = RetriableClipboard.GetDataObject() as DataObject; List <object> workflowData = null; metaData = null; if (dataObject != null) { if (dataObject.GetDataPresent(WorkflowClipboardFormat)) { bool isCopyingFromHigherFrameworkToLowerFramework = false; if (multiTargetingService != null && config != null) { isCopyingFromHigherFrameworkToLowerFramework = GetTargetFrameworkFromClipboard(dataObject).Version > config.TargetFrameworkName.Version; } string clipBoardString = (string)TryGetData(dataObject, WorkflowClipboardFormat); using (StringReader stringReader = new StringReader(clipBoardString)) { try { XamlSchemaContext schemaContext; if (isCopyingFromHigherFrameworkToLowerFramework) { schemaContext = new MultiTargetingXamlSchemaContext(multiTargetingService); } else { schemaContext = new XamlSchemaContext(); } using (XamlXmlReader xamlXmlReader = new XamlXmlReader(stringReader, schemaContext)) { ClipboardData clipboardData = (ClipboardData)XamlServices.Load(xamlXmlReader); metaData = clipboardData.Metadata; workflowData = clipboardData.Data; } } catch (Exception e) { Trace.WriteLine(e.Message); } } } else if (dataObject.GetDataPresent(WorkflowCallbackClipboardFormat)) { ClipboardData localData = (ClipboardData)TryGetData(dataObject, WorkflowCallbackClipboardFormat); metaData = null; workflowData = localData.Data; workflowData.Add(CutCopyPasteHelper.workflowCallbackContext); } } return(workflowData); }
public void Load(string fileName) { if (string.IsNullOrEmpty(fileName)) { throw FxTrace.Exception.AsError(new ArgumentNullException("fileName")); } DesignerConfigurationService service = this.Context.Services.GetService <DesignerConfigurationService>(); service.SetDefaultOfLoadingFromUntrustedSourceEnabled(); if (!service.LoadingFromUntrustedSourceEnabled && !IsFromUnrestrictedPath(fileName)) { throw FxTrace.Exception.AsError(new SecurityException(string.Format(CultureInfo.CurrentUICulture, SR.UntrustedSourceDetected, fileName))); } try { IDocumentPersistenceService documentPersistenceService = this.Context.Services.GetService <IDocumentPersistenceService>(); if (documentPersistenceService != null) { this.Load(documentPersistenceService.Load(fileName)); } else { using (StreamReader fileStream = new StreamReader(fileName)) { this.loadedFile = fileName; WorkflowFileItem fileItem = new WorkflowFileItem(); fileItem.LoadedFile = fileName; this.context.Items.SetValue(fileItem); this.Text = fileStream.ReadToEnd(); this.Load(); } } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } else { this.Context.Items.SetValue(new ErrorItem() { Message = e.Message, Details = e.ToString() }); } } if (!this.IsInErrorState()) { this.lastWorkflowSymbol = GetAttachedWorkflowSymbol(); if (this.debuggerService != null) { this.debuggerService.InvalidateSourceLocationMapping(fileName); } } }
public static bool IsBackgroundValidationEnabled(EditingContext editingContext) { Fx.Assert(editingContext != null, "editingContext should not be null"); DesignerConfigurationService config = editingContext.Services.GetService <DesignerConfigurationService>(); if (config != null) { return(config.BackgroundValidationEnabled); } return(false); }
static internal FrameworkName GetTargetFramework(EditingContext context) { if (context != null) { DesignerConfigurationService designerConfigurationService = context.Services.GetService <DesignerConfigurationService>(); if (designerConfigurationService != null) { return(designerConfigurationService.TargetFrameworkName); } } return(DesignerConfigurationService.DefaultTargetFrameworkName); }
static public void PreviewLoadRoot(object sender, WorkflowDesigner.PreviewLoadEventArgs args) { object root = args.Instance; DesignerConfigurationService configService = args.Context.Services.GetService <DesignerConfigurationService>(); if (configService != null && configService.NamespaceConversionEnabled) { ConvertNamespaces(root, args.Context); } if (root.GetType() == WorkflowServiceType) { args.Context.Services.Subscribe <ModelTreeManager>(manager => manager.Root.PropertyChanged += new PropertyChangedEventHandler(OnRootPropertyChanged)); } TypeDescriptor.AddProvider(new RootModelTypeDescriptionProvider(root), root); }
public WorkflowDesigner() { // create our perf trace provider first this.perfEventProvider = new DesignerPerfEventProvider(); this.idManager = new ViewStateIdManager(); this.context = new EditingContext(); this.ModelSearchService = new ModelSearchServiceImpl(this); this.context.Items.SetValue(new ReadOnlyState { IsReadOnly = false }); this.view = new Grid(); this.view.Focusable = false; //add the resource dictionary to application resource so every component could reference it if (Application.Current == null) { //create an application if it doesn't exist, make sure it will not shutdown after windows being shut down Application app = new Application(); app.ShutdownMode = ShutdownMode.OnExplicitShutdown; } Fx.Assert(Application.Current != null, "Application and resources must be there"); Application.Current.Resources.MergedDictionaries.Add(WorkflowDesignerColors.FontAndColorResources); Application.Current.Resources.MergedDictionaries.Add(WorkflowDesignerIcons.IconResourceDictionary); AttachedPropertiesService propertiesService = new AttachedPropertiesService(); this.context.Services.Publish(typeof(AttachedPropertiesService), propertiesService); undoEngine = new UndoEngine(context); this.context.Services.Publish(typeof(UndoEngine), undoEngine); undoEngine.UndoCompleted += new EventHandler <UndoUnitEventArgs>(OnUndoCompleted); this.context.Services.Publish <ValidationService>(this.ValidationService); this.context.Services.Publish <ObjectReferenceService>(this.ObjectReferenceService); this.context.Services.Publish <DesignerPerfEventProvider>(this.perfEventProvider); this.context.Services.Publish <FeatureManager>(new FeatureManager(this.context)); this.context.Services.Publish <DesignerConfigurationService>(new DesignerConfigurationService()); if (!LocalAppContextSwitches.UseLegacyAccessibilityFeatures) { // Keeps track of a dictionary of session objects on current Workflow Designer. // The initial purpose is to pass the focused VisualBasicEditor from NetFx to VS. this.context.Services.Publish <Dictionary <string, object> >(new Dictionary <string, object>()); } this.context.Services.Subscribe <ICommandService>((s) => { const string addinTypeName = "Microsoft.VisualStudio.Activities.AddIn.WorkflowDesignerAddIn"; if (s != null && s.GetType().FullName.Equals(addinTypeName)) { DesignerConfigurationService service = this.context.Services.GetService <DesignerConfigurationService>(); if (service != null) { service.WorkflowDesignerHostId = WorkflowDesignerHostId.Dev10; } } }); this.context.Services.Subscribe <IVSSqmService>((service) => { const string serviceTypeName = "Microsoft.VisualStudio.Activities.AddIn.VSSqmService"; if (service != null && service.GetType().FullName.Equals(serviceTypeName)) { DesignerConfigurationService configurationService = this.context.Services.GetService <DesignerConfigurationService>(); if (configurationService != null) { configurationService.WorkflowDesignerHostId = WorkflowDesignerHostId.Dev11; } } }); this.Context.Items.Subscribe <ErrorItem>(delegate(ErrorItem errorItem) { ErrorView errorView = new ErrorView(); errorView.Message = errorItem.Message; errorView.Details = errorItem.Details; errorView.Context = this.Context; // Clear views this.view.Children.Clear(); this.view.Children.Add(errorView); if (this.outlineView != null) { this.outlineView.Children.Clear(); } } ); this.context.Items.Subscribe <ReadOnlyState>(new SubscribeContextCallback <ReadOnlyState>(OnReadonlyStateChanged)); this.context.Services.Subscribe <IXamlLoadErrorService>(s => this.xamlLoadErrorService = s); this.PreviewLoad += NamespaceSettingsHandler.PreviewLoadRoot; this.view.Loaded += (s, e) => { //when view is loaded, check if user did provide his own WindowHelperService - if not, provide a default one if (!this.context.Services.Contains <WindowHelperService>()) { IntPtr hWND = IntPtr.Zero; Window ownerWindow = Window.GetWindow(this.view); if (null != ownerWindow) { WindowInteropHelper helper = new WindowInteropHelper(ownerWindow); hWND = helper.Handle; } this.Context.Services.Publish <WindowHelperService>(new WindowHelperService(hWND)); } WindowHelperService whs = this.context.Services.GetService <WindowHelperService>(); whs.View = this.view; //check if workflow command extension item is available - if not, provide default one if (!this.context.Items.Contains <WorkflowCommandExtensionItem>()) { WorkflowCommandExtensionItem item = new WorkflowCommandExtensionItem(new DefaultCommandExtensionCallback()); this.context.Items.SetValue(item); } ComponentDispatcher.EnterThreadModal += new EventHandler(ComponentDispatcher_EnterThreadModal); ComponentDispatcher.LeaveThreadModal += new EventHandler(ComponentDispatcher_LeaveThreadModal); }; this.view.Unloaded += (s, e) => { ComponentDispatcher.EnterThreadModal -= new EventHandler(ComponentDispatcher_EnterThreadModal); ComponentDispatcher.LeaveThreadModal -= new EventHandler(ComponentDispatcher_LeaveThreadModal); }; this.view.IsKeyboardFocusWithinChanged += (s, e) => { // The ModelTreeManager is null when there is an active ErrorItem. // We have nothing to write to text in this case. if (this.modelTreeManager != null && (bool)e.NewValue == false) { if ((FocusManager.GetFocusedElement(this.view) as TextBox) != null) { FocusManager.SetFocusedElement(this.view, null); this.NotifyModelChanged(); } } }; }