/// <summary>
        /// Loads all of the settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="personalInformation">The personal information.</param>
        public void Load(BackpackPlannerSettings settings, PersonalInformation personalInformation)
        {
            // TODO: put these in a LoadMetaSettings() method

            settings.MetaSettings.FirstRun = GetBoolean(MetaSettings.FirstRunPreferenceKey, settings.MetaSettings.FirstRun);

            // TODO: put these in a LoadSettings() method

            settings.ConnectGooglePlayServices = GetBoolean(BackpackPlannerSettings.ConnectGooglePlayServicesPreferenceKey, settings.ConnectGooglePlayServices);

            // NOTE: have to read the unit system/currency settings first in order
            // to properly interpret the rest of the settings

            string unitSystemPreference = GetString(BackpackPlannerSettings.UnitSystemPreferenceKey, settings.Units.ToString());

            UnitSystem unitSystem;
            if(Enum.TryParse(unitSystemPreference, out unitSystem)) {
                settings.Units = unitSystem;
            } else {
                Logger.Error("Error parsing unit system preference!");
            }

            string currencyPreference = GetString(BackpackPlannerSettings.CurrencyPreferenceKey, settings.Currency.ToString());

            Currency currency;
            if(Enum.TryParse(currencyPreference, out currency)) {
                settings.Currency = currency;
            } else {
                Logger.Error("Error parsing currency preference!");
            }

            // TODO: put these in a LoadPersonalInformation() method

            personalInformation.Name = GetString(PersonalInformation.NamePreferenceKey, personalInformation.Name);

            string birthDatePreference = GetString(PersonalInformation.DateOfBirthPreferenceKey, personalInformation.DateOfBirth?.ToString() ?? string.Empty);

            if(!string.IsNullOrWhiteSpace(birthDatePreference)) {
                try {
                    personalInformation.DateOfBirth = Convert.ToDateTime(birthDatePreference);
                } catch(FormatException) {
                    Logger.Error("Error parsing date of birth preference!");
                }
            }

            string userSexPreference = GetString(PersonalInformation.UserSexPreferenceKey, personalInformation.Sex.ToString());

            UserSex userSex;
            if(Enum.TryParse(userSexPreference, out userSex)) {
                personalInformation.Sex = userSex;
            } else {
                Logger.Error("Error parsing user sex preference!");
            }

            personalInformation.HeightInUnits = GetFloat(PersonalInformation.HeightPreferenceKey, (float)personalInformation.HeightInUnits);

            personalInformation.WeightInUnits = GetFloat(PersonalInformation.WeightPreferenceKey, (float)personalInformation.WeightInUnits);
        }
Example #2
0
 /// <summary>
 /// Undoes the action in a background task.
 /// </summary>
 /// <param name="databaseState">State of the database.</param>
 /// <param name="settings">The settings.</param>
 /// <param name="actionFinishedCallback">The action finished callback.</param>
 public void UndoActionInBackground(DatabaseState databaseState, BackpackPlannerSettings settings, Action<Command> actionFinishedCallback)
 {
     Task.Run(async () =>
         {
             await UndoActionAsync(databaseState, settings).ConfigureAwait(false);
             actionFinishedCallback?.Invoke(this);
         }
     );
 }
Example #3
0
 public TripPlan(BackpackPlannerSettings settings) : base(settings)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PersonalInformation" /> class.
 /// </summary>
 /// <param name="settingsManager">The settings manager.</param>
 /// <param name="settings">The settings.</param>
 public PersonalInformation(SettingsManager settingsManager, BackpackPlannerSettings settings)
 {
     _settingsManager = settingsManager;
     _settings = settings;
 }
 public GearCollection(BackpackPlannerSettings settings) : base(settings)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="BackpackPlannerState" /> class.
        /// </summary>
        /// <param name="platformHockeyAppManager">The platform HockeyApp manager.</param>
        /// <param name="platformSettingsManager">The platform settings manager.</param>
        /// <param name="platformPlayServicesManager">The platform google play services manager.</param>
        /// <param name="platformDatabaseSyncManager">The platform database sync manager.</param>
        /// <param name="sqlitePlatform">The SQLite platform.</param>
        public BackpackPlannerState(IHockeyAppManager platformHockeyAppManager, SettingsManager platformSettingsManager, PlayServicesManager platformPlayServicesManager, DatabaseSyncManager platformDatabaseSyncManager, ISQLitePlatform sqlitePlatform)
        {
            if(null == platformHockeyAppManager) {
                throw new ArgumentNullException(nameof(platformHockeyAppManager));
            }

            if(null == platformSettingsManager) {
                throw new ArgumentNullException(nameof(platformSettingsManager));
            }

            if(null == platformPlayServicesManager) {
                throw new ArgumentNullException(nameof(platformPlayServicesManager));
            }

            if(null == platformDatabaseSyncManager) {
                throw new ArgumentNullException(nameof(platformDatabaseSyncManager));
            }

            if(null == sqlitePlatform) {
                throw new ArgumentNullException(nameof(sqlitePlatform));
            }

            PlatformHockeyAppManager = platformHockeyAppManager;

            PlatformSettingsManager = platformSettingsManager;
            Settings = new BackpackPlannerSettings(PlatformSettingsManager);

            DatabaseState.SQLitePlatform = sqlitePlatform;

            PlatformPlayServicesManager = platformPlayServicesManager;
            PlatformDatabaseSyncManager = platformDatabaseSyncManager;

            PersonalInformation = new PersonalInformation(PlatformSettingsManager, Settings);
        }
Example #7
0
 public GearSystem(BackpackPlannerSettings settings) : base(settings)
 {
 }
        /// <summary>
        /// Updates a setting from the prferences.
        /// </summary>
        /// <param name="key">The setting key.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="personalInformation">The personal information.</param>
        public void UpdateFromPreferences(string key, BackpackPlannerSettings settings, PersonalInformation personalInformation)
        {
            switch(key)
            {
            // TODO: put these in an UpdateMetaSettingsFromPreferences() method
            case MetaSettings.FirstRunPreferenceKey:
                settings.MetaSettings.FirstRun = GetBoolean(MetaSettings.FirstRunPreferenceKey, settings.MetaSettings.FirstRun);
                break;
            // TODO: put these in an UpdateSettingsFromPreferences() method
            case BackpackPlannerSettings.ConnectGooglePlayServicesPreferenceKey:
                settings.ConnectGooglePlayServices = GetBoolean(BackpackPlannerSettings.ConnectGooglePlayServicesPreferenceKey, settings.ConnectGooglePlayServices);
                break;
            case BackpackPlannerSettings.UnitSystemPreferenceKey:
                string unitSystemPreference = GetString(BackpackPlannerSettings.UnitSystemPreferenceKey, settings.Units.ToString());

                UnitSystem unitSystem;
                if(Enum.TryParse(unitSystemPreference, out unitSystem)) {
                    settings.Units = unitSystem;
                } else {
                    Logger.Error("Error parsing unit system preference!");
                }
                break;
            case BackpackPlannerSettings.CurrencyPreferenceKey:
                string currencyPreference = GetString(BackpackPlannerSettings.CurrencyPreferenceKey, settings.Currency.ToString());

                Currency currency;
                if(Enum.TryParse(currencyPreference, out currency)) {
                    settings.Currency = currency;
                } else {
                    Logger.Error("Error parsing currency preference!");
                }
                break;
            // TODO: put these in an UpdatePersonalInformationFromPreferences() method
            case PersonalInformation.NamePreferenceKey:
                personalInformation.Name = GetString(PersonalInformation.NamePreferenceKey, personalInformation.Name);
                break;
            case PersonalInformation.DateOfBirthPreferenceKey:
                string birthDatePreference = GetString(PersonalInformation.DateOfBirthPreferenceKey, personalInformation.DateOfBirth?.ToString() ?? string.Empty);

                if(!string.IsNullOrWhiteSpace(birthDatePreference)) {
                    try {
                        personalInformation.DateOfBirth = Convert.ToDateTime(birthDatePreference);
                    } catch(FormatException) {
                        Logger.Error("Error parsing date of birth preference!");
                    }
                }
                break;
            case PersonalInformation.UserSexPreferenceKey:
                string userSexPreference = GetString(PersonalInformation.UserSexPreferenceKey, personalInformation.Sex.ToString());

                UserSex userSex;
                if(Enum.TryParse(userSexPreference, out userSex)) {
                    personalInformation.Sex = userSex;
                } else {
                    Logger.Error("Error parsing user sex preference!");
                }
                break;
            case PersonalInformation.HeightPreferenceKey:
                personalInformation.HeightInUnits = GetFloat(PersonalInformation.HeightPreferenceKey, (float)personalInformation.HeightInUnits);
                break;
            case PersonalInformation.WeightPreferenceKey:
                personalInformation.WeightInUnits = GetFloat(PersonalInformation.WeightPreferenceKey, (float)personalInformation.WeightInUnits);
                break;
            default:
                Logger.Warn($"Unhandled preference key: {key}");
                break;
            }
        }
Example #9
0
 /// <summary>
 /// Undoes the action.
 /// </summary>
 /// <param name="databaseState">State of the database.</param>
 /// <param name="settings">The settings.</param>
 public virtual async Task UndoActionAsync(DatabaseState databaseState, BackpackPlannerSettings settings)
 {
     await ValidateDatabaseStateAsync(databaseState).ConfigureAwait(false);
 }
Example #10
0
 /// <summary>
 /// Does the action.
 /// </summary>
 /// <param name="databaseState">State of the database.</param>
 /// <param name="settings">The settings.</param>
 public abstract Task DoActionAsync(DatabaseState databaseState, BackpackPlannerSettings settings);
Example #11
0
 public TripItinerary(BackpackPlannerSettings settings) : base(settings)
 {
 }
Example #12
0
        private async Task PopulateInitialDatabaseAsync(BackpackPlannerSettings settings)
        {
#if DEBUG
            Logger.Debug("Populating test data, this will take a while...");

#region Test Gear Items
            Logger.Debug("Inserting test gear items...");
            await DatabaseItem.InsertItemsAsync(this, new List<GearItem>
                {
                    new GearItem(settings)
                    {
                        Name = "Alcohol Stove",
                        Make = "Zelph's Stoveworks",
                        Model = "StarLyte",
                        Url = "http://www.woodgaz-stove.com/starlyte-burner-with-lid.php",
                        WeightInGrams = 19,
                        CostInUSDP = 1300,
                    },
                    new GearItem(settings)
                    {
                        Name = "Backpack",
                        Make = "ULA",
                        Model = "Circuit",
                        Url = "http://www.ula-equipment.com/product_p/circuit.htm",
                        WeightInGrams = 986,
                        CostInUSDP = 22500,
                        Note = "Medium torso (18\" - 21\"). Medium hipbelt (34\" - 38\"). J-Curve shoulder strap. Aluminum stay removed. Includes hanging s-biner \"Ahhh\" and water shoe carabiner. 39L main body. Max 15 pound base weight, 30-35 pack weight."
                    },
                    new GearItem(settings)
                    {
                        Name = "Hammock",
                        Make = "Aaron Erbe",
                        Model = "DIY",
                        WeightInGrams = 422,
                        CostInUSDP = 0,
                        Note = "Includes adjustable ridge line and 2x whoopie slings from whoopieslings.com, and bishop bag."
                    },
                    new GearItem(settings)
                    {
                        Name = "Head Lamp",
                        Make = "Petzl",
                        Model = "Tikka Plus 2",
                        WeightInGrams = 79,
                        CostInUSDP = 2995
                    },
                    new GearItem(settings)
                    {
                        Name = "Kilt",
                        Make = "Utilikilt",
                        Model = "Survival",
                        Url = "http://www.utilikilts.com/index.php/the-survival.html",
                        Carried = GearCarried.Worn,
                        WeightInGrams = 989,
                        CostInUSDP = 33000,
                        Note = "100% cotton. Cargo pockets removed (3.8 ounces each)."
                    },
                    new GearItem(settings)
                    {
                        Name = "New Underquilt",
                        Make = "Arrowhead Equipment",
                        Model = "Anniversary Jarbridge 3S (25F)",
                        Url = "http://www.arrowhead-equipment.com/store/p510/Anniversary_Jarbidge_UnderQuilt.htmll",
                        WeightInGrams = 566,
                        CostInUSDP = 7500,
                        Note = "6oz APEX Climashield synthetic"
                    },
                    new GearItem(settings)
                    {
                        Name = "Old Underquilt",
                        Make = "Aaron Erbe",
                        Model = "DIY",
                        WeightInGrams = 887,
                        CostInUSDP = 0,
                        Note = "Synthetic material. Need to have Aaron or Joe possibly remove some material from the overstuff collars to get the size and weight down on this."
                    },
                    new GearItem(settings)
                    {
                        Name = "Overquilt",
                        Make = "Arrowhead Equipment",
                        Model = "Owyhee Top Quilt Regular 3S (25F)",
                        Url = "http://www.arrowhead-equipment.com/store/p314/Owyhee_Top_Quilt_Regular.html",
                        WeightInGrams = 802,
                        CostInUSDP = 17900,
                        Note = "6oz APEX Climashield synthetic"
                    },
                    new GearItem(settings)
                    {
                        Name = "Toilet Paper",
                        IsConsumable = true,
                        ConsumedPerDay = 10,
                        WeightInGrams = 1,
                        CostInUSDP = 1,
                        Note = "Can't have too much!"
                    },
                    new GearItem(settings)
                    {
                        Name = "Tree Straps",
                        Url = "http://shop.whoopieslings.com/Tree-Huggers-TH.htm",
                        WeightInGrams = 198,
                        CostInUSDP = 1200,
                        Note = "12'x1\". Includes dutch buckle and titanium dutch clip (max 300 pounds)."
                    },
                    new GearItem(settings)
                    {
                        Name = "5g Water Jug",
                        Carried = GearCarried.NotCarried
                    },
                    new GearItem(settings)
                    {
                        Name = "Wind Screen",
                        Make = "Trail Designs",
                        Model = "Caldera Cone System",
                        Url = "http://www.traildesigns.com/stoves/caldera-cone-system",
                        WeightInGrams = 141,
                        CostInUSDP = 3400
                    }
                }
            );
#endregion

#region Test Gear Systems
            Logger.Debug("Inserting test gear systems...");
            await DatabaseItem.InsertItemsAsync(this, new List<GearSystem>
                {
                    new GearSystem(settings)
                    {
                        Name = "One"
                    },
                    new GearSystem(settings)
                    {
                        Name = "Two"
                    },
                    new GearSystem(settings)
                    {
                        Name = "Three"
                    },
                    new GearSystem(settings)
                    {
                        Name = "Four"
                    },
                    new GearSystem(settings)
                    {
                        Name = "Five"
                    },
                    new GearSystem(settings)
                    {
                        Name = "Six"
                    },
                    new GearSystem(settings)
                    {
                        Name = "Seven"
                    },
                    new GearSystem(settings)
                    {
                        Name = "Eight"
                    },
                    new GearSystem(settings)
                    {
                        Name = "Nine"
                    },
                    new GearSystem(settings)
                    {
                        Name = "Ten"
                    }
                }
            );
#endregion

#region Test Gear Collections
            Logger.Debug("Inserting test gear collections...");
            await DatabaseItem.InsertItemsAsync(this, new List<GearCollection>
                {
                    new GearCollection(settings)
                    {
                        Name = "One"
                    },
                    new GearCollection(settings)
                    {
                        Name = "Two"
                    },
                    new GearCollection(settings)
                    {
                        Name = "Three"
                    },
                    new GearCollection(settings)
                    {
                        Name = "Four"
                    },
                    new GearCollection(settings)
                    {
                        Name = "Five"
                    },
                    new GearCollection(settings)
                    {
                        Name = "Six"
                    },
                    new GearCollection(settings)
                    {
                        Name = "Seven"
                    },
                    new GearCollection(settings)
                    {
                        Name = "Eight"
                    },
                    new GearCollection(settings)
                    {
                        Name = "Nine"
                    },
                    new GearCollection(settings)
                    {
                        Name = "Ten"
                    }
                }
            );
#endregion

#region Test Meals
            Logger.Debug("Inserting test meals...");
            await DatabaseItem.InsertItemsAsync(this, new List<Meal>
                {
                    new Meal(settings)
                    {
                        Name = "One",
                        MealTime = MealTime.Dinner,
                        ServingCount = 1,
                        Calories = 50,
                        ProteinInGrams = 1,
                        FiberInGrams = 1,
                        WeightInGrams = 1,
                        CostInUSDP = 20
                    },
                    new Meal(settings)
                    {
                        Name = "Two",
                        MealTime = MealTime.Lunch,
                        ServingCount = 1,
                        Calories = 50,
                        ProteinInGrams = 1,
                        FiberInGrams = 1,
                        WeightInGrams = 2,
                        CostInUSDP = 19
                    },
                    new Meal(settings)
                    {
                        Name = "Three",
                        MealTime = MealTime.Breakfast,
                        ServingCount = 1,
                        Calories = 50,
                        ProteinInGrams = 1,
                        FiberInGrams = 1,
                        WeightInGrams = 3,
                        CostInUSDP = 18
                    },
                    new Meal(settings)
                    {
                        Name = "Four",
                        MealTime = MealTime.Drink,
                        ServingCount = 1,
                        Calories = 50,
                        ProteinInGrams = 1,
                        FiberInGrams = 1,
                        WeightInGrams = 4,
                        CostInUSDP = 17
                    },
                    new Meal(settings)
                    {
                        Name = "Five",
                        MealTime = MealTime.Snack,
                        ServingCount = 1,
                        Calories = 50,
                        ProteinInGrams = 1,
                        FiberInGrams = 1,
                        WeightInGrams = 5,
                        CostInUSDP = 16
                    },
                    new Meal(settings)
                    {
                        Name = "Six",
                        MealTime = MealTime.Other,
                        ServingCount = 1,
                        Calories = 50,
                        ProteinInGrams = 1,
                        FiberInGrams = 1,
                        WeightInGrams = 6,
                        CostInUSDP = 15
                    },
                    new Meal(settings)
                    {
                        Name = "Seven",
                        MealTime = MealTime.Breakfast,
                        ServingCount = 1,
                        Calories = 50,
                        ProteinInGrams = 1,
                        FiberInGrams = 1,
                        WeightInGrams = 7,
                        CostInUSDP = 14
                    },
                    new Meal(settings)
                    {
                        Name = "Eight",
                        MealTime = MealTime.Lunch,
                        ServingCount = 1,
                        Calories = 50,
                        ProteinInGrams = 1,
                        FiberInGrams = 1,
                        WeightInGrams = 8,
                        CostInUSDP = 13
                    },
                    new Meal(settings)
                    {
                        Name = "Nine",
                        MealTime = MealTime.Dinner,
                        ServingCount = 1,
                        Calories = 50,
                        ProteinInGrams = 1,
                        FiberInGrams = 1,
                        WeightInGrams = 9,
                        CostInUSDP = 12
                    },
                    new Meal(settings)
                    {
                        Name = "Ten",
                        MealTime = MealTime.Snack,
                        ServingCount = 1,
                        Calories = 50,
                        ProteinInGrams = 1,
                        FiberInGrams = 1,
                        WeightInGrams = 10,
                        CostInUSDP = 11
                    }
                }
            );
#endregion

#region Test Trip Itineraries
            Logger.Debug("Inserting test trip itineraries...");
            await DatabaseItem.InsertItemsAsync(this, new List<TripItinerary>
                {
                    new TripItinerary(settings)
                    {
                        Name = "One"
                    },
                    new TripItinerary(settings)
                    {
                        Name = "Two"
                    },
                    new TripItinerary(settings)
                    {
                        Name = "Three"
                    },
                    new TripItinerary(settings)
                    {
                        Name = "Four"
                    },
                    new TripItinerary(settings)
                    {
                        Name = "Five"
                    },
                    new TripItinerary(settings)
                    {
                        Name = "Six"
                    },
                    new TripItinerary(settings)
                    {
                        Name = "Seven"
                    },
                    new TripItinerary(settings)
                    {
                        Name = "Eight"
                    },
                    new TripItinerary(settings)
                    {
                        Name = "Nine"
                    },
                    new TripItinerary(settings)
                    {
                        Name = "Ten"
                    }
                }
            );
#endregion

#region Test Trip Plans
            Logger.Debug("Inserting test trip plans...");
            await DatabaseItem.InsertItemsAsync(this, new List<TripPlan>
                {
                    new TripPlan(settings)
                    {
                        Name = "One"
                    },
                    new TripPlan(settings)
                    {
                        Name = "Two"
                    },
                    new TripPlan(settings)
                    {
                        Name = "Three"
                    },
                    new TripPlan(settings)
                    {
                        Name = "Four"
                    },
                    new TripPlan(settings)
                    {
                        Name = "Five"
                    },
                    new TripPlan(settings)
                    {
                        Name = "Six"
                    },
                    new TripPlan(settings)
                    {
                        Name = "Seven"
                    },
                    new TripPlan(settings)
                    {
                        Name = "Eight"
                    },
                    new TripPlan(settings)
                    {
                        Name = "Nine"
                    },
                    new TripPlan(settings)
                    {
                        Name = "Ten"
                    }
                }
            );
#endregion

            Logger.Debug("Finished populating test data!");
#else
            await Task.Delay(0).ConfigureAwait(false);
#endif
        }
Example #13
0
 public Meal(BackpackPlannerSettings settings) : base(settings)
 {
 }