private IShapeHandler GetShapeHandler(Hashtable dictionary, Shape shape, string shapeName, string mode) { IShapeHandler shapeHandler = (IShapeHandler)dictionary[shape]; if (shapeHandler != null) { return(shapeHandler); } XmlForm form = new XmlForm(); form.LoadDefinition(shapeName, shape); form.SkipDesign = _skip; if (!_skip) { form.Design(mode); } shapeHandler = (IShapeHandler)form.Tag; shapeHandler.LoadProperties(); dictionary[shape] = shapeHandler; return(shapeHandler); }
private string[] GetFields(IShapeHandler shape) { if (null == shape.GetProperties()["fields"]) { return(new string[0]); } string fieldInfo = shape.GetProperties()["fields"].InnerXml; int begin = 0, end = 0, pointer = 0; List <string> toReturn = new List <string>(); while (true) { begin = fieldInfo.IndexOf("<value>", pointer); if (-1 == begin) { break; } pointer = begin; end = fieldInfo.IndexOf("</value>", pointer); pointer = end; toReturn.Add(fieldInfo.Substring(begin + 7, end - (begin + 7))); } return(toReturn.ToArray()); }
private PageReport PaintInvalid(Page page, PageReport report, string mode) { int invalidCount = 0; Hashtable shapeHandlers = new Hashtable(); CgoConfig[] Cgo = CgoConfigs.Search(); GroupElementTable groupElementTable = new GroupElementTable(); ElementTable elementTable = new ElementTable(); foreach (Shape shape in page.Shapes) { string shapeName = VisioUtils.GetProperty(shape, "User", "ScreenShape"); if (shapeName == null) { continue; } IShapeHandler shapeHandler = GetShapeHandler(shapeHandlers, shape, shapeName, mode); if (shape.Data1 == _INVALID) { shapeHandler.PaintAsInvalid(); } else { if (Cgo != null) { XmlNode shapeProperties = shapeHandler.GetProperties(); XmlNode cgoNode = shapeProperties.SelectSingleNode("cgoName"); if (cgoNode != null) { string cgoCode = cgoNode.InnerText; if (!CgoConfigs.Exists(Cgo, cgoCode)) { } } } } invalidCount++; string groupElementName = VisioUtils.GetProperty(shape, "Prop", "Group"); string elementName = VisioUtils.GetProperty(shape, "Prop", "Element"); if ((groupElementName == null) || (elementName == null)) { continue; } GroupElement groupElement = new GroupElement(groupElementName); groupElementTable.AddGroupElement(groupElement); Element element = new Element(elementName); elementTable.AddElement(element); } report = ShapeGroupValidation.Validate(groupElementTable, elementTable, report); return(report); }
private void SetShapeConn(Hashtable connections, Shape shape, IShapeHandler shapeHandler) { ArrayList list = (ArrayList)connections[shape]; if (list == null) { list = new ArrayList(); connections[shape] = list; } list.Add(shapeHandler); }
/// <summary> /// Handles the marker events. /// </summary> /// <param name="context">Parsed event context.</param> private void HandleMarkerEvent(NameValueCollection context) { Shape shape = VisioUtils.GetShape(_application, context); if (shape == null) { return; } string shapeName = VisioUtils.GetProperty(shape, "User", "Midgard"); if (shapeName == null) { // se for um visio desenhado com a versão antiga (sem os layers) shapeName = VisioUtils.GetShapeType(shape); if (shapeName == null) { return; } } string command = context["cmd"]; if (command == null) { return; } /* * */ string mode = "live";// GetMode(); using (XmlForm form = new XmlForm()) { form.LoadDefinition(shapeName, shape); form.Design(mode, Application.ActivePage); IShapeHandler shapeHandler = (IShapeHandler)form.Tag; DisplaySettings newSettings = shapeHandler.Execute(command, context, _displaySettings, _forceFormChange); if (newSettings != null) { _displaySettings = newSettings; } } }
/// <summary> /// Performs context validation on the current shape. /// </summary> /// <param name="validationData">Context dependent validation data.</param> /// <returns>A non-empty string in case of error, otherwise null.</returns> protected override string DoContextValidation(object validationData) { StringBuilder sb = new StringBuilder(); Hashtable handlers = (Hashtable)validationData; if (VisioShape.Connects.Count != 2) { sb.Append(Resources.GetString(ResourceTokens.TransitionNotConnected)); } else { IShapeHandler from = (IShapeHandler)handlers[VisioShape.Connects[1].ToCell.Shape]; IShapeHandler to = (IShapeHandler)handlers[VisioShape.Connects[2].ToCell.Shape]; if (from == null) { sb.Append(Resources.GetString(ResourceTokens.TransitionConnectedFromInvalidShape)); } else if (from.Type == ModelShapeType.Transition) { sb.Append(Resources.GetString(ResourceTokens.TransitionConnectedFromTransitionShape)); } if (to == null) { sb.Append(Resources.GetString(ResourceTokens.TransitionConnectedToInvalidShape)); } else if (to.Type == ModelShapeType.Transition) { sb.Append(Resources.GetString(ResourceTokens.TransitionConnectedToTransitionShape)); } } return(sb.ToString()); }
/// <summary> /// Adds a single export error, originated in the given shape. /// </summary> /// <param name="shape">Handler for the invalid shape.</param> /// <param name="message">Error message.</param> public void Add( IShapeHandler shape, string message ) { ShapeError e = new ShapeError( shape, message ); Add( e ); }
private string[] GetFields(IShapeHandler shape) { if (null == shape.GetProperties()["fields"]) return new string[0]; string fieldInfo = shape.GetProperties()["fields"].InnerXml; int begin = 0, end = 0, pointer = 0; List<string> toReturn = new List<string>(); while (true) { begin = fieldInfo.IndexOf("<value>", pointer); if (-1 == begin) break; pointer = begin; end = fieldInfo.IndexOf("</value>", pointer); pointer = end; toReturn.Add(fieldInfo.Substring(begin+7,end-(begin+7))); } return toReturn.ToArray(); }
public ShapeError(string message) { _shapeHandler = null; _message = message; }
/// <summary> /// Initializes a new instance of the ShapeError class. /// </summary> /// <param name="shapeHandler">Handler class for shape.</param> /// <param name="message">Error message.</param> public ShapeError( IShapeHandler shapeHandler, string message ) { _shapeHandler = shapeHandler; _message = message; }
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); }
/// <summary> /// Initializes a new instance of the ShapeError class. /// </summary> /// <param name="shapeHandler">Handler class for shape.</param> /// <param name="message">Error message.</param> public ShapeError(IShapeHandler shapeHandler, string message) { _shapeHandler = shapeHandler; _message = message; }
/// <summary> /// Adds a single export error, originated in the given shape. /// </summary> /// <param name="shape">Handler for the invalid shape.</param> /// <param name="message">Error message.</param> public void Add(IShapeHandler shape, string message) { ShapeError e = new ShapeError(shape, message); Add(e); }