1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| public class SAccess
{
private const string GetLastPositionUrl = @"http://localhost/images/{0}.trk";
private const string GetAddressUrl = @"http://192.168.1.88/webform1.aspx?rGeo=getaddress&latitude={0}&longitude={1}";
public static string GetLastPosition(string deviceName)
{
string url = string.Format(GetLastPositionUrl, deviceName);
// DateTime dt = File.GetLastWriteTime(url);
// TimeSpan TS=DateTime.Now.Subtract(dt);
// {
// if (TS.Days > 0)
// {
// return string.Empty;
// }
// }
WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Stream data = client.OpenRead(url);
StreamReader reader = new StreamReader(data);
String sTemp = reader.ReadToEnd();
data.Close();
reader.Close();
int iLengthString = sTemp.Length;
sTemp = sTemp.Substring(0, iLengthString - 2); // Remove the last carriage return
int iLastSpace = sTemp.LastIndexOf("\n");
return sTemp.Substring(iLastSpace + 1); // Retrieve the last line by splitting at the last carrage return
}
} |
Partager