Beispiel #1
0
        /// <summary>
        /// Method that exports the configuration for the forecast
        /// </summary>
        /// <param name="path">Path where the files will be located</param>
        public async Task <bool> exportForecastSetupAsync(string path)
        {
            // Create directory
            if (!Directory.Exists(path + Program.settings.Out_PATH_FS_FILES))
            {
                Directory.CreateDirectory(path + Program.settings.Out_PATH_FS_FILES);
            }
            var crops = await db.crop.listEnableAsync();

            foreach (var cp in crops)
            {
                Console.WriteLine("Exporting " + cp.name);
                string dir_crop = path + Program.settings.Out_PATH_FS_FILES + @"\" + Tools.folderCropName(cp.name);
                Directory.CreateDirectory(dir_crop);
                foreach (var st in cp.setup.Where(p => p.track.enable))
                {
                    string dir_setup = dir_crop + @"\" + st.weather_station.ToString() + "_" + st.cultivar.ToString() + "_" + st.soil.ToString() + "_" + st.days.ToString();
                    Directory.CreateDirectory(dir_setup);
                    foreach (var f in st.conf_files)
                    {
                        File.Copy(f.path, dir_setup + @"\" + f.name + COut.getExtension(f.path), true);
                    }
                    // Add csv file with geolocation for rice crop only
                    if (Program.settings.Out_CROPS_COORDINATES.Contains(Tools.folderCropName(cp.name)))
                    {
                        WeatherStation ws = await db.weatherStation.byIdAsync(st.weather_station.ToString());

                        StringBuilder coords = new StringBuilder();
                        coords.Append("name,value\n");
                        coords.Append("lat," + ws.latitude.ToString() + "\n");
                        coords.Append("long," + ws.longitude.ToString() + "\n");
                        coords.Append("elev," + ws.elevation.ToString() + "\n");
                        File.WriteAllText(dir_setup + @"\" + Program.settings.Out_PATH_FILE_COORDINATES, coords.ToString());
                    }
                }
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Method to export the configuration files by weather station
        /// </summary>
        /// <param name="path">Path where the files will be located</param>
        /// <param name="name">Name of file to filter</param>
        public async Task <bool> exportFilesWeatherStationAsync(string path, string name)
        {
            // Create directory
            if (!Directory.Exists(path + Program.settings.Out_PATH_WS_FILES))
            {
                Directory.CreateDirectory(path + Program.settings.Out_PATH_WS_FILES);
            }
            var weather_stations = await db.weatherStation.listEnableAsync();

            foreach (var ws in weather_stations.Where(p => p.visible && p.conf_files.Count() > 0))
            {
                Console.WriteLine("Exporting files ws: " + ws.name);
                var f = ws.conf_files.Where(p => p.name.Equals(name)).OrderByDescending(p => p.date).FirstOrDefault();
                if (f != null)
                {
                    File.Copy(f.path, path + Program.settings.Out_PATH_WS_FILES + Path.DirectorySeparatorChar + ws.id.ToString() + COut.getExtension(f.path), true);
                }
                else
                {
                    Console.WriteLine("File not found");
                }
            }
            return(true);
        }