/// <summary>
        /// Adds a Farm4Prophet job to the APSIM cloud.
        /// </summary>
        /// <param name="f4p">The job specification.</param>
        /// <returns>The unique job name.</returns>
        public string AddFarm4Prophet(Farm4Prophet f4p)
        {
            string newJobName = DateTime.Now.ToString("yyyy-MM-dd (HH-mm-ss) ") + f4p.TaskName + "_F4P";

            string xml = Farm4ProphetUtility.Farm4ProphetToXML(f4p);

            AddAsXML(newJobName, xml);
            return newJobName;
        }
Beispiel #2
0
        /// <summary>Constructor</summary>
        /// <param name="xml">Job specification xml.</param>
        /// <param name="environment">The runtime environment to use for the run</param>
        public RunF4PJob(string xml, RuntimeEnvironment environment)
        {
            // Save f4p.xml to working folder.
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            doc.Save(Path.Combine(workingDirectory, "f4p.xml"));

            Farm4Prophet spec = Farm4ProphetUtility.Farm4ProphetFromXML(xml);

            Initialise(spec, environment);
        }
Beispiel #3
0
        /// <summary>Constructor</summary>
        /// <param name="xml">Job specification xml.</param>
        /// <param name="environment">The runtime environment to use for the run</param>
        public RunF4PJob(string xml, RuntimeEnvironment environment)
        {
            workingDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            Directory.CreateDirectory(workingDirectory);

            // Save f4p.xml to working folder.
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            doc.Save(Path.Combine(workingDirectory, "f4p.xml"));

            Farm4Prophet spec = Farm4ProphetUtility.Farm4ProphetFromXML(xml);

            Initialise(spec, environment);
        }
Beispiel #4
0
        /// <summary>Initialise the job</summary>
        /// <param name="f4p">Job specification</param>
        /// <param name="environment">The runtime environment to use for the run</param>
        private void Initialise(Farm4Prophet f4p, RuntimeEnvironment environment)
        {
            List <AusFarmSpec> simulations = Farm4ProphetToAusFarm.ToAusFarm(f4p);

            // Writes the sdml files to the workingDirectory and returns a list of names
            files = AusFarmFiles.Create(simulations, workingDirectory).ToList();

            // Setup the runtime environment.
            binFolder = RunYPJob.SetupRunTimeEnvironment(environment);

            // Copy in the .prm files.
            foreach (string prmFileName in Directory.GetFiles(binFolder, "*.prm"))
            {
                File.Copy(prmFileName, Path.Combine(workingDirectory, Path.GetFileName(prmFileName)));
            }
        }
        /// <summary>
        /// Create simulation specifications.
        /// </summary>
        /// <param name="f4Prophet">The farm 4 prophet specification</param>
        /// <returns>A list of AusFarm specs. </returns>
        private static List<AusFarmSpec> SimulationRuns(Farm4Prophet f4Prophet)
        {
            List<AusFarmSpec> ausfarmSpecs = new List<AusFarmSpec>();

            foreach (FarmSystem farm in f4Prophet.FarmList)
            {
                AusFarmSpec simulation = CreateBaseSimulation(farm);
                simulation.Name = farm.Name;
                simulation.Area = farm.Area;
                simulation.StartDate = farm.StartSeasonDate;
                simulation.EndDate = simulation.StartDate.AddMonths(farm.RunLength);
                simulation.ReportName = farm.ReportName;
                ausfarmSpecs.Add(simulation);
            }
            return ausfarmSpecs;
        }
        /// <summary>
        /// Create simulation specifications.
        /// </summary>
        /// <param name="f4Prophet">The farm 4 prophet specification</param>
        /// <returns>A list of AusFarm specs. </returns>
        private static List <AusFarmSpec> SimulationRuns(Farm4Prophet f4Prophet)
        {
            List <AusFarmSpec> ausfarmSpecs = new List <AusFarmSpec>();

            foreach (FarmSystem farm in f4Prophet.FarmList)
            {
                AusFarmSpec simulation = CreateBaseSimulation(farm);
                simulation.Name       = farm.Name;
                simulation.Area       = farm.Area;
                simulation.StartDate  = farm.StartSeasonDate;
                simulation.EndDate    = simulation.StartDate.AddMonths(farm.RunLength);
                simulation.ReportName = farm.ReportName;
                ausfarmSpecs.Add(simulation);
            }
            return(ausfarmSpecs);
        }
 /// <summary>Convert the Farm4Prophet spec to XML.</summary>
 /// <returns>The XML string.</returns>
 public static string Farm4ProphetToXML(Farm4Prophet f4Prophet)
 {
     XmlSerializer serial = new XmlSerializer(typeof(Farm4Prophet));
     XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
     ns.Add("", "");
     StringWriter writer = new StringWriter();
     serial.Serialize(writer, f4Prophet, ns);
     string xml = writer.ToString();
     if (xml.Length > 5 && xml.Substring(0, 5) == "<?xml")
     {
         // remove the first line: <?xml version="1.0"?>/n
         int posEol = xml.IndexOf("\n");
         if (posEol != -1)
             return xml.Substring(posEol + 1);
     }
     return xml;
 }
Beispiel #8
0
        /// <summary>Convert the Farm4Prophet spec to XML.</summary>
        /// <returns>The XML string.</returns>
        public static string Farm4ProphetToXML(Farm4Prophet f4Prophet)
        {
            XmlSerializer           serial = new XmlSerializer(typeof(Farm4Prophet));
            XmlSerializerNamespaces ns     = new XmlSerializerNamespaces();

            ns.Add("", "");
            StringWriter writer = new StringWriter();

            serial.Serialize(writer, f4Prophet, ns);
            string xml = writer.ToString();

            if (xml.Length > 5 && xml.Substring(0, 5) == "<?xml")
            {
                // remove the first line: <?xml version="1.0"?>/n
                int posEol = xml.IndexOf("\n");
                if (posEol != -1)
                {
                    return(xml.Substring(posEol + 1));
                }
            }
            return(xml);
        }
Beispiel #9
0
 /// <summary>Constructor</summary>
 /// <param name="f4p">Job specification</param>
 /// <param name="environment">The runtime environment to use for the run</param>
 public RunF4PJob(Farm4Prophet f4p, RuntimeEnvironment environment)
 {
     Initialise(f4p, environment);
 }
Beispiel #10
0
 /// <summary>Constructor</summary>
 /// <param name="f4p">Job specification</param>
 /// <param name="environment">The runtime environment to use for the run</param>
 public RunF4PJob(Farm4Prophet f4p, RuntimeEnvironment environment)
 {
     workingDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
     Directory.CreateDirectory(workingDirectory);
     Initialise(f4p, environment);
 }
 /// <summary>Converts a Farm4Prophet specification to a list of AusFarm simulations.</summary>
 /// <param name="f4Prophet">The farm 4 prophet spec.</param>
 /// <returns>The list of AusFarm simulations that will need to be run.</returns>
 public static List<AusFarmSpec> ToAusFarm(Farm4Prophet f4Prophet)
 {
         return SimulationRuns(f4Prophet);
 }
 /// <summary>Converts a Farm4Prophet specification to a list of AusFarm simulations.</summary>
 /// <param name="f4Prophet">The farm 4 prophet spec.</param>
 /// <returns>The list of AusFarm simulations that will need to be run.</returns>
 public static List <AusFarmSpec> ToAusFarm(Farm4Prophet f4Prophet)
 {
     return(SimulationRuns(f4Prophet));
 }