public static Project FromFile(string input, IFileSystem fileSystem) { var jObject = JsonConvert.DeserializeObject<Dictionary<string, JToken>>(input); var project = new Project(); foreach (var entry in jObject) { var kindObj = entry.Key; string[] list; if (entry.Value is JArray) list = entry.Value.ToObject<string[]>(); else list = new[] {entry.Value.ToObject<string>()}; foreach (var item in list) { var info = fileSystem.GetFileInfo(PathInfo.Create(item)); if (info == null) { var globPattern = GlobPattern.Create(item); if (!globPattern.IsWildcard) throw new InvalidProjectFileException($"Could not find file {item}."); var items = fileSystem.GetFiles(globPattern); foreach (var file in items) { var fileItem = new FileProjectItem(kindObj, file, fileSystem); ProjectItem existing; if (!project.TryGetItemById(fileItem.Identifier, out existing)) project.AddItem(fileItem); } project.AddSubscription(fileSystem.Subscribe(globPattern, a => { HandleChange(a, project, kindObj, fileSystem); })); } else { AddFile(fileSystem, project, kindObj, info, item); } } } return project; }
public BuildViewTask(Project project) { _project = project; }
public BuildThtmlTask(Project project) { _project = project; }
private static void HandleChange(FileChangeEventArgs a, Project project, string kindObj, IFileSystem fileSystem) { if (a.ChangeType == FileChangeType.Created) { var item = new FileProjectItem(kindObj, a.FileInfo, fileSystem); if (!project.Contains(item.Identifier)) project.AddItem(item); } else { var changedItem = project.GetItems() .OfType<FileProjectItem>() .FirstOrDefault(f => f.FileInfo.FilePath.Equals(a.FileInfo.FilePath)); if (changedItem != null) { if (a.ChangeType == FileChangeType.Changed) project.Touch(changedItem); else if (a.ChangeType == FileChangeType.Deleted) project.RemoveItem(changedItem); } } }
private static void AddFile(IFileSystem fileSystem, Project project, string kindObj, IFileInfo info, string item) { project.AddItem(new FileProjectItem(kindObj, info, fileSystem)); project.AddSubscription(fileSystem.Subscribe(GlobPattern.Exact(item), a => { HandleChange(a, project, kindObj, fileSystem); })); }