Exemplo n.º 1
0
        private async void CopyAsProfileAction()
        {
            CustomDialog customDialog = new CustomDialog()
            {
                Title = LocalizationManager.GetStringByKey("String_Header_CopyProfile")
            };

            TracerouteProfileViewModel tracerouteProfileViewModel = new TracerouteProfileViewModel(instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);

                TracerouteProfileInfo tracerouteProfileInfo = new TracerouteProfileInfo
                {
                    Name  = instance.Name,
                    Host  = instance.Host,
                    Group = instance.Group,
                    Tags  = instance.Tags
                };

                TracerouteProfileManager.AddProfile(tracerouteProfileInfo);
            }, instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
            }, TracerouteProfileManager.GetProfileGroups(), SelectedProfile);

            customDialog.Content = new TracerouteProfileDialog
            {
                DataContext = tracerouteProfileViewModel
            };

            await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
        }
Exemplo n.º 2
0
        public TracerouteHostViewModel(IDialogCoordinator instance)
        {
            dialogCoordinator = instance;

            InterTabClient = new DragablzTracerouteInterTabClient();

            TabItems = new ObservableCollection <DragablzTabItem>()
            {
                new DragablzTabItem(LocalizationManager.GetStringByKey("String_Header_NewTab"), new TracerouteView(_tabId), _tabId)
            };

            // Load profiles
            if (TracerouteProfileManager.Profiles == null)
            {
                TracerouteProfileManager.Load();
            }

            _tracerouteProfiles = CollectionViewSource.GetDefaultView(TracerouteProfileManager.Profiles);
            _tracerouteProfiles.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
            _tracerouteProfiles.SortDescriptions.Add(new SortDescription("Group", ListSortDirection.Ascending));
            _tracerouteProfiles.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
            _tracerouteProfiles.Filter = o =>
            {
                if (string.IsNullOrEmpty(Search))
                {
                    return(true);
                }

                TracerouteProfileInfo info = o as TracerouteProfileInfo;

                string search = Search.Trim();

                // Search by: Tag
                if (search.StartsWith(tagIdentifier, StringComparison.OrdinalIgnoreCase))
                {
                    if (string.IsNullOrEmpty(info.Tags))
                    {
                        return(false);
                    }
                    else
                    {
                        return(info.Tags.Replace(" ", "").Split(';').Any(str => search.Substring(tagIdentifier.Length, search.Length - tagIdentifier.Length).IndexOf(str, StringComparison.OrdinalIgnoreCase) > -1));
                    }
                }
                else // Search by: Name, Hostname
                {
                    return(info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1 || info.Host.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1);
                }
            };

            LoadSettings();

            _isLoading = false;
        }
        public TracerouteProfileViewModel(Action <TracerouteProfileViewModel> saveCommand, Action <TracerouteProfileViewModel> cancelHandler, List <string> groups, TracerouteProfileInfo profileInfo = null)
        {
            _saveCommand   = new RelayCommand(p => saveCommand(this));
            _cancelCommand = new RelayCommand(p => cancelHandler(this));

            _profileInfo = profileInfo ?? new TracerouteProfileInfo();

            Name = _profileInfo.Name;
            Host = _profileInfo.Host;

            // Get the group, if not --> get the first group (ascending), fallback --> default group
            Group = string.IsNullOrEmpty(_profileInfo.Group) ? (groups.Count > 0 ? groups.OrderBy(x => x).First() : LocalizationManager.GetStringByKey("String_Default")) : _profileInfo.Group;
            Tags  = _profileInfo.Tags;

            _groups = CollectionViewSource.GetDefaultView(groups);
            _groups.SortDescriptions.Add(new SortDescription());

            _isLoading = false;
        }