public PlantPower ProcessLine(string line, string fileName, ApiPlant apiPlant) { var plant = apiPlant; var utcDateTime = extractUtcDateFromFileLine(line, plant.TimeZone); var utcUpdatedDateTime = string.Format("{0:yyyyMMddHHmmss}", utcDateTime); var utcInsertionDateTime = string.Format("{0:yyyyMMddHH0000}", DateTime.UtcNow); var power = extractValueFromFileLine(line); return new PlantPower(plant.Id, utcInsertionDateTime, utcUpdatedDateTime, power); }
private void processFile(string filePath, ApiPlant plant) { string conStr = ""; //Initialize conStr = _configProvider.GetConnnectionString(); OleDbConnection conn = new OleDbConnection(conStr + "Data Source=" + filePath + ";" + "Extended Properties=Excel 8.0"); conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; DataSet ds = new DataSet(); DataTable dt = new DataTable(); if (dt != null) { String[] excelSheets = new String[dt.Rows.Count]; int i = 0; string ExcelSheet = ""; // Add the sheet name to the string array. foreach (DataRow row in dt.Rows) { excelSheets[i] = row["TABLE_NAME"].ToString(); if (excelSheets[i].Length < 13) { if (_fileExtracter.FindSheet(excelSheets[i])) { ExcelSheet = excelSheets[i]; } } } if (ExcelSheet != "") { cmd.CommandText = "SELECT * FROM [" + ExcelSheet + "]"; dt.TableName = ExcelSheet; OleDbDataAdapter da = new OleDbDataAdapter(cmd); da.Fill(dt); ds.Tables.Add(dt); List<List<string>> data = new List<List<string>>(); foreach (DataRow row in dt.Rows) { //if (row == null) continue; List<string> gettedData = new List<string>(); i = 0; foreach (var columnitem in row.ItemArray) // Loop over the items. { //Console.Write("Item: "); // Print label. //Console.WriteLine(item); // Invokes ToString abstract method. if (i == 0 && columnitem.ToString() == "") ; else gettedData.Add(columnitem.ToString()); //add data i++; } data.Add(gettedData); } } } // jvr var measures = getAllMeasuresFromFile(filePath, plant); //var plantPower=updatePlantPowerFromFile(filePath, plant); /*if (measures == null || !measures.Any()) { _logger.Warn("No measures found inside the file"); // jvr we check as processed even when no data is found //AQUI var processedFileTextToAppend = _configProvider.GetFtpProcessedFilesPath(); _ftpClient.MoveFtpProcessedFile(filePath, processedFileTextToAppend, ".nodata"); return; } _logger.InfoFormat("Found {0} measures to send", measures.Count); */ // jvr sendMeasures(filePath, measures); /*if (plantPower == null || !plantPower.Any()) { _logger.Warn("No change Power found inside the file"); return; }*/ //_logger.InfoFormat("Found {0} change power to update", plantPower.Count); }
public void ExtractMeasuresFromFile() { var expected = new List<Measure> { new Measure("MAREE01","CLIENTE1H","E","20130826",1,0,0,6622030,1,0,"1H") }; var file = @"TestData\Production NALBANT Jan-Jul16 2015.xls"; IList<string> fileList = new List<String>(); IList<string> lineList = new List<String>(); fileList.Add(file); var mockConfigProvider = new Mock<IConfigurationProvider>(); mockConfigProvider.Setup(x => x.GetHourlyPlantsString()).Returns("MAREE01"); mockConfigProvider.Setup(x => x.GetMeasureSourceFor1HResolution()).Returns("CLIENTE1H"); mockConfigProvider.Setup(x => x.GetDataVariable()).Returns("E"); mockConfigProvider.Setup(x => x.GetResolution()).Returns("1H"); mockConfigProvider.Setup(x => x.GetENEXToGnarumOffsetHours()).Returns(-1); mockConfigProvider.Setup(x => x.GetMeasureValueMultiplier()).Returns(1); var apiPlant = new ApiPlant { Id = "MAREE01", Technology = "EO", CountryCode = "ES", RegionCode = "28", TimeZone = "E. Europe Standard Time", Latitude = 40.4293, Longitude = -3.6574, Power = 22668 }; var mockPlantService = new Mock<IPlantService>(); mockPlantService.Setup(x => x.GetPlant("MAREE01")).Returns(apiPlant); var _jobdetail = new JobDetailImpl("jobsettings", typeof(IJob)); var mockExecutionContext = new Mock<IJobExecutionContext>(); mockExecutionContext.SetupGet(p => p.JobDetail).Returns(_jobdetail); MeasuresLoaderJob measureJob = new MeasuresLoaderJob(); MeasureFileExtracter measureFile = new MeasureFileExtracter(mockConfigProvider.Object, mockPlantService.Object); var result = new List<Measure>(); foreach (var filePath in fileList) { var cont = 0; foreach (var line in File.ReadAllLines(filePath)) { if (cont != 0) { var measure = measureFile.ProcessLine(line, file,apiPlant); result.Add(measure); } cont++; } } Assert.AreEqual(expected.Count, result.Count); for (int i = 1; i < expected.Count; ++i) { Assert.AreEqual(expected[i], result[i]); } }
public Measure ProcessLine(string line, string fileName, ApiPlant plant) { //var plant = _plantService.GetPlant(_confProvider.GetHourlyPlantsString()); //var plant = _plantService.GetPlant(getPlantName(fileName)); var source = _confProvider.GetMeasureSourceFor1HResolution(); var datavariable = _confProvider.GetDataVariable(); var resolution = _confProvider.GetResolution(); var utcDateTime = extractUtcDateFromFileLine(line, plant.TimeZone, resolution); var utcDate = string.Format("{0:yyyyMMdd}", utcDateTime.Date); var utcHour = utcDateTime.Hour; var utcMinute = utcDateTime.Minute; var utcSecond = utcDateTime.Second; var value = extractValueFromFileLine(line); var percentage = 1; var reliability = 0; return new Measure(plant.Id, source, datavariable, utcDate, utcHour, utcMinute, utcSecond, value, percentage, reliability, resolution); }