Exemplo n.º 1
0
        private static void EnsureDefaultChildHierarchy(IDesignerHost designerHost)
        {
            //When we are adding the root activity we need to make sure that all the child activities which are required by the parent
            //activity are looked up in the toolboxitem and added appropriately
            //If the composite activity already has a some child activities but not all then it
            //means that user has changed the InitializeComponent and hence we do nothing
            //This is the simple check to get the designer working in case of selecting composite
            //root activities
            CompositeActivity rootActivity = designerHost.RootComponent as CompositeActivity;

            if (rootActivity != null && rootActivity.Activities.Count == 0)
            {
                object[]             attribs           = rootActivity.GetType().GetCustomAttributes(typeof(ToolboxItemAttribute), false);
                ToolboxItemAttribute toolboxItemAttrib = (attribs != null && attribs.GetLength(0) > 0) ? attribs[0] as ToolboxItemAttribute : null;
                if (toolboxItemAttrib != null && toolboxItemAttrib.ToolboxItemType != null)
                {
                    ToolboxItem  item       = Activator.CreateInstance(toolboxItemAttrib.ToolboxItemType, new object[] { rootActivity.GetType() }) as ToolboxItem;
                    IComponent[] components = item.CreateComponents();

                    //I am assuming here that there will be always one top level component created.
                    //If there are multiple then there is a bigger problem as we dont know how
                    //to use those
                    CompositeActivity compositeActivity = null;
                    foreach (IComponent component in components)
                    {
                        if (component.GetType() == rootActivity.GetType())
                        {
                            compositeActivity = component as CompositeActivity;
                            break;
                        }
                    }

                    //Add the children
                    if (compositeActivity != null && compositeActivity.Activities.Count > 0)
                    {
                        IIdentifierCreationService identifierCreationService = designerHost.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService;
                        if (identifierCreationService != null)
                        {
                            //We do not go thru the composite designer here as composite activity
                            //might have simple designer
                            Activity[] activities = compositeActivity.Activities.ToArray();
                            compositeActivity.Activities.Clear();

                            identifierCreationService.EnsureUniqueIdentifiers(rootActivity, activities);
                            // Work around : Don't called AddRange because it doesn't send the ListChange notifications
                            // to the activity collection.  Use multiple Add calls instaead
                            foreach (Activity newActivity in activities)
                            {
                                rootActivity.Activities.Add(newActivity);
                            }

                            foreach (Activity childActivity in activities)
                            {
                                WorkflowDesignerLoader.AddActivityToDesigner(designerHost, childActivity);
                            }
                        }
                    }
                }
            }
        }
        private bool IsRecursiveDropOperation(ActivityDesigner dropTargetDesigner)
        {
            if (dropTargetDesigner == null)
                return false;

            ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService));
            CompositeActivity dropTargetComponent = dropTargetDesigner.Activity as CompositeActivity;
            if (dropTargetComponent == null || selectionService == null)
                return false;

            // First check for activity designer specific recursion - possible recursion when drag-n-drop from outside the current 
            // designer such toolbox or other activity designers.
            WorkflowView workflowView = GetService(typeof(WorkflowView)) as WorkflowView;
            IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost;
            WorkflowDesignerLoader loader = GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;

            // When drag-n-drop within the same designer, if the drag drop is not within designer or no valid droptarget, we do not do anything
            if (this.draggedActivities.Count == 0 || this.existingDraggedActivities.Count == 0)
                return false;

            //Go thru all the components in dragged components and check for recursive dragdrop
            //Get all the top level activities being dragged dropped
            ArrayList topLevelActivities = new ArrayList(Helpers.GetTopLevelActivities(selectionService.GetSelectedComponents()));
            CompositeActivity parentActivity = dropTargetComponent;
            while (parentActivity != null)
            {
                if (topLevelActivities.Contains(parentActivity))
                    return true;

                parentActivity = parentActivity.Parent;
            }


            return false;
        }
        internal static List <CustomProperty> GetCustomProperties(IServiceProvider serviceProvider)
        {
            WorkflowDesignerLoader service = serviceProvider.GetService(typeof(IDesignerLoaderService)) as WorkflowDesignerLoader;

            if (service != null)
            {
                service.Flush();
            }
            System.Type customActivityType = GetCustomActivityType(serviceProvider);
            if (customActivityType == null)
            {
                return(null);
            }
            List <CustomProperty> list = new List <CustomProperty>();

            foreach (PropertyInfo info in customActivityType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                if (info.PropertyType != null)
                {
                    list.Add(CreateCustomProperty(serviceProvider, customActivityType, info, info.PropertyType));
                }
            }
            foreach (EventInfo info2 in customActivityType.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                if (info2.EventHandlerType != null)
                {
                    CustomProperty item = CreateCustomProperty(serviceProvider, customActivityType, info2, info2.EventHandlerType);
                    item.IsEvent = true;
                    list.Add(item);
                }
            }
            return(list);
        }
Exemplo n.º 4
0
        internal static void AddActivityToDesigner(IServiceProvider serviceProvider, Activity activity)
        {
            WorkflowDesignerLoader service = serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;

            if (service == null)
            {
                throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(WorkflowDesignerLoader).FullName }));
            }
            service.AddActivityToDesigner(activity);
        }
Exemplo n.º 5
0
        internal static void RemoveActivityFromDesigner(IServiceProvider serviceProvider, Activity activity)
        {
            WorkflowDesignerLoader workflowLoader = serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;

            if (workflowLoader == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(WorkflowDesignerLoader).FullName));
            }

            workflowLoader.RemoveActivityFromDesigner(activity);
        }
Exemplo n.º 6
0
        internal static List <CustomProperty> GetCustomProperties(IServiceProvider serviceProvider)
        {
            // We need to perform a flush just before getting the custom properties so that we are sure that type system is updated
            // and we always get the updated properties
            WorkflowDesignerLoader loader = serviceProvider.GetService(typeof(IDesignerLoaderService)) as WorkflowDesignerLoader;

            if (loader != null)
            {
                loader.Flush();
            }

            Type customActivityType = GetCustomActivityType(serviceProvider);

            if (customActivityType == null)
            {
                return(null);
            }

            List <CustomProperty> cpc = new List <CustomProperty>();

            PropertyInfo[] properties = customActivityType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo property in properties)
            {
                if (property.PropertyType != null)
                {
                    cpc.Add(CreateCustomProperty(serviceProvider, customActivityType, property, property.PropertyType));
                }
            }

            EventInfo[] events = customActivityType.GetEvents(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
            foreach (EventInfo evt in events)
            {
                if (evt.EventHandlerType == null)
                {
                    continue;
                }
                CustomProperty eventProperty = CreateCustomProperty(serviceProvider, customActivityType, evt, evt.EventHandlerType);
                eventProperty.IsEvent = true;
                cpc.Add(eventProperty);
            }

            return(cpc);
        }
        internal static ReadOnlyCollection <DesignerView> GetViews(StructuredCompositeActivityDesigner designer)
        {
            if (designer.Activity == null)
            {
                throw new ArgumentException("Component can not be null!");
            }
            bool            flag = !designer.IsEditable;
            List <object[]> list = new List <object[]>();
            string          toolboxDisplayName = ActivityToolboxItem.GetToolboxDisplayName(designer.Activity.GetType());

            list.Add(new object[] { designer.Activity.GetType(), DR.GetString("ViewActivity", new object[] { toolboxDisplayName }) });
            if (designer.Activity.Site != null)
            {
                WorkflowDesignerLoader service = designer.Activity.Site.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                Type c = designer.Activity.GetType();
                if ((service == null) || (typeof(CompositeActivity).IsAssignableFrom(c) && (!flag || (FindActivity(designer, typeof(CancellationHandlerActivity)) != null))))
                {
                    list.Add(new object[] { typeof(CancellationHandlerActivity), DR.GetString("ViewCancelHandler", new object[0]) });
                }
                if ((service == null) || (typeof(CompositeActivity).IsAssignableFrom(c) && (!flag || (FindActivity(designer, typeof(FaultHandlersActivity)) != null))))
                {
                    list.Add(new object[] { typeof(FaultHandlersActivity), DR.GetString("ViewExceptions", new object[0]) });
                }
                if ((service == null) || (((designer.Activity is ICompensatableActivity) && typeof(CompositeActivity).IsAssignableFrom(c)) && (!flag || (FindActivity(designer, typeof(CompensationHandlerActivity)) != null))))
                {
                    list.Add(new object[] { typeof(CompensationHandlerActivity), DR.GetString("ViewCompensation", new object[0]) });
                }
                if ((service == null) || (Type.GetType("System.Workflow.Activities.EventHandlingScopeActivity, System.Workflow.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35").IsAssignableFrom(c) && (!flag || (FindActivity(designer, Type.GetType("System.Workflow.Activities.EventHandlersActivity, System.Workflow.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")) != null))))
                {
                    list.Add(new object[] { Type.GetType("System.Workflow.Activities.EventHandlersActivity, System.Workflow.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"), DR.GetString("ViewEvents", new object[0]) });
                }
            }
            List <DesignerView> list2 = new List <DesignerView>();

            for (int i = 0; i < list.Count; i++)
            {
                Type         activityType = list[i][0] as Type;
                DesignerView item         = new SecondaryView(designer, i + 1, list[i][1] as string, activityType);
                list2.Add(item);
            }
            return(list2.AsReadOnly());
        }
Exemplo n.º 8
0
        private static void EnsureDefaultChildHierarchy(IDesignerHost designerHost)
        {
            CompositeActivity rootComponent = designerHost.RootComponent as CompositeActivity;

            if ((rootComponent != null) && (rootComponent.Activities.Count == 0))
            {
                object[]             customAttributes = rootComponent.GetType().GetCustomAttributes(typeof(ToolboxItemAttribute), false);
                ToolboxItemAttribute attribute        = ((customAttributes != null) && (customAttributes.GetLength(0) > 0)) ? (customAttributes[0] as ToolboxItemAttribute) : null;
                if ((attribute != null) && (attribute.ToolboxItemType != null))
                {
                    IComponent[]      componentArray = (Activator.CreateInstance(attribute.ToolboxItemType, new object[] { rootComponent.GetType() }) as ToolboxItem).CreateComponents();
                    CompositeActivity activity2      = null;
                    foreach (IComponent component in componentArray)
                    {
                        if (component.GetType() == rootComponent.GetType())
                        {
                            activity2 = component as CompositeActivity;
                            break;
                        }
                    }
                    if ((activity2 != null) && (activity2.Activities.Count > 0))
                    {
                        IIdentifierCreationService service = designerHost.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService;
                        if (service != null)
                        {
                            Activity[] childActivities = activity2.Activities.ToArray();
                            activity2.Activities.Clear();
                            service.EnsureUniqueIdentifiers(rootComponent, childActivities);
                            foreach (Activity activity3 in childActivities)
                            {
                                rootComponent.Activities.Add(activity3);
                            }
                            foreach (Activity activity4 in childActivities)
                            {
                                WorkflowDesignerLoader.AddActivityToDesigner(designerHost, activity4);
                            }
                        }
                    }
                }
            }
        }
 public void OnEndEditing(Point point, bool commitChanges)
 {
     if (this.activeEditPoint != null)
     {
         this.Invalidate();
         if (commitChanges)
         {
             this.UpdateEditPoints(point);
             EditPoint activeEditPoint = this.activeEditPoint;
             this.activeEditPoint = null;
             this.UpdateEditPoints(point);
             bool flag = false;
             if (activeEditPoint.Type == EditPoint.EditPointTypes.ConnectionEditPoint)
             {
                 ConnectionManager        service            = this.GetService(typeof(ConnectionManager)) as ConnectionManager;
                 FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(activeEditPoint.EditedConnectionPoint.AssociatedDesigner);
                 if (((service != null) && (service.SnappedConnectionPoint != null)) && (connectorContainer != null))
                 {
                     ConnectionPoint source = this.editedConnector.Source;
                     ConnectionPoint target = this.editedConnector.Target;
                     if (target.Equals(activeEditPoint.EditedConnectionPoint))
                     {
                         target = service.SnappedConnectionPoint;
                     }
                     else if (source.Equals(activeEditPoint.EditedConnectionPoint))
                     {
                         source = service.SnappedConnectionPoint;
                     }
                     if ((connectorContainer == ConnectionManager.GetConnectorContainer(target.AssociatedDesigner)) && connectorContainer.CanConnectContainedDesigners(source, target))
                     {
                         this.editedConnector.Source = source;
                         this.editedConnector.Target = target;
                         if (this.editedConnector.ParentDesigner == null)
                         {
                             this.editedConnector = connectorContainer.AddConnector(source, target);
                             WorkflowDesignerLoader loader = this.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                             if (loader != null)
                             {
                                 loader.SetModified(true);
                             }
                         }
                         connectorContainer.OnContainedDesignersConnected(source, target);
                     }
                     flag = true;
                 }
             }
             else
             {
                 flag = true;
             }
             if (flag)
             {
                 this.editedConnector.SetConnectorSegments(this.GetPointsFromEditPoints(this.editPoints));
                 if (this.editedConnector.ParentDesigner != null)
                 {
                     this.editedConnector.ParentDesigner.OnConnectorChanged(new ConnectorEventArgs(this.editedConnector));
                     WorkflowDesignerLoader loader2 = this.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                     if (loader2 != null)
                     {
                         loader2.SetModified(true);
                     }
                 }
             }
             this.PerformLayout();
         }
         this.Invalidate();
     }
 }
 internal IdentifierCreationService(IServiceProvider serviceProvider, WorkflowDesignerLoader loader)
 {
     this.serviceProvider = serviceProvider;
     this.loader          = loader;
 }
 internal IdentifierCreationService(IServiceProvider serviceProvider, WorkflowDesignerLoader loader)
 {
     this.serviceProvider = serviceProvider;
     this.loader = loader;
 }
        protected override void OnPrintPage(PrintPageEventArgs printPageArg)
        {
            base.OnPrintPage(printPageArg);
            AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
            Graphics     graphics     = printPageArg.Graphics;

            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode     = SmoothingMode.HighQuality;
            if (this.currentPrintablePage.IsEmpty)
            {
                this.PrepareToPrint(printPageArg);
            }
            Margins   hardMargins = this.GetHardMargins(graphics);
            Margins   margins2    = new Margins(Math.Max(printPageArg.PageSettings.Margins.Left, hardMargins.Left), Math.Max(printPageArg.PageSettings.Margins.Right, hardMargins.Right), Math.Max(printPageArg.PageSettings.Margins.Top, hardMargins.Top), Math.Max(printPageArg.PageSettings.Margins.Bottom, hardMargins.Bottom));
            Size      size        = new Size(printPageArg.PageBounds.Size.Width - (margins2.Left + margins2.Right), printPageArg.PageBounds.Size.Height - (margins2.Top + margins2.Bottom));
            Rectangle rect        = new Rectangle(margins2.Left, margins2.Top, size.Width, size.Height);
            Region    region      = new Region(rect);

            try
            {
                graphics.TranslateTransform((float)-hardMargins.Left, (float)-hardMargins.Top);
                graphics.FillRectangle(ambientTheme.BackgroundBrush, rect);
                graphics.DrawRectangle(ambientTheme.ForegroundPen, rect);
                if (ambientTheme.WorkflowWatermarkImage != null)
                {
                    ActivityDesignerPaint.DrawImage(graphics, ambientTheme.WorkflowWatermarkImage, rect, new Rectangle(Point.Empty, ambientTheme.WorkflowWatermarkImage.Size), ambientTheme.WatermarkAlignment, 0.25f, false);
                }
                Matrix transform = graphics.Transform;
                Region clip      = graphics.Clip;
                graphics.Clip = region;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                Point point = new Point((this.currentPrintablePage.X * size.Width) - this.workflowAlignment.X, (this.currentPrintablePage.Y * size.Height) - this.workflowAlignment.Y);
                graphics.TranslateTransform((float)(rect.Left - point.X), (float)(rect.Top - point.Y));
                graphics.ScaleTransform(this.scaling, this.scaling);
                Size empty = Size.Empty;
                empty.Width  = Convert.ToInt32(Math.Ceiling((double)(((float)size.Width) / this.scaling)));
                empty.Height = Convert.ToInt32(Math.Ceiling((double)(((float)size.Height) / this.scaling)));
                Point point2 = Point.Empty;
                point2.X = Convert.ToInt32(Math.Ceiling((double)(((float)this.workflowAlignment.X) / this.scaling)));
                point2.Y = Convert.ToInt32(Math.Ceiling((double)(((float)this.workflowAlignment.Y) / this.scaling)));
                Rectangle viewPort = new Rectangle((this.currentPrintablePage.X * empty.Width) - point2.X, (this.currentPrintablePage.Y * empty.Height) - point2.Y, empty.Width, empty.Height);
                using (PaintEventArgs args = new PaintEventArgs(graphics, this.workflowView.RootDesigner.Bounds))
                {
                    ((IWorkflowDesignerMessageSink)this.workflowView.RootDesigner).OnPaint(args, viewPort);
                }
                graphics.Clip      = clip;
                graphics.Transform = transform;
                HeaderFooterData headerFooterPrintData = new HeaderFooterData {
                    Font       = ambientTheme.Font,
                    PageBounds = printPageArg.PageBounds,
                    PageBoundsWithoutMargin = rect,
                    HeaderFooterMargins     = new Margins(0, 0, this.pageSetupData.HeaderMargin, this.pageSetupData.FooterMargin),
                    PrintTime   = this.printTime,
                    CurrentPage = (this.currentPrintablePage.X + (this.currentPrintablePage.Y * this.totalPrintablePages.X)) + 1,
                    TotalPages  = this.totalPrintablePages.X * this.totalPrintablePages.Y,
                    Scaling     = this.scaling
                };
                WorkflowDesignerLoader service = ((IServiceProvider)this.workflowView).GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                headerFooterPrintData.FileName = (service != null) ? service.FileName : string.Empty;
                if (this.pageSetupData.HeaderTemplate.Length > 0)
                {
                    this.PrintHeaderFooter(graphics, true, headerFooterPrintData);
                }
                if (this.pageSetupData.FooterTemplate.Length > 0)
                {
                    this.PrintHeaderFooter(graphics, false, headerFooterPrintData);
                }
                printPageArg.HasMorePages = this.MoveNextPage();
            }
            catch (Exception exception)
            {
                DesignerHelpers.ShowError(this.workflowView, DR.GetString("SelectedPrinterIsInvalidErrorMessage", new object[0]) + "\n" + exception.Message);
                printPageArg.Cancel       = true;
                printPageArg.HasMorePages = false;
            }
            finally
            {
                region.Dispose();
            }
            if (!printPageArg.HasMorePages)
            {
                this.workflowView.PerformLayout();
            }
        }
        public override void OnPaintWorkflow(PaintEventArgs e, ViewPortData viewPortData)
        {
            Graphics graphics = e.Graphics;

            Debug.Assert(graphics != null);
            Bitmap memoryBitmap = viewPortData.MemoryBitmap;

            Debug.Assert(memoryBitmap != null);

            //Get the drawing canvas
            AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;

            //We set the highest quality interpolation so that we do not loose the image quality
            GraphicsContainer graphicsState = graphics.BeginContainer();

            //Fill the background using the workspace color so that we communicate the paging concept
            Rectangle workspaceRectangle = new Rectangle(Point.Empty, memoryBitmap.Size);

            graphics.FillRectangle(AmbientTheme.WorkspaceBackgroundBrush, workspaceRectangle);

            using (Font headerFooterFont = new Font(ambientTheme.Font.FontFamily, ambientTheme.Font.Size / this.scaling, ambientTheme.Font.Style))
            {
                int    currentPage = 0;
                Matrix emptyMatrix = new Matrix();

                //Create the transformation matrix and calculate the physical viewport without translation and scaling
                //We need to get the physical view port due to the fact that there can be circustances when zoom percentage
                //is very high, logical view port can be empty in such cases
                Matrix coOrdTxMatrix = new Matrix();
                coOrdTxMatrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend);
                coOrdTxMatrix.Invert();
                Point[] points = new Point[] { viewPortData.Translation, new Point(viewPortData.ViewPortSize) };
                coOrdTxMatrix.TransformPoints(points);
                coOrdTxMatrix.Invert();
                Rectangle physicalViewPort = new Rectangle(points[0], new Size(points[1]));

                //Create the data for rendering header/footer
                WorkflowPrintDocument.HeaderFooterData headerFooterData = new WorkflowPrintDocument.HeaderFooterData();
                headerFooterData.HeaderFooterMargins = this.headerFooterMargins;
                headerFooterData.PrintTime           = this.previewTime;
                headerFooterData.TotalPages          = this.pageLayoutInfo.Count;
                headerFooterData.Scaling             = this.scaling;
                headerFooterData.Font = headerFooterFont;
                WorkflowDesignerLoader serviceDesignerLoader = this.serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                headerFooterData.FileName = (serviceDesignerLoader != null) ? serviceDesignerLoader.FileName : String.Empty;

                //Create the viewport transformation matrix
                Matrix viewPortMatrix = new Matrix();
                viewPortMatrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend);
                viewPortMatrix.Translate(-viewPortData.Translation.X, -viewPortData.Translation.Y, MatrixOrder.Append);

                //We now have the viewport properly drawn, now we need to draw it on the actual graphics object
                //Now that we have the designer bitmap we start splicing it based on the pages
                //Note that this is quite expensive operation and hence one should try to use
                //The memory bitmap we have got is scaled appropriately
                foreach (PageLayoutData pageLayoutData in this.pageLayoutInfo)
                {
                    currentPage += 1;

                    //We do not draw the non intersecting pages, get the intersected viewport
                    //We purposely use the physical viewport here because, there are cases in which the viewport
                    //will not contain any logical bitmap areas in which case we atleast need to draw the pages properly
                    if (!pageLayoutData.PageBounds.IntersectsWith(physicalViewPort) || pageLayoutData.PageBounds.Width <= 0 || pageLayoutData.PageBounds.Height <= 0)
                    {
                        continue;
                    }

                    //******START PAGE DRAWING, FIRST DRAW THE OUTLINE
                    //Scale and translate so that we can draw the pages
                    graphics.Transform = viewPortMatrix;
                    graphics.FillRectangle(Brushes.White, pageLayoutData.PageBounds);
                    ActivityDesignerPaint.DrawDropShadow(graphics, pageLayoutData.PageBounds, Color.Black, AmbientTheme.DropShadowWidth, LightSourcePosition.Left | LightSourcePosition.Top, 0.2f, false);

                    //***START BITMAP SPLICING
                    //Draw spliced bitmap for the page if we have any displayable area
                    Rectangle intersectedViewPort = pageLayoutData.LogicalPageBounds;
                    intersectedViewPort.Intersect(viewPortData.LogicalViewPort);
                    if (!intersectedViewPort.IsEmpty)
                    {
                        //Make sure that we now clear the translation factor
                        graphics.Transform = emptyMatrix;
                        //Paint bitmap on the pages
                        //Now that the page rectangle is actually drawn, we will scale down the Location of page rectangle
                        //so that we can draw the viewport bitmap part on it
                        Point bitmapDrawingPoint = Point.Empty;
                        bitmapDrawingPoint.X = pageLayoutData.ViewablePageBounds.X + Math.Abs(pageLayoutData.LogicalPageBounds.X - intersectedViewPort.X);
                        bitmapDrawingPoint.Y = pageLayoutData.ViewablePageBounds.Y + Math.Abs(pageLayoutData.LogicalPageBounds.Y - intersectedViewPort.Y);
                        points = new Point[] { bitmapDrawingPoint };
                        coOrdTxMatrix.TransformPoints(points);
                        bitmapDrawingPoint = new Point(points[0].X - viewPortData.Translation.X, points[0].Y - viewPortData.Translation.Y);

                        //This is the area of the viewport bitmap we need to copy on the page
                        Rectangle viewPortBitmapArea = Rectangle.Empty;
                        viewPortBitmapArea.X      = intersectedViewPort.X - viewPortData.LogicalViewPort.X;
                        viewPortBitmapArea.Y      = intersectedViewPort.Y - viewPortData.LogicalViewPort.Y;
                        viewPortBitmapArea.Width  = intersectedViewPort.Width;
                        viewPortBitmapArea.Height = intersectedViewPort.Height;

                        //This rectangle is in translated logical units, we need to scale it down
                        points = new Point[] { viewPortBitmapArea.Location, new Point(viewPortBitmapArea.Size) };
                        coOrdTxMatrix.TransformPoints(points);
                        viewPortBitmapArea.Location = points[0];
                        viewPortBitmapArea.Size     = new Size(points[1]);

                        ActivityDesignerPaint.DrawImage(graphics, memoryBitmap, new Rectangle(bitmapDrawingPoint, viewPortBitmapArea.Size), viewPortBitmapArea, DesignerContentAlignment.Fill, 1.0f, WorkflowTheme.CurrentTheme.AmbientTheme.DrawGrayscale);
                    }
                    //***END BITMAP SPLICING

                    //Draw the page outline
                    graphics.Transform = viewPortMatrix;
                    graphics.DrawRectangle(Pens.Black, pageLayoutData.PageBounds);

                    //Draw the printable page outline
                    graphics.DrawRectangle(ambientTheme.ForegroundPen, pageLayoutData.ViewablePageBounds.Left - 3, pageLayoutData.ViewablePageBounds.Top - 3, pageLayoutData.ViewablePageBounds.Width + 6, pageLayoutData.ViewablePageBounds.Height + 6);

                    //Draw the header and footer after we draw the actual page
                    headerFooterData.PageBounds = pageLayoutData.PageBounds;
                    headerFooterData.PageBoundsWithoutMargin = pageLayoutData.ViewablePageBounds;
                    headerFooterData.CurrentPage             = currentPage;

                    //Draw the header
                    if (this.printDocument.PageSetupData.HeaderTemplate.Length > 0)
                    {
                        this.printDocument.PrintHeaderFooter(graphics, true, headerFooterData);
                    }

                    //Draw footer
                    if (this.printDocument.PageSetupData.FooterTemplate.Length > 0)
                    {
                        this.printDocument.PrintHeaderFooter(graphics, false, headerFooterData);
                    }
                    //***END DRAWING HEADER FOOTER
                }

                graphics.EndContainer(graphicsState);
            }
        }
        public override void OnPaintWorkflow(PaintEventArgs e, ViewPortData viewPortData)
        {
            Graphics          graphics     = e.Graphics;
            Bitmap            memoryBitmap = viewPortData.MemoryBitmap;
            AmbientTheme      ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
            GraphicsContainer container    = graphics.BeginContainer();
            Rectangle         rect         = new Rectangle(Point.Empty, memoryBitmap.Size);

            graphics.FillRectangle(AmbientTheme.WorkspaceBackgroundBrush, rect);
            using (Font font = new Font(ambientTheme.Font.FontFamily, ambientTheme.Font.Size / this.scaling, ambientTheme.Font.Style))
            {
                int    num     = 0;
                Matrix matrix  = new Matrix();
                Matrix matrix2 = new Matrix();
                matrix2.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend);
                matrix2.Invert();
                Point[] pts = new Point[] { viewPortData.Translation, new Point(viewPortData.ViewPortSize) };
                matrix2.TransformPoints(pts);
                matrix2.Invert();
                Rectangle rectangle2 = new Rectangle(pts[0], new Size(pts[1]));
                WorkflowPrintDocument.HeaderFooterData headerFooterPrintData = new WorkflowPrintDocument.HeaderFooterData {
                    HeaderFooterMargins = this.headerFooterMargins,
                    PrintTime           = this.previewTime,
                    TotalPages          = this.pageLayoutInfo.Count,
                    Scaling             = this.scaling,
                    Font = font
                };
                WorkflowDesignerLoader service = base.serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                headerFooterPrintData.FileName = (service != null) ? service.FileName : string.Empty;
                Matrix matrix3 = new Matrix();
                matrix3.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend);
                matrix3.Translate((float)-viewPortData.Translation.X, (float)-viewPortData.Translation.Y, MatrixOrder.Append);
                foreach (PageLayoutData data2 in this.pageLayoutInfo)
                {
                    num++;
                    if ((data2.PageBounds.IntersectsWith(rectangle2) && (data2.PageBounds.Width > 0)) && (data2.PageBounds.Height > 0))
                    {
                        graphics.Transform = matrix3;
                        graphics.FillRectangle(Brushes.White, data2.PageBounds);
                        ActivityDesignerPaint.DrawDropShadow(graphics, data2.PageBounds, Color.Black, 4, LightSourcePosition.Top | LightSourcePosition.Left, 0.2f, false);
                        Rectangle logicalPageBounds = data2.LogicalPageBounds;
                        logicalPageBounds.Intersect(viewPortData.LogicalViewPort);
                        if (!logicalPageBounds.IsEmpty)
                        {
                            graphics.Transform = matrix;
                            Point empty = Point.Empty;
                            empty.X = data2.ViewablePageBounds.X + Math.Abs((int)(data2.LogicalPageBounds.X - logicalPageBounds.X));
                            empty.Y = data2.ViewablePageBounds.Y + Math.Abs((int)(data2.LogicalPageBounds.Y - logicalPageBounds.Y));
                            pts     = new Point[] { empty };
                            matrix2.TransformPoints(pts);
                            empty = new Point(pts[0].X - viewPortData.Translation.X, pts[0].Y - viewPortData.Translation.Y);
                            Rectangle source = Rectangle.Empty;
                            source.X      = logicalPageBounds.X - viewPortData.LogicalViewPort.X;
                            source.Y      = logicalPageBounds.Y - viewPortData.LogicalViewPort.Y;
                            source.Width  = logicalPageBounds.Width;
                            source.Height = logicalPageBounds.Height;
                            pts           = new Point[] { source.Location, new Point(source.Size) };
                            matrix2.TransformPoints(pts);
                            source.Location = pts[0];
                            source.Size     = new Size(pts[1]);
                            ActivityDesignerPaint.DrawImage(graphics, memoryBitmap, new Rectangle(empty, source.Size), source, DesignerContentAlignment.Fill, 1f, WorkflowTheme.CurrentTheme.AmbientTheme.DrawGrayscale);
                        }
                        graphics.Transform = matrix3;
                        graphics.DrawRectangle(Pens.Black, data2.PageBounds);
                        graphics.DrawRectangle(ambientTheme.ForegroundPen, (int)(data2.ViewablePageBounds.Left - 3), (int)(data2.ViewablePageBounds.Top - 3), (int)(data2.ViewablePageBounds.Width + 6), (int)(data2.ViewablePageBounds.Height + 6));
                        headerFooterPrintData.PageBounds = data2.PageBounds;
                        headerFooterPrintData.PageBoundsWithoutMargin = data2.ViewablePageBounds;
                        headerFooterPrintData.CurrentPage             = num;
                        if (this.printDocument.PageSetupData.HeaderTemplate.Length > 0)
                        {
                            this.printDocument.PrintHeaderFooter(graphics, true, headerFooterPrintData);
                        }
                        if (this.printDocument.PageSetupData.FooterTemplate.Length > 0)
                        {
                            this.printDocument.PrintHeaderFooter(graphics, false, headerFooterPrintData);
                        }
                    }
                }
                graphics.EndContainer(container);
            }
        }
        internal static ReadOnlyCollection <DesignerView> GetViews(StructuredCompositeActivityDesigner designer)
        {
            Debug.Assert(designer.Activity != null);
            if (designer.Activity == null)
            {
                throw new ArgumentException("Component can not be null!");
            }

            bool locked = !designer.IsEditable;

            //Get all the possible view types
            List <object[]> viewTypes = new List <object[]>();

            string displayName = ActivityToolboxItem.GetToolboxDisplayName(designer.Activity.GetType());

            viewTypes.Add(new object[] { designer.Activity.GetType(), DR.GetString(DR.ViewActivity, displayName) });

            //Only show the views in workflow designer or for nested activities
            if (designer.Activity.Site != null)
            {
                WorkflowDesignerLoader loader = designer.Activity.Site.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                Type activityType             = designer.Activity.GetType();

                if (loader == null ||
                    (typeof(CompositeActivity).IsAssignableFrom(activityType) &&
                     (!locked || FindActivity(designer, typeof(CancellationHandlerActivity)) != null)))
                {
                    viewTypes.Add(new object[] { typeof(CancellationHandlerActivity), DR.GetString(DR.ViewCancelHandler) });
                }

                if (loader == null ||
                    (typeof(CompositeActivity).IsAssignableFrom(activityType) &&
                     (!locked || FindActivity(designer, typeof(FaultHandlersActivity)) != null)))
                {
                    viewTypes.Add(new object[] { typeof(FaultHandlersActivity), DR.GetString(DR.ViewExceptions) });
                }

                if (loader == null ||
                    (designer.Activity is ICompensatableActivity && typeof(CompositeActivity).IsAssignableFrom(activityType) &&
                     (!locked || FindActivity(designer, typeof(CompensationHandlerActivity)) != null)))
                {
                    viewTypes.Add(new object[] { typeof(CompensationHandlerActivity), DR.GetString(DR.ViewCompensation) });
                }

                if (loader == null ||
                    (Type.GetType(EventHandlingScopeRef).IsAssignableFrom(activityType) &&
                     (!locked || FindActivity(designer, Type.GetType(EventHandlersRef)) != null)))
                {
                    viewTypes.Add(new object[] { Type.GetType(EventHandlersRef), DR.GetString(DR.ViewEvents) });
                }
            }

            //Now go through the view types and create views
            List <DesignerView> views = new List <DesignerView>();

            for (int i = 0; i < viewTypes.Count; i++)
            {
                Type         viewType = viewTypes[i][0] as Type;
                DesignerView view     = new SecondaryView(designer, i + 1, viewTypes[i][1] as string, viewType);
                views.Add(view);
            }

            return(views.AsReadOnly());
        }
Exemplo n.º 16
0
 public CustomMessageFilter(IServiceProvider provider, WorkflowView workflowView, WorkflowDesignerLoader loader)
 {
     this.serviceProvider = provider;
     this.workflowView = workflowView;
     this.loader = loader;
 }
Exemplo n.º 17
0
        protected override void OnPrintPage(PrintPageEventArgs printPageArg)
        {
            base.OnPrintPage(printPageArg);

            AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;

            Graphics graphics = printPageArg.Graphics;

            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode     = SmoothingMode.HighQuality;

            //STEP1: We get the printer graphics only in the OnPrintPage function hence for layouting we need to call this function
            if (this.currentPrintablePage.IsEmpty)
            {
                PrepareToPrint(printPageArg);
            }

            //STEP2: GET ALL THE VALUES NEEDED FOR CALCULATION
            Margins hardMargins = GetHardMargins(graphics);
            Margins margins     = new Margins(Math.Max(printPageArg.PageSettings.Margins.Left, hardMargins.Left),
                                              Math.Max(printPageArg.PageSettings.Margins.Right, hardMargins.Right),
                                              Math.Max(printPageArg.PageSettings.Margins.Top, hardMargins.Top),
                                              Math.Max(printPageArg.PageSettings.Margins.Bottom, hardMargins.Bottom));
            Size      printableArea     = new Size(printPageArg.PageBounds.Size.Width - (margins.Left + margins.Right), printPageArg.PageBounds.Size.Height - (margins.Top + margins.Bottom));
            Rectangle boundingRectangle = new Rectangle(margins.Left, margins.Top, printableArea.Width, printableArea.Height);
            Region    clipRegion        = new Region(boundingRectangle);

            try
            {
                graphics.TranslateTransform(-hardMargins.Left, -hardMargins.Top);
                graphics.FillRectangle(ambientTheme.BackgroundBrush, boundingRectangle);
                graphics.DrawRectangle(ambientTheme.ForegroundPen, boundingRectangle);

                //Draw the watermark image
                if (ambientTheme.WorkflowWatermarkImage != null)
                {
                    ActivityDesignerPaint.DrawImage(graphics, ambientTheme.WorkflowWatermarkImage, boundingRectangle, new Rectangle(Point.Empty, ambientTheme.WorkflowWatermarkImage.Size), ambientTheme.WatermarkAlignment, AmbientTheme.WatermarkTransparency, false);
                }

                Matrix oldTransform  = graphics.Transform;
                Region oldClipRegion = graphics.Clip;
                graphics.Clip = clipRegion;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                //STEP3: PRINT
                //Printer bitmap starts at the unprintable top left corner, hence, need to take it into account - move by the unprintable area:
                //Setup the translation and scaling for the page printing
                Point pageOffset = new Point(this.currentPrintablePage.X * printableArea.Width - this.workflowAlignment.X, this.currentPrintablePage.Y * printableArea.Height - this.workflowAlignment.Y);
                graphics.TranslateTransform(boundingRectangle.Left - pageOffset.X, boundingRectangle.Top - pageOffset.Y);
                graphics.ScaleTransform(this.scaling, this.scaling);

                //Calculate the viewport by reverse scaling the printable area size
                Size viewPortSize = Size.Empty;
                viewPortSize.Width  = Convert.ToInt32(Math.Ceiling((float)printableArea.Width / this.scaling));
                viewPortSize.Height = Convert.ToInt32(Math.Ceiling((float)printableArea.Height / this.scaling));

                Point scaledAlignment = Point.Empty;
                scaledAlignment.X = Convert.ToInt32(Math.Ceiling((float)this.workflowAlignment.X / this.scaling));
                scaledAlignment.Y = Convert.ToInt32(Math.Ceiling((float)this.workflowAlignment.Y / this.scaling));

                Rectangle viewPort = new Rectangle(this.currentPrintablePage.X * viewPortSize.Width - scaledAlignment.X, this.currentPrintablePage.Y * viewPortSize.Height - scaledAlignment.Y, viewPortSize.Width, viewPortSize.Height);

                using (PaintEventArgs paintEventArgs = new PaintEventArgs(graphics, this.workflowView.RootDesigner.Bounds))
                {
                    ((IWorkflowDesignerMessageSink)this.workflowView.RootDesigner).OnPaint(paintEventArgs, viewPort);
                }

                graphics.Clip      = oldClipRegion;
                graphics.Transform = oldTransform;

                //Now prepare the graphics for header footer printing
                HeaderFooterData headerFooterData = new HeaderFooterData();
                headerFooterData.Font       = ambientTheme.Font;
                headerFooterData.PageBounds = printPageArg.PageBounds;
                headerFooterData.PageBoundsWithoutMargin = boundingRectangle;
                headerFooterData.HeaderFooterMargins     = new Margins(0, 0, this.pageSetupData.HeaderMargin, this.pageSetupData.FooterMargin);
                headerFooterData.PrintTime   = this.printTime;
                headerFooterData.CurrentPage = this.currentPrintablePage.X + this.currentPrintablePage.Y * this.totalPrintablePages.X + 1;
                headerFooterData.TotalPages  = this.totalPrintablePages.X * this.totalPrintablePages.Y;
                headerFooterData.Scaling     = this.scaling;
                WorkflowDesignerLoader serviceDesignerLoader = ((IServiceProvider)this.workflowView).GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                headerFooterData.FileName = (serviceDesignerLoader != null) ? serviceDesignerLoader.FileName : String.Empty;

                //Print the header
                if (this.pageSetupData.HeaderTemplate.Length > 0)
                {
                    PrintHeaderFooter(graphics, true, headerFooterData);
                }

                //footer
                if (this.pageSetupData.FooterTemplate.Length > 0)
                {
                    PrintHeaderFooter(graphics, false, headerFooterData);
                }

                //are there more pages left?
                printPageArg.HasMorePages = MoveNextPage();
            }
            catch (Exception exception)
            {
                DesignerHelpers.ShowError(this.workflowView, DR.GetString(DR.SelectedPrinterIsInvalidErrorMessage) + "\n" + exception.Message);
                printPageArg.Cancel       = true;
                printPageArg.HasMorePages = false;
            }
            finally
            {
                clipRegion.Dispose();
            }

            if (!printPageArg.HasMorePages)
            {
                this.workflowView.PerformLayout(); //no more pages - redo regular layout using screen graphics
            }
        }