Beispiel #1
0
        public NetworkServicesPageViewModel(IServiceProvider serviceProvider, AppViewModel appViewModel)
            : base(serviceProvider, appViewModel)
        {
            m_selectedUserServices.CollectionChanged += OnSelectedUserServicesCollectionChanged;

            m_addUserServiceCommand = new DelegateCommand <UIElement>(e => { OnAddUserServiceCommand(e); });

            m_removeUserServiceCommand = new DelegateCommand(async() =>
            {
                if (m_selectedUserServices.Count > 0)
                {
                    var userServiceSelectionsToRemove = m_selectedUserServices.Cast <NetworkServicePresenter <V1Service> >().ToArray();
                    var userServices = new V1UserServices();
                    foreach (var serviceSelection in m_userNetworkServices)
                    {
                        if (!userServiceSelectionsToRemove.Contains(serviceSelection))
                        {
                            var service   = serviceSelection.Service;
                            var isEnabled = serviceSelection.IsEnabled;
                            userServices.Services.Add(new V1Service(service.Name, service.Protocol, service.Port, isEnabled));
                        }
                    }
                    await NetworkServiceConfigurator.WriteUserServicesAsync(userServices);
                    foreach (var serviceSelection in userServiceSelectionsToRemove)
                    {
                        m_userNetworkServices.Remove(serviceSelection);
                    }
                }
            },
                                                             () => m_selectedUserServices.Count > 0);

            var t = LoadServiceConfigurationAsync();
        }
Beispiel #2
0
        private void OnAddUserServiceCommand(UIElement element)
        {
            var addUserServiceControl = new AddUserServiceControl();
            var flyout = new Flyout();

            flyout.Content         = addUserServiceControl;
            flyout.Placement       = PlacementMode.Top;
            flyout.PlacementTarget = element;
            flyout.IsOpen          = true;
            flyout.Background      = addUserServiceControl.Background;

            addUserServiceControl.AddClicked += async(sender, e) =>
            {
                flyout.IsOpen = false;

                var service = new V1Service(
                    addUserServiceControl.SelectedName,
                    addUserServiceControl.SelectedProtocol.Convert(),
                    UInt16.Parse(addUserServiceControl.SelectedPort),
                    true);
                AddUserServiceSelection(service);

                var userServices = new V1UserServices();
                userServices.Services.AddRange(m_userNetworkServices.Select(x => x.Service));
                await NetworkServiceConfigurator.WriteUserServicesAsync(userServices);
            };
        }
Beispiel #3
0
        private async void OnUserServiceSelectionIsEnabledChanged(object sender, IsEnabledChangedEventArgs e)
        {
            var userServices = new V1UserServices();

            foreach (var serviceSelection in m_userNetworkServices)
            {
                var service   = serviceSelection.Service;
                var isEnabled = serviceSelection.IsEnabled;
                userServices.Services.Add(new V1Service(service.Name, service.Protocol, service.Port, isEnabled));
            }
            await NetworkServiceConfigurator.WriteUserServicesAsync(userServices);
        }