Esempio n. 1
0
        public IActionResult Index(string command)
        {
            IShapeDefinition definition = null;
            string           error      = null;

            try
            {
                definition = shapeDefinitionParser.Parse(command);
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }
            return(View("Index", new IndexViewModel
            {
                Command = command,
                Shape = definition,
                Error = error
            }));
        }
Esempio n. 2
0
        public void Initialize(IShapeDefinition shape, string mode, string shapeCode, string shapeXml)
        {
            #region Validations

            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            if (mode == null)
            {
                throw new ArgumentNullException(nameof(mode));
            }

            #endregion


            /*
             *
             */
            if (string.IsNullOrEmpty(shapeCode) == true)
            {
                this.Text = shape.FriendlyName;
            }
            else
            {
                this.Text = string.Concat(shape.FriendlyName, ": ", shapeCode);
            }


            /*
             *
             */
            Dictionary <string, string> values = new Dictionary <string, string>();

            if (string.IsNullOrEmpty(shapeXml) == false)
            {
                XmlDocument docShapeXml = new XmlDocument();
                docShapeXml.LoadXml(shapeXml);

                foreach (XmlElement elem in docShapeXml.SelectNodes(" /r/* "))
                {
                    values.Add(elem.LocalName, elem.InnerText);
                }
            }


            /*
             *
             */
            var config = FormsConfiguration.Current;

            XmlDocument document = shape.FormDefinition;
            _properties     = new Dictionary <string, IFormProperty>();
            _propertiesList = new List <IFormProperty>();

            foreach (XmlElement section in document.SelectNodes(" /xf:shape/xf:section ", config.NsManager))
            {
                string sectionName = section.GetAttribute("name");


                TabPage tabPage = new TabPage(sectionName);
                tabPage.Name = sectionName;

                Panel tabPanel = new Panel();
                tabPanel.Dock    = DockStyle.Fill;
                tabPanel.Padding = new Padding(5);

                tabPage.Controls.Add(tabPanel);


                /*
                 *
                 */
                foreach (XmlElement property in section.SelectNodes(" *[ @id and @name ] ", config.NsManager))
                {
                    string propertyId = property.GetAttribute("id");


                    /*
                     *
                     */
                    var propertyConfig = config.Find(property);

                    if (propertyConfig == null)
                    {
                        continue;
                    }


                    /*
                     *
                     */
                    IFormProperty prop = Platinum.Activator.Create <IFormProperty>(propertyConfig.Moniker);
                    prop.Control.Dock = DockStyle.Top;
                    prop.Initialize(property, mode);

                    if (values.ContainsKey(propertyId) == true)
                    {
                        prop.Value = values[propertyId];
                    }
                    else
                    {
                        prop.Value = null;
                    }

                    prop.EvaluateConditional(values);
                    prop.RebuildConditionals += new EventHandler(RebuildConditionals);

                    tabPanel.Controls.Add(prop.Control);

                    _properties.Add(prop.Id, prop);
                    _propertiesList.Add(prop);
                }


                /*
                 * This effectively re-orders the children, so that the z-Index
                 * matches their position. This will allow the user to tab
                 * correctly from field to field.
                 */
                foreach (Control c in tabPanel.Controls)
                {
                    c.BringToFront();
                }

                tabs.TabPages.Add(tabPage);
            }


            /*
             *
             */
            _propertiesList.Reverse();


            /*
             * Ergonomy: keep a preference of the last used tab, and automatically
             * set the current selected tab. This will allow an end-user to keep
             * focussed on the most relevant tab.
             */
            if (string.IsNullOrEmpty(Properties.Settings.Default.SelectedTab) == false)
            {
                tabs.SelectTab(Properties.Settings.Default.SelectedTab);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Implementation of the marker event logic.
        /// </summary>
        /// <param name="app">Visio application.</param>
        /// <param name="sequenceNum">Sequence number.</param>
        /// <param name="contextString">Context string, as defined in shape.</param>
        private void Application_MarkerEventDo(Visio.Application app, int sequenceNum, string contextString)
        {
            /*
             *
             */
            if (_initializedOk == false)
            {
                return;
            }

            if (contextString == null)
            {
                return;
            }

            if (contextString.Contains("/au=1") == false)
            {
                return;
            }


            /*
             * Don't process any marker events that are being fired as a result
             * of a redo.
             */
            if (this.Application.IsUndoingOrRedoing == true)
            {
                return;
            }



            /*
             *
             */
            Dictionary <string, string> ctx = VU.ParseContext(contextString);

            if (ctx.ContainsKey("cmd") == false)
            {
                return;
            }


            /*
             *
             */
            Visio.Shape shape = VU.GetShape(app, ctx);

            if (shape == null)
            {
                return;
            }

            string modelName = VU.GetProperty(shape, "User", "ModelName");
            string shapeName = VU.GetProperty(shape, "User", "ModelShape");

            if (string.IsNullOrEmpty(modelName) == true ||
                string.IsNullOrEmpty(shapeName) == true)
            {
                return;
            }


            /*
             * Model
             */
            IModelDefinition model;

            try
            {
                model = ModelCache.Load(modelName);
            }
            catch (Exception ex)
            {
                ExceptionMessageBox.Show("Model failed to load.", ex);
                return;
            }

            if (model == null)
            {
                ExceptionMessageBox.Show($"Model '{ modelName }' not found.");
                return;
            }



            /*
             *
             */
            IShapeDefinition shapeDef = model.Shapes.Where(x => x.Name == shapeName).FirstOrDefault();

            if (shapeDef == null)
            {
                ExceptionMessageBox.Show($"No shape definition for '{ shapeName }' found.");
                return;
            }


            /*
             * Drop command
             */
            if (ctx["cmd"] == "drop")
            {
                /*
                 * .Id
                 */
                string shapeId = Guid.NewGuid().ToString();
                VU.SetProperty(shape, "Prop", "ShapeId", shapeId);


                /*
                 * .Code
                 */
                string shapeCode = null;

                if (string.IsNullOrEmpty(shapeDef.ShapeCodePrefix) == false)
                {
                    int sequence = PageIncrementSequence(shape, shapeDef.ShapeCodePrefix);
                    shapeCode = string.Format(CultureInfo.InvariantCulture, shapeDef.ShapeCodeFormat, shapeDef.ShapeCodePrefix, sequence);

                    VU.SetProperty(shape, "Prop", "ShapeCode", shapeCode);
                }


                /*
                 * .Text
                 */
                string shapeXml  = VU.GetProperty(shape, "Prop", "ShapeXml");
                string shapeText = shapeDef.TextGet(shapeCode, shapeXml);

                if (string.IsNullOrEmpty(shapeText) == false)
                {
                    VU.TextSet(shape, shapeText);
                }
            }


            /*
             *
             */
            if (ctx["cmd"] == "edit")
            {
                string mode      = "analysis"; //_toolbar.CurrentMode;
                string shapeCode = VU.GetProperty(shape, "Prop", "ShapeCode");
                string shapeXml  = VU.GetProperty(shape, "Prop", "ShapeXml");

                XmlForm form = new XmlForm();
                form.Initialize(shapeDef, mode, shapeCode, shapeXml);

                DialogResult result = form.ShowDialog();

                if (result == DialogResult.OK)
                {
                    VU.SetProperty(shape, "Prop", "ShapeXml", form.ShapeXml);
                    VU.ShapeColorSet(shape, Visio.VisDefaultColors.visBlack);

                    string shapeText = shapeDef.TextGet(shapeCode, form.ShapeXml);

                    if (string.IsNullOrEmpty(shapeText) == false)
                    {
                        VU.TextSet(shape, shapeText);
                    }
                }
            }
        }