/// <summary>
        /// Default Constructor
        /// </summary>
        public AddHotspotUserProfileViewModel(IEventAggregator eventAggregator, HotspotUserProfile toEdit = null)
        {
            _eventAggregator = eventAggregator;
            _toEdit          = toEdit;

            // Call helper methods
            InitCommands();
        }
Beispiel #2
0
        /// <summary>
        /// Adds a certain profile
        /// </summary>
        /// <param name="profile">The profile to add</param>
        /// <returns>The status of the adding process</returns>
        public Task <bool> AddProfileAsync(HotspotUserProfile profile) => Task.Run(() =>
        {
            try
            {
                //_connection.Save(profile);
                _connection.CreateCommand("/ip/hotspot/user/profile/add",
                                          _connection.CreateParameter("name", profile.Name),
                                          _connection.CreateParameter("shared-users", profile.SharedUsers),
                                          _connection.CreateParameter("rate-limit", profile.RateLimit)
                                          ).ExecuteNonQuery();

                return(true);
            }
            catch { return(false); }
        });
Beispiel #3
0
        public void AddUserWithProfileWillNotFail()
        {
            string profileName = "TEST " + DateTime.Now.ToString();
            var profile = new HotspotUserProfile()
            {
                Name = profileName,
            };
            Connection.Save(profile);

            var user = new HotspotUser()
            {
                Name = "User for " + profileName,
                Profile = profileName,
                LimitUptime = "1:00:00",
            };
            Connection.Save(user);
        }
Beispiel #4
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="profile"></param>
        public HotspotUserProfileViewModel(HotspotUserProfile profile)
        {
            UserProfileModel = profile;
            Name             = profile.Name;

            if (string.IsNullOrEmpty(UserProfileModel.RateLimit?.Trim()))
            {
                DownloadSpeed = UploadSpeed = "N/A";
                return;
            }
            else
            {
                var rate = UserProfileModel.RateLimit.Split('/');
                DownloadSpeed = rate[0];
                UploadSpeed   = rate.Length > 1 ? rate[1] : rate[0];
            }
        }
        /// <summary>
        /// A Helper method to init viewmodel commands
        /// </summary>
        private void InitCommands()
        {
            // Init the finish command
            OkayCommand = new DelegateCommand(() =>
            {
                if (HasErrors)
                {
                    return;
                }

                var rate = string.Empty;

                if (!string.IsNullOrEmpty(DownloadSpeed) && !string.IsNullOrEmpty(UploadSpeed))
                {
                    rate = $"{DownloadSpeed}/{UploadSpeed}";
                }
                else if (!string.IsNullOrEmpty(DownloadSpeed))
                {
                    rate = DownloadSpeed;
                }
                else
                {
                    rate = UploadSpeed;
                }

                var profile = new HotspotUserProfile
                {
                    Name        = Name,
                    SharedUsers = SharedUsers,
                    RateLimit   = rate
                };

                _eventAggregator.GetEvent <AddHotspotUserProfileEvent>().Publish(new HotspotUserProfileViewModel(profile));
                DialogHost.CloseDialogCommand.Execute(null, null);
            }, () => CanAdd);
        }
Beispiel #6
0
 /// <summary>
 /// Removes a certain profile
 /// </summary>
 /// <param name="profile">The profile to remove</param>
 /// <returns>The status of the deletion process</returns>
 public Task <bool> RemoveProfileAsync(HotspotUserProfile profile) => Task.Run(() =>
 {
     try { _connection.Delete(profile); return(true); }
     catch { return(false); }
 });