public void OnInitialised() { co2 = 350; inputFile.Open(inputFilename); MaxTIndex = StringManip.IndexOfCaseInsensitive(inputFile.Headings, "Maxt"); MinTIndex = StringManip.IndexOfCaseInsensitive(inputFile.Headings, "Mint"); RadnIndex = StringManip.IndexOfCaseInsensitive(inputFile.Headings, "Radn"); RainIndex = StringManip.IndexOfCaseInsensitive(inputFile.Headings, "Rain"); if (MaxTIndex == -1) { throw new Exception("Cannot find MaxT in weather file: " + inputFilename); } if (MinTIndex == -1) { throw new Exception("Cannot find MinT in weather file: " + inputFilename); } if (RadnIndex == -1) { throw new Exception("Cannot find Radn in weather file: " + inputFilename); } if (RainIndex == -1) { throw new Exception("Cannot find Rain in weather file: " + inputFilename); } }
/// <summary> /// Read in the APSIM header - headings/units and constants. /// </summary> private void ReadApsimHeader(StreamReaderRandomAccess In) { StringCollection ConstantLines = new StringCollection(); StringCollection HeadingLines = new StringCollection(); ReadApsimHeaderLines(In, ref ConstantLines, ref HeadingLines); bool TitleFound = false; foreach (string ConstantLine in ConstantLines) { string Line = ConstantLine; string Comment = StringManip.SplitOffAfterDelimiter(ref Line, "!"); Comment.Trim(); int PosEquals = Line.IndexOf('='); if (PosEquals != -1) { string Name = Line.Substring(0, PosEquals).Trim(); if (Name.ToLower() == "title") { TitleFound = true; Name = "Title"; } string Value = Line.Substring(PosEquals + 1).Trim(); string Unit = StringManip.SplitOffBracketedValue(ref Value, '(', ')'); _Constants.Add(new APSIMConstant(Name, Value, Unit, Comment)); } } if (HeadingLines.Count >= 2) { if (CSV) { HeadingLines[0] = HeadingLines[0].TrimEnd(','); HeadingLines[1] = HeadingLines[1].TrimEnd(','); Headings = new StringCollection(); Units = new StringCollection(); Headings.AddRange(HeadingLines[0].Split(",".ToCharArray())); Units.AddRange(HeadingLines[1].Split(",".ToCharArray())); for (int i = 0; i < Headings.Count; i++) { Headings[i] = Headings[i].Trim(); } for (int i = 0; i < Units.Count; i++) { Units[i] = Units[i].Trim(); } } else { Headings = StringManip.SplitStringHonouringQuotes(HeadingLines[0], " \t"); Units = StringManip.SplitStringHonouringQuotes(HeadingLines[1], " \t"); } TitleFound = TitleFound || StringManip.IndexOfCaseInsensitive(Headings, "title") != -1; if (Headings.Count != Units.Count) { throw new Exception("The number of headings and units doesn't match in file: " + _FileName); } } if (!TitleFound) { _Constants.Add(new APSIMConstant("Title", Path.GetFileNameWithoutExtension(_FileName), "", "")); } }
/// <summary> /// Report the number of diffs to the database. /// </summary> private static int ReportNumDiffs(string ApsimDirectoryName, List <string> ModifiedFiles, string PatchFileName, string outZip) { // Some of the diffs in ModifiedFiles will be from the patch, so to get a count of // the number of files that were changed by APSIM running we need to remove those // files from the list that were sent in the patch. string[] PatchFileNames = new string [0]; if (File.Exists(PatchFileName)) { PatchFileNames = Zip.FileNamesInZip(PatchFileName, ""); } foreach (string FileNameInPatch in PatchFileNames) { Stream PatchContents = Zip.UnZipFile(PatchFileName, FileNameInPatch, ""); if (PatchContents == null) { throw new Exception("missing file " + FileNameInPatch + " in patchfile"); } string localVersionOfPatchedFile = Path.Combine(ApsimDirectoryName, FileNameInPatch).Replace('\\', '/'); bool AreEqual; if (Path.GetFileName(FileNameInPatch) == "DotNetProxies.cs") { AreEqual = true; } else { AreEqual = FilesAreIdentical(PatchContents, localVersionOfPatchedFile); } // If the files are identical then remove it from the list of ModifiedFiles, // otherwise make sure it is in the list. int I = StringManip.IndexOfCaseInsensitive(ModifiedFiles, localVersionOfPatchedFile); if (AreEqual) { if (I != -1) { ModifiedFiles.RemoveAt(I); } } else { if (I == -1 && Path.GetFileName(FileNameInPatch) != "patch.revisions") { ModifiedFiles.Add(localVersionOfPatchedFile); } } } // Now we should have a list of the "real" diffs. int JobID = Convert.ToInt32(System.Environment.GetEnvironmentVariable("JOB_ID")); string url = "https://apsimdev.apsim.info/APSIM.Builds.Service/BuildsClassic.svc/UpdateNumDiffs" + "?JobID=" + JobID + "&NumDiffs=" + ModifiedFiles.Count + "&DbConnectPassword="******"DB_CONN_PSW"); Utils.REST.CallService <object>(url); if (ModifiedFiles.Count != 0) { Console.WriteLine("Files that are different:"); foreach (string FileName in ModifiedFiles) { Console.WriteLine(FileName); } Console.WriteLine("Build is not clean"); return(1); } return(0); }