protected void BuildStyleFile(int fileID, CancelDelegate cancelled) { File file = EngineInstance.Files.FromID(fileID); // Will return null if the file isn't used by this builder Path outputFile = Styles_OutputFile(file.FileName); if (outputFile == null) { return; } if (file.Deleted) { if (System.IO.File.Exists(outputFile)) { System.IO.File.Delete(outputFile); lock (accessLock) { buildState.FoldersToCheckForDeletion.Add(outputFile.ParentFolder); } } } else // file new or changed { // Creates all subdirectories needed. Does nothing if it already exists. System.IO.Directory.CreateDirectory(outputFile.ParentFolder); string extension = outputFile.Extension.ToLower(); if (extension == "js" || extension == "json") { ResourceProcessors.JavaScript jsProcessor = new ResourceProcessors.JavaScript(); string output = jsProcessor.Process(System.IO.File.ReadAllText(file.FileName), EngineInstance.Config.ShrinkFiles); System.IO.File.WriteAllText(outputFile, output); } else if (extension == "css") { ResourceProcessors.CSS cssProcessor = new ResourceProcessors.CSS(); string output = cssProcessor.Process(System.IO.File.ReadAllText(file.FileName), EngineInstance.Config.ShrinkFiles); System.IO.File.WriteAllText(outputFile, output); } else { System.IO.File.Copy(file.FileName, outputFile, true); } } }
// Group: Files.IStyleChangeWatcher Functions // __________________________________________________________________________ public Files.Manager.ReleaseClaimedFileReason OnAddOrChangeFile(Path originalStyleFile) { Path outputStyleFile = Styles_OutputFile(originalStyleFile); if (outputStyleFile == null) { return(Files.Manager.ReleaseClaimedFileReason.SuccessfullyProcessed); } else { // Creates all subdirectories needed. Does nothing if it already exists. System.IO.Directory.CreateDirectory(outputStyleFile.ParentFolder); try { string extension = outputStyleFile.Extension.ToLower(); if (extension == "js" || extension == "json") { ResourceProcessors.JavaScript jsProcessor = new ResourceProcessors.JavaScript(); string output = jsProcessor.Process(System.IO.File.ReadAllText(originalStyleFile), EngineInstance.Config.ShrinkFiles); System.IO.File.WriteAllText(outputStyleFile, output); } else if (extension == "css") { ResourceProcessors.CSS cssProcessor = new ResourceProcessors.CSS(); string output = cssProcessor.Process(System.IO.File.ReadAllText(originalStyleFile), EngineInstance.Config.ShrinkFiles); System.IO.File.WriteAllText(outputStyleFile, output); } else { System.IO.File.Copy(originalStyleFile, outputStyleFile, true); } } catch (System.IO.FileNotFoundException) { return(Files.Manager.ReleaseClaimedFileReason.FileDoesntExist); } catch (System.IO.DirectoryNotFoundException) { return(Files.Manager.ReleaseClaimedFileReason.FileDoesntExist); } catch (System.UnauthorizedAccessException) { return(Files.Manager.ReleaseClaimedFileReason.CantAccessFile); } catch (System.IO.IOException) { return(Files.Manager.ReleaseClaimedFileReason.CantAccessFile); } return(Files.Manager.ReleaseClaimedFileReason.SuccessfullyProcessed); } }