Пример #1
0
 /// <summary>
 /// Where the shape is connected from
 /// </summary>
 /// <returns>The name of the shape</returns>
 public string ConnectedFrom()
 {
     if (VisioShape.Connects.Count > 1)
     {
         Microsoft.Office.Interop.Visio.Shape to = VisioShape.Connects[1].ToCell.Shape;
         return(VisioUtils.GetProperty(to, "User", "QuartzShape"));
     }
     return(null);
 }
Пример #2
0
        /// <summary>
        /// Called when the drop occurs onto a page, performing sequence
        /// initialization.
        /// </summary>
        protected void OnPageDrop()
        {
            XmlNodeList sequenceElemts = (XmlNodeList)_attributes.SelectNodes("sequence[ @ref ]", FormsNamespace.NamespaceManager);

            if (sequenceElemts == null)
            {
                return;
            }
            StringBuilder sb = new StringBuilder("<properties>");

            foreach (XmlNode sequenceElem in sequenceElemts)
            {
                string property = sequenceElem.Attributes["ref"].Value;
                string format   = sequenceElem.Attributes["format"].Value;
                string pattern  = string.Format(CultureInfo.InvariantCulture,
                                                "<{0}>{1}</{0}>",
                                                property,
                                                sequenceElem.Attributes["pattern"].Value);

                Regex regex = new Regex(pattern, RegexOptions.ExplicitCapture);
                int   max   = 0;

                foreach (Shape iterShape in _shape.ContainingPage.Shapes)
                {
                    string shapeName = VisioUtils.GetProperty(iterShape, "User", "QuartzShape");
                    if (shapeName == null)
                    {
                        continue;
                    }

                    string shapeXml = VisioUtils.GetProperty(iterShape, "Prop", "ShapeXML");

                    Match m = regex.Match(shapeXml);
                    if (m.Success == false)
                    {
                        continue;
                    }

                    int index = int.Parse(m.Groups["index"].Value, CultureInfo.InvariantCulture);

                    if (index > max)
                    {
                        max = index;
                    }
                }


                sb.AppendFormat("<{0}>", property);
                sb.AppendFormat(format, ++max);
                sb.AppendFormat("</{0}>", property);
            }
            sb.AppendFormat("</properties>");
            VisioUtils.SetProperty(_shape, "Prop", "ShapeXML", sb.ToString());
        }
Пример #3
0
        /// <summary>
        /// Requests that the shape process the shape command.
        /// </summary>
        /// <param name="command">Command requested by the shape.</param>
        /// <param name="context">Execution context: these are the arguments specified in the event. Please
        /// note that the command is one of the arguments.</param>
        /// <param name="settings">Display settings.</param>
        /// <returns>New display settings.</returns>
        public DisplaySettings Execute(string command, NameValueCollection context, DisplaySettings settings, bool forceChange)
        {
            bool dropEvent = (string.IsNullOrEmpty(VisioUtils.GetProperty(_shape, "Prop", "ShapeXML")));

            if (command == "drop" && !dropEvent)
            {
                return(settings);
            }

            /*
             * If the command was a "drop" (shape dragged from stencil into page)
             * then execute it right now. This must be done before the following
             * statement.
             */
            if (command == "drop")
            {
                OnPageDrop();
            }


            /*
             *
             */
            string shapeXml = null;

            if (forceChange && VisioUtils.ShapeCustomProps != null)
            {
                shapeXml = VisioUtils.ShapeCustomProps;
                VisioUtils.SetProperty(VisioShape, "Prop", "ShapeXML", shapeXml);
            }
            else
            {
                shapeXml = VisioUtils.GetProperty(VisioShape, "Prop", "ShapeXML");
            }
            Form.SetShapeXml(shapeXml);

            /*
             * Command router.
             */
            switch (command)
            {
            case "drop":
            case "edit":
                return(OnShapeEdit(command, context, settings, forceChange));

            default:
                return(OnExecuteCustom(command, context, settings));
            }
        }
Пример #4
0
        /// <summary>
        /// Loads the properties from the Visio shape.
        /// </summary>
        public void LoadProperties()
        {
            string shapeXml = VisioUtils.GetProperty(VisioShape, "Prop", "ShapeXML");

            Form.SetShapeXml(shapeXml);
        }
Пример #5
0
        private PageReport DoPageValidation(Page page, string mode,
                                            out Dictionary <IShapeHandler, Shape> mapping,
                                            out List <IShapeHandler> webPages, out List <IShapeHandler> transitions)
        {
            PageReport report        = new PageReport(page);
            Hashtable  shapeHandlers = new Hashtable();
            Hashtable  fromConns     = new Hashtable();
            Hashtable  toConns       = new Hashtable();

            mapping     = new Dictionary <IShapeHandler, Shape>();
            webPages    = new List <IShapeHandler>();
            transitions = new List <IShapeHandler>();

            try
            {
                int processedShapes = 0;

                /*
                 * Iterate through all the shapes in the current page, generating
                 * the overall graph of the shapes. This effectively preloads all
                 * of the information into memory.
                 */
                #region Preloading, Construct Graph

                foreach (Shape shape in page.Shapes)
                {
                    string progressMessage = string.Format("Page: {0}, Shape: {1}, scanning...", page.Name, shape.Name);
                    OnStartStep(progressMessage);

                    string shapeName = VisioUtils.GetProperty(shape, "User", "Midgard");


                    if (shapeName == null)
                    {
                        OnEndStep("skip");
                        continue;
                    }

                    processedShapes++;

                    IShapeHandler shapeHandler = GetShapeHandler(shapeHandlers, shape, shapeName, mode);
                    mapping.Add(shapeHandler, shape);

                    if ("transition" == shapeHandler.Element && 2 <= shape.Connects.Count)
                    {
                        SetShapeConn(fromConns, shape.Connects[1].ToCell.Shape, shapeHandler);
                        SetShapeConn(toConns, shape.Connects[2].ToCell.Shape, shapeHandler);
                    }
                    OnEndStep("ok.");
                }

                /*
                 * If no processable shapes have been encountered, then reset the
                 * processed bit to false and quit early...
                 */
                if (processedShapes == 0)
                {
                    report.Processed = false;
                    _currentStep    += page.Shapes.Count;

                    return(report);
                }

                #endregion

                #region Connections Validation (client side)

                foreach (IShapeHandler h in shapeHandlers.Values)
                {
                    ShapeError error;
                    OnStartStep(string.Format("A validar localmente a shape {0}", h.Text.Replace('\n', ' ')));
                    switch (h.Element)
                    {
                    case "transition":
                        error = h.Validate(shapeHandlers);
                        transitions.Add(h);
                        break;

                    default:
                        ArrayList from = (ArrayList)fromConns[h.VisioShape];
                        ArrayList to   = (ArrayList)toConns[h.VisioShape];
                        error = h.Validate(new object[] { from, to });
                        webPages.Add(h);
                        break;
                    }

                    if (error != null)
                    {
                        report.Errors.Add(error);
                    }
                }

                /*
                 * Contains errors: abort! || only clientValidation
                 */
                if (report.Errors.Count > 0)
                {
                    _currentStep += page.Shapes.Count;
                    return(report);
                }

                if (0 == shapeHandlers.Count)
                {
                    report.Errors.Add(new ShapeError(Resources.GetString(ResourceTokens.NoDiagram)));
                    return(report);
                }

                #endregion Connections Validation (client side)

                #region Data Validation (server side)

                if (report.Errors.Count > 0)
                {
                    _currentStep += page.Shapes.Count;
                    return(report);
                }

                #endregion Data Validation (server side)
            }
            catch (Exception e)
            {
                report.Errors.Add(new ShapeError(e.StackTrace));
            }
            finally
            {
                /*
                 * Avoid maintaining a reference to Interop COM objects. Release
                 * all of the content of the graph to avoid memory leaks.
                 */
                foreach (IShapeHandler h in shapeHandlers.Values)
                {
                    (h as IDisposable).Dispose();
                }

                shapeHandlers.Clear();
                fromConns.Clear();
                toConns.Clear();
            }

            return(report);
        }