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 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()); }
public static bool TryCreateFromXml(string xml, out V1UserServices output) { output = default(V1UserServices); if (xml == null) { throw new ArgumentNullException("xml"); } V1UserServices temp; if (!SerializationHelper.TryCreateFromXml<V1UserServices>(Serializer, xml, out temp)) { return false; } output = temp; return true; }
public static bool TryCreateFromXml(string xml, out V1UserServices output) { output = default(V1UserServices); if (xml == null) { throw new ArgumentNullException("xml"); } V1UserServices temp; if (!SerializationHelper.TryCreateFromXml <V1UserServices>(Serializer, xml, out temp)) { return(false); } output = temp; return(true); }
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); }
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); }; }