static void Main(string[] args) { DeviceCreator myDCreator = new DeviceCreator(); UIDevice myUI = new UIDevice(); Dictionary<string, Device> myDict; Dictionary<string, Device> smartHoseDevices = new Dictionary<string, Device>(); smartHoseDevices.Add("nord", myDCreator.CreateDevice("refrigerator")); smartHoseDevices.Add("mitsubishi", myDCreator.CreateDevice("conditioner")); smartHoseDevices.Add("spidola", myDCreator.CreateDevice("radio")); while (true) { // Console.Clear(); Console.WriteLine("Devices in you smart house - " + smartHoseDevices.Count.ToString() + ":"); foreach (KeyValuePair<string, Device> devices in smartHoseDevices) { devices.Value.deviceNotificator += ServiceMessages.Message; Console.WriteLine(devices.Key + " is: " + devices.Value); Console.WriteLine(); } Console.WriteLine(); Console.Write("Enter command: "); string[] commands = Console.ReadLine().ToLower().Split(' '); switch (commands[0]) { case "file": SaveLoadMenu(smartHoseDevices); break; case "exit": //FileOperations.SaveBinaryFormat(myDict, "SmartHouse.dat"); return; case "add": try { smartHoseDevices.Add(commands[1], myDCreator.CreateDevice(commands[2])); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadKey(); } break; case "del": smartHoseDevices.Remove(commands[1]); break; case "power": { foreach (string name in smartHoseDevices.Keys) { if (name == commands[1]) { if ((smartHoseDevices[commands[1]] as IElectricDevice) != null) { myUI.PowerDevice(smartHoseDevices[commands[1]]); } else { Console.WriteLine("Device does not have such a function!"); Console.WriteLine("Press any key"); Console.ReadKey(); } } } } break; case "modework": { foreach (string name in smartHoseDevices.Keys) { if (name == commands[1]) { if ((smartHoseDevices[commands[1]] as IModeOfWork) != null) { myUI.ModeWorkForDevice((IModeOfWork)smartHoseDevices[commands[1]]); } else { Console.WriteLine("Device does not have such a function!"); Console.WriteLine("Press any key"); Console.ReadKey(); } } } } break; case "controlvalue": { foreach (string name in smartHoseDevices.Keys) { if (name == commands[1]) { if ((smartHoseDevices[commands[1]] as IValueControl) != null) { myUI.ValueInDevice((IValueControl)smartHoseDevices[commands[1]]); } else { Console.WriteLine("Device does not have such a function!"); Console.WriteLine("Press any key"); Console.ReadKey(); } } } } break; case "door": { foreach (string name in smartHoseDevices.Keys) { if (name == commands[1]) { if ((smartHoseDevices[commands[1]] as IDoorDevice) != null) { myUI.DoorDevice((IDoorDevice)smartHoseDevices[commands[1]]); } else { Console.WriteLine("Device does not have such a function!"); Console.WriteLine("Press any key"); Console.ReadKey(); } } } } break; default: Help(); break; } } }
static void Main(string[] args) { DeviceCreator myDCreator = new DeviceCreator(); UIDevice myUI = new UIDevice(); Dictionary <string, Device> myDict; Dictionary <string, Device> smartHoseDevices = new Dictionary <string, Device>(); smartHoseDevices.Add("nord", myDCreator.CreateDevice("refrigerator")); smartHoseDevices.Add("mitsubishi", myDCreator.CreateDevice("conditioner")); smartHoseDevices.Add("spidola", myDCreator.CreateDevice("radio")); while (true) { // Console.Clear(); Console.WriteLine("Devices in you smart house - " + smartHoseDevices.Count.ToString() + ":"); foreach (KeyValuePair <string, Device> devices in smartHoseDevices) { devices.Value.deviceNotificator += ServiceMessages.Message; Console.WriteLine(devices.Key + " is: " + devices.Value); Console.WriteLine(); } Console.WriteLine(); Console.Write("Enter command: "); string[] commands = Console.ReadLine().ToLower().Split(' '); switch (commands[0]) { case "file": SaveLoadMenu(smartHoseDevices); break; case "exit": //FileOperations.SaveBinaryFormat(myDict, "SmartHouse.dat"); return; case "add": try { smartHoseDevices.Add(commands[1], myDCreator.CreateDevice(commands[2])); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadKey(); } break; case "del": smartHoseDevices.Remove(commands[1]); break; case "power": { foreach (string name in smartHoseDevices.Keys) { if (name == commands[1]) { if ((smartHoseDevices[commands[1]] as IElectricDevice) != null) { myUI.PowerDevice(smartHoseDevices[commands[1]]); } else { Console.WriteLine("Device does not have such a function!"); Console.WriteLine("Press any key"); Console.ReadKey(); } } } } break; case "modework": { foreach (string name in smartHoseDevices.Keys) { if (name == commands[1]) { if ((smartHoseDevices[commands[1]] as IModeOfWork) != null) { myUI.ModeWorkForDevice((IModeOfWork)smartHoseDevices[commands[1]]); } else { Console.WriteLine("Device does not have such a function!"); Console.WriteLine("Press any key"); Console.ReadKey(); } } } } break; case "controlvalue": { foreach (string name in smartHoseDevices.Keys) { if (name == commands[1]) { if ((smartHoseDevices[commands[1]] as IValueControl) != null) { myUI.ValueInDevice((IValueControl)smartHoseDevices[commands[1]]); } else { Console.WriteLine("Device does not have such a function!"); Console.WriteLine("Press any key"); Console.ReadKey(); } } } } break; case "door": { foreach (string name in smartHoseDevices.Keys) { if (name == commands[1]) { if ((smartHoseDevices[commands[1]] as IDoorDevice) != null) { myUI.DoorDevice((IDoorDevice)smartHoseDevices[commands[1]]); } else { Console.WriteLine("Device does not have such a function!"); Console.WriteLine("Press any key"); Console.ReadKey(); } } } } break; default: Help(); break; } } }