예제 #1
0
        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;
        }
예제 #2
0
 public BuildViewTask(Project project)
 {
     _project = project;
 }
예제 #3
0
 public BuildThtmlTask(Project project)
 {
     _project = project;
 }
예제 #4
0
        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);
                }
            }
        }
예제 #5
0
        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); }));
        }