// For recieving and sending replies to host as far as I can tell private static bool ApiReceiver(SoapAPI api) { try { // Based on what myApi.MessageType is switch (api.MessageType) { case MessageTypes.Request: // Did we recieve a request for a reply from the host? OnRequest?.Invoke(api, new VmsRequestEventArgs { Request = new VmsCommand(api) }); break; case MessageTypes.Reply: // Did we recieve a reply from the host? OnReply?.Invoke(api, new VmsReplyEventArgs { Reply = new VmsCommand(api) }); break; default: break; } return(true); } catch (Exception ex) { //MessageBox.Show("Error: " + ex.ToString()); return(false); } }
public void Cancel(long userId) { userRepository.UpdateUser(new UserRecord(userId) { Status = UserStatusRecord.DefaultStatus }); OnReply?.Invoke(this, new ReplyOnCancel(userId)); }
public void GetPlantsByUserEvent(long userId) { var plants = plantRepository.GetPlantsByUser(userId) .Select(record => record.Name); ChangeUserStatus(userId, UserStatus.GetPlantsNames); OnReply?.Invoke(this, new ReplyOnGetPlants(userId, plants)); }
public void Reply(SentMessage message, [CanBeNull] ReceivedMessage receivedMessage, User.User user) { OnReply?.Invoke(user, new Tuple <SentMessage, ReceivedMessage>(message, receivedMessage)); foreach (var messenger in _messengers) { messenger.Send(message, receivedMessage, user); } }
public void CheckUserExistEvent(long userId, string userName) { var isAdded = AddUser(userId, userName); if (isAdded) { OnReply?.Invoke(this, new ReplyOnStart(userId, userName, isAdded)); } }
public void GetWeekSchedule(long userId) { var user = GetUserById(userId); var plants = GetPlantsByUser(user).Split('\n').TakeWhile(p => p != "") .Select(p => GetPlantByUser(user, p)); var stats = new Schedule(plants); OnReply?.Invoke(this, new ReplyOnSchedule(userId, stats.GetStatistics())); }
public void GetPlantsToDeleteEvent(long userId) { var plants = plantRepository.GetPlantsByUser(userId) .Select(record => record.Name); if (plants.Any()) { ChangeUserStatus(userId, UserStatus.DeletePlantByName); } OnReply?.Invoke(this, new ReplyOnGetPlantsToDelete(userId, plants)); }
public RepairDroid(IntCodeStateMachine cpu, ICommandInput commandInput) { _cpu = cpu; _commandInput = commandInput; _commandInput.InputReceived += (_, v) => { var cmd = (MovementCommand)v; if (v < 1 || v > 4) { throw new Exception("Wrong input value"); } _cpu.SetInput((int)cmd); }; _cpu.OnOutput += (_, o) => { _lastOutput = (RepairDroidStatusCode)o; OnReply?.Invoke(this, _lastOutput); commandInput.AwaitInput(); }; }
public void AddPlantPhotoEvent(long userId, string plantName, string photoId) { var isAdded = AddPhoto(userId, plantName, photoId); OnReply?.Invoke(this, new ReplyOnSetPlantPhoto(userId, plantName, isAdded)); }
public void AddPlantByUserEvent(long userId) { ChangeUserStatus(userId, UserStatus.SendPlantName); OnReply?.Invoke(this, new ReplyOnWantedAddPlant(userId)); }
public void StartEvent(long userId, string userName) { OnReply?.Invoke(this, new ReplyOnStart(userId, userName, AddUser(userId, userName))); }
public void HandleNonexistingCommand(long userId, string message) { var status = GetUserStatus(userId); switch (status) { case UserStatus.GetPlantsNames: { var existingPlants = GetPlantsByUser(new User(userId)); if (existingPlants.Contains(message)) { var plant = GetPlantByUser(new User(userId), message); if (string.IsNullOrEmpty(plant.FirstPhotoId)) { OnReply?.Invoke(this, new ReplyOnGetPlantPhoto(userId, false)); } else { OnReply?.Invoke( this, new ReplyOnGetPlantPhoto(userId, plant.Name, plant.FirstPhotoId, plant.LastPhotoId, plant.AddingDate, true)); } } break; } case UserStatus.SendPlantName: { var input = message.Split("\n", StringSplitOptions.RemoveEmptyEntries); var existingPlants = GetPlantsByUser(new User(userId)); if (input.Length != 1 || input[0].Length > 25 || existingPlants.Contains(input[0])) { OnReply?.Invoke(this, new ReplyOnWantedAddPlant(userId, true)); return; } SetNewPlantName(userId, message); OnReply?.Invoke(this, new ReplyOnSetPlantName(userId)); break; } case UserStatus.SendPlantWateringInterval: { if (!int.TryParse(message, out var interval) || interval <= 0) { OnReply?.Invoke(this, new ReplyOnSetPlantName(userId, true)); return; } AddNewPlantFromActivePlantWithWateringInterval(userId, interval); OnReply?.Invoke(this, new ReplyOnSetWateringInterval(userId)); break; } case UserStatus.DeletePlantByName: OnReply?.Invoke(this, new ReplyOnDeletedPlant(userId, message, DeletePlant(userId, message))); break; default: OnReply?.Invoke(this, new ReplyOnNotCommand(userId)); break; } }
public void GetHelp(long userId) { OnReply?.Invoke(this, new ReplyOnHelp(userId)); }
public string Send() { Reply = KodiBridge.SendMessage(this.Request); OnReply?.Invoke(this, new MessageReplyEventArgs(Reply)); return(Reply); }