示例#1
0
        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);
        }
示例#2
0
        private static string GetCalibrationFilePath(CalibrationInfo info)
        {
            string filename = info.Id.ToString() + EXTENSION_CALIBRATION;
            string path     = Path.Combine(RootFolderPath, filename);

            return(path);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }