public ResultFileEntry([NotNull] string name, [NotNull] FileInfo fileinfo, bool displayEntry, ResultFileID rfid, [NotNull] string householdKey, [CanBeNull] string?additionalFileIndex, CalcOption enablingOption) { Name = name; FileName = fileinfo.Name; FullFileName = fileinfo.FullName; DisplayEntry = displayEntry; ResultFileID = rfid; HouseholdKey = householdKey; AdditionalFileIndex = additionalFileIndex; EnablingCalcOption = enablingOption; if (FileName == FullFileName) { throw new LPGException("Full filename was same as filename"); } if (FileName.Contains(":")) { throw new LPGException("Somehow the full path ended up in the Filename"); } }
public bool CheckForResultFileEntry(ResultFileID rfid, [NotNull] string loadTypeName, [NotNull] HouseholdKey householdKey, [CanBeNull] PersonInformation pi, [CanBeNull] string additionalFileIndex) { var key = ResultFileEntry.CalculateHashKey(rfid, _calcObjectName, loadTypeName, householdKey.Key, pi?.Name, additionalFileIndex); return(ResultFileList.ResultFiles.ContainsKey(key)); }
public bool CheckForFile(ResultFileID rfid1, [NotNull] HouseholdKey householdKey, [CanBeNull] string additionalFileIndex = null) { string key = ResultFileEntry.CalculateHashKey(rfid1, null, null, householdKey.Key, null, additionalFileIndex); if (ResultFileList.ResultFiles.ContainsKey(key)) { return(true); } return(false); }
public ResultFileEntry GetResultFileEntry(ResultFileID rfid, [CanBeNull] string loadTypeName, [NotNull] HouseholdKey householdKey, [CanBeNull] PersonInformation pi, [CanBeNull] string additionalFileIndex) { var key = ResultFileEntry.CalculateHashKey(rfid, _calcObjectName, loadTypeName, householdKey.Key, pi?.Name, additionalFileIndex); if (!ResultFileList.ResultFiles.ContainsKey(key)) { throw new LPGException("The file with the ID " + rfid + ", the loadtype " + loadTypeName + ", and the householdID " + householdKey + " is missing. This is probably a bug. Please report."); } return(ResultFileList.ResultFiles[key]); }
public static string CalculateHashKey(ResultFileID resultFileID, [CanBeNull] string?householdName, [CanBeNull] string?loadTypeName, [CanBeNull] string?householdKey, [CanBeNull] string?personName, [CanBeNull] string?additionalFileIndex) { var s = ""; s += resultFileID + "#"; s += householdName + "#"; s += loadTypeName + "#"; s += householdKey + "#"; s += personName + "#"; s += additionalFileIndex + "#"; return(s); }
#pragma warning restore CA1036 // Override methods on comparable types public ResultFileEntry([NotNull] string name, [NotNull] FileInfo fileInfo, bool displayEntry, [CanBeNull] StreamWriter streamWriter, [CanBeNull] BinaryWriter binaryWriter, [NotNull] Stream stream, ResultFileID rfid, [NotNull] string householdName, [NotNull] string householdKey, [NotNull] LoadTypeInformation lti, [NotNull] PersonInformation pi, [NotNull] string additionalFileIndex, TimeSpan timeResolution, CalcOption enablingOption) { EnablingCalcOption = enablingOption; TimeResolution = timeResolution; Name = name; FileName = fileInfo.Name; FullFileName = fileInfo.FullName; Stream = stream; DisplayEntry = displayEntry; StreamWriter = streamWriter; BinaryWriter = binaryWriter; ResultFileID = rfid; HouseholdName = householdName; LoadTypeInformation = lti; HouseholdKey = householdKey; PersonInformation = pi; AdditionalFileIndex = additionalFileIndex; if (FileName == FullFileName) { throw new LPGException("Full filename was same as filename"); } if (FileName.Contains(":")) { throw new LPGException("Somehow the full path ended up in the Filename"); } }
public T MakeFile <T>([NotNull] string fileName, [NotNull] string description, bool displayResultFileEntry, ResultFileID rfid1, [NotNull] HouseholdKey householdKey, TargetDirectory targetDirectory, TimeSpan timeResolution, CalcOption enablingOption, [CanBeNull] LoadTypeInformation lti = null, [CanBeNull] PersonInformation pi = null, [CanBeNull] string additionalFileIndex = null) { if (string.IsNullOrWhiteSpace(fileName)) { throw new LPGException("Filename was empty"); } if (!HouseholdRegistry.IsHouseholdRegistered(householdKey)) { throw new LPGException("Forgotten Household Key: " + householdKey); } if (fileName.Contains("..")) { throw new LPGException("Filename with two dots. This looks bad. Please fix: " + fileName); } if (fileName.Contains(" ")) { throw new LPGException("Filename with two spaces. This looks bad. Please fix: " + fileName); } var rfid = rfid1; var cleanFileName = AutomationUtili.CleanFileName(fileName); string targetDir = GetFullPathForTargetdirectry(targetDirectory); if (!Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } var fileInfo = new FileInfo(Path.Combine(targetDir, cleanFileName)); if (fileInfo.FullName.Length > 250) { throw new LPGException("The result filename " + fileInfo.FullName + " was longer than 250 characters which is a problem for Windows. Maybe chose a shorter directory name or nest less deep and try again?"); } if (fileInfo.Exists) { throw new LPGException("The file " + fileInfo.Name + " already exists. Can't create it again!"); } bool tryagain; if (!_allValidIds.Contains((int)rfid)) { throw new LPGException("Invalid result file ID"); } do { try { if (typeof(T) == typeof(StreamWriter)) { var stream = _getStream.GetWriterStream(fileInfo.FullName); #pragma warning disable S2930 // "IDisposables" should be disposed var sw = new StreamWriter(stream); #pragma warning restore S2930 // "IDisposables" should be disposed var ret = (T)(object)sw; var rfe = new ResultFileEntry(description, fileInfo, displayResultFileEntry, sw, null, stream, rfid, _calcObjectName, householdKey.Key, lti, pi, additionalFileIndex, timeResolution, enablingOption); ResultFileList.ResultFiles.Add(rfe.HashKey, rfe); _inputDataLogger.Save(rfe); return(ret); } if (typeof(T) == typeof(BinaryWriter)) { var stream = _getStream.GetWriterStream(fileInfo.FullName); #pragma warning disable S2930 // "IDisposables" should be disposed var bw = new BinaryWriter(stream); #pragma warning restore S2930 // "IDisposables" should be disposed var ret = (T)(object)bw; var rfe = new ResultFileEntry(description, fileInfo, displayResultFileEntry, null, bw, stream, rfid, _calcObjectName, householdKey.Key, lti, pi, additionalFileIndex, timeResolution, enablingOption); ResultFileList.ResultFiles.Add(rfe.HashKey, rfe); _inputDataLogger.Save(rfe); return(ret); } if (typeof(T) == typeof(Stream)) { var stream = _getStream.GetWriterStream(fileInfo.FullName); var ret = (T)(object)stream; var rfe = new ResultFileEntry(description, fileInfo, displayResultFileEntry, null, null, stream, rfid, _calcObjectName, householdKey.Key, lti, pi, additionalFileIndex, timeResolution, enablingOption); ResultFileList.ResultFiles.Add(rfe.HashKey, rfe); _inputDataLogger.Save(rfe); return(ret); } if (typeof(T) == typeof(FileStream)) { var stream = _getStream.GetWriterStream(fileInfo.FullName); var ret = (T)(object)stream; var rfe = new ResultFileEntry(description, fileInfo, displayResultFileEntry, null, null, stream, rfid, _calcObjectName, householdKey.Key, lti, pi, additionalFileIndex, timeResolution, enablingOption); ResultFileList.ResultFiles.Add(rfe.HashKey, rfe); _inputDataLogger.Save(rfe); return(ret); } throw new LPGException("Unknown stream type in Makefile<T>"); } catch (IOException ioe) { if (!Config.IsInUnitTesting) { var errormessage = "The file " + fileInfo.FullName + " could not be opened. The exact error message was:" + Environment.NewLine + ioe.Message + Environment.NewLine + Environment.NewLine; errormessage += " Maybe you forgot to close Excel? Press YES to try again!"; var dr = MessageWindowHandler.Mw.ShowYesNoMessage(errormessage, "Error opening file!"); if (dr == LPGMsgBoxResult.Yes) { tryagain = true; } else { tryagain = false; } } else { tryagain = false; } } } while (tryagain); throw new DataIntegrityException("Couldn't open file \"" + fileInfo.FullName + "\". Aborting."); }
public void RegisterFile([NotNull] string fileName, [NotNull] string description, bool displayResultFileEntry, ResultFileID rfid1, [NotNull] HouseholdKey householdKey, TargetDirectory targetDirectory, CalcOption enablingOption, [CanBeNull] string additionalFileIndex = null) { if (!HouseholdRegistry.IsHouseholdRegistered(householdKey)) { throw new LPGException("Forgotten Household Key: " + householdKey); } if (fileName.Contains("..")) { throw new LPGException("Filename with two dots. This looks bad. Please fix: " + fileName); } if (fileName.Contains(" ")) { throw new LPGException("Filename with two spaces. This looks bad. Please fix: " + fileName); } string fullFileName = Path.Combine(GetFullPathForTargetdirectry(targetDirectory), fileName); FileInfo fi = new FileInfo(fullFileName); ResultFileEntry rfe = new ResultFileEntry(description, fi, displayResultFileEntry, rfid1, householdKey.Key, additionalFileIndex, enablingOption); _inputDataLogger.Save(rfe); ResultFileList.ResultFiles.Add(rfe.HashKey, rfe); }
public ResultFileEntry GetResultFileEntry(ResultFileID rfid, string loadTypeName, HouseholdKey householdKey, PersonInformation pi, string additionalFileIndex) => throw new NotImplementedException();
public T MakeFile <T>(string fileName, string description, bool displayResultFileEntry, ResultFileID rfid1, HouseholdKey householdKey, TargetDirectory targetDirectory, TimeSpan timeResolution, CalcOption enablingOption, LoadTypeInformation lti = null, PersonInformation pi = null, string additionalFileIndex = null) => throw new NotImplementedException();