public QaList LoadStubs(QaListStubs stubs) { var list = new QaList { Name = stubs.Name }; list.Items.AddRange(stubs.Items.Select(GetItemById).Where(it => it != null)); return(list); }
public void LoadList(string file) { var list = new QaListStubs() { Name = Path.GetFileNameWithoutExtension(file), Filename = file }; list.Items.AddRange(File.ReadAllLines(file)); lists.Add(list); OnListModified?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, list)); }
public QaListStubs CreateList(string name, IList <QaItem> initialMembers = null) { if (string.IsNullOrWhiteSpace(name)) { throw new IllegalListNameException(); } if (_lists.Any(it => it.Name == name)) { throw new DuplicateListNameException(); } if (name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { throw new IllegalListNameException(); } var filename = MarsherFilesystem.GetPath(ListDirectoryName, name + ExtensionName); if (File.Exists(filename)) { LoadList(filename); throw new DuplicateListNameException(); } try { File.Create(filename).Close(); } catch (IOException) { throw new IllegalListNameException(); } var list = new QaListStubs() { Name = name, Filename = filename }; _lists.Add(list); if (initialMembers != null) { list.Items.AddRange(initialMembers.Select(it => it.Id)); } OnListModified?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, list)); return(list); }
public bool CheckDuplicateListName(string name, QaListStubs current = null) { if (_lists.Any(it => it.Name == name && !ReferenceEquals(it, current))) { return(true); } if (current != null) { return(false); } var filename = MarsherFilesystem.GetPath(ListDirectoryName, name + ExtensionName); if (!File.Exists(filename)) { return(false); } LoadList(filename); return(true); }
public QaListStubs CreateList(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new IllegalListNameException(); } if (lists.Any(it => it.Name == name)) { throw new DuplicateListNameException(); } if (name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { throw new IllegalListNameException(); } var filename = Path.Combine(ListDirectoryName, name + ExtensionName); if (File.Exists(filename)) { LoadList(filename); throw new DuplicateListNameException(); } try { File.Create(filename).Close(); } catch (IOException) { throw new IllegalListNameException(); } var list = new QaListStubs() { Name = name, Filename = filename }; lists.Add(list); OnListModified?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, list)); return(list); }
public void UpdateList(QaListStubs stub, bool filenameChanged = false) { var filename = Path.Combine(ListDirectoryName, stub.Name + ExtensionName); if (filenameChanged) { if (string.IsNullOrWhiteSpace(stub.Name)) { throw new IllegalListNameException(); } if (lists.Any(it => it.Name == stub.Name && it != stub)) { throw new DuplicateListNameException(); } if (stub.Name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { throw new IllegalListNameException(); } try { File.Move(stub.Filename, filename); } catch (FileNotFoundException) { // Ignored } catch (IOException) { throw new IllegalListNameException(); } stub.Filename = filename; } File.WriteAllLines(filename, stub.Items); OnListModified?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, stub, stub)); }
public void RemoveList(QaListStubs stub) { lists.Remove(stub); OnListModified?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, stub)); File.Delete(stub.Filename); }