public FileModel(MainModel parent, string file, UrlSate sate) { Parent = parent; _file = file; _sate = sate; Name = Path.GetFileNameWithoutExtension(file); try { Urls = new ObservableCollection <UrlModel>(File.ReadAllLines(file) .Distinct() .Where(line => !string.IsNullOrEmpty(line) && !Regex.IsMatch(line, @"^\s*#")) .Select((item, index) => { var model = new UrlModel(this) { Index = index + 1, Value = item }; return(model); })); } catch (Exception e) { MessageBox.Show(e.GetBaseException().Message); Urls = new ObservableCollection <UrlModel>(); } _selectedUrl = Urls.FirstOrDefault(url => _sate.Value == url.Value) ?? Urls.FirstOrDefault(); _curentUrl = _selectedUrl; _sate.Value = _selectedUrl?.Value; BackCommand = new DelegateCommand(Back, CanBack); ForwardCommand = new DelegateCommand(Forward, CanForward); }
public bool HasDiff(UrlSate state) { return(File != state.File || Value != state.Value); }