/// <summary> /// creates new importer, sets importer settings /// </summary> /// <param name="tm">TM to import to</param> /// <param name="settings">import settings</param> public Importer(FileBasedTranslationMemory tm, DataImportSettings settings) { _settings = settings; _importer = new TranslationMemoryImporter(tm.LanguageDirection); ChangeSettings(); }
/// <summary> /// To validate the AppImportSettings /// </summary> /// <returns>returns true if it has valid AppImportSettings</returns> private static bool HasValidAppImportSettings() { Logger.Log.Info("Inside Method"); DataImportSettings importSettings = ConfigurationManager.GetSection("DataImportSettings") as DataImportSettings; if (importSettings == null) { Logger.Log.Error("DataImportSettings missing in congfiguration file"); return(false); } if (importSettings.AppImportSettings.Count == 0) { Logger.Log.Error("There is no AppImportSetting configured in congfiguration file"); return(false); } foreach (AppImportSetting setting in importSettings.AppImportSettings) { if (string.IsNullOrEmpty(setting.ID)) { Logger.Log.Error("App ID missing in congfiguration"); return(false); } if (string.IsNullOrEmpty(setting.Name)) { Logger.Log.Error("App Name missing in congfiguration"); return(false); } if (setting.XsdValidationRequired) { if (string.IsNullOrEmpty(setting.XsdFile)) { Logger.Log.Error("Xsd File is missing in congfiguration"); return(false); } string xsdFile = string.Format("{0}\\XSD\\{1}", AppDomain.CurrentDomain.BaseDirectory, setting.XsdFile); if (!File.Exists(xsdFile)) { Logger.Log.Error("Xsd file congfigured is not available"); return(false); } } if (setting.DataImportRequired) { if (string.IsNullOrEmpty(setting.DataImportProcedureName)) { Logger.Log.Error("DataImportProcedureName is missing in congfiguration"); return(false); } } } return(true); }
/// <summary> /// performs task /// </summary> /// <param name="fileName">file full path to perform task on</param> public void Execute(string fileName) { if (fileName.Length > 0) { RevertIndexSettings userSettings = (RevertIndexSettings)Control.Options; Progress(0, -1); LogAdded(string.Format(Properties.Resources.logFileProcessing, fileName)); try { TMFileManager manager = new TMFileManager(fileName); manager.OnProgress += new TMFileManager.OnProgressDelegate(Progress); // check password if (manager.IsProtected && !IsPswValid(manager)) { LogAdded(string.Format(Properties.Resources.logCancelledFile, fileName)); } else { // settings DataImportSettings setts = new DataImportSettings(userSettings.Scenario); setts.OverwriteExistingTUs = userSettings.IsOverwriteTUs; setts.PreservePsw = userSettings.IsPreservePsw; setts.CreateBackupFile = false; // progress & perform task manager.ReverseIndex(string.Format(@"{0}\{1}", userSettings.TargetFolder, Path.GetFileName(fileName)), setts); LogAdded(Properties.Resources.logTaskFinished); LogAdded(string.Format(Properties.Resources.logTUDetails, manager.TUsCount, manager.TUsImportedCount)); } } catch (Exception ex) { LogAdded(string.Format(Properties.Resources.errRevertTaskFailed, fileName, ex.Message)); MessageBox.Show(string.Format(Properties.Resources.errRevertTaskFailed, fileName, ex.Message).Replace("\\r\\n", "\r\n"), Properties.Resources.Title); } Progress(100, -1); } }
public static string ProcessActigraph(string id, string filepath, string filename, int studymeasID) { DateTime starttime = DateTime.Now; string results = String.Format("<br/>Begin processing. {0}", System.DateTime.Now.ToString()); List <string> lines = DataImporter.ReadLinesFromFiles(filepath, filename); //TOFIX - now hardcoded for Sleep Pilot study List <int> chunk_studymeasID = new List <int> { 8015, 8015, 8015, 6998, -1, 8014 }; // -1 because we are not yet processing Marker/Score List //combine subject, actiwatch, and analysis inputs into the same table with 3 fields: parameter, value, units ActigraphChunkMarkers markers = new ActigraphChunkMarkers(studymeasID); markers.PopulateIndices(lines); for (int i = 0; i < markers.Count; i++) { int smID = 0; // markers[i].studymeasID; if (smID > 0) { bool resetDaynum = false; string fldDaynum = ""; DataImportSettings act_settings = new DataImportSettings(id, smID); act_settings.rowstoprocess = markers[i].linenumber_end - markers[i].linenumber_start; act_settings.markerstring = markers[i].text.Replace("-", "").Replace(" Properties", ""); //Num rows to skip varies by section if (markers[i].text.Contains("Statistics")) { act_settings.skipstartingrows = 3; } else if (markers[i].text.Contains("Epoch")) { act_settings.skipstartingrows = 18; } else { act_settings.skipstartingrows = 1; //Because we are sending just the text to parse we just skip the header } //Set the constString for fields with mode = FieldExtractionMode.useMarkerString if (markers[i].text.Contains("Subject") | markers[i].text.Contains("Actiwatch") | markers[i].text.Contains("Analysis")) { act_settings.markerstring = markers[i].text.Replace("-", "").Replace(" Properties", ""); } foreach (Importfield fld in act_settings.fields) { if (fld.mode == FieldExtractionMode.useMarkerString) { fld.constString = act_settings.markerstring; } if (fld.mode == FieldExtractionMode.calcDayNum) { resetDaynum = true; fldDaynum = fld.field; } } Debug.WriteLine(String.Format(" >>>> {0} {1} {2}", act_settings.skipstartingrows, act_settings.rowstoprocess, markers[i].text)); string text_to_parse; if (act_settings.measureID == 4853) //Actigraph Epoch { Debug.WriteLine(" ************** lines.Count = " + lines.Count.ToString()); List <string> lines_no_excluded = lines.GetRange(markers[i].linenumber_start - 1, (markers[i].linenumber_end - markers[i].linenumber_start)); lines_no_excluded = lines_no_excluded.Where(f => !f.Contains("EXCLUDED")).ToList(); Debug.WriteLine(" ************** lines_no_excluded.Count = " + lines_no_excluded.Count.ToString()); text_to_parse = String.Join(Environment.NewLine, lines_no_excluded); } else { text_to_parse = String.Join(Environment.NewLine, lines.GetRange(markers[i].linenumber_start - 1, (markers[i].linenumber_end - markers[i].linenumber_start))); } DataImporter importer = new DataImporter(id, smID); //DataTable dt = DataImporter.GetDataTableFromText(text_to_parse, act_settings); DataTable dt = importer.GetDataTableFromText(text_to_parse, act_settings); results += "</br>" + markers[i].text + " >> Found " + dt.Rows.Count.ToString() + " records. >> "; if (dt.HasRows()) { //reset Daynum to begin at 1. Needed because the actigraph starts a few days earlier before actual data is obtained if (resetDaynum & fldDaynum != "") { int minDaynum = dt.AsEnumerable().Select(f => f.Field <int>(fldDaynum)).Min(); foreach (DataRow row in dt.Rows) { int tmp = Convert.ToInt32(row[fldDaynum]); row[fldDaynum] = tmp + (-1 * (minDaynum - 1)); } } SQL_utils sql = new SQL_utils("data"); results += sql.BulkInsert(dt, act_settings.tblname); sql.Close(); } else { results += "</br> No Rows!!"; } } } double timeelapsed = Math.Round((DateTime.Now - starttime).TotalSeconds, 2); string daylightinfo_results = LogDaylightInfo(id, studymeasID, 0); results += String.Format("<br/>{0}", daylightinfo_results); results += String.Format("<br/>End processing. {0} {1} seconds.", System.DateTime.Now.ToString(), timeelapsed); return(results); }
public IActionResult SaveSettings([FromBody] DataImportSettings settings) { _dataLoader.ChangeSettings(settings); return(Ok()); }