private static void CheckArguments() { //If an output file is not specified, then use inputfile as the outputfile if (string.IsNullOrWhiteSpace(outputFile)) { outputFile = inputFile; } if (string.IsNullOrEmpty(inputFile)) { Usage(); } if (!File.Exists(inputFile)) { Usage($"Input file does not exist: {inputFile}"); } //If the outputfile exists and it is not the inputfile, then //We don't want to overwrite it. if ((String.CompareOrdinal(inputFile, outputFile) != 0) && File.Exists(outputFile)) { Usage($"Output file already exits: {outputFile}"); } companyTemplate = CopyrightUtil.ReadTemplate(inputFile, template, Usage); }
private static void Main(string[] args) { paramList.Add("input", a => inputFile = a); paramList.Add("output", a => outputFile = a); paramList.Add("template", a => template = a); paramList.Add("linecount", a => lineCount = int.Parse(a)); ParseArguments(args); CheckArguments(); var buffer = CopyrightUtil.ReadFile(inputFile); if (buffer.Count > 0) { if (lineCount > buffer.Count) { lineCount = buffer.Count; } var copyright = new Copyright(companyTemplate); if (copyright.FindCurrentCopyright(buffer, lineCount)) { Console.WriteLine("Current Copyright already exists."); return; } copyright.AddOrModifyCopyright(buffer, lineCount); CopyrightUtil.WriteFile(outputFile, buffer); } }
private static void GetCommentInfo(string inputFile, CopyrightTemplate companyTemplate, Action <string> errorAction = null) { const string commentSpecFile = "CommentSpecification.json"; try { var ext = Path.GetExtension(inputFile); using (var resource = CopyrightUtil.ResourceStream(commentSpecFile)) { if (resource != null) { var serializer = new DataContractJsonSerializer(typeof(CommentSpec[])); var commentSpecs = (CommentSpec[])serializer.ReadObject(resource); var commentSpec = commentSpecs.Find(ext); if (commentSpec == null) { errorAction?.Invoke($"Unsupported file: {inputFile}"); } Console.WriteLine($"Using {commentSpec?.Name} extension specification"); companyTemplate.CommentSpec = commentSpec; } } } catch (Exception e) { errorAction?.Invoke(e.Message); } }