Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="regionShapeFile"></param>
        /// <returns></returns>
        public static async Task <bool> AddRegionShapeFile(RegionShapeFile regionShapeFile)
        {
            bool success = false;

            try
            {
                using (DbConnection db = new DbConnection())
                {
                    MySqlCommand cmd = await db.GetCommandAsync();

                    cmd.CommandText = "INSERT INTO region_shape_file (PlantID, LinkToFile) VALUES " +
                                      "(@PlantID, @LinkToFile);";

                    cmd.Parameters.AddWithValue("@PlantID", regionShapeFile.PlantID);
                    cmd.Parameters.AddWithValue("@LinkToFile", regionShapeFile.LinkToFile);

                    success = await cmd.ExecuteNonQueryAsync() > 0;
                }
            }
            catch (Exception ex)
            {
            }

            return(success);
        }
        private List <Polygon> readKmzFiles(TableFileRecordUtility fileRecordUtility)
        {
            List <Polygon> allPolygons = new List <Polygon>();

            FileIDNameUtility fileIdUtility = new FileIDNameUtility();

            fileIdUtility.ReadInfoFile(Program.DriveFileIDCsvPath);

            for (int idx = 0; idx < fileRecordUtility.RegionShapeFileRecords.Count; idx++)
            {
                RegionShapeFile rsf = fileRecordUtility.RegionShapeFileRecords[idx];

                KmzFileToPointCollectionUtility kmzUtility = new KmzFileToPointCollectionUtility();
                string      fileId = rsf.LinkToFile.Split("id=")[1];
                KmzFileInfo fInfo  = fileIdUtility.FileInfos.Find(it =>
                                                                  it.FileID.Equals(fileId));

                if (fInfo != null)
                {
                    kmzUtility.GetPolygons(rsf.PlantID, fInfo.FullPath, fileId)
                    .ForEach(x => allPolygons.Add(x));
                }
            }

            return(allPolygons);
        }
 public async Task <ActionResult> AddRegionShapeFile(RegionShapeFile regionShapefile)
 {
     if (await PlantModel.AddRegionShapeFile(regionShapefile))
     {
         return(Ok());
     }
     return(new BadRequestResult());
 }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="plantIdOffsetIdx"></param>
        /// <returns></returns>
        public List <RegionShapeFile> ReadRegionShapeFileCsv(string filepath, int plantIdOffsetIdx)
        {
            List <RegionShapeFile> regionShapeFiles = new List <RegionShapeFile>();

            if (!string.IsNullOrEmpty(filepath))
            {
                using (TextFieldParser parser = new TextFieldParser(filepath))
                {
                    parser.SetDelimiters(Delimiters);
                    parser.HasFieldsEnclosedInQuotes = true;

                    parser.ReadLine();

                    while (!parser.EndOfData)
                    {
                        string[] fields = parser.ReadFields();

                        try
                        {
                            int offsetPlantId = Convert.ToInt32(fields[1]) +
                                                (KeyCombinationBaseOffset * plantIdOffsetIdx);

                            string url = fields[2];
                            url = url.Replace("open?", "uc?export=download&");
                            url = url.Replace("#", "");

                            RegionShapeFile rsf = new RegionShapeFile()
                            {
                                PlantID    = offsetPlantId,
                                LinkToFile = url
                            };

                            regionShapeFiles.Add(rsf);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"Failed to get a PlantID ID on RegionShapeFileID: {fields[0]}");
                        }
                    }
                }
            }

            return(regionShapeFiles);
        }