This repository was archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4761022
commit fa1a7d8
Showing
5 changed files
with
41 additions
and
54 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
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 |
---|---|---|
|
@@ -13,63 +13,50 @@ public static class UsageFactory | |
/// <summary> | ||
/// Regex pour définir l'utilisation | ||
/// </summary> | ||
private readonly static Regex regexUsage = | ||
private readonly static Regex RegexUsage = | ||
new Regex("<TR><TD>(.*)</TD><TD>(.*)</TD><TD ALIGN=\"RIGHT\">(.*)</TD><TD ALIGN=\"RIGHT\">(.*)</TD></TR>"); | ||
|
||
/// <summary> | ||
/// Regex pour définir l'utilisation maximale permise | ||
/// </summary> | ||
private static readonly Regex regexMax = | ||
private static readonly Regex RegexMax = | ||
new Regex("<TD>Quota permis pour la période</TD><TD ALIGN=\"RIGHT\">(.*)</TD></TD></TR>"); | ||
|
||
/// <summary> | ||
/// Le parsing des doubles de cooptel dépendent de la culture locale | ||
/// </summary> | ||
private static readonly CultureInfo Culture = CultureInfo.CreateSpecificCulture("en-CA"); | ||
|
||
/// <summary> | ||
/// Retourne un objet Dataset Usage pour la phase, appart et mois spécifié | ||
/// </summary> | ||
/// <param name="phase"></param> | ||
/// <param name="appart"></param> | ||
/// <param name="mois"></param> | ||
/// <returns></returns> | ||
public static Usage GetUsage(int phase, int appart, int mois) | ||
{ | ||
var usage = new Usage(); | ||
return GetUsage(usage, phase, appart, mois); | ||
} | ||
|
||
/// <summary> | ||
/// Ajoute les informations de la consommation internet pour un appart dans un objet Usage donné | ||
/// </summary> | ||
/// <param name="usage"></param> | ||
/// <param name="phase"></param> | ||
/// <param name="appart"></param> | ||
/// <param name="mois"></param> | ||
/// <returns></returns> | ||
public static Usage GetUsage(Usage usage, int phase, int appart, int mois) | ||
/// <returns>Objet usage plein de data</returns> | ||
public static Usage GetUsage(this Usage usage, int phase, int appart, int mois) | ||
{ | ||
// Build query string | ||
// http://ets-res2-772:[email protected]/services/temps/?mois=9&cmd=Visualiser | ||
string query = "http://www2.cooptel.qc.ca/services/temps/?mois=" + mois + "&cmd=Visualiser"; | ||
string user = "ets-res" + phase + "-" + appart; | ||
string pass = "ets" + appart; | ||
var query = string.Format("http://www2.cooptel.qc.ca/services/temps/?mois={0}&cmd=Visualiser", mois); | ||
var user = string.Format("ets-res{0}-{1}", phase, appart); | ||
var pass = string.Format("ets{0}", appart); | ||
|
||
string html; | ||
try | ||
{ | ||
// Fetch data into a string | ||
html = SPACEBAR.Net.DownloadHTML(query, user, pass); | ||
html = NetHelper.DownloadHtml(query, user, pass); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new Exception("Could not download html:" + ex.Message); | ||
} | ||
|
||
// Match du regeex | ||
MatchCollection mc = regexUsage.Matches(html); | ||
usage.Maximum = Math.Round(Double.Parse(regexMax.Matches(html)[0].Groups[1].Value, Culture), 0); | ||
MatchCollection mc = RegexUsage.Matches(html); | ||
usage.Maximum = Math.Round(Double.Parse(RegexMax.Matches(html)[0].Groups[1].Value, Culture), 0); | ||
|
||
// Objets temporaires | ||
for (var i = 0; i <= mc.Count - 1; i++) | ||
|
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