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); }; }
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 void Services_should_match_expected() { V1UserServices temp; V1UserServices.TryCreateFromXml(Xml, out temp); m_output.Services.ShouldEqual(temp.Services, Comparer); }
protected override void BecauseOf() { V1UserServices source; V1UserServices.TryCreateFromXml(Xml, out source); var temp = source.ToXml(); V1UserServices.TryCreateFromXml(temp, out m_output); }
private static async Task <V1UserServices> ReadUserServicesAsync() { var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(V1UserServicesFileName, CreationCollisionOption.OpenIfExists); var xml = await FileIO.ReadTextAsync(file); V1UserServices output; V1UserServices.TryCreateFromXml(xml, out output); return(output); }
public static async Task WriteUserServicesAsync(V1UserServices input) { if (input == null) { throw new ArgumentNullException("input"); } var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(V1UserServicesFileName, CreationCollisionOption.OpenIfExists); await FileIO.WriteTextAsync(file, input.ToXml()); }
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); }
protected override void BecauseOf() { m_result = V1UserServices.TryCreateFromXml(Xml, out m_output); }
protected override void BecauseOf() { m_exception = Catch(() => V1UserServices.TryCreateFromXml(null, out m_output)); }