/// <summary>
        /// Creates a settings file object
        /// </summary>
        /// <returns>The settings file with the parameters of each controller</returns>
        public static HelicopterSettings Load()
        {
            var settingsFile = GetSettingsFile();

            var helicopterSettings = new HelicopterSettings
            {
                FilePath = settingsFile,
                XmlText = File.ReadAllText(settingsFile),
            };

            helicopterSettings.XDocument = XDocument.Parse(helicopterSettings.XmlText);

            var settingsElement = helicopterSettings.XDocument.Element("Settings");
            var helicopterElement = settingsElement.Element("Helicopter");

            helicopterSettings.PidThreadRefreshIntervalMilliseconds = helicopterElement.Attribute("PidThreadRefreshIntervalMilliseconds").ParseInt();
            helicopterSettings.ConnectionType = (ConnectionType)Enum.Parse(typeof(ConnectionType), helicopterElement.Attribute("ConnectionType").Value);
            helicopterSettings.ControllerSettings = HelicopterControllerSettings.FromXmlElement(helicopterElement.Element("Controller"));

            return helicopterSettings;
        }
        public static SessionRecord CreateNewSessionRecord(Session session, HelicopterSettings settings)
        {
            SessionRecord sessionRecord;
            var yaw = session.YawDataSeries;
            var tilt = session.TiltDataSeries;

            using (var context = new HelicopterModelEntities())
            {
                var settingsRecordId = UpdateSettingsRecord(settings, context);

                sessionRecord = new SessionRecord
                {
                    SettingsId = settingsRecordId,
                    StartTime = session.StartTime,
                    EndTime = session.EndTime,
                    Comment = String.Empty
                };

                var yawRecord = new ControllerRecord
                {
                    MotorType = yaw.MotorType.ToString(),
                    DriverType = yaw.MotorDriver.ToString(),
                    CWProportionalGain = yaw.CWProportionalGain,
                    CWIntegralGain = yaw.CWIntegralGain,
                    CWDerivativeGain = yaw.CWDerivativeGain,
                    CCWProportionalGain = yaw.CCWProportionalGain,
                    CCWIntegralGain = yaw.CCWIntegralGain,
                    CCWDerivativeGain = yaw.CCWDerivativeGain,
                    IntegralWindupThreshold = yaw.IWindupThreshold,
                    OutputRateLimit = yaw.OutputRateLimit,
                    MeasurementRecords = yaw.ControllerData.Select(x => new MeasurementRecord
                    {
                        TimeStamp = x.TimeStamp,
                        SetPoint = x.SetPoint,
                        CurrentAngle = x.CurrentAngle
                    }).ToList()
                };

                var tiltRecord = new ControllerRecord
                {
                    MotorType = tilt.MotorType.ToString(),
                    DriverType = tilt.MotorDriver.ToString(),
                    CWProportionalGain = tilt.CWProportionalGain,
                    CWIntegralGain = tilt.CWIntegralGain,
                    CWDerivativeGain = tilt.CWDerivativeGain,
                    IntegralWindupThreshold = tilt.IWindupThreshold,
                    OutputRateLimit = tilt.OutputRateLimit,
                    MeasurementRecords = tilt.ControllerData.Select(x => new MeasurementRecord
                    {
                        TimeStamp = x.TimeStamp,
                        SetPoint = x.SetPoint,
                        CurrentAngle = x.CurrentAngle
                    }).ToList()
                };

                sessionRecord.ControllerRecords.Add(yawRecord);
                sessionRecord.ControllerRecords.Add(tiltRecord);

                context.SessionRecords.Add(sessionRecord);
                context.SaveChanges();
                Log.Debug("Created and saved new session with ID");
            }

            return sessionRecord;
        }
        private static int UpdateSettingsRecord(HelicopterSettings settings, HelicopterModelEntities context)
        {
            var hash = GetSHA1Hash(settings.XmlText);
            var settingsRecord = context.SettingsRecords.SingleOrDefault(x => x.Hash == hash);

            if (settingsRecord != null) return settingsRecord.Id;

            settingsRecord = new SettingsRecord
            {
                Created = DateTime.Now,
                Hash = hash,
                Text = settings.XmlText
            };

            context.SettingsRecords.Add(settingsRecord);
            context.SaveChanges();

            return settingsRecord.Id;
        }