<commit_before>﻿//******************************************************************************************************
//  EditDetails.cs - Gbtc
//
//  Copyright © 2021, Grid Protection Alliance.  All Rights Reserved.
//
//  Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
//  the NOTICE file distributed with this work for additional information regarding copyright ownership.
//  The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
//  file except in compliance with the License. You may obtain a copy of the License at:
//
//      http://opensource.org/licenses/MIT
//
//  Unless agreed to in writing, the subject software distributed under the License is distributed on an
//  "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
//  License for the specific language governing permissions and limitations.
//
//  Code Modification History:
//  ----------------------------------------------------------------------------------------------------
//  01/25/2021 - <NAME>
//       Generated original version of source code.
//
//******************************************************************************************************

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using GSF.Configuration;
using GSF.Data.Model;
using GSF.PhasorProtocols;
using SELPDCImporter.Model;

namespace SELPDCImporter
{
    public partial class EditDetails : Form
    {
        private readonly Color m_matchedColor = Color.FromArgb(192, 255, 192);
        private readonly Color m_unmatchedColor = SystemColors.Control;
        private readonly List<CheckBox> m_deleteCheckBoxes = new List<CheckBox>();
        private readonly List<Control> m_validatedControls = new List<Control>();

        public EditDetails()
        {
            InitializeComponent();
        }

        public ImportParameters ImportParams { get; set; }

        public ConfigurationFrame TargetConfigFrame { get; private set; }

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
                return cp;
            }
        }

        private void LoadHistorians()
        {
            ConfigurationFile configurationFile = ConfigurationFile.Current;
            CategorizedSettingsElementCollection systemSettings = configurationFile.Settings["systemSettings"];
            string targetHistorianIDValue = systemSettings["TargetHistorianID"]?.Value ?? "0";

            TableOperations<Historian> historianTable = new TableOperations<Historian>(ImportParams.Connection);
            Dictionary<int, string> historians = historianTable.QueryHistorians().ToDictionary(historian => historian.ID, historian => historian.Acronym);
            historians.Add(0, "None");

            comboBoxHistorian.DataSource = new BindingSource(historians, null);
            comboBoxHistorian.ValueMember = "Key";
            comboBoxHistorian.DisplayMember = "Value";

            void updateSelectedHistorian()
            {
                if (!int.TryParse(comboBoxHistorian.SelectedValue.ToString(), out int historianID))
                    historianID = -1;

                TargetConfigFrame.HistorianID = historianID <= 0 ? null : historianID;
                systemSettings["TargetHistorianID", true].Update(historianID, "Target historian ID.", false, SettingScope.User);
            }

            comboBoxHistorian.SelectedValueChanged += (_, _) => updateSelectedHistorian();
            
            if (!int.TryParse(targetHistorianIDValue, out int targetHistorianID) || !historians.ContainsKey(targetHistorianID))
                targetHistorianID = -1;

            if (targetHistorianID == -1)
            {
                // Attempt to select an ideal initial target historian
                if (historians.ContainsValue("PPA"))
                    targetHistorianID = historians.FirstOrDefault(kvp => string.Equals(kvp.Value, "PPA")).Key;
                else if (historians.Count > 1)
                    targetHistorianID = historians.FirstOrDefault(kvp => kvp.Key > 0).Key;

                if (targetHistorianID == -1)
                    targetHistorianID = 0;
            }

            comboBoxHistorian.SelectedValue = targetHistorianID;
            updateSelectedHistorian();
        }

        private void EditDetails_Load(object sender, EventArgs e)
        {
            ConfigurationFrame selPDCConfigFrame = ImportParams.SELPDCConfigFrame;
            ConfigurationFrame gsfPDCConfigFrame = ImportParams.GSFPDCConfigFrame;

            TargetConfigFrame = ConfigurationFrame.Clone(gsfPDCConfigFrame ?? selPDCConfigFrame, false);

            checkBoxDeleteAll.CheckedChanged += (_, _) =>
            {
                foreach (CheckBox checkBox in m_deleteCheckBoxes)<commit_msg>SELPDCImporter: Do not auto-target STAT historian when this is only historian available, choose NONE otherwise.<commit_after>﻿//******************************************************************************************************
//  EditDetails.cs - Gbtc
//
//  Copyright © 2021, Grid Protection Alliance.  All Rights Reserved.
//
//  Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
//  the NOTICE file distributed with this work for additional information regarding copyright ownership.
//  The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
//  file except in compliance with the License. You may obtain a copy of the License at:
//
//      http://opensource.org/licenses/MIT
//
//  Unless agreed to in writing, the subject software distributed under the License is distributed on an
//  "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
//  License for the specific language governing permissions and limitations.
//
//  Code Modification History:
//  ----------------------------------------------------------------------------------------------------
//  01/25/2021 - <NAME>
//       Generated original version of source code.
//
//******************************************************************************************************

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using GSF.Configuration;
using GSF.Data.Model;
using GSF.PhasorProtocols;
using SELPDCImporter.Model;

namespace SELPDCImporter
{
    public partial class EditDetails : Form
    {
        private readonly Color m_matchedColor = Color.FromArgb(192, 255, 192);
        private readonly Color m_unmatchedColor = SystemColors.Control;
        private readonly List<CheckBox> m_deleteCheckBoxes = new List<CheckBox>();
        private readonly List<Control> m_validatedControls = new List<Control>();

        public EditDetails()
        {
            InitializeComponent();
        }

        public ImportParameters ImportParams { get; set; }

        public ConfigurationFrame TargetConfigFrame { get; private set; }

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
                return cp;
            }
        }

        private void LoadHistorians()
        {
            ConfigurationFile configurationFile = ConfigurationFile.Current;
            CategorizedSettingsElementCollection systemSettings = configurationFile.Settings["systemSettings"];
            string targetHistorianIDValue = systemSettings["TargetHistorianID"]?.Value ?? "0";

            TableOperations<Historian> historianTable = new TableOperations<Historian>(ImportParams.Connection);
            Dictionary<int, string> historians = historianTable.QueryHistorians().ToDictionary(historian => historian.ID, historian => historian.Acronym);
            historians.Add(0, "None");

            comboBoxHistorian.DataSource = new BindingSource(historians, null);
            comboBoxHistorian.ValueMember = "Key";
            comboBoxHistorian.DisplayMember = "Value";

            void updateSelectedHistorian()
            {
                if (!int.TryParse(comboBoxHistorian.SelectedValue.ToString(), out int historianID))
                    historianID = -1;

                TargetConfigFrame.HistorianID = historianID <= 0 ? null : historianID;
                systemSettings["TargetHistorianID", true].Update(historianID, "Target historian ID.", false, SettingScope.User);
            }

            comboBoxHistorian.SelectedValueChanged += (_, _) => updateSelectedHistorian();
            
            if (!int.TryParse(targetHistorianIDValue, out int targetHistorianID) || !historians.ContainsKey(targetHistorianID))
                targetHistorianID = -1;

            if (targetHistorianID == -1)
            {
                // Attempt to select an ideal initial target historian
                if (historians.ContainsValue("PPA"))
                    targetHistorianID = historians.FirstOrDefault(kvp => string.Equals(kvp.Value, "PPA")).Key;
                else if (historians.Count > 1)
                    targetHistorianID = historians.FirstOrDefault(kvp => kvp.Key > 0 && !string.Equals(kvp.Value, "STAT")).Key;

                if (targetHistorianID == -1)
                    targetHistorianID = 0;
            }

            comboBoxHistorian.SelectedValue = targetHistorianID;
            updateSelectedHistorian();
        }

        private void EditDetails_Load(object sender, EventArgs e)
        {
            ConfigurationFrame selPDCConfigFrame = ImportParams.SELPDCConfigFrame;
            ConfigurationFrame gsfPDCConfigFrame = ImportParams.GSFPDCConfigFrame;

            TargetConfigFrame = ConfigurationFrame.Clone(gsfPDCConfigFrame ?? selPDCConfigFrame, false);

            checkBoxDeleteAll.CheckedChanged += (_, _) =>
            {
                foreach (CheckBox checkBox in m_deleteCheckBoxes)
{'fraction_non_alphanumeric': 0.1378839590443686, 'fraction_numerical': 0.0078010726474890294, 'mean_word_length': 2.517146776406036, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1072128', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2354, 'n_words': 667}