public Task <Errorable <TagID> > ResolvePartialID(TagID.Partial id) { FileInfo[] fis = system.getPathsByPartialID(id); if (fis.Length == 1) { return(Task.FromResult(TagID.TryParse(id.ToString().Substring(0, 2) + fis[0].Name))); } if (fis.Length == 0) { return(Task.FromResult((Errorable <TagID>) new TagIDPartialNoResolutionError(id))); } return(Task.FromResult((Errorable <TagID>) new TagIDPartialAmbiguousResolutionError(id, fis.SelectAsArray(f => TagID.TryParse(id.ToString().Substring(0, 2) + f.Name).Value)))); }
private async Task <Errorable <TagID> > getTagIDByName(TagName tagName) { FileInfo fiTracker = system.getTagPathByTagName(tagName); Debug.Assert(fiTracker != null); if (!fiTracker.Exists) { return(new TagNameDoesNotExistError(tagName)); } byte[] buf; int nr = 0; using (var fs = new FileStream(fiTracker.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, 16384, true)) { // TODO: implement an async buffered Stream: buf = new byte[16384]; nr = await fs.ReadAsync(buf, 0, 16384).ConfigureAwait(continueOnCapturedContext: false); if (nr >= 16384) { // My, what a large tag you have! throw new NotSupportedException(); } } // Parse the TagID: using (var ms = new MemoryStream(buf, 0, nr, false)) using (var sr = new StreamReader(ms, Encoding.UTF8)) { string line = sr.ReadLine(); if (line == null) { return(new TagNameDoesNotExistError(tagName)); } return(TagID.TryParse(line)); } }