From: gu.martinm@gmail.com Date: Sun, 17 Aug 2014 17:41:52 +0000 (+0200) Subject: OpenWeatherMap API: using just long and double nullables X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=57d122467b9dce0f38053db9f7ec29c8c96b5f38;p=CSharpForFun%2F.git OpenWeatherMap API: using just long and double nullables --- diff --git a/Allgemeines/HttpServersExamples/HttpServersExamples.sln b/Allgemeines/HttpServersExamples/HttpServersExamples.sln new file mode 100644 index 0000000..a0b4546 --- /dev/null +++ b/Allgemeines/HttpServersExamples/HttpServersExamples.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30501.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpServersExamples", "HttpServersExamples\HttpServersExamples.csproj", "{41EA8377-2483-4D2C-A56C-A1F90832FB69}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {41EA8377-2483-4D2C-A56C-A1F90832FB69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {41EA8377-2483-4D2C-A56C-A1F90832FB69}.Debug|Any CPU.Build.0 = Debug|Any CPU + {41EA8377-2483-4D2C-A56C-A1F90832FB69}.Release|Any CPU.ActiveCfg = Release|Any CPU + {41EA8377-2483-4D2C-A56C-A1F90832FB69}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Allgemeines/HttpServersExamples/HttpServersExamples/App.config b/Allgemeines/HttpServersExamples/HttpServersExamples/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Allgemeines/HttpServersExamples/HttpServersExamples/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Allgemeines/HttpServersExamples/HttpServersExamples/HttpServersExamples.csproj b/Allgemeines/HttpServersExamples/HttpServersExamples/HttpServersExamples.csproj new file mode 100644 index 0000000..87c4217 --- /dev/null +++ b/Allgemeines/HttpServersExamples/HttpServersExamples/HttpServersExamples.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {41EA8377-2483-4D2C-A56C-A1F90832FB69} + Exe + Properties + HttpServersExamples + HttpServersExamples + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Allgemeines/HttpServersExamples/HttpServersExamples/Program.cs b/Allgemeines/HttpServersExamples/HttpServersExamples/Program.cs new file mode 100644 index 0000000..98f1630 --- /dev/null +++ b/Allgemeines/HttpServersExamples/HttpServersExamples/Program.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace HttpServersExamples +{ + class Program + { + private static AutoResetEvent autoEvent = new AutoResetEvent(false); + + static void Main(string[] args) + { + HttpListener server = new HttpListener(); + + server.Prefixes.Add("http://127.0.0.1:10002/"); + + server.Start(); + + while(server.IsListening) + { + var asyncResult = server.BeginGetContext(ListenerCallback, server); + Thread.Sleep(3000); + } + + } + + private static void ListenerCallback(IAsyncResult result) + { + autoEvent.Set(); + autoEvent.Reset(); + + HttpListener server = (HttpListener)result.AsyncState; + + HttpListenerContext context = server.EndGetContext(result); + + HandleRemoteRequest(context); + } + + private static void HandleRemoteRequest(HttpListenerContext context) + { + HttpListenerRequest request = context.Request; + + HttpListenerResponse response = context.Response; + + string responseString = "Hello World!"; + byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); + response.ContentLength64 = buffer.Length; + using(Stream output = response.OutputStream) + { + output.Write(buffer, 0, buffer.Length); + } + + int waitResult = WaitHandle.WaitAny(new[] { autoEvent }, TimeSpan.FromSeconds(30), false); + + if (waitResult == 0 || waitResult == 1) + { + Console.WriteLine("Done..."); + } + else if (waitResult == WaitHandle.WaitTimeout) + { + Console.WriteLine("Done by timeout"); + } + + } + } +} diff --git a/Allgemeines/HttpServersExamples/HttpServersExamples/Properties/AssemblyInfo.cs b/Allgemeines/HttpServersExamples/HttpServersExamples/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..335146c --- /dev/null +++ b/Allgemeines/HttpServersExamples/HttpServersExamples/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// La información general sobre un ensamblado se controla mediante el siguiente +// conjunto de atributos. Cambie estos atributos para modificar la información +// asociada con un ensamblado. +[assembly: AssemblyTitle("HttpServersExamples")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("HttpServersExamples")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Si establece ComVisible como false, los tipos de este ensamblado no estarán visibles +// para los componentes COM. Si necesita obtener acceso a un tipo de este ensamblado desde +// COM, establezca el atributo ComVisible como true en este tipo. +[assembly: ComVisible(false)] + +// El siguiente GUID sirve como identificador de typelib si este proyecto se expone a COM +[assembly: Guid("adac396b-85c0-4896-b7b1-ec87e82d310f")] + +// La información de versión de un ensamblado consta de los cuatro valores siguientes: +// +// Versión principal +// Versión secundaria +// Número de compilación +// Revisión +// +// Puede especificar todos los valores o establecer como predeterminados los números de compilación y de revisión +// mediante el carácter '*', como se muestra a continuación: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Clouds.cs b/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Clouds.cs index 561bcaf..94f47f6 100644 --- a/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Clouds.cs +++ b/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Clouds.cs @@ -4,7 +4,7 @@ namespace jsonparser.currentweather { public class Clouds { - public int? all { get; set; } + public double? all { get; set; } } } diff --git a/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/CurrentWeather.cs b/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/CurrentWeather.cs index bb6909b..96e467b 100644 --- a/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/CurrentWeather.cs +++ b/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/CurrentWeather.cs @@ -13,10 +13,10 @@ namespace jsonparser.currentweather public Wind wind { get; set; } public Rain rain { get; set; } public Clouds clouds { get; set; } - public int? dt { get; set; } - public int? id { get; set; } + public long? dt { get; set; } + public long? id { get; set; } public string name { get; set; } - public int? cod { get; set; } + public long? cod { get; set; } } } diff --git a/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Main.cs b/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Main.cs index c972bcf..092a431 100644 --- a/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Main.cs +++ b/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Main.cs @@ -5,8 +5,8 @@ namespace jsonparser.currentweather public class Main { public double? temp { get; set; } - public int? pressure { get; set; } - public int? humidity { get; set; } + public double? pressure { get; set; } + public double? humidity { get; set; } public double? temp_min { get; set; } public double? temp_max { get; set; } } diff --git a/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Sys.cs b/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Sys.cs index 1ea4afd..96f0929 100644 --- a/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Sys.cs +++ b/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Sys.cs @@ -6,8 +6,8 @@ namespace jsonparser.currentweather { public double? message { get; set; } public string country { get; set; } - public int? sunrise { get; set; } - public int? sunset { get; set; } + public long? sunrise { get; set; } + public long? sunset { get; set; } } } diff --git a/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Weather.cs b/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Weather.cs index bd0d5f2..58411ec 100644 --- a/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Weather.cs +++ b/Allgemeines/openweathermap/jsonparser/jsonparser/currentweather/Weather.cs @@ -4,7 +4,7 @@ namespace jsonparser.currentweather { public class Weather { - public int? id { get; set; } + public long? id { get; set; } public string main { get; set; } public string description { get; set; } public string icon { get; set; } diff --git a/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/City.cs b/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/City.cs index 11308ed..5e98d08 100644 --- a/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/City.cs +++ b/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/City.cs @@ -4,11 +4,11 @@ namespace jsonparser.forecastweather { public class City { - public int? id { get; set; } + public long? id { get; set; } public string name { get; set; } public Coord coord { get; set; } public string country { get; set; } - public int? population { get; set; } + public long? population { get; set; } } } diff --git a/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/List.cs b/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/List.cs index acac33b..23212d9 100644 --- a/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/List.cs +++ b/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/List.cs @@ -5,14 +5,14 @@ namespace jsonparser.forecastweather { public class List { - public int? dt { get; set; } + public long? dt { get; set; } public Temp temp { get; set; } public double? pressure { get; set; } - public int? humidity { get; set; } + public double? humidity { get; set; } public List weather { get; set; } public double? speed { get; set; } - public int? deg { get; set; } - public int? clouds { get; set; } + public double? deg { get; set; } + public double? clouds { get; set; } public double? rain { get; set; } } } diff --git a/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/Weather.cs b/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/Weather.cs index 31324eb..e2a021e 100644 --- a/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/Weather.cs +++ b/Allgemeines/openweathermap/jsonparser/jsonparser/forecastweather/Weather.cs @@ -4,7 +4,7 @@ namespace jsonparser.forecastweather { public class Weather { - public int? id { get; set; } + public long? id { get; set; } public string main { get; set; } public string description { get; set; } public string icon { get; set; }