Пример #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();
        }
Пример #2
0
        private async void OnPredefinedServiceSelectionIsEnabledChanged(object sender, IsEnabledChangedEventArgs e)
        {
            var disabledServices = new V1DisabledServices();

            disabledServices.Guids.AddRange(m_predefinedServiceSelections.Where(x => !x.IsEnabled).Select(x => x.Service.Guid));
            await NetworkServiceConfigurator.WriteDisabledServicesAsync(disabledServices);
        }
Пример #3
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);
            };
        }
Пример #4
0
        private static async Task <NetworkServicePresenter <NetworkServiceRegistryEntry>[]> GetPredefinedNetworkServicesAsync()
        {
            var temp = await NetworkServiceConfigurator.LoadPredefinedNetworkServicesAsync();

            var result = temp
                         .Select(x => new NetworkServicePresenter <NetworkServiceRegistryEntry>(x.Name, x.Protocol, x.Port, x.IsEnabled, x.Service))
                         .ToArray();

            return(result);
        }
Пример #5
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);
        }
Пример #6
0
        private static async Task <INetworkServiceCore[]> GetNetworkServicesAsync()
        {
            var predefinedNetworkServices = await NetworkServiceConfigurator.LoadPredefinedNetworkServicesAsync();

            var userNetworkServices = await NetworkServiceConfigurator.LoadUserNetworkServicesAsync();

            var allNetworkServices = predefinedNetworkServices.Cast <INetworkService>().Concat(userNetworkServices.Cast <INetworkService>());
            var tcpNetworkServices = allNetworkServices
                                     .Where(x => x.IsEnabled && x.Protocol == Protocol.Tcp)
                                     .Distinct(NetworkServiceCoreComparer.Instance)
                                     .OrderBy(x => x.Port);
            var udpNetworkServices = allNetworkServices
                                     .Where(x => x.IsEnabled && x.Protocol == Protocol.Udp)
                                     .Distinct(NetworkServiceCoreComparer.Instance)
                                     .OrderBy(x => x.Port);

            return(tcpNetworkServices.Concat(udpNetworkServices).ToArray());
        }