private void GoTwoWordsCommands() { if (CheckDeviseType(command[0])) { if ("create" == command[1].ToLower()) { CreateNewDevice(); } else { command = null; throw new ArgumentException("Command is wrong"); } } else if ("delete" == command[1].ToLower()) { if (deviceList.ContainsKey(command[0])) { deviceList.Remove(command[0]); Console.WriteLine("Device {0} has been removed", command[0]); } else { throw new ArgumentException("Wrong device name"); } } else if ("on" == command[1].ToLower()) { IEnablable device = deviceList[command[0]]; device.On(); } else if ("off" == command[1].ToLower()) { IEnablable device = deviceList[command[0]]; device.Off(); } else if ("defrost" == command[1].ToLower()) { if (deviceList[command[0]] is IDefrostable) { IDefrostable device = (IDefrostable)deviceList[command[0]]; device.Defrost(); } else { throw new ArgumentException("Wrong device"); } } else if ("reset" == command[1].ToLower()) { if (deviceList[command[0]] is IResetable) { IResetable device = (IResetable)deviceList[command[0]]; device.Reset(); } else { throw new ArgumentException("Wrong device"); } } else if ("write" == command[1].ToLower()) { if (deviceList[command[0]] is IGetChannelList) { IGetChannelList device = (IGetChannelList)deviceList[command[0]]; List <string> channelList = device.GetChannelList(); Console.WriteLine("Channel list of {0}", command[0]); foreach (string item in channelList) { Console.WriteLine(item); } Console.ReadLine(); } else { throw new ArgumentException("Wrong device"); } } else { throw new ArgumentException("Wrong command"); } }
public MonorailMailer EnableChanged(IEnablable item, string comment = null) { Template = "EnableChanged"; To = Config != null ? Config.RegisterListEmail : "*****@*****.**"; From = "*****@*****.**"; var lastDisable = "неизвестно"; var reasonDisable = "неизвестно"; var type = ""; var clazz = NHibernateUtil.GetClass(item); if (clazz == typeof(User)) { type = "пользователя"; var user = (User)item; PropertyBag["service"] = user.RootService; var disable = UserLogRecord.LastOff(user.Id); if (disable != null) { lastDisable = String.Format("{0} пользователем {1}", disable.LogTime, disable.OperatorName); if (!item.Enabled) { disable.Comment = comment; disable.Save(); } reasonDisable = disable.Comment; } } if (clazz == typeof(Address)) { type = "адреса"; var address = (Address)item; PropertyBag["service"] = address.Client; var disable = ArHelper.WithSession(session => AddressLogRecord.LastOff(session, address.Id)); if (disable != null) { lastDisable = String.Format("{0} пользователем {1}", disable.LogTime, disable.OperatorName); if (!item.Enabled) { disable.Comment = comment; ActiveRecordMediator.Save(disable); } reasonDisable = disable.Comment; } } if (clazz == typeof(Client)) { type = "клиента"; var client = ActiveRecordMediator <Client> .FindByPrimaryKey(((Service)item).Id); PropertyBag["service"] = client; var disable = ClientLogRecord.LastOff(client); if (disable != null) { lastDisable = String.Format("{0} пользователем {1}", disable.LogTime, disable.OperatorName); if (!item.Enabled) { disable.Comment = comment; disable.Save(); } reasonDisable = disable.Comment; } } if (clazz == typeof(Supplier)) { type = "поставщика"; PropertyBag["service"] = item; var disable = DbSession.Query <SupplierLog>().Where(s => s.Supplier == (Supplier)item && s.Disabled != null && s.Disabled == true).OrderByDescending(s => s.LogTime).FirstOrDefault(); if (disable != null) { lastDisable = String.Format("{0} пользователем {1}", disable.LogTime, disable.OperatorName); if (!item.Enabled) { disable.Comment = comment; DbSession.Save(disable); } reasonDisable = disable.Comment; } } if (item.Enabled) { Subject = String.Format("Возобновлена работа {0}", type); } else { Subject = String.Format("Приостановлена работа {0}", type); } if (!string.IsNullOrEmpty(lastDisable)) { PropertyBag["lastDisable"] = lastDisable; } PropertyBag["item"] = item; PropertyBag["admin"] = SecurityContext.Administrator; if (!string.IsNullOrEmpty(reasonDisable)) { PropertyBag["reasonDisable"] = reasonDisable; } return(this); }