Successful error reporting and HTML parsing
This commit is contained in:
parent
f4781d30e9
commit
a62784037d
5 changed files with 53 additions and 16 deletions
|
@ -1,5 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using HtmlAgilityPack;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
@ -16,17 +18,22 @@ namespace Orarend
|
|||
/// <param name="csoportok">A csoportok, amiknek az óráit kérjük, szóközökkel elválasztva</param>
|
||||
/// <param name="nap">A nap egy betűs formában</param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Óra> Órák(string osztályid, string csoportok, string nap)
|
||||
public static IEnumerable<Óra> Órák(string osztályid, string csoportok, char nap)
|
||||
{
|
||||
return new Óra[] { new Óra { Azonosító = "test", Név = "Test", Tanár = new Tanár { Név = "A B" }, Terem = "222" }, new Óra { Azonosító = "asd", Név = "Asd", Tanár = new Tanár { Név = "B A" }, Terem = "216" } };
|
||||
}
|
||||
|
||||
public static async Task<IEnumerable<string>> Osztályok()
|
||||
/// <summary>
|
||||
/// <para>Visszatér az osztályok listájával, egy-egy kételemű tömbbel, az első elem az azonosító, a második a megjelenített név.</para>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static async Task<IEnumerable<string[]>> Osztályok()
|
||||
{ //TODO: Tárolja el az adatokat, és csak külön hívásra frissítse; csak a frissítés legyen async, ezek nem
|
||||
HtmlDocument doc = new HtmlDocument();
|
||||
var req = WebRequest.CreateHttp("http://deri.enaplo.net/ajax/orarend/orarendoszt.php");
|
||||
var resp = await req.GetResponseAsync();
|
||||
var doc = XDocument.Parse(new StreamReader(resp.GetResponseStream()).ReadToEnd());
|
||||
return new string[] { doc.Element(XName.Get("select")).Value };
|
||||
doc.Load(resp.GetResponseStream());
|
||||
return doc.GetElementbyId("uok").ChildNodes.Where(node => node.HasAttributes).Select(node => new string[] { node.GetAttributeValue("value", ""), node.InnerText });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,14 +33,21 @@
|
|||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<!-- A reference to the entire .NET Framework is automatically included -->
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="API.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Tanár.cs" />
|
||||
<Compile Include="Óra.cs" />
|
||||
<Compile Include="Órarend.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="HtmlAgilityPack, Version=1.4.9.5, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\HtmlAgilityPack.1.4.9.5\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid+MonoTouch\HtmlAgilityPack.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
4
Orarend/packages.config
Normal file
4
Orarend/packages.config
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="HtmlAgilityPack" version="1.4.9.5" targetFramework="portable45-net45+win8+wpa81" />
|
||||
</packages>
|
14
Orarend/Órarend.cs
Normal file
14
Orarend/Órarend.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Orarend
|
||||
{
|
||||
public class Órarend
|
||||
{
|
||||
public Dictionary<char, List<Óra>> Órák { get; set; }
|
||||
public string Név { get; set; }
|
||||
}
|
||||
}
|
|
@ -15,11 +15,13 @@ namespace OrarendAndroidApp
|
|||
[Activity(Label = "OrarendAndroidApp", MainLauncher = true, Icon = "@drawable/icon")]
|
||||
public class MainActivity : Activity
|
||||
{
|
||||
private Handler handler;
|
||||
|
||||
protected override void OnCreate(Bundle bundle)
|
||||
{
|
||||
base.OnCreate(bundle);
|
||||
SetContentView(Resource.Layout.MainLayout);
|
||||
//ViewPager viewPager = FindViewById<ViewPager>(Resource.Id.viewpager);
|
||||
handler = new Handler();
|
||||
var table = FindViewById<TableLayout>(Resource.Id.tableLayout1);
|
||||
Action<string, Color, TableRow> addCell = (text, color, tr1) =>
|
||||
{
|
||||
|
@ -37,13 +39,16 @@ namespace OrarendAndroidApp
|
|||
TableRow tr = new TableRow(this);
|
||||
API.Osztályok().ContinueWith(t =>
|
||||
{
|
||||
if (t.Exception.InnerExceptions.Count > 0)
|
||||
foreach (var ex in t.Exception.InnerExceptions)
|
||||
addCell(ex.ToString().Substring(0, 50), Color.Red, tr); //TODO: Handler, main thread
|
||||
else
|
||||
foreach (var osztály in t.Result)
|
||||
addCell(osztály, Color.Aqua, tr);
|
||||
table.AddView(tr);
|
||||
handler.Post(() =>
|
||||
{
|
||||
if (t.Exception?.InnerExceptions.Count > 0)
|
||||
foreach (var ex in t.Exception.InnerExceptions)
|
||||
addCell(ex.ToString(), Color.Red, tr);
|
||||
else
|
||||
foreach (var osztály in t.Result)
|
||||
addCell(osztály[0], Color.Aqua, tr);
|
||||
table.AddView(tr);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue