-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.2.9] The PüMa Release See merge request monica/lora-map/lora-map!2
- Loading branch information
Showing
27 changed files
with
1,856 additions
and
849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net; | ||
|
||
using BlubbFish.Utils; | ||
|
||
using LitJson; | ||
|
||
namespace Fraunhofer.Fit.IoT.LoraMap.Lib { | ||
public class WebRequests { | ||
private static readonly Object getLock = new Object(); | ||
public JsonData GetJson(String url) { | ||
String text = null; | ||
for(Int32 i = 0; i < 3; i++) { | ||
try { | ||
text = this.GetString(url); | ||
break; | ||
} catch(Exception e) { | ||
Helper.WriteError(e.Message); | ||
if(i == 2) { | ||
throw; | ||
} | ||
System.Threading.Thread.Sleep(30000); | ||
} | ||
} | ||
if(text == null) { | ||
return new JsonData(); | ||
} | ||
try { | ||
return JsonMapper.ToObject(text); | ||
} catch(Exception) { | ||
return new JsonData(); | ||
} | ||
} | ||
|
||
private String GetString(String url, Boolean withoutput = true) { | ||
String ret = null; | ||
lock(getLock) { | ||
HttpWebRequest request = WebRequest.CreateHttp(url); | ||
request.Timeout = 10000; | ||
//request.Headers.Add(HttpRequestHeader.Authorization, this.auth); | ||
try { | ||
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { | ||
if(response.StatusCode == HttpStatusCode.Unauthorized) { | ||
Console.Error.WriteLine("Benutzer oder Passwort falsch!"); | ||
throw new Exception("Benutzer oder Passwort falsch!"); | ||
} | ||
if(withoutput) { | ||
StreamReader reader = new StreamReader(response.GetResponseStream()); | ||
ret = reader.ReadToEnd(); | ||
} | ||
} | ||
} catch(Exception e) { | ||
//Helper.WriteError("Konnte keine Verbindung zum Razzbery Server herstellen. Resource: \"" + this.server + v + "\" Fehler: " + e.Message); | ||
//return null; | ||
throw new Exception("Konnte keine Verbindung zum Server herstellen: " + e.Message); | ||
} | ||
} | ||
return ret; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.