/// <summary> /// Constructs a new watcher. /// </summary> /// <param name="project">The project to watch.</param> public SiteWatcher(SiteProject project) { this.Project = project; this.Watcher.EnableRaisingEvents = false; this.Watcher.Path = this.Project.Directory.FullName; this.Watcher.Filter = "*.*"; this.Watcher.IncludeSubdirectories = true; this.Watcher.Changed += OnChanged; this.Watcher.Created += OnChanged; this.Timer = new Timer(this.OnTick, null, Timeout.Infinite, Timeout.Infinite); }
/// <summary> /// Constructs a new handler. /// </summary> /// <param name="project"></param> public SiteHandler(SiteProject project) { this.Project = project; this.ReloadScript = GetScript(); Service.Started += () => { // Bind the watcher this.Watcher = new SiteWatcher(project); this.Watcher.Bind(() => { this.Project.Update(); }); }; }
/// <summary> /// Spins a in-process webserver. /// </summary> /// <param name="path"></param> public static void Serve(DirectoryInfo path) { // Load the project and fetch the files using (var project = SiteProject.FromDisk(path)) { // Rebuid everything first SiteProject.Bake(path, BakeMode.Fast); // Register the handler Service.Http.Register(new SiteHandler(project)); // Spin Spike Engine on this thread Service.Listen( new TcpBinding(IPAddress.Any, project.Configuration.Port) ); } }
/// <summary> /// Creates a site project from disk. /// </summary> /// <param name="path">The path to the configuration file.</param> /// <returns>The project.</returns> public static SiteProject FromDisk(DirectoryInfo path, string language = null) { if (!path.Exists) { throw new FileNotFoundException("Unable to load the project, as the directory specified does not exist. Directory: " + path.FullName); } // Prepare a project var project = new SiteProject(); // Set the path where the project lives project.Directory = path; project.Configuration = SiteConfig.Read(path); // If we don't have the language specified, find the first language // in the configuration file. if (language == null && project.Configuration.Languages != null) { language = project.Configuration.Languages.FirstOrDefault(); } if (language == null) { language = "default"; } // Set the destination to the sub-language destination if (language != "default") { project.Configuration.Destination = Path.Combine(project.Configuration.Destination, language); } // Set the language of the project project.Language = language; // Load translation provider project.Translations = new TranslationProvider(project); // Assign a provider project.Assets = new DiskAssetProvider(path); project.ViewEngine = new RazorViewEngine(project); // We have a project! return(project); }
/// <summary> /// Builds the project. /// </summary> /// <param name="path"></param> /// <param name="mode"></param> public static void Bake(DirectoryInfo path, BakeMode mode) { // Read the configuration file at destination var config = SiteConfig.Read(path); if (config.Languages == null || config.Languages.Count == 0) { // Make sure we have a default language config.Languages = new List <string>(); config.Languages.Add("default"); } Tracing.Info("Bake", "Baking: " + path.FullName); foreach (var language in config.Languages) { // Load the project and fetch the files using (var project = SiteProject.FromDisk(path, language)) { // Bake the project project.Bake(mode); } } }
static void Main(string[] args) { var options = new Options(); if (args.Length == 0) { Console.Write(options.GetUsage()); } if (CommandLine.Parser.Default.ParseArguments(args, options)) { try { if (options.Bake != null) { // Bake is requested SiteProject.Bake(new DirectoryInfo(options.Bake), BakeMode.Optimized); } else if (options.Serve != null) { // Serve is requested SiteProject.Serve(new DirectoryInfo(options.Serve)); } else if (Debugger.IsAttached) { // Under debugger, just serve SiteProject.Serve(new DirectoryInfo(@"..\..\..\Test\")); } } catch (Exception ex) { Tracing.Error("Baker", ex.Message); Tracing.Error("Baker", ex.StackTrace); } } }
/// <summary> /// Constructs a new file wrapper around a file info. /// </summary> /// <param name="project">The project to which this file belongs.</param> /// <param name="file">The file info to wrap.</param> public AssetFile(SiteProject project, FileInfo file) { this.Info = file; this.Owner = project; }
/// <summary> /// Creates a site project from disk. /// </summary> /// <param name="path">The path to the configuration file.</param> /// <returns>The project.</returns> public static SiteProject FromDisk(DirectoryInfo path, string language = null) { if (!path.Exists) throw new FileNotFoundException("Unable to load the project, as the directory specified does not exist. Directory: " + path.FullName); // Prepare a project var project = new SiteProject(); // Set the path where the project lives project.Directory = path; project.Configuration = SiteConfig.Read(path); // If we don't have the language specified, find the first language // in the configuration file. if (language == null && project.Configuration.Languages != null) language = project.Configuration.Languages.FirstOrDefault(); if (language == null) language = "default"; // Set the destination to the sub-language destination if (language != "default") project.Configuration.Destination = Path.Combine(project.Configuration.Destination, language); // Set the language of the project project.Language = language; // Load translation provider project.Translations = new TranslationProvider(project); // Assign a provider project.Assets = new DiskAssetProvider(path); project.ViewEngine = new RazorViewEngine(project); // We have a project! return project; }
/// <summary> /// Constructs a new file wrapper around a file info. /// </summary> /// <param name="file">The file info to wrap.</param> /// <param name="project">The project of this file.</param> public AssetInputFile(SiteProject project, FileInfo file) : base(project, file) { }
/// <summary> /// Constructs a new file wrapper around a file info. /// </summary> /// <param name="file">The file info to wrap.</param> /// <param name="meta">The metadata associated with the output file.</param> /// <param name="project">The project of this file.</param> /// <param name="content">The content of the output file.</param> public AssetOutputFile(SiteProject project, FileInfo file, AssetHeader meta, byte[] content) : base(project, file) { this.CachedContent = content; this.Meta = meta; }
/// <summary> /// Fetches the assets from the data source. /// </summary> /// <param name="project">The project to fetch the data for.</param> /// <returns>The enumerable set of assets.</returns> public abstract IEnumerable<IAssetFile> Fetch(SiteProject project);
/// <summary> /// Fetches the assets from the data source. /// </summary> /// <param name="project">The project to fetch the data for.</param> /// <returns>The enumerable set of assets.</returns> public abstract IEnumerable <IAssetFile> Fetch(SiteProject project);