Esempio n. 1
0
        private void exportAllOneFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_DataMessage.Count() <= 0 || _IsBusy)
            {
                return;
            }
            string fileName = DiaglogManager.SaveFile("Sqex03DataMessage.txt", "Text files (*.txt)|*.txt|All files (*.*)|*.*");

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            _IsBusy = true;
            Task.Run(() =>
            {
                try
                {
                    Operation.ExportAll(fileName, _DataMessage, this.progressBar);
                }
                catch (Exception err)
                {
                    _IsBusy = false;
                    MessageBox.Show($"An error occurred:\n\n{err.Message}", _MessageBoxTitle);
                }
            }).GetAwaiter().OnCompleted(() => { _IsBusy = false; });
        }
Esempio n. 2
0
        public static void Export(DataMessage dataMessage)
        {
            List <string> messages = new List <string>();

            if (dataMessage.Speakers == null)
            {
                messages = dataMessage.Strings;
            }
            else
            {
                for (int i = 0; i < dataMessage.Strings.Count; i++)
                {
                    messages.Add($"{dataMessage.Strings[i]}{(char)123}#Name={(char)34}{dataMessage.Speakers[i].Name}{(char)34}{(char)125}");
                }
            }
            byte[] data      = Encoding.UTF8.GetBytes(String.Join("\r\n", messages.ToArray()));
            Thread newThread = new Thread(new ThreadStart(() =>
            {
                string fileName = DiaglogManager.SaveFile($"{dataMessage.Name}", "Text files (*.txt)|*.txt|All files (*.*)|*.*");
                if (!string.IsNullOrEmpty(fileName))
                {
                    File.WriteAllBytes(fileName, data);
                }
            }));

            newThread.SetApartmentState(ApartmentState.STA);
            newThread.Start();
            newThread.Join();
        }