예제 #1
0
        public UserApiForwardViewModel(IHexApiService aHexApi, User aUser, ApiSite aApiSite)
        {
            mHexApi  = aHexApi;
            mUser    = aUser;
            mApiSite = aApiSite;

            mMessagesToForward = new ObservableCollection <EMessageType>(aApiSite.SupportedMessages);
            mMessagesToIgnore  = new ObservableCollection <EMessageType>();

            foreach (var theUserApiForward in aUser.Forwards)
            {
                if (theUserApiForward.Type == aApiSite.Type)
                {
                    mForwardToThis = theUserApiForward.ForwardToThis;
                    mApiKey        = theUserApiForward.ApiKey;

                    foreach (var theMessageType in aApiSite.SupportedMessages)
                    {
                        if (!theUserApiForward.Messages.Contains(theMessageType))
                        {
                            mMessagesToIgnore.Add(theMessageType);
                            mMessagesToForward.Remove(theMessageType);
                        }
                    }
                }
            }

            SendToRightCommand    = new RelayCommand <EMessageType>(SendToRight);
            SendToLeftCommand     = new RelayCommand <EMessageType>(SendToLeft);
            SendAllToRightCommand = new RelayCommand(SendAllToRight, () => MessagesToForward.Any());
            SendAllToLeftCommand  = new RelayCommand(SendAllToLeft, () => MessagesToIgnore.Any());
        }
예제 #2
0
        private void UpdateUser()
        {
            UserApiForward theNewForward = new UserApiForward()
            {
                Type          = mApiSite.Type,
                ApiKey        = this.ApiKey,
                ForwardToThis = this.ForwardToThis,
                Messages      = MessagesToForward.ToList()
            };

            UserApiForward theOldForward = null;

            foreach (var theUserApiForward in mUser.Forwards)
            {
                if (theUserApiForward.Type == theNewForward.Type)
                {
                    theOldForward = theUserApiForward;
                }
            }

            if (theOldForward != null)
            {
                mUser.Forwards.Remove(theOldForward);
            }

            mUser.Forwards.Add(theNewForward);
            mHexApi.UpdateUser(mUser);

            SendAllToLeftCommand.RaiseCanExecuteChanged();
            SendAllToRightCommand.RaiseCanExecuteChanged();
        }
예제 #3
0
        SendAllToLeft()
        {
            foreach (var theType in MessagesToIgnore)
            {
                MessagesToForward.Add(theType);
            }
            MessagesToIgnore.Clear();

            UpdateUser();
        }
예제 #4
0
        SendToLeft
        (
            EMessageType aType
        )
        {
            if (aType == EMessageType.Unknown)
            {
                return;
            }

            MessagesToForward.Add(aType);
            MessagesToIgnore.Remove(aType);

            UpdateUser();
        }