예제 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="jasonFilePath"></param>

        public DiagramFormat(string jasonFilePath)
        {
            // use 'Deserializing Partial JSON Fragments'
            JObject jObject;

            try
            {
                // Read JSON
                string text = Util.ReadAllText(jasonFilePath);
                jObject = JObject.Parse(text);
            }
            catch (Exception e)
            {
                MessageBox.Show($@"Can't read '{jasonFilePath}!'

{e}", $@"Can't import Diagram Styles and Bulk change Element definitions from Settings.json{Environment.NewLine}Consider resetting to Factory Settings.");
                return;
            }

            //----------------------------------------------------------------------
            // Deserialize "DiagramStyle", "DiagramObjectStyle",""DiagramLinkStyle"
            // get JSON result objects into a list
            // Don't throw an error if the json settings aren't available!!!!
            // - Reason: To much error messages which aren't understandable and are annoying.

            DiagramStyleItems       = (List <DiagramStyleItem>)JasonHelper.GetConfigurationStyleItems <DiagramStyleItem>(jObject, "DiagramStyle");
            DiagramObjectStyleItems = (List <DiagramObjectStyleItem>)JasonHelper.GetConfigurationStyleItems <DiagramObjectStyleItem>(jObject, "DiagramObjectStyle");
            DiagramLinkStyleItems   = (List <DiagramLinkStyleItem>)JasonHelper.GetConfigurationStyleItems <DiagramLinkStyleItem>(jObject, "DiagramLinkStyle");
            BulkElementItems        = (List <BulkElementItem>)JasonHelper.GetConfigurationStyleItems <BulkElementItem>(jObject, "BulkItems");
        }
        /// <summary>
        /// Port services like: Label, Connect, Copy, Delete,..
        /// </summary>
        /// <param name="rep"></param>
        public PortServices(Repository rep)
        {
            _rep   = rep;
            _count = 0;


            // global configuration parameters independent from EA-Instance and used by services
            var globalCfg = HoToolsGlobalCfg.Instance;

            // use 'Deserializing Partial JSON Fragments'
            JObject search;

            try
            {
                // Read JSON
                string text = Util.ReadAllText(globalCfg.JasonFilePath);
                search = JObject.Parse(text);
            }
            catch (Exception e)
            {
                MessageBox.Show($@"Can't read '{globalCfg.JasonFilePath}'

{e}", @"Can't import 'PortAlignment' settings from Settings.json. ");
                return;
            }

            _portAlignmentItems = (List <PortAlignmentItem>)JasonHelper.GetConfigurationStyleItems <PortAlignmentItem>(search, "PortAlignment", ignoreError: true);

            // nothing imported, use default values
            if (_portAlignmentItems == null)
            {
                _portAlignmentItems = new List <PortAlignmentItem>();
                _portAlignmentItems.Add(new PortAlignmentItem("Port",
                                                              "-80", "0", "0", "0",
                                                              "20", "0", "0", "0",
                                                              "0", "-90", "0", "1",
                                                              "0", "50", "0", "1"
                                                              ));
                _portAlignmentItems.Add(new PortAlignmentItem("Interface",
                                                              "-80", "0", "0", "0",
                                                              "50", "0", "0", "0",
                                                              "0", "-80", "0", "1",
                                                              "0", "70", "0", "1"
                                                              ));
                _portAlignmentItems.Add(new PortAlignmentItem("Port1",
                                                              "25", "0", "0", "0",
                                                              "-140", "0", "0", "0",
                                                              "0", "30", "0", "1",
                                                              "0", "-105", "0", "1"
                                                              ));
                _portAlignmentItems.Add(new PortAlignmentItem("Interface1",
                                                              "60", "0", "0", "0",
                                                              "-100", "0", "0", "0",
                                                              "0", "65", "0", "1",
                                                              "0", "-120", "0", "1"
                                                              ));
            }
        }