Beispiel #1
0
        public void Show()
        {
            if (ComponentShelf == null)
            {
                try
                {
                    IDesktopWindow desktopWindow = Context.DesktopWindow;

                    ImagePropertiesApplicationComponent component =
                        new ImagePropertiesApplicationComponent(Context.DesktopWindow);

                    IShelf shelf = ApplicationComponent.LaunchAsShelf(Context.DesktopWindow, component,
                                                                      SR.TitleImageProperties, "ImageProperties", ShelfDisplayHint.DockLeft);

                    Shelves.Add(Context.DesktopWindow, shelf);
                    shelf.Closed += delegate { Shelves.Remove(desktopWindow); };
                }
                catch (Exception e)
                {
                    ExceptionHandler.Report(e, Context.DesktopWindow);
                }
            }
            else
            {
                ComponentShelf.Show();
            }
        }
Beispiel #2
0
        public void RemoveShelf(Shelf shelf)
        {
            var default_shelf = GetDefaultshelf();
            var books_to_move = shelf.Books.ToList();

            books_to_move.Apply(b => b.Shelf = default_shelf);
            Shelves.Remove(shelf);
        }
Beispiel #3
0
 /// <summary>
 ///     Removes a shelf from the collection
 /// </summary>
 public void Remove(Shelf shelf)
 {
     TotalPrice    -= shelf.Price;
     TotalQuantity -= shelf.Quantity;
     if (Shelves.Contains(shelf))
     {
         Shelves.Remove(shelf);
     }
 }
Beispiel #4
0
        private async void DeletShelf(ShelfViewModel vm)
        {
            logger.Trace($"Deleting shelf [{vm.Name}]");

            var result = (bool)await DialogManager.ShowPromptDialogAsync("Deleting Shelf", "All books on the shelf will be moved to the default shelf.\n\rDo you want to continue");

            if (result)
            {
                state_manager.CurrentCollection.RemoveShelf(vm.Obj);
                Shelves.Remove(vm);
            }
        }
Beispiel #5
0
        private static void OnShelfClosed(object sender, ClosedEventArgs e)
        {
            // We need to cache the owner DesktopWindow (_desktopWindow) because this tool is an
            // ImageViewer tool, disposed when the viewer component is disposed.  Shelves, however,
            // exist at the DesktopWindow level and there can only be one of each type of shelf
            // open at the same time per DesktopWindow (otherwise things look funny).  Because of
            // this, we need to allow this event handling method to be called after this tool has
            // already been disposed (e.g. viewer workspace closed), which is why we store the
            // _desktopWindow variable.

            IShelf shelf = (IShelf)sender;

            shelf.Closed -= OnShelfClosed;
            Shelves.Remove(shelf.DesktopWindow);
        }
Beispiel #6
0
 public void Run()
 {
     while (true)
     {
         Console.WriteLine("Welcome to the FridgeSimulator! Press \n" +
                           " 1) to create a new fridge\n" +
                           " 2) to use a fridge\n" +
                           " 3) to list all food on the table\n" +
                           " 4) to list all available fridges\n" +
                           " 5) to list all shelfes \n" +
                           " 6) to delete a fridge \n" +
                           " 7) to save\n" +
                           " 8) to load previous\n" +
                           " 9) to check consumed calories\n" +
                           "10) to eat food from table\n" +
                           "11) to throw out food from table\n" +
                           "12) to throw out a shelf\n" +
                           " 0) to exit");
         var ans = Console.ReadLine();
         if (ans == "1")
         {
             Console.Clear();
             try
             {
                 var newFridge = AddRefig();
                 Console.WriteLine($"You have created a new {newFridge.fridgeSize} fridge it has {newFridge.shelfContainer.Length} shelves, {newFridge.shelfContainer[0].Capacity} unit free space each!");
             }
             catch (FridgeAlreadyExistsException)
             {
                 Console.WriteLine("Please choose an uniqe name for your fridge!");
             }
         }
         else if (ans == "2")
         {
             Console.Clear();
             try
             {
                 if (Refigrigators.Count > 0)
                 {
                     Console.WriteLine("Which Fridge you want to use?");
                     var fridgeName = Console.ReadLine();
                     var refig      = mh.FindFrifgeByName(fridgeName, Refigrigators);
                     inFridge = true;
                     Console.Clear();
                     while (inFridge)
                     {
                         FridgeMenuLogic(refig, FridgeMenu(refig));
                     }
                 }
                 Console.WriteLine("You have no fridge yet!");
             }
             catch (NoSuchRefigrigatorException)
             {
                 Console.WriteLine("There is no Fridge called like that!");
             }
         }
         else if (ans == "3")
         {
             Console.Clear();
             if (Foods.Count > 0)
             {
                 foreach (var food in Foods)
                 {
                     if (food.Size > 80)
                     {
                         Console.WriteLine($"{food.Name} it's a big item!");
                     }
                     else
                     {
                         Console.WriteLine(food.Name);
                     }
                 }
             }
             else
             {
                 Console.WriteLine("There are no foods on the table!");
             }
         }
         else if (ans == "4")
         {
             Console.Clear();
             if (Refigrigators.Count > 0)
             {
                 foreach (var fridge in Refigrigators)
                 {
                     Console.WriteLine(fridge.Name);
                 }
             }
             else
             {
                 Console.WriteLine("There are no fridges yet!");
             }
         }
         else if (ans == "5")
         {
             Console.Clear();
             if (Shelves.Count > 0)
             {
                 foreach (var shelf in Shelves)
                 {
                     Console.WriteLine($"The ID of the shelf: {shelf.ID}, the size is: {shelf.ShelfSize}  ");
                 }
             }
             else
             {
                 Console.WriteLine("No shelves outside of the fridge!");
             }
         }
         else if (ans == "6")
         {
             Console.Clear();
             try
             {
                 if (Refigrigators.Count > 0)
                 {
                     Console.WriteLine("Which Fridge you want to remove?");
                     var fridgeName = Console.ReadLine();
                     var refig      = mh.FindFrifgeByName(fridgeName, Refigrigators);
                     Refigrigators.Remove(refig);
                     Console.WriteLine($"The {fridgeName} has been removed!");
                 }
                 else
                 {
                     Console.WriteLine("You have no fridge yet!");
                 }
             }
             catch (NoSuchRefigrigatorException)
             {
                 Console.WriteLine("There is no Fridge called like that!");
             }
         }
         else if (ans == "7")
         {
             Console.Clear();
             //save
             logger.Save(Refigrigators);
             if (Shelves.Count > 0)
             {
                 logger.SaveShelf(Shelves, "shelfInventory.xml");
             }
             if (Foods.Count > 0)
             {
                 logger.SaveFood(Foods, "foodInventory.xml");
             }
             Console.WriteLine("We saved your work!");
         }
         else if (ans == "8")
         {
             //Load
             Console.Clear();
             try
             {
                 Refigrigators = logger.Load("Inventory.xml");
                 if (File.Exists("shelfInventory.xml"))
                 {
                     Shelves = logger.LoadShelf("shelfInventory.xml");
                 }
                 if (File.Exists("foodInventory.xml"))
                 {
                     Foods = logger.LoadFood("foodInventory.xml");
                 }
                 Console.WriteLine("We loaded your previous simulation");
             }
             catch (System.IO.FileNotFoundException)
             {
                 Console.WriteLine("No previous save!");
             }
         }
         else if (ans == "9")
         {
             Console.Clear();
             Console.WriteLine($"You consumed {consumedCalories} calories");
         }
         else if (ans == "10")
         {
             Console.Clear();
             try
             {
                 if (Foods.Count > 0)
                 {
                     Console.WriteLine("What you want to eat?");
                     var foodToEatFromTable = Console.ReadLine();
                     consumedCalories += mh.ConsumFoodFromTable(Foods, foodToEatFromTable);
                     Console.WriteLine($"You have eat {foodToEatFromTable} from table!");
                 }
                 else
                 {
                     Console.WriteLine("There are no foods on the table!");
                 }
             }
             catch (FoodNotExistsException)
             {
                 Console.WriteLine("You have no food called like that in the table!");
             }
         }
         else if (ans == "11")
         {
             Console.Clear();
             try
             {
                 if (Foods.Count > 0)
                 {
                     Console.WriteLine("What you want to throw out?");
                     var foodToRemoveFromTable = Console.ReadLine();
                     mh.ConsumFoodFromTable(Foods, foodToRemoveFromTable);
                     Console.WriteLine($"You have thrown out {foodToRemoveFromTable} from table!");
                 }
                 else
                 {
                     Console.WriteLine("There are no foods on the table!");
                 }
             }
             catch (FoodNotExistsException)
             {
                 Console.WriteLine("You have no food called like that in the table!");
             }
         }
         else if (ans == "12")
         {
             Console.Clear();
             try
             {
                 if (Shelves.Count > 0)
                 {
                     Console.WriteLine("Which shelf you want to remove?\n(If you still have the fridge better to keep the shelf, it can't be recreate later!)\n");
                     for (int i = 0; i < Shelves.Count; i++)
                     {
                         Console.WriteLine($"{i + 1}) {Shelves[i].ShelfSize} shelf.");
                     }
                     var shelfToRemove = Convert.ToInt32(Console.ReadLine());
                     Shelves.Remove(Shelves[shelfToRemove - 1]);
                     Console.WriteLine("You removed a shelf!");
                 }
                 else
                 {
                     Console.WriteLine("No shelf outside!");
                 }
             }
             catch (System.ArgumentOutOfRangeException)
             {
                 Console.WriteLine("Invalid input!");
             }
         }
         else if (ans == "0")
         {
             Console.WriteLine("Bye!");
             System.Environment.Exit(0);
         }
         else
         {
             Console.WriteLine("Invalid input");
             Thread.Sleep(600);
             Console.Clear();
         }
     }
 }