public override void SetValue(object component, object value)
        {
            Activity activity = component as Activity;

            if (activity != null)
            {
                ISite site = PropertyDescriptorUtils.GetSite(ServiceProvider, component);
                if (site == null)
                {
                    throw new Exception(SR.GetString(SR.General_MissingService, typeof(ISite).FullName));
                }

                IIdentifierCreationService identifierCreationService = site.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService;
                if (identifierCreationService == null)
                {
                    throw new Exception(SR.GetString(SR.General_MissingService, typeof(IIdentifierCreationService).FullName));
                }

                string newID = value as string;
                identifierCreationService.ValidateIdentifier(activity, newID);

                DesignerHelpers.UpdateSiteName(activity, newID);
                base.SetValue(component, value);
            }
        }
        internal static object EditValue(ITypeDescriptorContext context)
        {
            object obj2 = null;

            if (((context != null) && (context.PropertyDescriptor != null)) && (context.Instance != null))
            {
                BindUITypeEditor editor = new BindUITypeEditor();
                obj2 = context.PropertyDescriptor.GetValue(context.Instance);
                obj2 = editor.EditValue(context, context, obj2);
                try
                {
                    context.PropertyDescriptor.SetValue(context.Instance, obj2);
                }
                catch (Exception exception)
                {
                    string message = SR.GetString("Error_CanNotBindProperty", new object[] { context.PropertyDescriptor.Name });
                    if (!string.IsNullOrEmpty(exception.Message))
                    {
                        message = message + "\n\n" + exception.Message;
                    }
                    DesignerHelpers.ShowError(context, message);
                }
            }
            return(obj2);
        }
 private void OnMenuPrint(object sender, EventArgs e)
 {
     if (PrinterSettings.InstalledPrinters.Count < 1)
     {
         DesignerHelpers.ShowError(this.serviceProvider, DR.GetString("ThereIsNoPrinterInstalledErrorMessage", new object[0]));
     }
     else
     {
         PrintDocument printDocument = this.workflowView.PrintDocument;
         PrintDialog   dialog        = new PrintDialog {
             AllowPrintToFile = false,
             Document         = printDocument
         };
         try
         {
             if (DialogResult.OK == dialog.ShowDialog())
             {
                 PrinterSettings printerSettings     = printDocument.PrinterSettings;
                 PageSettings    defaultPageSettings = printDocument.DefaultPageSettings;
                 printDocument.PrinterSettings     = dialog.PrinterSettings;
                 printDocument.DefaultPageSettings = dialog.Document.DefaultPageSettings;
                 printDocument.Print();
                 printDocument.PrinterSettings     = printerSettings;
                 printDocument.DefaultPageSettings = defaultPageSettings;
             }
         }
         catch (Exception exception)
         {
             string message = DR.GetString("SelectedPrinterIsInvalidErrorMessage", new object[0]) + "\n" + exception.Message;
             DesignerHelpers.ShowError(this.serviceProvider, message);
         }
     }
 }
        private void OnStatusDelete(object sender, EventArgs e)
        {
            MenuCommand command = (MenuCommand)sender;

            command.Enabled = false;
            IDesignerHost service = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if (((service == null) || (service.RootComponent == null)) || !this.selectionService.GetComponentSelected(service.RootComponent))
            {
                ICollection selectedComponents = this.selectionService.GetSelectedComponents();
                if (DesignerHelpers.AreComponentsRemovable(selectedComponents))
                {
                    foreach (DictionaryEntry entry in Helpers.PairUpCommonParentActivities(Helpers.GetTopLevelActivities(selectedComponents)))
                    {
                        CompositeActivityDesigner designer = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner;
                        if ((designer != null) && !designer.CanRemoveActivities(new List <Activity>((Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity))).AsReadOnly()))
                        {
                            command.Enabled = false;
                            return;
                        }
                    }
                    command.Enabled = true;
                }
            }
        }
示例#5
0
        internal static object EditValue(ITypeDescriptorContext context)
        {
            object value = null;

            if (context != null && context.PropertyDescriptor != null && context.Instance != null)
            {
                BindUITypeEditor bindTypeEditor = new BindUITypeEditor();
                value = context.PropertyDescriptor.GetValue(context.Instance);

                value = bindTypeEditor.EditValue(context, context, value);

                try
                {
                    context.PropertyDescriptor.SetValue(context.Instance, value);
                }
                catch (Exception e)
                {
                    string message = SR.GetString(SR.Error_CanNotBindProperty, context.PropertyDescriptor.Name);
                    if (!String.IsNullOrEmpty(e.Message))
                    {
                        message += "\n\n" + e.Message;
                    }
                    DesignerHelpers.ShowError(context, message);
                }
            }
            return(value);
        }
示例#6
0
        private void InitiateDragDrop()
        {
            WorkflowView      parentView       = ParentView;
            ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService));
            IDesignerHost     designerHost     = (IDesignerHost)GetService(typeof(IDesignerHost));

            if (selectionService == null || designerHost == null)
            {
                return;
            }

            // check if we are cutting root component
            ICollection components = selectionService.GetSelectedComponents();

            if (components == null || components.Count < 1 || selectionService.GetComponentSelected(designerHost.RootComponent) || !Helpers.AreAllActivities(components))
            {
                return;
            }

            DragDropEffects effects = DragDropEffects.None;

            try
            {
                // get component serialization service
                this.existingDraggedActivities.AddRange(Helpers.GetTopLevelActivities(components));

                //IMPORTANT: FOR WITHIN DESIGNER COMPONENT MOVE WE REMOVE THE ACTIVITIES BEFORE WE ADD THEM WHICH IS IN
                //ONDRAGDROP FUNCTION. ALTHOUGH THIS VIOLATES THE DODRAGDROP FUNCTION SIMANTICS, WE NEED TO DO THIS
                //SO THAT WE CAN USE THE SAME IDS FOR THE ACTIVITIES
                DragDropEffects allowedEffects = (DesignerHelpers.AreAssociatedDesignersMovable(this.existingDraggedActivities)) ? DragDropEffects.Move | DragDropEffects.Copy : DragDropEffects.Copy;
                IDataObject     dataObject     = CompositeActivityDesigner.SerializeActivitiesToDataObject(ParentView, this.existingDraggedActivities.ToArray());
                effects = parentView.DoDragDrop(dataObject, allowedEffects);

                //
            }
            catch (Exception e)
            {
                DesignerHelpers.ShowError(ParentView, e.Message);
            }
            finally
            {
                //This means drag drop occurred across designer
                if (effects == DragDropEffects.Move && this.existingDraggedActivities.Count > 0)
                {
                    string transactionDescription = String.Empty;
                    if (this.existingDraggedActivities.Count > 1)
                    {
                        transactionDescription = SR.GetString(SR.MoveMultipleActivities, this.existingDraggedActivities.Count);
                    }
                    else
                    {
                        transactionDescription = SR.GetString(SR.MoveSingleActivity, this.existingDraggedActivities[0].GetType());
                    }

                    CompositeActivityDesigner.RemoveActivities(ParentView, this.existingDraggedActivities.AsReadOnly(), transactionDescription);
                }

                this.existingDraggedActivities.Clear();
            }
        }
示例#7
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider serviceProvider, object value)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            this.serviceProvider = serviceProvider;

            object returnValue = value;

            if (context != null && context.PropertyDescriptor is DynamicPropertyDescriptor)
            {
                try
                {
                    using (ActivityBindForm bindDialog = new ActivityBindForm(this.serviceProvider, context))
                    {
                        if (DialogResult.OK == bindDialog.ShowDialog())
                        {
                            //Now that OK has been pressed in the dialog we need to create members if necessary
                            if (bindDialog.CreateNew)
                            {
                                //Emit the field / property as required
                                if (bindDialog.CreateNewProperty)
                                {
                                    List <CustomProperty> properties = CustomActivityDesignerHelper.GetCustomProperties(context);
                                    if (properties != null)
                                    {
                                        properties.Add(CustomProperty.CreateCustomProperty(this.serviceProvider, bindDialog.NewMemberName, context.PropertyDescriptor, context.Instance));
                                        CustomActivityDesignerHelper.SetCustomProperties(properties, context);
                                    }
                                }
                                else
                                {
                                    ActivityBindPropertyDescriptor.CreateField(context, bindDialog.Binding, true);
                                }
                            }
                            returnValue = bindDialog.Binding;
                        }
                    }
                }
                catch (Exception e)
                {
                    string message = SR.GetString(SR.Error_CanNotBindProperty, context.PropertyDescriptor.Name);
                    if (!String.IsNullOrEmpty(e.Message))
                    {
                        message += "\n\n" + e.Message;
                    }
                    DesignerHelpers.ShowError(context, message);
                }
            }
            else
            {
                DesignerHelpers.ShowError(this.serviceProvider, SR.GetString(SR.Error_MultipleSelectNotSupportedForBindAndPromote));
            }

            return(returnValue);
        }
 protected override void OnActivate(ActivityDesigner designer)
 {
     if ((designer != null) && (designer.DesignerActions.Count > 0))
     {
         Rectangle bounds   = this.GetBounds(designer, false);
         Point     location = designer.ParentView.LogicalPointToScreen(new Point(bounds.Left, bounds.Bottom));
         DesignerHelpers.ShowDesignerVerbs(designer, location, DesignerHelpers.GetDesignerActionVerbs(designer, designer.DesignerActions));
     }
 }
示例#9
0
        private void UpdateDesignerSize(Point point, ActivityDesigner designerToSize, DesignerEdges sizingEdge)
        {
            if (base.ParentView == null)
            {
                throw new InvalidOperationException(DR.GetString("WorkflowViewNull", new object[0]));
            }
            Rectangle empty = Rectangle.Empty;

            if (designerToSize.ParentDesigner != null)
            {
                empty = designerToSize.ParentDesigner.Bounds;
                Size selectionSize = WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize;
                empty.Inflate(-2 * selectionSize.Width, -2 * selectionSize.Height);
            }
            Rectangle bounds = designerToSize.Bounds;

            if ((sizingEdge & DesignerEdges.Left) > DesignerEdges.None)
            {
                int x = point.X;
                if (!empty.IsEmpty)
                {
                    x = Math.Max(x, empty.X);
                }
                x             = DesignerHelpers.SnapToGrid(new Point(x, 0)).X;
                bounds.Width += bounds.Left - x;
                int num2 = (bounds.Width < designerToSize.MinimumSize.Width) ? (bounds.Width - designerToSize.MinimumSize.Width) : 0;
                bounds.X = x + num2;
            }
            if ((sizingEdge & DesignerEdges.Top) > DesignerEdges.None)
            {
                int y = point.Y;
                if (!empty.IsEmpty)
                {
                    y = Math.Max(y, empty.Y);
                }
                y              = DesignerHelpers.SnapToGrid(new Point(0, y)).Y;
                bounds.Height += bounds.Top - y;
                int num4 = (bounds.Height < designerToSize.MinimumSize.Height) ? (bounds.Height - designerToSize.MinimumSize.Height) : 0;
                bounds.Y = y + num4;
            }
            if ((sizingEdge & DesignerEdges.Right) > DesignerEdges.None)
            {
                bounds.Width += point.X - bounds.Right;
            }
            if ((sizingEdge & DesignerEdges.Bottom) > DesignerEdges.None)
            {
                bounds.Height += point.Y - bounds.Bottom;
            }
            bounds.Width  = Math.Max(bounds.Width, designerToSize.MinimumSize.Width);
            bounds.Height = Math.Max(bounds.Height, designerToSize.MinimumSize.Height);
            if (!empty.IsEmpty)
            {
                bounds = Rectangle.Intersect(bounds, empty);
            }
            ((IWorkflowDesignerMessageSink)designerToSize).OnResizing(sizingEdge, bounds);
        }
        protected override void OnBeginPrint(PrintEventArgs printArgs)
        {
            base.OnBeginPrint(printArgs);
            this.currentPrintablePage = Point.Empty;
            bool flag = (base.PrinterSettings.IsValid && (PrinterSettings.InstalledPrinters.Count > 0)) && new ArrayList(PrinterSettings.InstalledPrinters).Contains(base.PrinterSettings.PrinterName);

            if (!flag)
            {
                DesignerHelpers.ShowError(this.workflowView, DR.GetString("SelectedPrinterIsInvalidErrorMessage", new object[0]));
            }
            printArgs.Cancel = !flag || (this.workflowView.RootDesigner == null);
        }
 protected override void OnThemeChange(ActivityDesignerTheme newTheme)
 {
     base.OnThemeChange(newTheme);
     if (WorkflowTheme.CurrentTheme.AmbientTheme.ShowGrid)
     {
         foreach (ActivityDesigner designer in this.ContainedDesigners)
         {
             designer.Location = DesignerHelpers.SnapToGrid(designer.Location);
         }
         base.PerformLayout();
     }
 }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider serviceProvider, object value)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            this.serviceProvider = serviceProvider;
            object obj2 = value;

            if ((context != null) && (context.PropertyDescriptor is DynamicPropertyDescriptor))
            {
                try
                {
                    using (ActivityBindForm form = new ActivityBindForm(this.serviceProvider, context))
                    {
                        if (DialogResult.OK != form.ShowDialog())
                        {
                            return(obj2);
                        }
                        if (form.CreateNew)
                        {
                            if (form.CreateNewProperty)
                            {
                                List <CustomProperty> customProperties = CustomActivityDesignerHelper.GetCustomProperties(context);
                                if (customProperties != null)
                                {
                                    customProperties.Add(CustomProperty.CreateCustomProperty(this.serviceProvider, form.NewMemberName, context.PropertyDescriptor, context.Instance));
                                    CustomActivityDesignerHelper.SetCustomProperties(customProperties, context);
                                }
                            }
                            else
                            {
                                ActivityBindPropertyDescriptor.CreateField(context, form.Binding, true);
                            }
                        }
                        return(form.Binding);
                    }
                }
                catch (Exception exception)
                {
                    string message = SR.GetString("Error_CanNotBindProperty", new object[] { context.PropertyDescriptor.Name });
                    if (!string.IsNullOrEmpty(exception.Message))
                    {
                        message = message + "\n\n" + exception.Message;
                    }
                    DesignerHelpers.ShowError(context, message);
                }
                return(obj2);
            }
            DesignerHelpers.ShowError(this.serviceProvider, SR.GetString("Error_MultipleSelectNotSupportedForBindAndPromote"));
            return(obj2);
        }
示例#13
0
        internal bool IsValidDropContext(HitTestInfo dropLocation)
        {
            if (this.draggedActivities.Count == 0)
            {
                return(false);
            }

            if (dropLocation == null || dropLocation.AssociatedDesigner == null)
            {
                return(false);
            }

            CompositeActivityDesigner compositeDesigner = dropLocation.AssociatedDesigner as CompositeActivityDesigner;

            if (compositeDesigner == null)
            {
                return(false);
            }

            if (!compositeDesigner.IsEditable || !compositeDesigner.CanInsertActivities(dropLocation, new List <Activity>(this.draggedActivities).AsReadOnly()))
            {
                return(false);
            }

            if (!this.wasCtrlKeyPressed && this.existingDraggedActivities.Count > 0)
            {
                //We are trying to move the actvities with designer
                if (!DesignerHelpers.AreAssociatedDesignersMovable(this.draggedActivities))
                {
                    return(false);
                }

                if (IsRecursiveDropOperation(dropLocation.AssociatedDesigner))
                {
                    return(false);
                }

                IDictionary commonParentActivities = Helpers.PairUpCommonParentActivities(this.draggedActivities);
                foreach (DictionaryEntry entry in commonParentActivities)
                {
                    CompositeActivityDesigner compositeActivityDesigner = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner;
                    Activity[] activitiesToMove = (Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity));
                    if (compositeActivityDesigner != null && !compositeActivityDesigner.CanMoveActivities(dropLocation, new List <Activity>(activitiesToMove).AsReadOnly()))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
 private void OnMenuPageSetup(object sender, EventArgs e)
 {
     if (PrinterSettings.InstalledPrinters.Count < 1)
     {
         DesignerHelpers.ShowError(this.serviceProvider, DR.GetString("ThereIsNoPrinterInstalledErrorMessage", new object[0]));
     }
     else
     {
         WorkflowPageSetupDialog dialog = new WorkflowPageSetupDialog(this.serviceProvider);
         if (DialogResult.OK == dialog.ShowDialog())
         {
             this.workflowView.PerformLayout(false);
         }
     }
 }
示例#15
0
        internal static Point[] GetDesignerLocations(Point startPoint, Point endPoint, ICollection <Activity> activitiesToMove)
        {
            List <Point> list = new List <Point>();

            foreach (Activity activity in activitiesToMove)
            {
                Point            location = endPoint;
                ActivityDesigner designer = ActivityDesigner.GetDesigner(activity);
                if ((designer != null) && !startPoint.IsEmpty)
                {
                    Size size = new Size(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y);
                    location = new Point(designer.Location.X + size.Width, designer.Location.Y + size.Height);
                }
                location = DesignerHelpers.SnapToGrid(location);
                list.Add(location);
            }
            return(list.ToArray());
        }
 protected override void SaveViewState(BinaryWriter writer)
 {
     base.SaveViewState(writer);
     if (this.containedDesignSurface != null)
     {
         writer.Write(true);
         IDesignerHost service = this.containedDesignSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
         if (service == null)
         {
             throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName }));
         }
         DesignerHelpers.SerializeDesignerStates(service, writer);
     }
     else
     {
         writer.Write(false);
     }
 }
示例#17
0
        protected override void OnBeginPrint(PrintEventArgs printArgs)
        {
            base.OnBeginPrint(printArgs);

            this.currentPrintablePage = Point.Empty;

            //Validate the printer
            bool validPrinter = (PrinterSettings.IsValid &&
                                 PrinterSettings.InstalledPrinters.Count > 0 &&
                                 new ArrayList(PrinterSettings.InstalledPrinters).Contains(PrinterSettings.PrinterName));

            if (!validPrinter)
            {
                DesignerHelpers.ShowError(this.workflowView, DR.GetString(DR.SelectedPrinterIsInvalidErrorMessage));
            }

            printArgs.Cancel = (!validPrinter || this.workflowView.RootDesigner == null);
        }
        private void InitiateDragDrop()
        {
            WorkflowView      parentView = base.ParentView;
            ISelectionService service    = (ISelectionService)base.GetService(typeof(ISelectionService));
            IDesignerHost     host       = (IDesignerHost)base.GetService(typeof(IDesignerHost));

            if ((service != null) && (host != null))
            {
                ICollection selectedComponents = service.GetSelectedComponents();
                if (((selectedComponents != null) && (selectedComponents.Count >= 1)) && (!service.GetComponentSelected(host.RootComponent) && Helpers.AreAllActivities(selectedComponents)))
                {
                    DragDropEffects none = DragDropEffects.None;
                    try
                    {
                        this.existingDraggedActivities.AddRange(Helpers.GetTopLevelActivities(selectedComponents));
                        DragDropEffects allowedEffects = DesignerHelpers.AreAssociatedDesignersMovable(this.existingDraggedActivities) ? (DragDropEffects.Move | DragDropEffects.Copy) : DragDropEffects.Copy;
                        IDataObject     data           = CompositeActivityDesigner.SerializeActivitiesToDataObject(base.ParentView, this.existingDraggedActivities.ToArray());
                        none = parentView.DoDragDrop(data, allowedEffects);
                    }
                    catch (Exception exception)
                    {
                        DesignerHelpers.ShowError(base.ParentView, exception.Message);
                    }
                    finally
                    {
                        if ((none == DragDropEffects.Move) && (this.existingDraggedActivities.Count > 0))
                        {
                            string transactionDescription = string.Empty;
                            if (this.existingDraggedActivities.Count > 1)
                            {
                                transactionDescription = SR.GetString("MoveMultipleActivities", new object[] { this.existingDraggedActivities.Count });
                            }
                            else
                            {
                                transactionDescription = SR.GetString("MoveSingleActivity", new object[] { this.existingDraggedActivities[0].GetType() });
                            }
                            CompositeActivityDesigner.RemoveActivities(base.ParentView, this.existingDraggedActivities.AsReadOnly(), transactionDescription);
                        }
                        this.existingDraggedActivities.Clear();
                    }
                }
            }
        }
        internal bool IsValidDropContext(System.Workflow.ComponentModel.Design.HitTestInfo dropLocation)
        {
            if (this.draggedActivities.Count == 0)
            {
                return(false);
            }
            if ((dropLocation == null) || (dropLocation.AssociatedDesigner == null))
            {
                return(false);
            }
            CompositeActivityDesigner associatedDesigner = dropLocation.AssociatedDesigner as CompositeActivityDesigner;

            if (associatedDesigner == null)
            {
                return(false);
            }
            if (!associatedDesigner.IsEditable || !associatedDesigner.CanInsertActivities(dropLocation, new List <Activity>(this.draggedActivities).AsReadOnly()))
            {
                return(false);
            }
            if (!this.wasCtrlKeyPressed && (this.existingDraggedActivities.Count > 0))
            {
                if (!DesignerHelpers.AreAssociatedDesignersMovable(this.draggedActivities))
                {
                    return(false);
                }
                if (this.IsRecursiveDropOperation(dropLocation.AssociatedDesigner))
                {
                    return(false);
                }
                foreach (DictionaryEntry entry in Helpers.PairUpCommonParentActivities(this.draggedActivities))
                {
                    CompositeActivityDesigner designer = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner;
                    Activity[] collection = (Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity));
                    if ((designer != null) && !designer.CanMoveActivities(dropLocation, new List <Activity>(collection).AsReadOnly()))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
 protected override void LoadViewState(BinaryReader reader)
 {
     base.LoadViewState(reader);
     if (reader.ReadBoolean())
     {
         if (this.containedDesignSurface == null)
         {
             this.containedRootDesigner = this.LoadHostedWorkflow();
         }
         if (this.containedDesignSurface != null)
         {
             IDesignerHost service = this.containedDesignSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
             if (service == null)
             {
                 throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName }));
             }
             DesignerHelpers.DeserializeDesignerStates(service, reader);
         }
     }
 }
示例#21
0
        private void OnRefreshDesignerActions(object sender, EventArgs e)
        {
            //NOTE: Make sure that we dont invalidate the workflow here. Workflow will be invalidated when'
            //the designer actions are refreshed on idle thread. Putting invalidation logic here causes the validation
            //to go haywire as before the idle message comes in we start getting to DesignerActions thru the paiting
            //logic to show smart tags. This causes problems and ConfigErrors appear everywhere on designer intermittently

            //PROBLEM: ConfigErrors appearing on the entire design surface
            //This is due to a race condition between the validation triggered during painting
            //logic and validation triggered when we try to access the DesignerActions from RefreshTask handler
            //In the validation logic we try to get to the types while doing so we Refresh the code compile unit
            //in typesystem which in turn triggers CodeDomLoader.Refresh. In this we remove types, call refresh handler
            //and add new types. While doing this after the remove types but before addtypes, call is made to the drawing
            //logic in which we try to grab the designer actions which triggers another set of validations hence now we
            //always call UpdateWindow after invalidatewindow so that the validation will always get triggered on painting thread.
            //NOTE: PLEASE DO NOT CHANGE SEQUENCE IN WHICH THE FOLLOWING HANDLERS ARE ADDED
            //THE PROBLEM CAN BE ALSO FIXED BY TRIGGERING VALIDATION IN RefreshDesignerActions ITSELF
            //FOR NOW THE REFRESH FIX WILL CAUSE MINIMAL IMPACT IN THE LIGHT OF M3

            WorkflowView workflowView = this.serviceProvider.GetService(typeof(WorkflowView)) as WorkflowView;

            if (this.refreshDesignerActionsHandler != null)
            {
                if (workflowView != null)
                {
                    workflowView.Idle -= this.refreshDesignerActionsHandler;
                }
                this.refreshDesignerActionsHandler = null;
            }

            DesignerHelpers.RefreshDesignerActions(this.serviceProvider);

            IPropertyValueUIService propertyValueService = this.serviceProvider.GetService(typeof(IPropertyValueUIService)) as IPropertyValueUIService;

            if (propertyValueService != null)
            {
                propertyValueService.NotifyPropertyValueUIItemsChanged();
            }

            RefreshTasks();
        }
        public override void SetValue(object component, object value)
        {
            Activity activity = component as Activity;

            if (activity != null)
            {
                IIdentifierCreationService service = activity.Site.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService;
                if (service == null)
                {
                    throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(IIdentifierCreationService).FullName }));
                }
                string identifier = value as string;
                service.ValidateIdentifier(activity, identifier);
                bool ignoreCase      = CompilerHelpers.GetSupportedLanguage(activity.Site) == SupportedLanguages.VB;
                Type dataSourceClass = Helpers.GetDataSourceClass(Helpers.GetRootActivity(activity), activity.Site);
                if ((dataSourceClass != null) && (ActivityBindPropertyDescriptor.FindMatchingMember(identifier, dataSourceClass, ignoreCase) != null))
                {
                    throw new ArgumentException(SR.GetString("Error_ActivityNameExist", new object[] { identifier }));
                }
                IMemberCreationService service2 = activity.Site.GetService(typeof(IMemberCreationService)) as IMemberCreationService;
                if (service2 == null)
                {
                    throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName }));
                }
                IDesignerHost host = activity.Site.GetService(typeof(IDesignerHost)) as IDesignerHost;
                if (host == null)
                {
                    throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName }));
                }
                string newClassName = identifier;
                int    num          = host.RootComponentClassName.LastIndexOf('.');
                if (num > 0)
                {
                    newClassName = host.RootComponentClassName.Substring(0, num + 1) + identifier;
                }
                service2.UpdateTypeName(((Activity)host.RootComponent).GetValue(WorkflowMarkupSerializer.XClassProperty) as string, newClassName);
                ((Activity)host.RootComponent).SetValue(WorkflowMarkupSerializer.XClassProperty, newClassName);
                base.SetValue(component, value);
                DesignerHelpers.UpdateSiteName((Activity)host.RootComponent, identifier);
            }
        }
        private void OnRefreshDesignerActions(object sender, EventArgs e)
        {
            WorkflowView view = this.serviceProvider.GetService(typeof(WorkflowView)) as WorkflowView;

            if (this.refreshDesignerActionsHandler != null)
            {
                if (view != null)
                {
                    view.Idle -= this.refreshDesignerActionsHandler;
                }
                this.refreshDesignerActionsHandler = null;
            }
            DesignerHelpers.RefreshDesignerActions(this.serviceProvider);
            IPropertyValueUIService service = this.serviceProvider.GetService(typeof(IPropertyValueUIService)) as IPropertyValueUIService;

            if (service != null)
            {
                service.NotifyPropertyValueUIItemsChanged();
            }
            this.RefreshTasks();
        }
        internal static Point[] GetDesignerLocations(Point startPoint, Point endPoint, ICollection <Activity> activitiesToMove)
        {
            List <Point> locations = new List <Point>();

            //We move all the designers
            foreach (Activity activityToMove in activitiesToMove)
            {
                Point            location       = endPoint;
                ActivityDesigner designerToMove = ActivityDesigner.GetDesigner(activityToMove);
                if (designerToMove != null && !startPoint.IsEmpty)
                {
                    Size delta = new Size(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y);
                    location = new Point(designerToMove.Location.X + delta.Width, designerToMove.Location.Y + delta.Height);
                }

                location = DesignerHelpers.SnapToGrid(location);
                locations.Add(location);
            }

            return(locations.ToArray());
        }
        private void OnMenuCut(object sender, EventArgs e)
        {
            IDesignerHost service = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if ((service == null) || !this.selectionService.GetComponentSelected(service.RootComponent))
            {
                ICollection selectedComponents = this.selectionService.GetSelectedComponents();
                if (Helpers.AreAllActivities(selectedComponents) && DesignerHelpers.AreAssociatedDesignersMovable(selectedComponents))
                {
                    this.OnMenuCopy(sender, e);
                    string description = string.Empty;
                    if (selectedComponents.Count > 1)
                    {
                        description = SR.GetString("CutMultipleActivities", new object[] { selectedComponents.Count });
                    }
                    else
                    {
                        ArrayList list = new ArrayList(selectedComponents);
                        if (list.Count > 0)
                        {
                            description = SR.GetString("CutSingleActivity", new object[] { (list[0] as Activity).Name });
                        }
                        else
                        {
                            description = SR.GetString("CutActivity");
                        }
                    }
                    DesignerTransaction transaction = service.CreateTransaction(description);
                    try
                    {
                        this.OnMenuDelete(sender, e);
                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Cancel();
                    }
                }
            }
        }
示例#26
0
        protected override void LoadViewState(BinaryReader reader)
        {
            base.LoadViewState(reader);

            if (reader.ReadBoolean())
            {
                //verify the hosted surface and designer are loaded
                if (this.containedDesignSurface == null)
                {
                    this.containedRootDesigner = LoadHostedWorkflow();
                }

                if (this.containedDesignSurface != null)
                {
                    IDesignerHost designerHost = this.containedDesignSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
                    if (designerHost == null)
                    {
                        throw new Exception(SR.GetString(SR.General_MissingService, typeof(IDesignerHost).FullName));
                    }
                    DesignerHelpers.DeserializeDesignerStates(designerHost, reader);
                }
            }
        }
示例#27
0
        protected override void SaveViewState(BinaryWriter writer)
        {
            base.SaveViewState(writer);

            if (this.containedDesignSurface != null)
            {
                // mark persistence for invoked workflow
                writer.Write(true);

                IDesignerHost designerHost = this.containedDesignSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
                if (designerHost == null)
                {
                    throw new Exception(SR.GetString(SR.General_MissingService, typeof(IDesignerHost).FullName));
                }

                DesignerHelpers.SerializeDesignerStates(designerHost, writer);
            }
            else
            {
                // no persistnce data for invoked workflow
                writer.Write(false);
            }
        }
示例#28
0
        protected override bool OnDragDrop(DragEventArgs eventArgs)
        {
            //Invalidate the entire rectangle so that we draw active placement glyphs on connectors
            WorkflowView parentView = ParentView;

            parentView.InvalidateClientRectangle(Rectangle.Empty);

            //By default we do not allow any drag drop operation
            eventArgs.Effect = DragDropEffects.None;

            DestroyDragFeedbackImages();

            //Get the coordinates
            Point clientPoint  = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y));
            Point logicalPoint = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y));

            //Now we check if the drag drop was in any valid area, if not then do not proceed further
            if (!parentView.IsClientPointInActiveLayout(clientPoint))
            {
                if (this.dropTargetDesigner != null)
                {
                    ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                }
                this.wasCtrlKeyPressed  = false;
                this.dropTargetDesigner = null;
                this.draggedActivities.Clear();
                return(false);
            }

            //Now we have a potential for successful drag drop, so construct drag event arguments with logical coordinates
            this.wasCtrlKeyPressed = ((eventArgs.KeyState & 8) == 8);
            ActivityDragEventArgs dragdropEventArgs = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, logicalPoint, this.draggedActivities);

            //Now check which designer is under the cursor, if we have the same designer as the old one
            //If not then we set the new one as drop target and pump in messages
            HitTestInfo hitTestInfo = MessageHitTestContext;

            if (this.dropTargetDesigner != hitTestInfo.AssociatedDesigner)
            {
                if (this.dropTargetDesigner != null)
                {
                    ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                    this.dropTargetDesigner = null;
                }

                if (hitTestInfo.AssociatedDesigner != null)
                {
                    this.dropTargetDesigner = hitTestInfo.AssociatedDesigner;
                    if (this.dropTargetDesigner != null)
                    {
                        ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(dragdropEventArgs);
                    }
                }
            }

            //We now have appropriate droptarget designer
            try
            {
                if (this.dropTargetDesigner != null)
                {
                    //We do not allow recursive drag and drop
                    if (!this.wasCtrlKeyPressed && IsRecursiveDropOperation(this.dropTargetDesigner) ||
                        (this.dropTargetDesigner is CompositeActivityDesigner && !((CompositeActivityDesigner)this.dropTargetDesigner).IsEditable))
                    {
                        ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                        dragdropEventArgs.Effect = DragDropEffects.None;
                    }
                    else
                    {
                        // IMPORTANT: Don't use draggedActivities variable, because components which are
                        // there may not be created using the assembly references  added to ITypeResultionService
                        // this.workflowView.time the components will be created using the assembly references got added to the project
                        List <Activity> droppedActivities      = new List <Activity>();
                        string          transactionDescription = SR.GetString(SR.DragDropActivities);

                        //This means that we are trying to move activities so we use the same activities for drop
                        if (!this.wasCtrlKeyPressed && this.existingDraggedActivities.Count > 0)
                        {
                            droppedActivities.AddRange(this.existingDraggedActivities);
                            if (droppedActivities.Count > 1)
                            {
                                transactionDescription = SR.GetString(SR.MoveMultipleActivities, droppedActivities.Count);
                            }
                            else if (droppedActivities.Count == 1)
                            {
                                transactionDescription = SR.GetString(SR.MoveSingleActivity, droppedActivities[0].GetType());
                            }
                        }
                        else
                        {
                            droppedActivities.AddRange(CompositeActivityDesigner.DeserializeActivitiesFromDataObject(ParentView, eventArgs.Data, true));
                            if (droppedActivities.Count > 0)
                            {
                                transactionDescription = SR.GetString(SR.CreateActivityFromToolbox, droppedActivities[0].GetType());
                            }
                        }

                        //Now that we have what needs to be dropped, we start the actual drag and drop
                        IDesignerHost       designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost;
                        DesignerTransaction transaction  = null;
                        if (droppedActivities.Count > 0)
                        {
                            transaction = designerHost.CreateTransaction(transactionDescription);
                        }

                        dragdropEventArgs = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, logicalPoint, droppedActivities);

                        try
                        {
                            ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragDrop(dragdropEventArgs);

                            if (dragdropEventArgs.Effect == DragDropEffects.Move)
                            {
                                this.existingDraggedActivities.Clear();
                            }

                            if (transaction != null)
                            {
                                transaction.Commit();
                            }
                        }
                        catch (Exception e)
                        {
                            if (transaction != null)
                            {
                                transaction.Cancel();
                            }
                            throw e;
                        }

                        //We deserialize the designers and try to store the designer states
                        if (droppedActivities.Count > 0)
                        {
                            Stream componentStateStream = eventArgs.Data.GetData(DragDropManager.CF_DESIGNERSTATE) as Stream;
                            if (componentStateStream != null)
                            {
                                Helpers.DeserializeDesignersFromStream(droppedActivities, componentStateStream);
                            }

                            //Set the current selection
                            ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService));
                            if (selectionService != null)
                            {
                                selectionService.SetSelectedComponents(droppedActivities, SelectionTypes.Replace);
                            }
                        }

                        //Active the design surface
                        if (designerHost != null)
                        {
                            designerHost.Activate();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //We purposely consume application thrown exception which are result of user cancelling the action
                //during dragdrop where we popup UI Wizards during drag drop. Ref: InvokeWebService
                ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                dragdropEventArgs.Effect = DragDropEffects.None;

                string dragDropException = ex.Message;
                if (ex.InnerException != null && !String.IsNullOrEmpty(ex.InnerException.Message))
                {
                    dragDropException = ex.InnerException.Message;
                }

                string errorMessage = DR.GetString(DR.Error_FailedToDeserializeComponents);
                errorMessage += "\r\n" + DR.GetString(DR.Error_Reason, dragDropException);
                DesignerHelpers.ShowError(ParentView, errorMessage);

                if (ex != CheckoutException.Canceled)
                {
                    throw new Exception(errorMessage, ex);
                }
            }
            finally
            {
                //Make sure that mouse over designer is set to null
                this.wasCtrlKeyPressed = false;
                this.draggedActivities.Clear();
                this.dropTargetDesigner  = null;
                this.exceptionInDragDrop = false;
                eventArgs.Effect         = dragdropEventArgs.Effect;
            }

            return(true);
        }
示例#29
0
        protected override bool OnKeyDown(KeyEventArgs eventArgs)
        {
            if ((eventArgs != null) && ((eventArgs.KeyCode == Keys.PageUp) || (eventArgs.KeyCode == Keys.Next)))
            {
                this.UpdateViewOnPageUpDown(eventArgs.KeyCode == Keys.PageUp);
            }
            ISelectionService service = ((IServiceProvider)base.ParentView).GetService(typeof(ISelectionService)) as ISelectionService;

            if (eventArgs.KeyCode == Keys.Enter)
            {
                IDesigner designer = ActivityDesigner.GetDesigner(service.PrimarySelection as Activity);
                if (designer != null)
                {
                    designer.DoDefaultAction();
                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Escape)
            {
                if (!eventArgs.Handled)
                {
                    CompositeActivityDesigner parentDesigner = ActivityDesigner.GetParentDesigner(service.PrimarySelection);
                    if (parentDesigner != null)
                    {
                        service.SetSelectedComponents(new object[] { parentDesigner.Activity }, SelectionTypes.Replace);
                    }
                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Delete)
            {
                IDesignerHost host = ((IServiceProvider)base.ParentView).GetService(typeof(IDesignerHost)) as IDesignerHost;
                if ((host != null) && !service.GetComponentSelected(host.RootComponent))
                {
                    ICollection selectedComponents = service.GetSelectedComponents();
                    if (DesignerHelpers.AreComponentsRemovable(selectedComponents))
                    {
                        List <Activity> activities = new List <Activity>(Helpers.GetTopLevelActivities(service.GetSelectedComponents()));
                        bool            flag       = activities.Count > 0;
                        foreach (DictionaryEntry entry in Helpers.PairUpCommonParentActivities(activities))
                        {
                            CompositeActivityDesigner designer3 = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner;
                            if ((designer3 != null) && !designer3.CanRemoveActivities(new List <Activity>((Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity))).AsReadOnly()))
                            {
                                flag = false;
                            }
                        }
                        if (flag)
                        {
                            List <ConnectorHitTestInfo> components = new List <ConnectorHitTestInfo>();
                            foreach (object obj2 in selectedComponents)
                            {
                                ConnectorHitTestInfo item = obj2 as ConnectorHitTestInfo;
                                if (item != null)
                                {
                                    components.Add(item);
                                }
                            }
                            CompositeActivityDesigner.RemoveActivities(base.ParentView, activities.AsReadOnly(), SR.GetString("DeletingActivities"));
                            if ((service != null) && (components.Count > 0))
                            {
                                service.SetSelectedComponents(components, SelectionTypes.Add);
                            }
                            eventArgs.Handled = true;
                        }
                    }
                }
            }
            else if (((eventArgs.KeyCode == Keys.Left) || (eventArgs.KeyCode == Keys.Right)) || (((eventArgs.KeyCode == Keys.Up) || (eventArgs.KeyCode == Keys.Down)) || (eventArgs.KeyCode == Keys.Tab)))
            {
                ActivityDesigner designer4 = ActivityDesigner.GetDesigner(service.PrimarySelection as Activity);
                if ((designer4 != null) && (designer4.ParentDesigner != null))
                {
                    ((IWorkflowDesignerMessageSink)designer4.ParentDesigner).OnKeyDown(eventArgs);
                    eventArgs.Handled = true;
                }
            }
            if (!eventArgs.Handled)
            {
                ActivityDesigner designerWithFocus = this.GetDesignerWithFocus();
                if (designerWithFocus != null)
                {
                    ((IWorkflowDesignerMessageSink)designerWithFocus).OnKeyDown(eventArgs);
                }
            }
            return(eventArgs.Handled);
        }
示例#30
0
        protected override bool OnKeyDown(KeyEventArgs eventArgs)
        {
            if (eventArgs != null && (eventArgs.KeyCode == Keys.PageUp || eventArgs.KeyCode == Keys.PageDown))
            {
                UpdateViewOnPageUpDown(eventArgs.KeyCode == Keys.PageUp);
            }
            ISelectionService selectionService = ((IServiceProvider)this.ParentView).GetService(typeof(ISelectionService)) as ISelectionService;

            //enter key (
            if (eventArgs.KeyCode == Keys.Enter)
            {
                // on enter key we want to do DoDefault of the designer
                IDesigner designer = ActivityDesigner.GetDesigner(selectionService.PrimarySelection as Activity) as IDesigner;
                if (designer != null)
                {
                    designer.DoDefaultAction();
                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Escape)
            {
                if (!eventArgs.Handled)
                {
                    CompositeActivityDesigner parentDesigner = ActivityDesigner.GetParentDesigner(selectionService.PrimarySelection);
                    if (parentDesigner != null)
                    {
                        selectionService.SetSelectedComponents(new object[] { parentDesigner.Activity }, SelectionTypes.Replace);
                    }

                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Delete)
            {
                // check if we are cutting root component
                IDesignerHost designerHost = ((IServiceProvider)this.ParentView).GetService(typeof(IDesignerHost)) as IDesignerHost;
                if (!(designerHost == null || selectionService.GetComponentSelected(designerHost.RootComponent)))
                {
                    //Check that we are cutting all activities
                    //Check if we are in writable context
                    ICollection components = selectionService.GetSelectedComponents();
                    if (DesignerHelpers.AreComponentsRemovable(components))
                    {
                        // check if we can delete these
                        List <Activity> topLevelActivities     = new List <Activity>(Helpers.GetTopLevelActivities(selectionService.GetSelectedComponents()));
                        bool            needToDelete           = (topLevelActivities.Count > 0);
                        IDictionary     commonParentActivities = Helpers.PairUpCommonParentActivities(topLevelActivities);
                        foreach (DictionaryEntry entry in commonParentActivities)
                        {
                            CompositeActivityDesigner compositeActivityDesigner = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner;
                            if (compositeActivityDesigner != null && !compositeActivityDesigner.CanRemoveActivities(new List <Activity>((Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity))).AsReadOnly()))
                            {
                                needToDelete = false;
                            }
                        }

                        if (needToDelete)
                        {
                            List <ConnectorHitTestInfo> connectors = new List <ConnectorHitTestInfo>();
                            foreach (object component in components)
                            {
                                ConnectorHitTestInfo connector = component as ConnectorHitTestInfo;
                                if (connector != null)
                                {
                                    connectors.Add(connector);
                                }
                            }

                            //cache selcted connectors before calling this func
                            CompositeActivityDesigner.RemoveActivities((IServiceProvider)this.ParentView, topLevelActivities.AsReadOnly(), SR.GetString(SR.DeletingActivities));

                            //add connectors back to the selection service
                            if (selectionService != null && connectors.Count > 0)
                            {
                                selectionService.SetSelectedComponents(connectors, SelectionTypes.Add);
                            }

                            eventArgs.Handled = true;
                        }
                    }
                }
            }
            //navigation (left, right, up, down, tab, shift-tab)
            else if (eventArgs.KeyCode == Keys.Left || eventArgs.KeyCode == Keys.Right || eventArgs.KeyCode == Keys.Up || eventArgs.KeyCode == Keys.Down || eventArgs.KeyCode == Keys.Tab)
            {
                //we'll pass it to the parent designer of the primary selected designer
                //sequential designers just navigate between their children
                //free form designers may move their children on arrow keys and navigate on tab
                ActivityDesigner designer = ActivityDesigner.GetDesigner(selectionService.PrimarySelection as Activity) as ActivityDesigner;
                if (designer != null && designer.ParentDesigner != null)
                {
                    //we will let the parent see if it wants to handle the event,
                    //otherwise the selected designer itself will be called from a designer message filter below
                    ((IWorkflowDesignerMessageSink)designer.ParentDesigner).OnKeyDown(eventArgs);
                    eventArgs.Handled = true;
                }
            }

            if (!eventArgs.Handled)
            {
                ActivityDesigner designerWithFocus = GetDesignerWithFocus();
                if (designerWithFocus != null)
                {
                    ((IWorkflowDesignerMessageSink)designerWithFocus).OnKeyDown(eventArgs);
                }
            }

            return(eventArgs.Handled);
        }