Beispiel #1
0
        public void Process(IList <string> filesIn, IList <string> filesOut,
                            ContourFormat formatIn, ContourFormat formatOut, bool changeFileExtension)
        {
            ContourFileFactory  factory     = new ContourFileFactory();
            IDataFile <Contour> dataFileIn  = factory.GetFile(formatIn);
            IDataFile <Contour> dataFileOut = factory.GetFile(formatOut);
            int successCount = 0;

            for (int i = 0; i < filesIn.Count(); i++)
            {
                try
                {
                    Logger.AddMessage(String.Format("Обрабатывается файл '{0}'. {1} из {2}",
                                                    filesIn[i], i + 1, filesIn.Count));

                    Contour contour = dataFileIn.Read(filesIn[i]);
                    if (changeFileExtension)
                    {
                        filesOut[i] = Path.ChangeExtension(filesOut[i], dataFileOut.DefaultExtension);
                    }
                    dataFileOut.Write(filesOut[i], contour);

                    successCount++;
                    Logger.AddMessage(String.Format("Файл успешно обработан."));
                }
                catch (Exception e)
                {
                    Logger.AddMessage(String.Format("Ошибка при обработке файла. {0}", e.Message));
                }
            }
            Logger.AddEmptyLine();
            Logger.AddMessage(String.Format("Успешно обработано файлов: {0} из {1}.", successCount, filesIn.Count));
        }
Beispiel #2
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            if (lstFiles.Items.Count == 0)
            {
                FormUtils.ShowWarning("Не выбраны файлы для обработки!");
                return;
            }
            if (cbxFormatIn.SelectedIndex == cbxFormatOut.SelectedIndex)
            {
                FormUtils.ShowWarning("Совпадают входной и выходной форматы файлов!");
                return;
            }

            IList <string> filesIn = lstFiles.Items.Cast <string>().ToList();
            IList <string> filesOut;

            try
            {
                filesOut = GetFileNamesOut(filesIn);
            }
            catch (ApplicationException exc)
            {
                FormUtils.ShowWarning(exc.Message);
                return;
            }

            AddMessage("Начало обработки файлов...\r\n");

            switch (_currentType)
            {
            case DataType.Contour:
                ContourFormat    contFormatIn  = (ContourFormat)cbxFormatIn.SelectedValue;
                ContourFormat    contFormatOut = (ContourFormat)cbxFormatOut.SelectedValue;
                ContourProcessor contProcessor = new ContourProcessor(this);
                contProcessor.Process(filesIn, filesOut, contFormatIn, contFormatOut, true);
                break;

            case DataType.Grid2D:
                Grid2DFormat    gridFormatIn  = (Grid2DFormat)cbxFormatIn.SelectedValue;
                Grid2DFormat    gridFormatOut = (Grid2DFormat)cbxFormatOut.SelectedValue;
                Grid2DProcessor gridProcessor = new Grid2DProcessor(this);
                gridProcessor.Process(filesIn, filesOut, gridFormatIn, gridFormatOut, true);
                break;

            case DataType.Point:
                break;
            }

            AddMessage("Обработка файлов завершена.");
        }
        public IDataFile <Contour> GetFile(ContourFormat contourFormat)
        {
            IDataFile <Contour> file;

            switch (contourFormat)
            {
            case ContourFormat.SurferTextSpace:
                file = new ContourSurferSpaceFile();
                break;

            case ContourFormat.SurferTextComma:
                file = new ContourSurferCommaFile();
                break;

            case ContourFormat.RoxarText:
                file = new ContourRoxarFile();
                break;

            default:
                throw new ArgumentException("Неправильно задан формат файла контура!");
            }

            return(file);
        }
Beispiel #4
0
 public void Process(IList <string> filesIn, IList <string> filesOut,
                     ContourFormat formatIn, ContourFormat formatOut)
 {
     Process(filesIn, filesOut, formatIn, formatOut, false);
 }