public bool RenderFile(File file) { bool success; var output = Render(file, out success); if (success) { if (output == null) { DeleteFile(file.FullName); } else { SaveFile(file.FullName, output); } } return success; }
private string GetOutputFilename(File file, string sourcePath) { var sourceFilename = Path.GetFileNameWithoutExtension(sourcePath); var extension = GetOutputExtension(); try { if (_configuration.Value.OutputFilenameFactory != null) { var filename = _configuration.Value.OutputFilenameFactory(file); filename = filename .Replace("<", "-") .Replace(">", "-") .Replace(":", "-") .Replace("\"", "-") //.Replace("/", "-") //.Replace("\\", "-") .Replace("|", "-") .Replace("?", "-") .Replace("*", "-"); if (filename.Contains(".") == false) filename += extension; return filename; } } catch (Exception exception) { Log.Warn($"Can't get output filename for '{sourcePath}' ({exception.Message})"); } return sourceFilename + extension; }
protected virtual void SaveFile(File file, string output, ref bool success) { ProjectItem item; var outputPath = GetOutputPath(file); if (string.Equals(file.FullName, outputPath, StringComparison.InvariantCultureIgnoreCase)) { Log.Error("Output filename cannot match source filename."); success = false; return; } if (HasChanged(outputPath, output)) { CheckOutFileFromSourceControl(outputPath); System.IO.File.WriteAllText(outputPath, output); item = FindProjectItem(outputPath) ?? _projectItem.ProjectItems.AddFromFile(outputPath); } else { item = FindProjectItem(outputPath); } SetMappedSourceFile(item, file.FullName); }
private string GetOutputPath(File file) { var path = file.FullName; var directory = Path.GetDirectoryName(_templatePath); var filename = GetOutputFilename(file, path); var outputPath = Path.Combine(directory, filename); for (var i = 1; i < 1000; i++) { var item = FindProjectItem(outputPath); if (item == null) { return(outputPath); } var mappedSourceFile = GetMappedSourceFile(item); if (mappedSourceFile == null || path.Equals(mappedSourceFile, StringComparison.InvariantCultureIgnoreCase)) { return(outputPath); } var name = filename.EndsWith(".d.ts", StringComparison.OrdinalIgnoreCase) ? filename.Substring(0, filename.Length - 5) : filename.Substring(0, filename.LastIndexOf(".", StringComparison.Ordinal)); var extension = filename.EndsWith(".d.ts", StringComparison.OrdinalIgnoreCase) ? ".d.ts" : filename.Substring(filename.LastIndexOf(".", StringComparison.Ordinal)); outputPath = Path.Combine(directory, $"{name} ({i}){extension}"); } throw new Exception("GetOutputPath"); }
public void DeleteFile(File file) { var outputPath = GetOutputPath(file); //var item = GetExistingItem(path); //item?.Delete(); if (System.IO.File.Exists(outputPath)) { System.IO.File.Delete(outputPath); Console.WriteLine($"Deleted: {outputPath}"); } }
protected virtual string SaveFile(File file, string output, ref bool success) { //ProjectItem item; var outputPath = GetOutputPath(file); if (string.Equals(file.FullName, outputPath, StringComparison.InvariantCultureIgnoreCase)) { //Log.Error("); Console.WriteLine($"Output filename cannot match source filename."); success = false; return(outputPath); } var hasChanged = HasChanged(outputPath, output); // if (ExtensionPackage.Instance.Options.AddGeneratedFilesToProject == false) // { // if (hasChanged) // { // WriteFile(outputPath, output); // Log.Debug($"Output file '{outputPath}' saved."); // } // return; // } if (hasChanged) { //CheckOutFileFromSourceControl(outputPath); WriteFile(outputPath, output); Console.WriteLine($"Generated: {outputPath}"); // item = FindProjectItem(outputPath); // // if (item == null) // { // try // { // item = _projectItem.ProjectItems.AddFromFile(outputPath); // } // catch (Exception exception) // { // Log.Error($"Unable to add '{outputPath}' to project. {exception.Message}"); // } // } } else { Console.WriteLine($"No changes: {outputPath}"); } return(outputPath); //SetMappedSourceFile(item, file.FullName); }
public string Render(File file, out bool success) { try { return(Parser.Parse(_projectItem, file.FullName, _template.Value, _customExtensions, file, out success)); } catch (Exception ex) { Log.Error(ex.Message + " Template: " + _templatePath); success = false; return(null); } }
protected virtual void SaveFile(File file, string output, ref bool success) { ProjectItem item; var outputPath = GetOutputPath(file); if (string.Equals(file.FullName, outputPath, StringComparison.InvariantCultureIgnoreCase)) { Log.Error("Output filename cannot match source filename."); success = false; return; } var hasChanged = HasChanged(outputPath, output); if (ExtensionPackage.Instance.AddGeneratedFilesToProject == false || _configuration.Value.SkipAddingGeneratedFilesToProject) { if (hasChanged) { WriteFile(outputPath, output); Log.Debug($"Output file '{outputPath}' saved."); } return; } if (hasChanged) { CheckOutFileFromSourceControl(outputPath); WriteFile(outputPath, output); item = FindProjectItem(outputPath); if (item == null) { try { item = _projectItem.ProjectItems.AddFromFile(outputPath); } catch (Exception exception) { Log.Error($"Unable to add '{outputPath}' to project. {exception.Message}"); } } } else { item = FindProjectItem(outputPath); } SetMappedSourceFile(item, file.FullName); }
public bool RenderFile(File file) { var output = Render(file, out var success); if (success) { if (output == null) { DeleteFile(file.FullName); } else { SaveFile(file, output, ref success); } } return(success); }
public void RenameFile(File file, string oldPath, string newPath) { var item = GetExistingItem(oldPath); if (item != null) { if (Path.GetFileName(oldPath)?.Equals(Path.GetFileName(newPath)) ?? false) { SetMappedSourceFile(item, newPath); return; } var newOutputPath = GetOutputPath(file); item.Name = Path.GetFileName(newOutputPath); SetMappedSourceFile(item, newPath); } }
public bool RenderFile(File file, bool saveProjectFile) { bool success; var output = Render(file, out success); if (success) { if (output == null) { DeleteFile(file.FullName, saveProjectFile); } else { SaveFile(file.FullName, output, saveProjectFile); } } return(success); }
protected virtual void SaveFile(File file, string output) { ProjectItem item; var outputPath = GetOutputPath(file); if (HasChanged(outputPath, output)) { CheckOutFileFromSourceControl(outputPath); System.IO.File.WriteAllText(outputPath, output); item = FindProjectItem(outputPath) ?? _projectItem.ProjectItems.AddFromFile(outputPath); } else { item = FindProjectItem(outputPath); } SetMappedSourceFile(item, file.FullName); }
public string RenderFile(File file) { bool success; var output = Render(file, out success); if (success) { if (output == null) { //DeleteFile(file); } else { return(SaveFile(file, output, ref success)); } } return(null); }
private string GetOutputFilename(File file, string sourcePath) { var sourceFilename = Path.GetFileNameWithoutExtension(sourcePath); var extension = GetOutputExtension(); try { if (_configuration.Value.OutputFilenameFactory != null) { var filename = _configuration.Value.OutputFilenameFactory(file); filename = filename .Replace("<", "-") .Replace(">", "-") .Replace(":", "-") .Replace("\"", "-") //.Replace("/", "-") //.Replace("\\", "-") .Replace("|", "-") .Replace("?", "-") .Replace("*", "-"); if (filename.Contains(".") == false) { filename += extension; } return(filename); } } catch (Exception exception) { //Log.Warn($"Can't get output filename for '{sourcePath}' ({exception.Message})"); Console.WriteLine($"Warn: Can't get output filename for '{sourcePath}' ({exception.Message})"); } return(sourceFilename + extension); }
protected override void SaveFile(File file, string output) { Trace.WriteLine("SaveFile intercepted"); Trace.WriteLine("Output: "); Trace.WriteLine(output); }
public string Render(File file, out bool success) { return(Parser.Parse(_template, _customExtensions, file, out success)); }
protected override void SaveFile(File file, string output) { Trace.WriteLine("SaveFile intercepted"); Trace.WriteLine("Output: "); Trace.WriteLine(output); }
public string Render(File file, out bool success) { try { return Parser.Parse(_projectItem, file.FullName, _template.Value, _customExtensions, file, out success); } catch (Exception ex) { Log.Error(ex.Message + " Template: " + _templatePath); success = false; return null; } }
protected virtual void SaveFile(File file, string output) { ProjectItem item; var outputPath = GetOutputPath(file); if (HasChanged(outputPath, output)) { CheckOutFileFromSourceControl(outputPath); System.IO.File.WriteAllText(outputPath, output); item = FindProjectItem(outputPath) ?? _projectItem.ProjectItems.AddFromFile(outputPath); } else { item = FindProjectItem(outputPath); } SetMappedSourceFile(item, file.FullName); }
protected FileTests(ITestFixture fixture) : base(fixture) { fileInfo = GetFile(@"Tests\CodeModel\Support\FileInfo.cs"); }
public void RenameFile(File file, string oldPath, string newPath) { var item = GetExistingItem(oldPath); if (item != null) { if (Path.GetFileName(oldPath)?.Equals(Path.GetFileName(newPath)) ?? false) { SetMappedSourceFile(item, newPath); return; } var newOutputPath = GetOutputPath(file); item.Name = Path.GetFileName(newOutputPath); SetMappedSourceFile(item, newPath); } }
private string GetOutputPath(File file) { var path = file.FullName; var directory = Path.GetDirectoryName(_templatePath); var filename = GetOutputFilename(file, path); var outputPath = Path.Combine(directory, filename); for (var i = 1; i < 1000; i++) { var item = FindProjectItem(outputPath); if (item == null) return outputPath; var mappedSourceFile = GetMappedSourceFile(item); if (mappedSourceFile == null || path.Equals(mappedSourceFile, StringComparison.InvariantCultureIgnoreCase)) return outputPath; var name = filename.EndsWith(".d.ts", StringComparison.OrdinalIgnoreCase) ? filename.Substring(0, filename.Length - 5) : filename.Substring(0, filename.LastIndexOf(".", StringComparison.Ordinal)); var extension = filename.EndsWith(".d.ts", StringComparison.OrdinalIgnoreCase) ? ".d.ts" : filename.Substring(filename.LastIndexOf(".", StringComparison.Ordinal)); outputPath = Path.Combine(directory, $"{name} ({i}){extension}"); } throw new Exception("GetOutputPath"); }
public string Render(File file, out bool success) { return Parser.Parse(_template, _customExtensions, file, out success); }
protected FileTests(ITestFixture fixture, GlobalServiceProvider sp) : base(fixture, sp) { fileInfo = GetFile(@"Tests\CodeModel\Support\FileInfo.cs"); }