public void CscHandlesTrueOrFalse() { var function = new Csc(); var input1 = true; var input2 = false; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); Assert.AreEqual(1.188395106, System.Math.Round(result1.ResultNumeric, 9)); Assert.AreEqual(eErrorType.Div0, ((ExcelErrorValue)result2.Result).Type); }
public void CscHandlesMilitaryTimesPast2400() { var function = new Csc(); var input1 = "01:00"; var input2 = "02:00"; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); Assert.AreEqual(24.00694585, System.Math.Round(result1.ResultNumeric, 8)); Assert.AreEqual(12.01390015, System.Math.Round(result2.ResultNumeric, 8)); }
public void CscHandlesInputDatesAreSeperatedByDashes() { var function = new Csc(); var input1 = "1-17-2017 2:00"; var input2 = "1-17-2017 2:00 am"; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); Assert.AreEqual(1.040610433, System.Math.Round(result1.ResultNumeric, 9)); Assert.AreEqual(1.040610433, System.Math.Round(result2.ResultNumeric, 9)); }
public void CscTestInputsWithDatesThatHaveSlashesInThem() { var function = new Csc(); var input1 = "1/17/2011 2:00 am"; var input2 = "17/01/2011 2:00 AM"; var input3 = "17/Jan/2011 2:00 AM"; var input4 = "17/January/2011 2:00 am"; var input5 = "1/17/2011 2:00:00 am"; var input6 = "17/01/2011 2:00:00 AM"; var input7 = "17/Jan/2011 2:00:00 AM"; var input8 = "17/January/2011 2:00:00 am"; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext); var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext); var result5 = function.Execute(FunctionsHelper.CreateArgs(input5), this.ParsingContext); var result6 = function.Execute(FunctionsHelper.CreateArgs(input6), this.ParsingContext); var result7 = function.Execute(FunctionsHelper.CreateArgs(input7), this.ParsingContext); var result8 = function.Execute(FunctionsHelper.CreateArgs(input8), this.ParsingContext); Assert.AreEqual(1.173980588, System.Math.Round(result1.ResultNumeric, 9)); Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result2.Result).Type); Assert.AreEqual(1.173980588, System.Math.Round(result3.ResultNumeric, 9)); Assert.AreEqual(1.173980588, System.Math.Round(result4.ResultNumeric, 9)); Assert.AreEqual(1.173980588, System.Math.Round(result5.ResultNumeric, 9)); Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result6.Result).Type); Assert.AreEqual(1.173980588, System.Math.Round(result7.ResultNumeric, 9)); Assert.AreEqual(1.173980588, System.Math.Round(result8.ResultNumeric, 9)); }
public void CscHandlesMilitaryTime() { var function = new Csc(); var input1 = "00:00"; var input2 = "00:01"; var input3 = "23:59:59"; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext); Assert.AreEqual(eErrorType.Div0, ((ExcelErrorValue)result1.Result).Type); Assert.AreEqual(1440.000116, System.Math.Round(result2.ResultNumeric, 6)); Assert.AreEqual(1.188403938, System.Math.Round(result3.ResultNumeric, 9)); }
public void AdditionalFile_HostObject() { IBuildEngine2 mockEngine = new MockEngine(); Csc csc = new Csc(); csc.BuildEngine = mockEngine; MockCscAnalyzerHostObject cscHostObject = new MockCscAnalyzerHostObject(); cscHostObject.SetDesignTime(true); csc.HostObject = cscHostObject; csc.UseHostCompilerIfAvailable = true; Assert.IsNull(cscHostObject.AdditionalFiles); csc.AdditionalFiles = new TaskItem[] { new TaskItem("web.config") }; csc.Sources = new TaskItem[] { new TaskItem("a.cs") }; bool cscSuccess = csc.Execute(); Assert.IsTrue(cscSuccess, "Csc task failed."); Assert.AreEqual(1, cscHostObject.AdditionalFiles.Length); Assert.AreEqual("web.config", cscHostObject.AdditionalFiles[0].ItemSpec); }
public void RuleSet_HostObject() { IBuildEngine2 mockEngine = new MockEngine(); Csc csc = new Csc(); csc.BuildEngine = mockEngine; MockCscAnalyzerHostObject cscHostObject = new MockCscAnalyzerHostObject(); cscHostObject.SetDesignTime(true); csc.HostObject = cscHostObject; csc.UseHostCompilerIfAvailable = true; Assert.IsNull(cscHostObject.RuleSet); csc.CodeAnalysisRuleSet = "Bar.ruleset"; csc.Sources = new TaskItem[] { new TaskItem("a.cs") }; bool cscSuccess = csc.Execute(); Assert.IsTrue(cscSuccess, "Csc task failed."); Assert.AreEqual("Bar.ruleset", cscHostObject.RuleSet); }
public void MultipleAnalyzers_HostObject() { IBuildEngine2 mockEngine = new MockEngine(); Csc csc = new Csc(); csc.BuildEngine = mockEngine; MockCscAnalyzerHostObject cscHostObject = new MockCscAnalyzerHostObject(); cscHostObject.SetDesignTime(true); csc.HostObject = cscHostObject; csc.UseHostCompilerIfAvailable = true; Assert.IsNull(cscHostObject.Analyzers); csc.Analyzers = new TaskItem[] { new TaskItem("Foo.dll"), new TaskItem("Bar.dll") }; csc.Sources = new TaskItem[] { new TaskItem("a.cs") }; bool cscSuccess = csc.Execute(); Assert.IsTrue(cscSuccess, "Csc task failed."); Assert.AreEqual(2, cscHostObject.Analyzers.Length); Assert.AreEqual("Foo.dll", cscHostObject.Analyzers[0].ItemSpec); Assert.AreEqual("Bar.dll", cscHostObject.Analyzers[1].ItemSpec); }
public void CscHandlesNormal12HourClockInputs() { var function = new Csc(); var input1 = "00:00:00 AM"; var input2 = "00:01:32 AM"; var input3 = "12:00 PM"; var input4 = "12:00 AM"; var input5 = "1:00 PM"; var input6 = "1:10:32 am"; var input7 = "3:42:32 pm"; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext); var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext); var result5 = function.Execute(FunctionsHelper.CreateArgs(input5), this.ParsingContext); var result6 = function.Execute(FunctionsHelper.CreateArgs(input6), this.ParsingContext); var result7 = function.Execute(FunctionsHelper.CreateArgs(input7), this.ParsingContext); Assert.AreEqual(eErrorType.Div0, ((ExcelErrorValue)result1.Result).Type); Assert.AreEqual(939.1306123, System.Math.Round(result2.ResultNumeric, 7)); Assert.AreEqual(2.085829643, System.Math.Round(result3.ResultNumeric, 9)); Assert.AreEqual(eErrorType.Div0, ((ExcelErrorValue)result1.Result).Type); Assert.AreEqual(1.939620425, System.Math.Round(result5.ResultNumeric, 9)); Assert.AreEqual(20.42404488, System.Math.Round(result6.ResultNumeric, 8)); Assert.AreEqual(1.642597072, System.Math.Round(result7.ResultNumeric, 9)); }
public void ExecuteComplexNumberTest() { var complex = new Complex(3, 2); var exp = new Csc(new ComplexNumber(complex)); var result = (Complex)exp.Execute(); Assert.Equal(ComplexExtensions.Csc(complex), result); Assert.Equal(0.040300578856891527, result.Real, 15); Assert.Equal(0.27254866146294021, result.Imaginary, 15); }
public void CscIsGivenAStringAsInput() { var function = new Csc(); var input1 = "string"; var input2 = "0"; var input3 = "1"; var input4 = "1.5"; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext); var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext); Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result1.Result).Type); Assert.AreEqual(eErrorType.Div0, ((ExcelErrorValue)result2.Result).Type); Assert.AreEqual(1.188395106, result3.ResultNumeric, .00001); Assert.AreEqual(1.002511304, result4.ResultNumeric, .00001); }
public void CscHandlesDateTimeInputs() { var function = new Csc(); var input1 = "1/17/2011 2:00"; var input2 = "1/17/2011 2:00 AM"; var input3 = "17/1/2011 2:00 AM"; var input4 = "17/Jan/2011 2:00 AM"; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext); var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext); Assert.AreEqual(1.173980588, System.Math.Round(result1.ResultNumeric, 9)); Assert.AreEqual(1.173980588, System.Math.Round(result1.ResultNumeric, 9)); Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result3.Result).Type); Assert.AreEqual(1.173980588, System.Math.Round(result1.ResultNumeric, 9)); }
public void CscHandlesInputsWithDatesInTheFormMonthDateCommaYearTime() { var function = new Csc(); var input1 = "Jan 17, 2011 2:00 am"; var input2 = "June 5, 2017 11:00 pm"; var input3 = "Jan 17, 2011 2:00:00 am"; var input4 = "June 5, 2017 11:00:00 pm"; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext); var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext); Assert.AreEqual(1.173980588, System.Math.Round(result1.ResultNumeric, 9)); Assert.AreEqual(4.884989474, System.Math.Round(result2.ResultNumeric, 9)); Assert.AreEqual(1.173980588, System.Math.Round(result3.ResultNumeric, 9)); Assert.AreEqual(4.884989474, System.Math.Round(result4.ResultNumeric, 9)); }
public void CscTestMilitaryTimeAndNormalTimeComparisions() { var function = new Csc(); var input1 = "16:30"; var input2 = "04:30 pm"; var input3 = "02:30"; var input4 = "2:30 am"; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext); var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext); Assert.AreEqual(1.575778196, System.Math.Round(result1.ResultNumeric, 9)); Assert.AreEqual(1.575778196, System.Math.Round(result2.ResultNumeric, 9)); Assert.AreEqual(9.617383114, System.Math.Round(result3.ResultNumeric, 9)); Assert.AreEqual(9.617383114, System.Math.Round(result4.ResultNumeric, 9)); }
public void CscHandlesPi() { var function = new Csc(); var Pi = System.Math.PI; var input1 = Pi; var input2 = Pi / 2; var input3 = 2 * Pi; var input4 = 60 * Pi / 180; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext); var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext); //Note: Neither Excel or EPPlus handle Pi perfectly. Both seem to have a small rounding issue that is not a problem if you are aware of it. Assert.AreEqual(8.16228E+15, System.Math.Round(result2.ResultNumeric, 9), 1.0E+16); Assert.AreEqual(1, System.Math.Round(result2.ResultNumeric, 9), .00001); Assert.AreEqual(-4.08114E+15, System.Math.Round(result3.ResultNumeric, 9), 1.0E+15); Assert.AreEqual(1.154700538, System.Math.Round(result4.ResultNumeric, 9)); }
public void CscInCscdDoublesAsInputs() { var function = new Csc(); var input1 = 20; var input2 = 100; var input3 = 1; var input4 = 1.0; var input5 = 1.5; var input6 = 1000; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext); var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext); var result5 = function.Execute(FunctionsHelper.CreateArgs(input5), this.ParsingContext); var result6 = function.Execute(FunctionsHelper.CreateArgs(input6), this.ParsingContext); Assert.AreEqual(1.095355936, System.Math.Round(result1.ResultNumeric, 9)); Assert.AreEqual(-1.974857531, System.Math.Round(result2.ResultNumeric, 9)); Assert.AreEqual(1.188395106, System.Math.Round(result3.ResultNumeric, 9)); Assert.AreEqual(1.188395106, System.Math.Round(result4.ResultNumeric, 9)); Assert.AreEqual(1.002511304, System.Math.Round(result5.ResultNumeric, 9)); Assert.AreEqual(1.209365997, System.Math.Round(result6.ResultNumeric, 9)); }
public void CscIsGivenValuesRanginFromNegative10to10() { var function = new Csc(); var input1 = -10; var input2 = -1; var input3 = 0; var input4 = 1; var input5 = 10; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext); var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext); var result5 = function.Execute(FunctionsHelper.CreateArgs(input5), this.ParsingContext); Assert.AreEqual(1.838163961, result1.ResultNumeric, .00001); Assert.AreEqual(-1.188395106, result2.ResultNumeric, .00001); Assert.AreEqual(eErrorType.Div0, ((ExcelErrorValue)result3.Result).Type); Assert.AreEqual(1.188395106, result4.ResultNumeric, .00001); Assert.AreEqual(-1.838163961, result5.ResultNumeric, .00001); }
public void CscHandlesDoublesCorrectly() { var function = new Csc(); var input1 = 0.5; var input2 = 0.25; var input3 = 0.9; var input4 = -0.9; var input5 = ".5"; var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext); var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext); var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext); var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext); var result5 = function.Execute(FunctionsHelper.CreateArgs(input5), this.ParsingContext); Assert.AreEqual(2.085829643, System.Math.Round(result1.ResultNumeric, 9)); Assert.AreEqual(4.041972501, System.Math.Round(result2.ResultNumeric, 9)); Assert.AreEqual(1.276606213, System.Math.Round(result3.ResultNumeric, 9)); Assert.AreEqual(-1.276606213, System.Math.Round(result4.ResultNumeric, 9)); Assert.AreEqual(2.085829643, System.Math.Round(result5.ResultNumeric, 9)); }
internal string CompileCSharpSource() { List <ITaskItem> sources = new List <ITaskItem>(); string codeFile = this.GeneratedCodeFile; sources.Add(new TaskItem(codeFile)); // If client has added extra user code into the // compile request, add it in now string userCodeFile = this.UserCodeFile; if (!string.IsNullOrEmpty(userCodeFile)) { sources.Add(new TaskItem(userCodeFile)); } List <ITaskItem> references = new List <ITaskItem>(); foreach (string s in ReferenceAssemblies) { references.Add(new TaskItem(s)); } var buildEngine = MockBuildEngine; var csc = new Csc { BuildEngine = buildEngine, TargetType = "library", Sources = sources.ToArray(), References = references.ToArray(), OutputAssembly = new TaskItem(OutputAssemblyName) }; csc.NoStandardLib = true; // don't include std lib stuff -- we're feeding it pcl csc.NoConfig = true; // don't load the csc.rsp file to get references var result = false; try { result = csc.Execute(); } catch (Exception ex) { Assert.Fail("Exception occurred invoking CSC task on " + sources[0].ItemSpec + ":\r\n" + ex); } Assert.IsTrue(result, "CSC failed to compile " + sources[0].ItemSpec + ":\r\n" + buildEngine.ConsoleLogger.Errors); return(csc.OutputAssembly.ItemSpec); }
/// <summary> /// Invokes CSC to build the given files against the given set of references /// </summary> /// <param name="files"></param> /// <param name="referenceAssemblies"></param> /// <param name="lang"></param> public static bool CompileCSharpSource(IEnumerable <string> files, IEnumerable <string> referenceAssemblies) { List <ITaskItem> sources = new List <ITaskItem>(); foreach (string f in files) { sources.Add(new TaskItem(f)); } List <ITaskItem> references = new List <ITaskItem>(); foreach (string s in referenceAssemblies) { references.Add(new TaskItem(s)); } Csc csc = new Csc(); MockBuildEngine buildEngine = new MockBuildEngine(); csc.BuildEngine = buildEngine; // needed before task can log csc.NoStandardLib = true; // don't include std lib stuff -- we're feeding it silverlight csc.NoConfig = true; // don't load the csc.rsp file to get references csc.TargetType = "library"; csc.Sources = sources.ToArray(); csc.References = references.ToArray(); bool result = false; try { result = csc.Execute(); } catch (Exception ex) { Assert.Fail("Exception occurred invoking CSC task on " + sources[0].ItemSpec + ":\r\n" + ex); } if (!result) { string sourceList = string.Empty; foreach (TaskItem t in sources) { sourceList += " " + t.ItemSpec + "\r\n"; } Assert.Fail("CSC failed to compile sources:\r\n" + sourceList + "\r\n" + buildEngine.ConsoleLogger.Errors + "\r\n\r\nReference assemblies were:\r\n" + ReferenceAssembliesAsString(referenceAssemblies)); } return(result); }
/// <summary> /// Invokes CSC to build the given files against the given set of references /// </summary> /// <param name="files"></param> /// <param name="referenceAssemblies"></param> /// <param name="lang"></param> /// <param name="documentationFile">If nonblank, the documentation file to generate during the compile.</param> public static bool CompileCSharpSource(IEnumerable <string> files, IEnumerable <string> referenceAssemblies, string documentationFile) { List <ITaskItem> sources = new List <ITaskItem>(); foreach (string f in files) { sources.Add(new TaskItem(f)); } List <ITaskItem> references = new List <ITaskItem>(); foreach (string s in referenceAssemblies) { references.Add(new TaskItem(s)); } Csc csc = new Csc(); MockBuildEngine buildEngine = new MockBuildEngine(); csc.BuildEngine = buildEngine; // needed before task can log csc.NoStandardLib = true; // don't include std lib stuff -- we're feeding it pcl csc.NoConfig = true; // don't load the csc.rsp file to get references csc.TargetType = "library"; csc.Sources = sources.ToArray(); csc.References = references.ToArray(); if (!string.IsNullOrEmpty(documentationFile)) { csc.DocumentationFile = documentationFile; } bool result = false; try { result = csc.Execute(); } catch (Exception ex) { Assert.Fail("Exception occurred invoking CSC task on " + sources[0].ItemSpec + ":\r\n" + ex); } Assert.IsTrue(result, "CSC failed to compile " + sources[0].ItemSpec + ":\r\n" + buildEngine.ConsoleLogger.Errors); return(result); }
public void CscHostObject3() { IBuildEngine2 mockEngine = new MockEngine(); Csc csc = new Csc(); csc.BuildEngine = mockEngine; MockCscHostObject3 cscHostObject = new MockCscHostObject3(); csc.HostObject = cscHostObject; csc.UseHostCompilerIfAvailable = true; Assert.IsTrue(!cscHostObject.CompileMethodWasCalled); csc.Sources = new TaskItem[] { new TaskItem("a.cs") }; bool cscSuccess = csc.Execute(); Assert.IsTrue(cscSuccess, "Csc task failed."); Assert.IsTrue(cscHostObject.CompileMethodWasCalled); }
public void NoAnalyzer_HostObject() { IBuildEngine2 mockEngine = new MockEngine(); Csc csc = new Csc(); csc.BuildEngine = mockEngine; MockCscAnalyzerHostObject cscHostObject = new MockCscAnalyzerHostObject(); cscHostObject.SetDesignTime(true); csc.HostObject = cscHostObject; csc.UseHostCompilerIfAvailable = true; Assert.IsNull(cscHostObject.Analyzers); csc.Sources = new TaskItem[] { new TaskItem("a.cs") }; bool cscSuccess = csc.Execute(); Assert.IsTrue(cscSuccess, "Csc task failed."); Assert.IsNull(cscHostObject.Analyzers); }
/// <summary> /// Executes a task. /// </summary> /// <returns> /// true if the task executed successfully; otherwise, false. /// </returns> public override bool Execute() { if (POFiles != null) { foreach (ITaskItem item in POFiles) { // Verify that POFile exists. if (!File.Exists(item.ItemSpec)) { _LogMessage(string.Format(CultureInfo.InvariantCulture, "File {0} does not exists.", item.ItemSpec)); return(false); } // Get file info from file. FileInfo fileInfo = new FileInfo(item.ItemSpec); // Assume that FileName is in the format: locale.extension // Get locale from FileName. string locale = fileInfo.Name.Replace(fileInfo.Extension, string.Empty); string outputPath = OutputPath + "\\" + locale; // If OutputPath directory does not exist, create it. if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } // Create the output assembly name. string assemblyFileName = Path.Combine(outputPath, AssemblyName + ".resources.dll"); // Verify if assemblyFile exists if (File.Exists(assemblyFileName)) { //FileInfo dllInfo = new FileInfo(assemblyFileName); //if (dllInfo.LastWriteTime.CompareTo(fileInfo.LastWriteTime) > 0) // continue; // Continue to next item cause Assembly is newer than current po file. //else File.Delete(assemblyFileName); } //Get the temporary path to store the C# classes. string csOutputPath = System.IO.Path.GetTempPath(); // Get the C# file template from embedded resources. string template = Resource.template; // Get the file name for the C# class string csFileName = Path.Combine(csOutputPath, string.Format(CultureInfo.InvariantCulture, "{0}.{1}", AssemblyName, "cs")); // Get the class name for the C# class string className = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", ConstructClassName(AssemblyName), locale.Replace("-", "_")); // String builder to hold the key value pairs retrieved from the po file. StringBuilder s = new StringBuilder(); using (FileStream fileStream = new FileStream(item.ItemSpec, FileMode.Open)) { // Read the po file. _ReadPOFile(s, new StreamReader(fileStream, Encoding.UTF8)); } // Get bytes for the new C# class byte[] bytes = Encoding.UTF8.GetBytes(template.Replace("{0}", className).Replace("{1}", s.ToString())); // Write the C# class to disk. using (FileStream csStream = new FileStream(csFileName, FileMode.Create)) { csStream.Write(bytes, 0, bytes.Length); } _LogMessage(string.Format(CultureInfo.InvariantCulture, "Created file {0}", csFileName)); // Log if GNU.Gettext.dll not found. if (!File.Exists(GNUGetTextAssemblyPath)) { _LogMessage(string.Format(CultureInfo.InvariantCulture, "Unable to find dependency file: {0}", GNUGetTextAssemblyPath)); return(false); } var fileinfo = new FileInfo(GNUGetTextAssemblyPath); // Compile c# class. Csc csc = new Csc(); csc.HostObject = this.HostObject; csc.BuildEngine = this.BuildEngine; csc.AdditionalLibPaths = new string[] { fileinfo.Directory.FullName }; csc.TargetType = "library"; csc.References = new TaskItem[] { new TaskItem(fileinfo.Name) }; csc.OutputAssembly = new TaskItem(assemblyFileName); csc.Sources = new TaskItem[] { new TaskItem(csFileName) }; csc.Execute(); _LogMessage(string.Format(CultureInfo.InvariantCulture, "Created assembly {0}", assemblyFileName)); } return(true); } return(true); }
public void ExecuteTestException() { var exp = new Csc(new Bool(false)); Assert.Throws <ResultIsNotSupportedException>(() => exp.Execute()); }
public void ExecuteGradianTest() { var exp = new Csc(new Number(1)); Assert.Equal(MathExtensions.Csc(Math.PI / 200), exp.Execute(AngleMeasurement.Gradian)); }
public void ExecuteDegreeTest() { var exp = new Csc(new Number(1)); Assert.Equal(MathExtensions.Csc(Math.PI / 180), exp.Execute(AngleMeasurement.Degree)); }
public void FileTrackerDoNotRecordWriteAsRead() { Console.WriteLine("Test: FileTrackerDoNotRecordWriteAsRead"); File.Delete("writenoread.read.1.tlog"); File.Delete("writenoread.write.1.tlog"); string testDirectory = Path.Combine(Directory.GetCurrentDirectory(), "FileTrackerDoNotRecordWriteAsRead"); if (Directory.Exists(testDirectory)) { ObjectModelHelpers.DeleteDirectory(testDirectory); Directory.Delete(testDirectory, true /* recursive delete */); } Directory.CreateDirectory(testDirectory); string codeFile = null; string writeFile = null; string outputFile = Path.Combine(testDirectory, "writenoread.exe"); try { writeFile = Path.Combine(testDirectory, "test.out"); codeFile = Path.Combine(testDirectory, "code.cs"); string codeContent = @" using System.IO; using System.Runtime.InteropServices; class X { static void Main() { FileStream f = File.Open(@""" + writeFile + @""", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite); f.WriteByte(8); f.Close(); } }"; File.WriteAllText(codeFile, codeContent); Csc csc = new Csc(); csc.BuildEngine = new MockEngine(); csc.Sources = new TaskItem[] { new TaskItem(codeFile) }; csc.OutputAssembly = new TaskItem(outputFile); bool success = csc.Execute(); Assert.True(success); string trackerPath = FileTracker.GetTrackerPath(ExecutableType.ManagedIL); string fileTrackerPath = FileTracker.GetFileTrackerPath(ExecutableType.ManagedIL); string commandArgs = "/d \"" + fileTrackerPath + "\" /o /c \"" + outputFile + "\""; int exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs); Console.WriteLine(""); Assert.Equal(0, exit); } finally { // Doesn't delete the directory itself, but deletes its contents. If you try to delete the directory, // even after calling this method, it sometimes throws IO exceptions due to not recognizing that the // contents have been deleted yet. ObjectModelHelpers.DeleteDirectory(testDirectory); } if (writeFile != null) { FileTrackerTestHelper.AssertDidntFindStringInTLog("CreateFileW, Desired Access=0xc0000000, Creation Disposition=0x1:" + writeFile.ToUpperInvariant(), "writenoread.read.1.tlog"); FileTrackerTestHelper.AssertFoundStringInTLog("CreateFileW, Desired Access=0xc0000000, Creation Disposition=0x1:" + writeFile.ToUpperInvariant(), "writenoread.write.1.tlog"); } else { Assert.True(false, "The output file was never assigned or written to"); } }
public void FileTrackerFindStrInIncludeDuplicates() { Console.WriteLine("Test: FileTrackerFindStrInIncludeDuplicates"); File.Delete("findstr.read.1.tlog"); FileTrackerTestHelper.WriteAll("test.in", "foo"); string codeFile = null; string outputFile = Path.Combine(Path.GetTempPath(), "readtwice.exe"); File.Delete(outputFile); try { string inputPath = Path.GetFullPath("test.in"); codeFile = FileUtilities.GetTemporaryFile(); string codeContent = @"using System.IO; class X { static void Main() { File.ReadAllText(@""" + inputPath + @"""); File.ReadAllText(@""" + inputPath + @"""); }}"; File.WriteAllText(codeFile, codeContent); Csc csc = new Csc(); csc.BuildEngine = new MockEngine(); csc.Sources = new TaskItem[] { new TaskItem(codeFile) }; csc.OutputAssembly = new TaskItem(outputFile); csc.Execute(); string trackerPath = FileTracker.GetTrackerPath(ExecutableType.ManagedIL); string fileTrackerPath = FileTracker.GetFileTrackerPath(ExecutableType.ManagedIL); string commandArgs = "/d \"" + fileTrackerPath + "\" /u /c \"" + outputFile + "\""; int exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs); Console.WriteLine(""); Assert.Equal(0, exit); } finally { File.Delete(codeFile); File.Delete(outputFile); } FileTrackerTestHelper.AssertFoundStringInTLog(Path.GetFullPath("test.in").ToUpperInvariant(), "readtwice.read.1.tlog", 2); }
public void FileTrackerExtendedDirectoryTracking() { Console.WriteLine("Test: FileTrackerExtendedDirectoryTracking"); File.Delete("directoryattributes.read.1.tlog"); File.Delete("directoryattributes.write.1.tlog"); string codeFile = null; string outputFile = Path.Combine(Path.GetTempPath(), "directoryattributes.exe"); string codeContent = @" using System.IO; using System.Runtime.InteropServices; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { File.GetAttributes(Directory.GetCurrentDirectory()); GetFileAttributes(Directory.GetCurrentDirectory()); } [DllImport(""Kernel32.dll"", SetLastError = true, CharSet = CharSet.Unicode)] private extern static uint GetFileAttributes(string FileName); } }"; File.Delete(outputFile); try { codeFile = FileUtilities.GetTemporaryFile(); File.WriteAllText(codeFile, codeContent); Csc csc = new Csc(); csc.BuildEngine = new MockEngine(); csc.Sources = new ITaskItem[] { new TaskItem(codeFile) }; csc.OutputAssembly = new TaskItem(outputFile); csc.Execute(); string trackerPath = FileTracker.GetTrackerPath(ExecutableType.ManagedIL); string fileTrackerPath = FileTracker.GetFileTrackerPath(ExecutableType.ManagedIL); string commandArgs = "/d \"" + fileTrackerPath + "\" /o /u /e /c \"" + outputFile + "\""; int exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs); Console.WriteLine(""); Assert.Equal(0, exit); // Should track directories when '/e' is passed FileTrackerTestHelper.AssertFoundStringInTLog("GetFileAttributesExW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog"); FileTrackerTestHelper.AssertFoundStringInTLog("GetFileAttributesW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog"); File.Delete("directoryattributes.read.1.tlog"); File.Delete("directoryattributes.write.1.tlog"); commandArgs = "/d \"" + fileTrackerPath + "\" /o /u /a /c \"" + outputFile + "\""; exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs); Console.WriteLine(""); Assert.Equal(0, exit); // With '/a', should *not* track GetFileAttributes on directories, even though we do so on files. FileTrackerTestHelper.AssertDidntFindStringInTLog("GetFileAttributesExW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog"); FileTrackerTestHelper.AssertDidntFindStringInTLog("GetFileAttributesW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog"); File.Delete("directoryattributes.read.1.tlog"); File.Delete("directoryattributes.write.1.tlog"); commandArgs = "/d \"" + fileTrackerPath + "\" /o /u /c \"" + outputFile + "\""; exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs); Console.WriteLine(""); Assert.Equal(0, exit); // With neither '/a' nor '/e', should not do any directory tracking whatsoever FileTrackerTestHelper.AssertDidntFindStringInTLog("GetFileAttributesExW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog"); FileTrackerTestHelper.AssertDidntFindStringInTLog("GetFileAttributesW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog"); File.Delete("directoryattributes.read.1.tlog"); File.Delete("directoryattributes.write.1.tlog"); commandArgs = "/d \"" + fileTrackerPath + "\" /u /e /c \"" + outputFile + "\""; exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs); Console.WriteLine(""); Assert.Equal(0, exit); // Should track directories when '/e' is passed FileTrackerTestHelper.AssertFoundStringInTLog(FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog"); File.Delete("directoryattributes.read.1.tlog"); File.Delete("directoryattributes.write.1.tlog"); commandArgs = "/d \"" + fileTrackerPath + "\" /u /a /c \"" + outputFile + "\""; exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs); Console.WriteLine(""); Assert.Equal(0, exit); // With '/a', should *not* track GetFileAttributes on directories, even though we do so on files. FileTrackerTestHelper.AssertDidntFindStringInTLog(FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog"); File.Delete("directoryattributes.read.1.tlog"); File.Delete("directoryattributes.write.1.tlog"); commandArgs = "/d \"" + fileTrackerPath + "\" /u /c \"" + outputFile + "\""; exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs); Console.WriteLine(""); Assert.Equal(0, exit); // With neither '/a' nor '/e', should not do any directory tracking whatsoever FileTrackerTestHelper.AssertDidntFindStringInTLog(FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog"); } finally { File.Delete(codeFile); File.Delete(outputFile); } }
// Ignore: Needs investigation public void LaunchMultipleOfSameTool_ToolLaunchesOthers() { string testDir = Path.Combine(Path.GetTempPath(), "LaunchMultipleOfSameTool_ToolLaunchesOthers"); try { if (FileUtilities.DirectoryExistsNoThrow(testDir)) { FileUtilities.DeleteDirectoryNoThrow(testDir, true); } Directory.CreateDirectory(testDir); // File to run findstr against. string tempFilePath = Path.Combine(testDir, "bar.txt"); File.WriteAllText(tempFilePath, ""); // Sample app that runs findstr. string codeFile = null; string outputFile = Path.Combine(testDir, "FindstrLauncher.exe"); string codeContent = @" using System; using System.Diagnostics; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { if (args.Length > 1) { for (int i = 0; i < Int32.Parse(args[0]); i++) { Process p = Process.Start(""findstr"", ""/i foo "" + args[1]); p.WaitForExit(); } } } } }"; File.Delete(outputFile); codeFile = Path.Combine(testDir, "Program.cs"); File.WriteAllText(codeFile, codeContent); Csc csc = new Csc(); csc.BuildEngine = new MockEngine(); csc.Sources = new ITaskItem[] { new TaskItem(codeFile) }; csc.OutputAssembly = new TaskItem(outputFile); csc.Platform = "x86"; bool compileSucceeded = csc.Execute(); Assert.True(compileSucceeded); // Item1: appname // Item2: command line // Item3: number of times to launch IList<Tuple<string, string, int>> toolsToLaunch = new List<Tuple<string, string, int>>(); toolsToLaunch.Add(new Tuple<string, string, int>(outputFile, outputFile + " 3 " + tempFilePath, 3)); // Item1: FileTracker context name // Item2: Tuple <string, string, int> as described above IList<Tuple<string, IList<Tuple<string, string, int>>>> contextSpecifications = new List<Tuple<string, IList<Tuple<string, string, int>>>>(); contextSpecifications.Add(new Tuple<string, IList<Tuple<string, string, int>>>("ProcessLaunchTest", toolsToLaunch)); contextSpecifications.Add(new Tuple<string, IList<Tuple<string, string, int>>>("ProcessLaunchTest2", toolsToLaunch)); // Item1: tlog pattern // Item2: # times it's expected to appear IList<Tuple<string, int>> tlogPatterns = new List<Tuple<string, int>>(); tlogPatterns.Add(new Tuple<string, int>("ProcessLaunchTest-FindstrLauncher-findstr*tlog", 3)); tlogPatterns.Add(new Tuple<string, int>("ProcessLaunchTest-FindstrLauncher.*-findstr*tlog", 6)); tlogPatterns.Add(new Tuple<string, int>("ProcessLaunchTest2-FindstrLauncher-findstr*tlog", 3)); tlogPatterns.Add(new Tuple<string, int>("ProcessLaunchTest2-FindstrLauncher.*-findstr*tlog", 6)); LaunchDuplicateToolsAndVerifyTlogExistsForEach(testDir, contextSpecifications, tlogPatterns, createTestDirectory: false); } finally { if (FileUtilities.DirectoryExistsNoThrow(testDir)) { FileUtilities.DeleteDirectoryNoThrow(testDir, true); } } }
public override bool Execute() { string defDir = SafePath(ThriftDefinitionDir.ItemSpec); //look for last compilation timestamp string lastBuildPath = Path.Combine(defDir, lastCompilationName); DirectoryInfo defDirInfo = new DirectoryInfo(defDir); string lastWrite = LastWriteTime(defDir); if (File.Exists(lastBuildPath)) { string lastComp = File.ReadAllText(lastBuildPath); //don't recompile if the thrift library has been updated since lastComp FileInfo f = new FileInfo(ThriftLibrary.ItemSpec); string thriftLibTime = f.LastWriteTimeUtc.ToFileTimeUtc().ToString(); if (lastComp.CompareTo(thriftLibTime) < 0) { //new thrift library, do a compile lastWrite = thriftLibTime; } else if (lastComp == lastWrite || (lastComp == thriftLibTime && lastComp.CompareTo(lastWrite) > 0)) { //the .thrift dir hasn't been written to since last compilation, don't need to do anything LogMessage("ThriftImpl up-to-date", MessageImportance.High); return(true); } } //find the directory of the thriftlibrary (that's where output will go) FileInfo thriftLibInfo = new FileInfo(SafePath(ThriftLibrary.ItemSpec)); string thriftDir = thriftLibInfo.Directory.FullName; string genDir = Path.Combine(thriftDir, "gen-csharp"); if (Directory.Exists(genDir)) { try { Directory.Delete(genDir, true); } catch { /*eh i tried, just over-write now*/ } } //run the thrift executable to generate C# foreach (string thriftFile in Directory.GetFiles(defDir, "*.thrift")) { LogMessage("Generating code for: " + thriftFile, MessageImportance.Normal); Process p = new Process(); p.StartInfo.FileName = SafePath(ThriftExecutable.ItemSpec); p.StartInfo.Arguments = "--gen csharp -o " + SafePath(thriftDir) + " -r " + thriftFile; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardOutput = false; p.Start(); p.WaitForExit(); if (p.ExitCode != 0) { LogMessage("thrift.exe failed to compile " + thriftFile, MessageImportance.High); return(false); } if (p.ExitCode != 0) { LogMessage("thrift.exe failed to compile " + thriftFile, MessageImportance.High); return(false); } } Csc csc = new Csc(); csc.TargetType = "library"; csc.References = new ITaskItem[] { new TaskItem(ThriftLibrary.ItemSpec) }; csc.EmitDebugInformation = true; string outputPath = Path.Combine(thriftDir, OutputName.ItemSpec); csc.OutputAssembly = new TaskItem(outputPath); csc.Sources = FindSources(Path.Combine(thriftDir, "gen-csharp")); csc.BuildEngine = this.BuildEngine; LogMessage("Compiling generated cs...", MessageImportance.Normal); if (!csc.Execute()) { return(false); } //write file to defDir to indicate a build was successfully completed File.WriteAllText(lastBuildPath, lastWrite); thriftImpl = new TaskItem(outputPath); return(true); }
public void ExecuteCscBuildTaskWithServer() { var csc = new Csc(); var srcFile = _tempDirectory.CreateFile(s_helloWorldSrcCs[0].Key).WriteAllText(s_helloWorldSrcCs[0].Value).Path; var exeFile = Path.Combine(_tempDirectory.Path, "hello.exe"); var engine = new MockEngine(); csc.BuildEngine = engine; csc.Sources = new[] { new Build.Utilities.TaskItem(srcFile) }; csc.NoLogo = true; csc.OutputAssembly = new Build.Utilities.TaskItem(exeFile); csc.ToolPath = ""; csc.ToolExe = ""; csc.UseSharedCompilation = true; csc.Execute(); Assert.Equal(0, csc.ExitCode); Assert.Equal(string.Empty, engine.Warnings); Assert.Equal(string.Empty, engine.Errors); Assert.True(File.Exists(exeFile)); var result = ProcessUtilities.Run(exeFile, ""); Assert.Equal(0, result.ExitCode); Assert.Equal("Hello, world.", result.Output.Trim()); }