Ejemplo n.º 1
0
 /// <summary>
 /// Checks the file name, file extension, tests overwrite permission...
 /// If child class doesn't need any file, it must override this method.
 /// </summary>
 protected virtual void CheckFileName()
 {
     ExportFileName = ExportFileName.Trim();
     if (ExportFileName == string.Empty)
     {
         throw new EnaxosExportException(Consts.EmptyFileName);
     }
     if (Path.GetExtension(ExportFileName) == string.Empty)
     {
         ExportFileName = Path.ChangeExtension(ExportFileName, DefaultExtension);
     }
 }
Ejemplo n.º 2
0
        public void GenerateFromTemplateWithoutIndexWithExt()
        {
            string         basicTemplate  = "templateWithoutIndex{0}.tif";
            string         exportTemplate = String.Format(basicTemplate, "");
            ExportFileName efn            = new ExportFileName(exportTemplate, FileType.Tiff, null);
            string         result         = efn.GenerateNext(ws, null);
            string         expectedResult = String.Format(basicTemplate, "001");

            Assert.AreEqual(expectedResult, result);
            result         = efn.GenerateNext(ws, null);
            expectedResult = String.Format(basicTemplate, "002");
            Assert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 3
0
        public void GenerateFromTemplateWithoutIndexNoExt()
        {
            FileType       ft             = FileType.Png;
            string         basicTemplate  = "templateWithoutIndex{0}";
            string         exportTemplate = String.Format(basicTemplate, "");
            ExportFileName efn            = new ExportFileName(exportTemplate, ft, null);
            string         result         = efn.GenerateNext(ws, null);
            string         expectedResult = String.Format(basicTemplate, "001");

            Assert.AreEqual(
                expectedResult + ft.ToFileNameExtension(), result);
            result         = efn.GenerateNext(ws, null);
            expectedResult = String.Format(
                basicTemplate + ft.ToFileNameExtension(), "002");
            Assert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 4
0
        public void GenerateExportFileName()
        {
            string basicTemplate  = "{0}_{1}_#{2}.png";
            string exportTemplate = String.Format(basicTemplate,
                                                  "{" + Strings.Workbook + "}",
                                                  "{" + Strings.Worksheet + "}",
                                                  "{" + Strings.Index + "}");
            ExportFileName efn            = new ExportFileName(exportTemplate, FileType.Png, null);
            string         result         = efn.GenerateNext(ws, null);
            string         expectedResult = String.Format(basicTemplate, wb.Name, ws.Name, "001");

            Assert.AreEqual(expectedResult, result);
            result         = efn.GenerateNext(ws, null);
            expectedResult = String.Format(basicTemplate, wb.Name, ws.Name, "002");
            Assert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 5
0
 private void UpdateExportFileExtension(string oldExtension, string newExtension)
 {
     if (newExtension == null)
     {
         return;
     }
     if (oldExtension == null)
     {
         ExportFileName = ExportFileName + "." + newExtension;
     }
     else
     {
         if (ExportFileName.EndsWith(oldExtension, StringComparison.OrdinalIgnoreCase))
         {
             ExportFileName = ExportFileName.Substring(0, ExportFileName.Length - oldExtension.Length) +
                              newExtension;
         }
     }
 }
Ejemplo n.º 6
0
        public void AddExtensionIfNoneExists()
        {
            FileType ft             = FileType.Tiff;
            string   basicTemplate  = "{0}_{1}_#{2}";
            string   exportTemplate = String.Format(basicTemplate,
                                                    "{" + Strings.Workbook + "}",
                                                    "{" + Strings.Worksheet + "}",
                                                    "{" + Strings.Index + "}");
            ExportFileName efn            = new ExportFileName(exportTemplate, ft, null);
            string         result         = efn.GenerateNext(ws, null);
            string         expectedResult = String.Format(
                basicTemplate + ft.ToFileNameExtension(), wb.Name, ws.Name, "001");

            Assert.AreEqual(expectedResult, result);
            result         = efn.GenerateNext(ws, null);
            expectedResult = String.Format(
                basicTemplate + ft.ToFileNameExtension(), wb.Name, ws.Name, "002");
            Assert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 7
0
        public Dictionary <int, Measurement> ImportCache(SectionInfoCollection SectionCollection)
        {
            string path = FileCollection.Filenames.FirstOrDefault();

            ExportFileName = path.Split(@"\").Last();
            string[] metaData = ExportFileName.Split("_");

            var dtReader = new CSVReader();

            dtReader.ReadPath = path;
            var Measurements = ImportIODPDataTable(dtReader);

            var MeasurementCache = MeasurementsConvertor.Convert(Measurements, SectionCollection);

            foreach (var record in MeasurementCache)
            {
                ImportMetaData(metaData, record.Value);
            }

            return(MeasurementCache);
        }
Ejemplo n.º 8
0
        private int CreateCSVFile(List <CSVTable> csvTables)
        {
            int processedExportRecordNbr = 0;

            GlobalContext.Log(string.Format("Creating CSV File: {0}...", ExportFileName), false);

            foreach (CSVTable csvTable in csvTables)
            {
                string strTemp;
                if (csvTable.Rows.Length <= 0)
                {
                    // Don't output empty extract file
                    GlobalContext.Log(string.Format("No Record Returned for CSV File: {0}.", ExportFileName), true);
                    //break;
                }

                // Add header record to extract file if needed
                if (processedExportRecordNbr == 0 && Properties.Settings.Default.FileHasHeaders == true)
                {
                    File.AppendAllText(ExportFileName, csvTable.Columns + "\r\n");
                }

                processedExportRecordNbr += csvTable.Rows.Length;

                foreach (string row in csvTable.Rows)
                {
                    // Are we doing Intra Day Data Report?
                    if (ExportFileName.Contains("Aspect_Intra_Day_Data"))
                    {
                        // Yes - Replace spaces in row with underscores
                        strTemp = row.Replace(" ", "_");
                        // Is file Pipe delimited?
                        if (Properties.Settings.Default.Delimiter == "|")
                        {
                            // Pipe delimited - Replace nulls with 0's
                            strTemp = strTemp.Replace("||||||||", "|0|0|0|0|0|0|0|0");
                            strTemp = strTemp.Replace("||||0|||0|", "|0|0|0|0|0|0|0|0");
                            strTemp = strTemp.Replace("||", "|0|");
                            // Make delimiter into a space
                            strTemp = strTemp.Replace("|", " ");
                        }
                        else
                        {
                            // Not Pipe Delimited (Assume it's comma delimited) - Replace nulls with 0's
                            strTemp = strTemp.Replace(",,,,,,,,", ",0,0,0,0,0,0,0,0");
                            strTemp = strTemp.Replace(",,,,0,,,0,", ",0,0,0,0,0,0,0,0");
                            strTemp = strTemp.Replace(",,", ",0,");
                            // Make delimiter into a space
                            strTemp = strTemp.Replace(",", " ");
                        }
                        File.AppendAllText(ExportFileName, strTemp + "\r\n");
                    }
                    else
                    {
                        // Not Intra Day Data Report - Leave code as it was
                        File.AppendAllText(ExportFileName, row + "\r\n");
                    }
                }  // end foreach (string row in csvTable.Rows)
            }
            return(processedExportRecordNbr);
        }