Esempio n. 1
0
 public async Task <HttpResponseMessage> getGPSDataList(GPSInputData parms)
 {
     try
     {
         return(Request.CreateResponse(HttpStatusCode.OK, await BasicInfoFunc.getGPSbyID(parms)));
     }
     catch (Exception SqlException)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Internal Server Error"));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 獲取GPS測站歷史資料列表
        /// </summary>
        public static async Task <List <GPSDataList> > getGPSbyID(GPSInputData parms)
        {
            String             line;
            List <GPSDataList> GPSData = new List <GPSDataList>();

            try
            {
                //Pass the file path and file name to the StreamReader constructor
                string       gpsPath = ConfigurationManager.ConnectionStrings["gpsPath"].ConnectionString;
                StreamReader sr      = new StreamReader(gpsPath + parms.gpsid + ".COR");

                //Read the first line of text
                line = sr.ReadLine();
                Int32 count    = 0;
                float starthgt = 0;
                float startn   = 0;
                float starte   = 0;
                //Continue to read until you reach end of file
                while (line != null)
                {
                    line = sr.ReadLine();
                    line = new System.Text.RegularExpressions.Regex("[\\s]+").Replace(line, " ");
                    char[]   delimiterChars = { ' ', '\t' };
                    string[] words          = line.Split(delimiterChars);

                    if (Int32.Parse(words[0]) >= Int32.Parse(parms.sdate) && Int32.Parse(words[0]) <= Int32.Parse(parms.edate))
                    {
                        GPSDataList GPS = new GPSDataList();
                        if (count == 0)
                        {
                            starthgt = float.Parse(words[3]);
                            startn   = float.Parse(words[4]);
                            starte   = float.Parse(words[5]);
                        }
                        float calhgt = (float.Parse(words[3]) - starthgt) * 1000;
                        float caln   = (float.Parse(words[4]) - startn);
                        float cale   = (float.Parse(words[5]) - starte);
                        GPS.year = words[0];
                        GPS.lat  = words[1];
                        GPS.lon  = words[2];
                        GPS.hgt  = calhgt.ToString();
                        GPS.dN   = caln.ToString();
                        GPS.dE   = cale.ToString();
                        GPS.dU   = words[6];
                        GPSData.Add(GPS);
                        count++;
                    }
                }

                //close the file
                sr.Close();
                Console.ReadLine();
            }
            catch (Exception r)
            {
                Console.WriteLine("Exception: " + r.Message);
            }
            finally
            {
                Console.WriteLine("Executing finally block.");
            }
            //return GPSData;
            //string jsonData = JsonConvert.SerializeObject(GPSData);
            //System.Console.WriteLine(jsonData);

            return(GPSData);
        }