Esempio n. 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();
        }
        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();
        }
Esempio n. 3
0
        public AppViewModel(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            m_serviceProvider = serviceProvider;
        }
Esempio n. 4
0
        public AppViewModel(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            m_serviceProvider = serviceProvider;
        }
Esempio n. 5
0
        protected PageViewModel(IServiceProvider serviceProvider, AppViewModel appViewModel)
            : base(serviceProvider)
        {
            if (appViewModel == null)
            {
                throw new ArgumentNullException("appViewModel");
            }

            m_appViewModel = appViewModel;
        }
Esempio n. 6
0
        protected PageViewModel(IServiceProvider serviceProvider, AppViewModel appViewModel)
            : base(serviceProvider)
        {
            if (appViewModel == null)
            {
                throw new ArgumentNullException("appViewModel");
            }

            m_appViewModel = appViewModel;
        }
Esempio n. 7
0
        public MainPageViewModel(IServiceProvider serviceProvider, AppViewModel appViewModel)
            : base(serviceProvider, appViewModel)
        {
            m_connectionInfoProperty           = CreateDictionaryProperty(() => ConnectionInfo, () => null);
            m_connectionInfoTaskStatusProperty = CreateDictionaryProperty(() => ConnectionInfoTaskStatus, () => TaskStatus.Created);
            m_dhcpInfoProperty                  = CreateDictionaryProperty(() => DhcpInfo, () => null);
            m_dhcpInfoTaskStatusProperty        = CreateDictionaryProperty(() => DhcpInfoTaskStatus, () => TaskStatus.Created);
            m_externalAddressProperty           = CreateDictionaryProperty(() => ExternalAddress, () => null);
            m_externalAddressTaskStatusProperty = CreateDictionaryProperty(() => ExternalAddressTaskStatus, () => TaskStatus.Created);
            m_statusProperty                  = CreateDictionaryProperty(() => Status, () => String.Empty);
            m_progressPercentProperty         = CreateDictionaryProperty(() => ProgressPercent, () => 0.0d);
            m_isScanInProgressProperty        = CreateDictionaryProperty(() => IsScanInProgress, () => false);
            m_customSelectionCommandsProperty = CreateDictionaryProperty(() => CustomSelectionCommands, () => new ObservableCollection <UICommand>());
            m_startAddressValueProperty       = CreateSettingsProperty(V1SettingsConstants.StartAddressValueKey, () => StartAddressValue, () => 0u, () => { UpdateActionBarControls(); });
            m_isStartAddressValidProperty     = CreateDictionaryProperty(() => IsStartAddressValid, () => false);
            m_endAddressValueProperty         = CreateSettingsProperty(V1SettingsConstants.EndAddressValueKey, () => EndAddressValue, () => 0u, () => { UpdateActionBarControls(); });
            m_isEndAddressValidProperty       = CreateDictionaryProperty(() => IsEndAddressValid, () => false);

            var hostInfoService = ServiceProvider.GetService <IHostInfoService>();
            var hostInfo        = hostInfoService.GetCurrentHostInfo();

            if (hostInfo == null)
            {
                Status = Strings.Status_GetHostInfoFailed;
            }
            else
            {
                var connectionInfoTask  = RunGetConnectionInfoAsync(hostInfo);
                var dhcpInfoTask        = RunGetDhcpInfoAsync(hostInfo);
                var externalAddressTask = RunGetExternalAddressAsync();

                Task.Factory.ContinueWhenAll(new[] { connectionInfoTask, dhcpInfoTask }, t =>
                {
                    if (ConnectionInfo != null)
                    {
                        if (DhcpInfo != null && DhcpInfo.DnsServerAddress != null)
                        {
                            m_dnsResolver = new UdpDnsResolver(
                                new DnsResolverOptions(),
                                new DatagramSocketFactory(),
                                new IPEndpoint(DhcpInfo.DnsServerAddress, Constants.DefaultDnsPort));
                        }

                        SetAddressValues(ConnectionInfo.Network);

                        IsScanInProgress       = false;
                        m_isScanCommandEnabled = true;
                        m_scanCommand.Refresh();
                        m_isCancelScanCommandEnabled = false;
                        m_cancelScanCommand.Refresh();
                    }
                },
                                             CancellationToken.None,
                                             TaskContinuationOptions.None,
                                             TaskScheduler.FromCurrentSynchronizationContext());
            }

            m_scanCommand = new DelegateCommand(async() =>
            {
                var scanStopwatch = new Stopwatch();
                scanStopwatch.Start();

                m_tokenSource = new CancellationTokenSource();

                AvailableServices.Clear();

                IsScanInProgress       = true;
                m_isScanCommandEnabled = false;
                m_scanCommand.Refresh();
                m_isCancelScanCommandEnabled = true;
                m_cancelScanCommand.Refresh();

                Status = Strings.Status_ScanStarted;

                var selectedAddresses = new IPAddressRange(StartAddressValue, EndAddressValue);
                var networkServices   = await GetNetworkServicesAsync();

                var index    = 0;
                var progress = (IProgress <ScanNetworkBatch>) new Progress <ScanNetworkBatch>(batch =>
                {
                    foreach (var result in batch.Results)
                    {
                        if (result.IsAvailable)
                        {
                            AvailableServices.Add(result);
                        }
                    }
                    index          += batch.Results.Count;
                    ProgressPercent = 100.0d * index / (selectedAddresses.Count * networkServices.Length);
                });

                var task = Task.Factory.StartNew(
                    arg => { Scanner.ScanNetwork(m_tokenSource.Token, m_dnsResolver, selectedAddresses, networkServices, progress); },
                    m_tokenSource.Token,
                    TaskCreationOptions.None);
                var t1 = task.ContinueWith(t =>
                {
                    IsScanInProgress       = false;
                    m_isScanCommandEnabled = true;
                    m_scanCommand.Refresh();
                    m_isCancelScanCommandEnabled = false;
                    m_cancelScanCommand.Refresh();

                    var isCancelled = m_tokenSource.Token.IsCancellationRequested;
                    if (isCancelled)
                    {
                        Status          = Strings.Status_ScanCancelled;
                        ProgressPercent = 0.0d;
                    }
                    else
                    {
                        scanStopwatch.Stop();
                        var timeSpan    = scanStopwatch.Elapsed;
                        Status          = Strings.Format_Status_ScanCompleted(timeSpan);
                        ProgressPercent = 100.0d;
                    }

                    m_tokenSource.Dispose();
                },
                                           CancellationToken.None,
                                           TaskContinuationOptions.None,
                                           TaskScheduler.FromCurrentSynchronizationContext());
            },
                                                () => m_isScanCommandEnabled);

            m_cancelScanCommand = new DelegateCommand(() =>
            {
                m_isCancelScanCommandEnabled = false;
                m_cancelScanCommand.Refresh();

                m_tokenSource.Cancel();
            },
                                                      () => m_isCancelScanCommandEnabled);

            m_showServicesCommand = new DelegateCommand(() =>
            {
                AppViewModel.NavigateToServicesPage();
            });

            m_launchUriCommand = new DelegateCommand <IPEndpoint>(endpoint =>
            {
                AppViewModel.NavigateToBrowserPage(endpoint);
            });
        }