public bool TrySaveCalibration(string name, CalibrationData calibration, out CalibrationInfo info) { var calibrations = GetStoredCalibrations(); info = calibrations.FirstOrDefault(c => c.Name.Equals(name) && c.DeviceFamilyName.Equals(calibration.DeviceFamilyName)); if (info == null) { info = CalibrationInfo.Create(name, calibration.DeviceFamilyName, calibration.DeviceName, DateTime.Now); calibrations = new List <CalibrationInfo>(calibrations.Prepend(info)); } else { info.CreatedAt = DateTime.Now; } string path = GetCalibrationFilePath(info); EnsureRootDirectoryExists(); File.WriteAllBytes(GetCalibrationFilePath(info), calibration.Data); SaveCalibrationsIndex(calibrations); return(true); }
private static string GetCalibrationFilePath(CalibrationInfo info) { string filename = info.Id.ToString() + EXTENSION_CALIBRATION; string path = Path.Combine(RootFolderPath, filename); return(path); }
public static CalibrationInfo Create(string name, string deviceFamilyName, string deviceName, DateTime createdAt) { var data = new CalibrationInfo() { Id = Guid.NewGuid(), Name = name, CreatedAt = createdAt, DeviceFamilyName = deviceFamilyName, DeviceName = deviceName }; return(data); }
public CalibrationData LoadCalibration(CalibrationInfo calibration) { calibration.ThrowIfNull(nameof(calibration)); string filepath = GetCalibrationFilePath(calibration); if (File.Exists(filepath)) { byte[] bytes = File.ReadAllBytes(filepath); var data = new CalibrationData(calibration.DeviceFamilyName, calibration.DeviceName, bytes); return(data); } throw new FileNotFoundException($"Calibration file {calibration.Name} does not exist at the location {filepath}", filepath); }