Пример #1
0
        // 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);
            }
        }
Пример #2
0
 public void Cancel(long userId)
 {
     userRepository.UpdateUser(new UserRecord(userId)
     {
         Status = UserStatusRecord.DefaultStatus
     });
     OnReply?.Invoke(this, new ReplyOnCancel(userId));
 }
Пример #3
0
        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));
        }
Пример #4
0
 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);
     }
 }
Пример #5
0
 public Statement(string id, Conversation conversation, string text, OnReply onReply, IsVisible isVisible)
 {
     this.id = id;
     this.conversation = conversation;
     this.text = text;
     this.onReplyCallBack = onReply;
     this.isVisible = isVisible;
 }
Пример #6
0
        public void CheckUserExistEvent(long userId, string userName)
        {
            var isAdded = AddUser(userId, userName);

            if (isAdded)
            {
                OnReply?.Invoke(this, new ReplyOnStart(userId, userName, isAdded));
            }
        }
Пример #7
0
        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()));
        }
Пример #8
0
        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));
        }
Пример #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="code"></param>
 /// <param name="tokens"></param>
 private void HandleDefaultReply(ReplyCode code, string[] tokens)
 {
     if (code >= ReplyCode.ERR_NOSUCHNICK && code <= ReplyCode.ERR_USERSDONTMATCH)
     {
         OnError.Fire(this, new ErrorMessageEventArgs(code, CondenseStrings(tokens, 3)));
     }
     else
     {
         OnReply.Fire(this, new ReplyEventArgs(code, CondenseStrings(tokens, 3)));
     }
 }
Пример #10
0
        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();
            };
        }
Пример #11
0
        public void AddPlantPhotoEvent(long userId, string plantName, string photoId)
        {
            var isAdded = AddPhoto(userId, plantName, photoId);

            OnReply?.Invoke(this, new ReplyOnSetPlantPhoto(userId, plantName, isAdded));
        }
Пример #12
0
 public void AddPlantByUserEvent(long userId)
 {
     ChangeUserStatus(userId, UserStatus.SendPlantName);
     OnReply?.Invoke(this, new ReplyOnWantedAddPlant(userId));
 }
Пример #13
0
 public void StartEvent(long userId, string userName)
 {
     OnReply?.Invoke(this, new ReplyOnStart(userId, userName, AddUser(userId, userName)));
 }
Пример #14
0
        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;
            }
        }
Пример #15
0
 public void GetHelp(long userId)
 {
     OnReply?.Invoke(this, new ReplyOnHelp(userId));
 }
Пример #16
0
 public string Send()
 {
     Reply = KodiBridge.SendMessage(this.Request);
     OnReply?.Invoke(this, new MessageReplyEventArgs(Reply));
     return(Reply);
 }