Example #1
0
 public void HrGetErrorString
     (int hrErr
     , out string pbstrErrorMsg
     , IConverterApplicationPreferences pcap)
 {
     _traceSource.TraceInformation("Converter.HrGetErrorString");
     pbstrErrorMsg = _errorMessage;
 }
Example #2
0
        public void HrExport
            (string bstrSourcePath
            , string bstrDestPath
            , string bstrClass
            , IConverterApplicationPreferences pcap
            , out IConverterPreferences ppcp
            , IConverterUICallback pcuic)
        {
//#if DEBUG
            UInt32 plcid;

            pcap.HrGetLcid(out plcid);
            String application;

            pcap.HrGetApplication(out application);
            Int32 pFormat;

            pcap.HrCheckFormat(out pFormat);

            //Int32 pid0;
            //pcuic.HrMessageBox(String.Format("bstrSourcePath: \"{0}\"\nbstrDestPath \"{1}\"\nbstrClass: \"{2}\"\nplcid: {3}, application: \"{4}\", pFormat: {5}", bstrSourcePath, bstrDestPath, bstrClass, plcid, application, pFormat), "HrExport", 0, out pid0);

            _traceSource.TraceInformation("Converter.HrExport\nbstrSourcePath: \"{0}\"\nbstrDestPath \"{1}\"\nbstrClass: \"{2}\"\nplcid: {3}, application: \"{4}\", pFormat: {5}", bstrSourcePath, bstrDestPath, bstrClass, plcid, application, pFormat);
// #endif

            ppcp = new ConverterPreferences();

            try
            {
                Encoding encoding = ComputeEncodeing(bstrClass);

                using (StreamWriter streamWriter = new StreamWriter(bstrDestPath, false, encoding))
                    using (CsvWriter csvWriter = new CsvWriter(streamWriter))
                    {
                        Rfc4180FileWriter  fileWriter         = new Rfc4180FileWriter(csvWriter);
                        WorksheetConverter worksheetConverter = new ProgressWorksheetConverter(pcuic.HrReportProgress);
                        XlsxConverter.Convert(bstrSourcePath, fileWriter, worksheetConverter);
                        fileWriter.Flush();
                        streamWriter.Flush();
                    }
            }
            catch (ActiveWorksheetException)
            {
                _errorMessage = "В книге активной листом является не таблица.\nПожалуйста, выберите лист с таблицей и попробуйте сохранить снова.";
                throw;
            }
            catch (Exception ex)
            {
                _errorMessage = "Возникла внутренняя ошибка. Невозможно сохранить файл.";

                _traceSource.TraceEvent(TraceEventType.Error, 1025, ex.ToString());
                Debug.Fail(ex.ToString());
                throw;
            }
        }
Example #3
0
        public void HrInitConverter
            (IConverterApplicationPreferences pcap
            , out IConverterPreferences ppcp
            , IConverterUICallback pcuic)
        {
            //int pidResult = 0;
            //pcuic.HrMessageBox("HrInitConverter", "FB Converter Server", 0, out pidResult);

            _traceSource.TraceInformation("Converter.HrInitConverter");

            ppcp = new ConverterPreferences();
        }
Example #4
0
        public void HrGetFormat
            (string bstrPath
            , out string pbstrClass
            , IConverterApplicationPreferences pcap
            , out IConverterPreferences ppcp
            , IConverterUICallback pcuic)
        {
#if DEBUG
            pcap.HrGetLcid(out UInt32 plcid);
            pcap.HrGetApplication(out String application);
            pcap.HrCheckFormat(out Int32 pFormat);

            // Int32 pid0;
            // pcuic.HrMessageBox(String.Format("bstrPath: \"{0}\"\nplcid: {1}, application: \"{2}\", pFormat: {3}", bstrPath, plcid, application, pFormat), "HrGetFormat", 0, out pid0);

            _traceSource.TraceInformation("Converter.HrGetFormat\nbstrPath: \"{0}\"\nplcid: {1}, application: \"{2}\", pFormat: {3}", bstrPath, plcid, application, pFormat);
#endif

            ResolveEncoding(bstrPath, out pbstrClass, out _encoding);
            ppcp = new ConverterPreferences();
        }
Example #5
0
        public void HrImport
            (string bstrSourcePath
            , string bstrDestPath
            , IConverterApplicationPreferences pcap
            , out IConverterPreferences ppcp
            , IConverterUICallback pcuic)
        {
            ppcp = new ConverterPreferences();

            try
            {
// #if DEBUG
                UInt32 plcid;
                pcap.HrGetLcid(out plcid);
                String application;
                pcap.HrGetApplication(out application);
                Int32 pFormat;
                pcap.HrCheckFormat(out pFormat);

                //                Int32 pid0;
                //                pcuic.HrMessageBox(String.Format("bstrSourcePath: \"{0}\"\nbstrDestPath \"{1}\"\nplcid: {2}, application: \"{3}\", pFormat: {4}", bstrSourcePath, bstrDestPath, plcid, application, pFormat), "HrImport", 0, out pid0);
// #endif
                _traceSource.TraceInformation("Converter.HrImport\nbstrSourcePath: \"{0}\"\nbstrDestPath \"{1}\"\nplcid: {2}, application: \"{3}\", pFormat: {4}", bstrSourcePath, bstrDestPath, plcid, application, pFormat);



                //using (CsvConverter csvConverter = new CsvConverter(bstrSourcePath, bstrDestPath))
                //{
                //if (fbDocument.ContentStatus != FB.ContentStatus.Correct)
                //{
                //    const UInt32 MB_YESNO = 0x00000004;
                //    const UInt32 MB_ICONWARNING = 0x00000030;
                //    const UInt32 type = MB_YESNO | MB_ICONWARNING;
                //    const Int32 IDYES = 6;


                //    Int32 pid;
                //    pcuic.HrMessageBox("Открываемый файл имеет неверный формат или повреждён.\nДалее будет осуществлена попытка его открыть, но при этом не гарантируется, что все данные будут отображены корректно.\n\nПродолжить?", "Внимание!", type, out pid);

                //    if (pid != IDYES)
                //        throw new ApplicationException();
                //}

                //DocInWords.Office.FBConversion.FBConverter fbConverter = new DocInWords.Office.FBConversion.FBConverter(bstrDestPath);
                //csvConverter.Convert();
                //}

                pcuic.HrReportProgress(0u);

                using (StreamReader sourceStream = new StreamReader(bstrSourcePath, _encoding))
                {
                    CsvReader         csvReader         = new CsvReader(sourceStream);
                    ProgressCsvReader progressCsvReader = new ProgressCsvReader(sourceStream, csvReader, pcuic.HrReportProgress);

                    using (FileStream destStream = File.OpenWrite(bstrDestPath))
                    {
                        CsvConverter.Convert(progressCsvReader, destStream);

                        destStream.Flush();
                    }
                }
            }
            catch (Exception ex)
            {
                _errorMessage = "Невозможно открыть файл. Возможно, он имеет неверный формат или повреждён.";

                _traceSource.TraceEvent(TraceEventType.Error, 1024, ex.ToString());
                Debug.Fail(ex.ToString());
                throw;
            }
            finally
            {
                pcuic.HrReportProgress(100u);
            }
        }