Esempio n. 1
0
        /// <summary>
        /// Attempts to load a Dairy-CropSyst scenario, including the CafoDairy
        /// file (*.NIFA_dairy_scenario) and a CropSyst scenario
        /// (*.CropSyst_scenario).
        /// <remark>Only loads the first CropSyst scenario found in the
        /// field directory</remark>
        /// </summary>
        /// <param name="filePath">Path to CafoDairy scenario file *.NIFA_dairy_scenario</param>
        /// <exception cref="ArgumentException">Cannot find/load CafoDairy scenario</exception>
        public void Load(string filePath)
        {
            bool didLoad = dDp.Load(filePath);

            if (!didLoad)
            {
                throw new ArgumentException("File path not valid");
            }

            //if (!String.IsNullOrEmpty(dDp.LoadedPath))
            //{
            //    // Load Field scenario
            //    string dairyDir = Path.GetDirectoryName(filePath);
            //    string fieldDir = Path.Combine(dairyDir, fieldDirName);
            //
            //    if(Directory.Exists(fieldDir))
            //    {
            //        string[] fields = Directory.GetDirectories(fieldDir);
            //
            //        if (fields.Length > 0)
            //        {
            //            // Currently only supporting one field
            //            string fieldFile = Path.Combine(fields[0], ".CropSyst_scenario");
            //            fDp.Load(fieldFile);
            //        }
            //    }
            //}
        }
Esempio n. 2
0
        public void LoadField(string pathToScenarioDir)
        {
            // Load Field scenario
            string dairyDir = pathToScenarioDir;
            string fieldDir = Path.Combine(dairyDir, fieldDirName);

            if (Directory.Exists(fieldDir))
            {
                string[] fields = Directory.GetDirectories(fieldDir);

                if (fields.Length > 0)
                {
                    // Currently only supporting one field
                    string fieldFile = Path.Combine(fields[0], ".CropSyst_scenario");
                    fDp.Load(fieldFile);
                }
            }
        }
Esempio n. 3
0
        public void Write(Scenario s, string dirPath)
        {
            if (!Directory.Exists(dirPath))
            {
                throw new NullReferenceException("Dir does not exist");
            }

            string filePath = Path.Combine(dirPath, dairyScenarioFilename);

            if (File.Exists(filePath))
            {
                throw new InvalidOperationException("File already exists, aborting");
            }

            File.Create(filePath).Close();

            dDp.Load(filePath);

            Write(s);
        }
Esempio n. 4
0
        private void copyFieldTemplate(Scenario s, string pathToParentDir)
        {
            if (!Directory.Exists(pathToParentDir))
            {
                throw new ArgumentException("Copy to path does not exist");
            }

            //string sourcePath =
            //    Path.Combine(
            //        Directory.GetCurrentDirectory(),
            //    @"Assets\Fields",
            //    s.Field.Crop);
            string sourcePath =
                Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                    "DairyCropSyst",
                    "Fields",
                    s.Field.Crop);
            string destinationPath =
                Path.Combine(pathToParentDir, s.Field.Crop);

            Directory.CreateDirectory(destinationPath);

            //Create all of the directories
            foreach (string dirPath in Directory.GetDirectories(sourcePath, "*",
                                                                SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(dirPath.Replace(sourcePath, destinationPath));
            }

            //Copy all the files & Replaces any files with the same name
            foreach (string newPath in Directory.GetFiles(sourcePath, "*.*",
                                                          SearchOption.AllDirectories))
            {
                File.Copy(newPath, newPath.Replace(sourcePath, destinationPath), true);
            }

            // Reload file
            fDp.Load(Path.Combine(destinationPath, fieldScenarioFilename));
        }