Exemplo n.º 1
0
        /// <summary>
        /// Paints the Visio shape as a valid shape.
        /// </summary>
        public virtual bool PaintAsValid()
        {
            string colorIndex = Resources.GetString(ResourceTokens.ShapeLineColorOk);

            VisioUtils.PaintShape(VisioShape, colorIndex);
            return(colorIndex != "2");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Paints the Visio shape as a not match shape.
        /// </summary>
        public virtual bool PaintAsNoMatch()
        {
            string colorIndex = Resources.GetString(ResourceTokens.ShapeLineColorNoMatch);

            VisioUtils.PaintShape(VisioShape, colorIndex);
            return(true);
        }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
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));
            }
        }
Exemplo n.º 6
0
 public override bool PaintAsValid()
 {
     return(VisioUtils.PaintColoredTransition(VisioShape, this.Attributes.SelectNodes("paint", FormsNamespace.NamespaceManager)));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Edits the properties of the designated shape.
        /// </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>
        protected DisplaySettings OnShapeEdit(string command, NameValueCollection context, DisplaySettings settings, bool forceChange)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (Form.PropertyCount == 0)
            {
                return(settings);
            }

            DisplaySettings ns = (DisplaySettings)settings.Clone();

            Form.Left            = settings.Left;
            Form.Top             = settings.Top;
            Form.SelectedTabName = settings.TabName;
            if (!forceChange)
            {
                Form.ShowDialog();
            }


            if (Form.DialogResult == DialogResult.OK || forceChange)
            {
                XmlDocument xml = Form.GetShapeXml();

                string shapeText = GetShapeText(xml);

                #region Channel Text
                StringBuilder channelText = new StringBuilder();

                foreach (XmlElement xe in xml.SelectNodes("properties/channels/channel"))
                {
                    if (channelText.Length == 0)
                    {
                        channelText.Append("[");
                    }
                    else
                    {
                        channelText.Append(", ");
                    }
                    channelText.Append(xe.InnerText);
                }
                if (channelText.Length > 0)
                {
                    channelText.Append(']');
                }

                #endregion

                SetShapeText(shapeText, channelText.ToString());

                VisioUtils.SetProperty(_shape, "Prop", "ShapeXML", xml.OuterXml);

                ns.TabName = Form.SelectedTabName;
            }
            else
            {
                if (command == "drop")
                {
                    try
                    {
                        VisioShape.Delete();
                    }
                    catch (Exception) { }
                }
            }

            ns.Left = Form.Left;
            ns.Top  = Form.Top;

            return(ns);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Loads the properties from the Visio shape.
        /// </summary>
        public void LoadProperties()
        {
            string shapeXml = VisioUtils.GetProperty(VisioShape, "Prop", "ShapeXML");

            Form.SetShapeXml(shapeXml);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Sets the shape text on a Tab shape.
        /// </summary>
        /// <param name="text">Text to show.</param>
        protected override void SetShapeText(string text)
        {
            try
            {
                XmlNode labelSpanNode  = null;
                string  labelSpanValue = labelSpanDefault;
                int     labelSpan;
                if (base.GetProperties() != null)
                {
                    labelSpanNode = base.GetProperties().SelectSingleNode("//labelSpan");
                    if (labelSpanNode != null)
                    {
                        labelSpanValue = labelSpanNode.InnerText;
                    }
                    try
                    {
                        labelSpan = int.Parse(labelSpanValue);
                        if (labelSpan < 1)
                        {
                            labelSpanValue = labelSpanDefault;
                        }
                    } catch (Exception)
                    {
                        labelSpanValue = labelSpanDefault;
                    }
                }

                bool writeText = false;

                // BEGIN_HAMMER
                Control c = (Control)Form["columns"];
                if (c == null)
                {
                    c = (Control)Form["items"];
                    if (c != null)
                    {
                        writeText = true;
                    }
                }
                if (c == null)
                {
                    c = (Control)Form["tabs"];
                }
                // END_HAMMER

                ListBox lb = (ListBox)c.Controls[5];
                int     count = lb.Items.Count;
                int     index, min, max;

                // Mostra por defeito 3 elementos (para o caso de ser populado por uma lov)
                int cnt = lb.Items.Count;
                if (cnt == 0)
                {
                    cnt = 3;
                }

                VisioUtils.SetProperty(VisioShape, "Prop", "ValidItems", lb.Items.Count.ToString());
                min = count + 1;
                max = columnsXMax + 1;
                for (index = min; index < max; index++)
                {
                    VisShape center = VisioShape.Shapes[index];
                    center.get_Cells("LockTextEdit").ResultIU = 0;
                    center.Text = string.Empty;
                    center.get_Cells("LockTextEdit").ResultIU = 1;
                }

                for (index = 1; index < min; index++)
                {
                    VisShape center = VisioShape.Shapes[index];
                    center.get_Cells("LockTextEdit").ResultIU = 0;
                    Object obj = lb.Items[index - 1];
                    center.Text = obj.ToString();
                    center.get_Cells("LockTextEdit").ResultIU = 1;
                }

                if (writeText)
                {
                    for (int i = 1; i <= VisioShape.Shapes.Count; i++)
                    {
                        VisShape center  = VisioShape.Shapes[i];
                        int      isInput = VisioUtils.GetPropertyInt(center, "Prop", "Label");
                        if (isInput > 0)
                        {
                            if (labelSpanValue != null)
                            {
                                VisioUtils.SetProperty(center, "User", "LabelLen", labelSpanValue);
                            }

                            center.get_Cells("LockTextEdit").ResultIU = 0;
                            center.Text = text;
                            center.get_Cells("LockTextEdit").ResultIU = 1;
                            i = VisioShape.Shapes.Count + 1;
                        }
                    }
                }
            } catch (FormatException)
            {
                ESIMessageBox.ShowError(Resources.GetString(ResourceTokens.ShapeTableColumns));
            }
        }