Exemple #1
0
        private void importAllOneFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_DataMessage.Count() <= 0 || _IsBusy)
            {
                return;
            }
            string jsonFile = DiaglogManager.FileBrowser("export.json", "JSON files (*.json)|*.json");

            if (string.IsNullOrEmpty(jsonFile))
            {
                return;
            }
            _IsBusy = true;
            Task.Run(() =>
            {
                try
                {
                    Operation.ImportJSON(jsonFile, this.progressBar);
                }
                catch (Exception err)
                {
                    _IsBusy = false;
                    MessageBox.Show($"An error occurred:\n\n{err.Message}", _MessageBoxTitle);
                }
            }).GetAwaiter().OnCompleted(() => { _IsBusy = false; });
        }
Exemple #2
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_DataMessage.Count() <= 0 || _IsBusy || listFiles.SelectedIndex <= -1)
            {
                return;
            }
            int    index      = listFiles.SelectedIndex;
            string fileName   = _DataMessage[index].Name;
            string fileImport = DiaglogManager.FileBrowser(fileName, "Text files (*.txt)|*.txt|All files (*.*)|*.*");

            if (string.IsNullOrEmpty(fileImport))
            {
                return;
            }
            _IsBusy = true;
            Task.Run(() =>
            {
                try
                {
                    double percent = 100.0 / _DataMessage[index].Strings.Count;
                    string[] lines = File.ReadAllLines(fileImport);
                    for (int i = 0; i < _DataMessage[index].Strings.Count; i++)
                    {
                        if (lines[i].Contains("{#Name="))
                        {
                            lines[i] = lines[i].Split(new string[] { "{#Name=" }, StringSplitOptions.None).First();
                        }
                        _DataMessage[index].Strings[i] = lines[i];
                        percent += 100.0 / _DataMessage[index].Strings.Count;
                        Operation.ProgressBar(this.progressBar, (int)percent);
                    }
                }
                catch (Exception err)
                {
                    _IsBusy = false;
                    MessageBox.Show($"An error occurred:\n\n{err.Message}", _MessageBoxTitle);
                }
            }).GetAwaiter().OnCompleted(() => { _IsBusy = false; });
        }