예제 #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>
        /// Constructor
        /// </summary>
        /// <param name="jasonFilePath"></param>

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

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

Consider Resetting to factory settings
- File, Reset Factory Settings!!!'

{e}", @"Can't import Chapter: 'Importer' from Settings.json");
                return;
            }

            //----------------------------------------------------------------------
            // Deserialize "DiagramStyle", "DiagramObjectStyle",""DiagramLinkStyle"
            // get JSON result objects into a list
            ImportSettings =
                (List <FileImportSettingsItem>)JasonHelper.GetConfigurationItems <FileImportSettingsItem>(
                    jObject, "Importer");
        }
예제 #3
0
        /// <summary>
        /// 从API中获取信息
        /// </summary>
        /// <returns></returns>
        private List <RepoDto> getReposWithApi()
        {
            List <RepoDto> list = new List <RepoDto>();

            HttpClient myHttpClient = new HttpClient();

            myHttpClient.DefaultRequestHeaders.Add("User-Agent", "leansoftX.Repos"); // 请求git的api接口需要带上应用信息,否则会报错
            var response = myHttpClient.GetAsync(_api).Result;
            var json     = response.Content.ReadAsStringAsync().Result;
            var array    = JasonHelper.ConvertToObj <JArray>(json);

            foreach (var item in array)
            {
                dynamic repo     = item;
                RepoDto reposDto = new RepoDto
                {
                    Name     = repo.name,
                    CodeNo   = repo.node_id,
                    FullName = repo.full_name,
                    Id       = repo.id,
                    GitUrl   = repo.git_url,
                    Content  = JasonHelper.ConvertToStr(repo)
                };
                list.Add(reposDto);
            }

            return(list);
        }
예제 #4
0
 /// <summary>
 /// Read Import Settings
 /// </summary>
 private void ReadImportSettings()
 {
     // Get settings from 'Settings.json', Chapter 'Importer'
     _importSettings = (List <FileImportSettingsItem>)JasonHelper
                       .GetConfigurationItems <FileImportSettingsItem>(JasonHelper
                                                                       .DeserializeSettings(_jsonFilePath), "Importer");
 }
        /// <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"
                                                              ));
            }
        }
 /// <summary>
 /// Create a ToolStripItem with DropDownitems for each importable feature .
 /// The Tag property contains the style. If no configuration is available insert a text as a hint to a missing configuration.
 /// </summary>
 /// <param name="items">List of items to visualize as toolstrip menue <see cref="T"/></param>
 /// <param name="nameRoot"></param>
 /// <param name="toolTipRoot"></param>
 /// <param name="eventHandler"></param>
 /// <param name="hoverHandler"></param>
 /// <param name="contectItem">A Context item (right click), optional</param>
 /// <param name="mouseDownEventHandlerContext"></param>
 /// <returns></returns>
 public ToolStripMenuItem ConstructImporterMenuItems <T>(List <T> items, string nameRoot, string toolTipRoot,
                                                         EventHandler eventHandler,
                                                         EventHandler hoverHandler = null,
                                                         string contectItem        = "", MouseEventHandler mouseDownEventHandlerContext = null
                                                         )
 {
     return(JasonHelper.ConstructStyleToolStripMenuDiagram(items, nameRoot, toolTipRoot,
                                                           eventHandler,
                                                           hoverHandler,
                                                           contectItem, mouseDownEventHandlerContext));
 }