Esempio n. 1
0
 public Indexer(DBSnapshot snapshot)
 {
     this.snapshot = snapshot;
     snapshot.recipeMap = new Dictionary<Guid, RecipeNode>();
     snapshot.ingredientMap = new Dictionary<Guid, IngredientNode>();
     snapshot.recipeList = new IEnumerable<RecipeNode>[RecipeTag.NUM_TAGS];
 }
Esempio n. 2
0
 public Indexer(DBSnapshot snapshot)
 {
     this.snapshot          = snapshot;
     snapshot.recipeMap     = new Dictionary <Guid, RecipeNode>();
     snapshot.ingredientMap = new Dictionary <Guid, IngredientNode>();
     snapshot.recipeList    = new IEnumerable <RecipeNode> [Enum.GetNames(typeof(RecipeTag)).Length];
 }
Esempio n. 3
0
 public Indexer(DBSnapshot snapshot)
 {
     this.snapshot          = snapshot;
     snapshot.recipeMap     = new Dictionary <Guid, RecipeNode>();
     snapshot.ingredientMap = new Dictionary <Guid, IngredientNode>();
     snapshot.recipeList    = new IEnumerable <RecipeNode> [RecipeTag.NUM_TAGS];
 }
Esempio n. 4
0
    private async Task <DBInstance> RestoreFromSnapshot(DBInstance instance, DBSnapshot snapshot)
    {
        _logger.Info("Creating new instance from snapshot.");
        RestoreDBInstanceFromDBSnapshotRequest restoreRequest = new RestoreDBInstanceFromDBSnapshotRequest()
        {
            DBSnapshotIdentifier = snapshot.DBSnapshotIdentifier,
            LicenseModel         = instance.LicenseModel,
            DBInstanceClass      = instance.DBInstanceClass,
            MultiAZ     = instance.MultiAZ,
            StorageType = instance.StorageType,

            DBInstanceIdentifier = instance.DBInstanceIdentifier,

            DBSubnetGroupName = instance.DBSubnetGroup.DBSubnetGroupName,
            AvailabilityZone  = instance.AvailabilityZone,

            AutoMinorVersionUpgrade = instance.AutoMinorVersionUpgrade,
            VpcSecurityGroupIds     = instance.VpcSecurityGroups.Select(x => x.VpcSecurityGroupId).ToList()
        };

        var restoreResponse = await _rdsClient.RestoreDBInstanceFromDBSnapshotAsync(restoreRequest);

        await WaitForDBToBeAvailable(restoreResponse.DBInstance.DbiResourceId);

        _logger.Info("Creation Successful.");

        return(restoreResponse.DBInstance);
    }
Esempio n. 5
0
    private async Task <DBSnapshot> SelectDBSnapshot(string sourceRDSName)
    {
        var snapshotResponses = await _rdsClient.DescribeDBSnapshotsAsync();

        Console.WriteLine("Select a snapshot");
        var snapshotsForInstance = snapshotResponses.DBSnapshots.Where(x => x.DBInstanceIdentifier == sourceRDSName).OrderByDescending(x => x.OriginalSnapshotCreateTime).Take(10).ToList();

        for (int index = 0; index < snapshotsForInstance.Count; index++)
        {
            DBSnapshot snapshot = snapshotsForInstance[index];
            Console.WriteLine($"{index}: {snapshot.DBInstanceIdentifier}|{snapshot.DBSnapshotIdentifier}");
        }

        string?snapshotSelection = Console.ReadLine();

        if (string.IsNullOrWhiteSpace(snapshotSelection))
        {
            throw new Exception("Invalid selection.");
        }

        DBSnapshot snapshotChosen = snapshotsForInstance[Convert.ToInt32(snapshotSelection)];

        _logger.Info($"Selected snapshot: {snapshotChosen.DBSnapshotIdentifier}");
        return(snapshotChosen);
    }
Esempio n. 6
0
 public Indexer(DBSnapshot snapshot)
 {
     this.snapshot = snapshot;
     snapshot.recipeMap = new Dictionary<Guid, RecipeNode>();
     snapshot.ingredientMap = new Dictionary<Guid, IngredientNode>();
     snapshot.recipeList = new IEnumerable<RecipeNode>[Enum.GetNames(typeof(RecipeTag)).Length];
 }
Esempio n. 7
0
    public async Task CopySourceToDestination()
    {
        DBInstance destinationDB = await GetDBInstanceByIdentifier(_destinationRdsName);

        _logger.Info($"Destination Database: {destinationDB.DBInstanceIdentifier}");

        DBSnapshot snapshotChosen = await SelectDBSnapshot(_sourceRdsName);

        _logger.Info($"Source Snapshot: {snapshotChosen.DBSnapshotIdentifier}");

        string newNameForOldServer = await RenameOldInstance(destinationDB);

        await RestoreFromSnapshot(destinationDB, snapshotChosen);

        DBInstance oldServer = await GetDBInstanceByIdentifier(newNameForOldServer);

        await DeleteInstance(oldServer);

        _logger.Info("Process Complete.");
    }
Esempio n. 8
0
        /// <summary>
        /// Create a ModelingSession instance.
        /// </summary>
        /// <param name="context">KitchenPC context used for this modeling session.</param>
        /// <param name="db">Object containing all available recipes, ratings, and trend information.</param>
        /// <param name="profile">Object containing user specific information, such as pantry and user ratings.</param>
        public ModelingSession(IKPCContext context, DBSnapshot db, IUserProfile profile)
        {
            this.db      = db;
            this.context = context;
            this.profile = profile;
            this.favTags = new bool[RecipeTag.NUM_TAGS];
            this.favIngs = new int[profile.FavoriteIngredients.Length];

            if (profile.Pantry != null && profile.Pantry.Length == 0) //Empty pantries must be null, not zero items
            {
                throw new EmptyPantryException();
            }

            if (profile.AllowedTags != null)
            {
                AllowedTags = profile.AllowedTags;
            }

            if (profile.Pantry != null)
            {
                pantryAmounts = new Dictionary <IngredientNode, float?>();
                foreach (var item in profile.Pantry)
                {
                    var node = this.db.FindIngredient(item.IngredientId);

                    //If an ingredient isn't used by any recipe, there's no reason for it to be in the pantry.
                    if (node == null)
                    {
                        continue;
                    }

                    //If an ingredient exists, but doesn't have any link to any allowed tags, there's no reason for it to be in the pantry.
                    if (AllowedTags != null && (node.AvailableTags & AllowedTags) == 0)
                    {
                        continue;
                    }

                    if (pantryAmounts.ContainsKey(node))
                    {
                        throw new DuplicatePantryItemException();
                    }

                    pantryAmounts.Add(node, item.Amt);
                }

                if (pantryAmounts.Keys.Count == 0)
                {
                    throw new ImpossibleQueryException();
                }

                pantryIngredients = pantryAmounts.Keys.ToArray();
            }

            if (profile.FavoriteIngredients != null)
            {
                var i = 0;
                foreach (var ing in profile.FavoriteIngredients)
                {
                    var node = this.db.FindIngredient(ing);
                    favIngs[i] = node.Key;
                }
            }

            if (profile.FavoriteTags != null)
            {
                foreach (var tag in profile.FavoriteTags)
                {
                    this.favTags[tag.Value] = true;
                }
            }

            if (profile.BlacklistedIngredients != null)
            {
                ingBlacklist = new List <IngredientNode>();
                foreach (var ing in profile.BlacklistedIngredients)
                {
                    var node = this.db.FindIngredient(ing);
                    ingBlacklist.Add(node);
                }
            }

            if (profile.Ratings != null)
            {
                ratings = new Dictionary <RecipeNode, byte>(profile.Ratings.Length);
                foreach (var r in profile.Ratings)
                {
                    var n = this.db.FindRecipe(r.RecipeId);
                    ratings.Add(n, r.Rating);
                }
            }
            else
            {
                ratings = new Dictionary <RecipeNode, byte>(0);
            }
        }
Esempio n. 9
0
 public void LoadSnapshot()
 {
     db = new DBSnapshot(context);
 }
Esempio n. 10
0
 public void LoadSnapshot()
 {
     db = new DBSnapshot(context);
 }
        Dictionary<IngredientNode, IngredientUsage> totals; //Hold totals for each scoring round so we don't have to reallocate map every time

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Create a ModelingSession instance.
        /// </summary>
        /// <param name="context">KitchenPC context used for this modeling session.</param>
        /// <param name="db">Object containing all available recipes, ratings, and trend information.</param>
        /// <param name="profile">Object containing user specific information, such as pantry and user ratings.</param>
        public ModelingSession(IKPCContext context, DBSnapshot db, IUserProfile profile)
        {
            this.db = db;
             this.context = context;
             this.profile = profile;
             this.favTags = new bool[RecipeTag.NUM_TAGS];
             this.favIngs = new int[profile.FavoriteIngredients.Length];

             if (profile.Pantry != null && profile.Pantry.Length == 0) //Empty pantries must be null, not zero items
             {
            throw new EmptyPantryException();
             }

             if (profile.AllowedTags != null)
             {
            AllowedTags = profile.AllowedTags;
             }

             if (profile.Pantry != null)
             {
            pantryAmounts = new Dictionary<IngredientNode, float?>();
            foreach (var item in profile.Pantry)
            {
               var node = this.db.FindIngredient(item.IngredientId);

               //If an ingredient isn't used by any recipe, there's no reason for it to be in the pantry.
               if (node == null)
               {
                  continue;
               }

               //If an ingredient exists, but doesn't have any link to any allowed tags, there's no reason for it to be in the pantry.
               if (AllowedTags != null && (node.AvailableTags & AllowedTags) == 0)
               {
                  continue;
               }

               if (pantryAmounts.ContainsKey(node))
               {
                  throw new DuplicatePantryItemException();
               }

               pantryAmounts.Add(node, item.Amt);
            }

            if (pantryAmounts.Keys.Count == 0)
            {
               throw new ImpossibleQueryException();
            }

            pantryIngredients = pantryAmounts.Keys.ToArray();
             }

             if (profile.FavoriteIngredients != null)
             {
            var i = 0;
            foreach (var ing in profile.FavoriteIngredients)
            {
               var node = this.db.FindIngredient(ing);
               favIngs[i] = node.Key;
            }
             }

             if (profile.FavoriteTags != null)
             {
            foreach (var tag in profile.FavoriteTags)
            {
               this.favTags[tag.Value] = true;
            }
             }

             if (profile.BlacklistedIngredients != null)
             {
            ingBlacklist = new List<IngredientNode>();
            foreach (var ing in profile.BlacklistedIngredients)
            {
               var node = this.db.FindIngredient(ing);
               ingBlacklist.Add(node);
            }
             }

             if (profile.Ratings != null)
             {
            ratings = new Dictionary<RecipeNode, byte>(profile.Ratings.Length);
            foreach (var r in profile.Ratings)
            {
               var n = this.db.FindRecipe(r.RecipeId);
               ratings.Add(n, r.Rating);
            }
             }
             else
             {
            ratings = new Dictionary<RecipeNode, byte>(0);
             }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ModelingSession"/> class.
        /// </summary>
        /// <param name="context">KitchenPC context used for this modeling session.</param>
        /// <param name="db">Object containing all available recipes, ratings, and trend information.</param>
        /// <param name="profile">Object containing user specific information, such as pantry and user ratings.</param>
        public ModelingSession(IKPCContext context, DBSnapshot db, IUserProfile profile)
        {
            Log = LogManager.GetLogger(typeof(ModelingSession));
            this.dataBase = db;
            this.context = context;
            this.profile = profile;
            this.favoriteTags = new bool[RecipeTag.NumberOfTags];
            this.favoriteIngredients = new int[profile.FavoriteIngredients.Length];

            // Empty pantries must be null, not zero items
            if (this.profile.Pantry != null && this.profile.Pantry.Length == 0)
            {
                throw new EmptyPantryException();
            }

            if (this.profile.AllowedTags != null)
            {
                this.allowedTags = this.profile.AllowedTags;
            }

            if (this.profile.Pantry != null)
            {
                this.pantryAmounts = new Dictionary<IngredientNode, float?>();
                foreach (var item in this.profile.Pantry)
                {
                    var node = this.dataBase.FindIngredient(item.IngredientId);

                    // If an ingredient isn't used by any recipe, there's no reason for it to be in the pantry.
                    if (node == null)
                    {
                        continue;
                    }

                    // If an ingredient exists, but doesn't have any link to any allowed tags, there's no reason for it to be in the pantry.
                    if (this.allowedTags != null && (node.AvailableTags & this.allowedTags) == 0)
                    {
                        continue;
                    }

                    if (this.pantryAmounts.ContainsKey(node))
                    {
                        throw new DuplicatePantryItemException();
                    }

                    this.pantryAmounts.Add(node, item.Amount);
                }

                if (this.pantryAmounts.Keys.Count == 0)
                {
                    throw new ImpossibleQueryException();
                }

                this.pantryIngredients = this.pantryAmounts.Keys.ToArray();
            }

            if (this.profile.FavoriteIngredients != null)
            {
                var i = 0;
                foreach (var ingredient in this.profile.FavoriteIngredients)
                {
                    var node = this.dataBase.FindIngredient(ingredient);
                    this.favoriteIngredients[i] = node.Key;
                }
            }

            if (this.profile.FavoriteTags != null)
            {
                foreach (var tag in this.profile.FavoriteTags)
                {
                    this.favoriteTags[tag.Value] = true;
                }
            }

            if (this.profile.BlacklistedIngredients != null)
            {
                this.ingredientBlacklist = new List<IngredientNode>();
                foreach (var ingredient in this.profile.BlacklistedIngredients)
                {
                    var node = this.dataBase.FindIngredient(ingredient);
                    this.ingredientBlacklist.Add(node);
                }
            }

            if (this.profile.Ratings != null)
            {
                this.ratings = new Dictionary<RecipeNode, byte>(profile.Ratings.Length);
                foreach (var recipe in this.profile.Ratings)
                {
                    var node = this.dataBase.FindRecipe(recipe.RecipeId);
                    this.ratings.Add(node, recipe.Rating);
                }
            }
            else
            {
                this.ratings = new Dictionary<RecipeNode, byte>(0);
            }
        }
Esempio n. 13
0
 public void LoadSnapshot()
 {
     this.dataBase = new DBSnapshot(this.context);
 }