Skip to content

Commit

Permalink
Update to FSharp.Data 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Guerra committed Mar 9, 2014
1 parent 2018a26 commit 783daa4
Show file tree
Hide file tree
Showing 15 changed files with 8,153 additions and 33 deletions.
2 changes: 1 addition & 1 deletion LearnOnTheGo.WP8/DownloadsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<ScrollViewer>
<Grid>
<StackPanel>
<TextBlock Text="Please note that files over 20MB can not be downloaded over cellular connection, and files over 100MB can not be downloaded unless connected to external power. This is a Windows Phone limitation."
<TextBlock Text="Please note that files over 20MB cannot be downloaded over cellular connection, and files over 100MB cannot be downloaded unless connected to external power. This is a Windows Phone limitation."
Margin="12,0,0,0"
Style="{StaticResource PhoneTextSmallStyle}"
TextWrapping="Wrap" />
Expand Down
16 changes: 8 additions & 8 deletions LearnOnTheGo/Crawler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ open System.Text
open System.Text.RegularExpressions
open HtmlAgilityPack.FSharp
open FSharp.Control
open FSharp.Net
open FSharp.Data.Json
open FSharp.Data.Json.Extensions
open FSharp.Data
open FSharp.Data.HttpRequestHeaders
open FSharp.Data.JsonExtensions

module URLs =
let Login = "https://accounts.coursera.org/api/v1/login"
Expand All @@ -33,11 +33,11 @@ module private Implementation =
let csrfToken = getCsrfToken()
let cookieContainer = new CookieContainer()
let! _ = Http.AsyncRequestString(URLs.Login,
headers = ["Origin", "https://accounts.coursera.org"
"X-CSRFToken", csrfToken
"Referer", "https://accounts.coursera.org/signin"],
body = RequestBody.FormValues ["email", email
"password", password],
headers = [ Origin "https://accounts.coursera.org"
"X-CSRFToken", csrfToken
Referer "https://accounts.coursera.org/signin" ],
body = FormValues ["email", email
"password", password],
cookies = ["csrftoken", csrfToken],
cookieContainer = cookieContainer)
return cookieContainer }
Expand Down
4 changes: 2 additions & 2 deletions LearnOnTheGo/DataModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Course =
{ Id : int
Name : string
StartDate : string
Duration : string
Duration : string option
HomeLink : string
Active : bool
HasFinished : bool
Expand All @@ -25,7 +25,7 @@ and Topic =
LargeIcon : string
Name : string
Photo : string
PreviewLink : string
PreviewLink : string option
SelfServiceCourseId : int option
ShortDescription : string
ShortName : string
Expand Down
3 changes: 2 additions & 1 deletion LearnOnTheGo/LearnOnTheGo.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@
<Compile Include="Crawler.fs" />
<Compile Include="SampleData.fs" />
<None Include="Tests.fsx" />
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="FSharp.Core">
<HintPath>$(MSBuildExtensionsPath32)\..\Reference Assemblies\Microsoft\FSharp\.NETPortable\$(TargetFSharpCoreVersion)\FSharp.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FSharp.Data">
<HintPath>..\packages\FSharp.Data.2.0.0-alpha\lib\portable-net40+sl5+wp8+win8\FSharp.Data.dll</HintPath>
<HintPath>..\packages\FSharp.Data.2.0.0-rc-a1403090010\lib\portable-net40+sl5+wp8+win8\FSharp.Data.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="HtmlAgilityPack-PCL">
Expand Down
10 changes: 5 additions & 5 deletions LearnOnTheGo/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ let parseTopicsJson getLectureSections topicsJsonStr =
let parseTopic (json:JsonT.Topic) =
{ Display = json.Display
Id = json.Id
Instructor = json.Instructor
Instructor = defaultArg json.Instructor ""
Language = json.Language
LargeIcon = json.LargeIcon
Name = json.Name
Photo = json.Photo
PreviewLink = json.PreviewLink
SelfServiceCourseId = json.SelfServiceCourseId.Number
SelfServiceCourseId = json.SelfServiceCourseId
ShortDescription = json.ShortDescription
ShortName = json.ShortName
SmallIcon = json.SmallIcon
SmallIconHover = json.SmallIcon }

let parseCourse topic (json:JsonT.Course) =
let id = json.Id
let homeLink = json.HomeLink
let homeLink = defaultArg json.HomeLink ""
{ Id = id
Name = json.Name.String.Value
StartDate =
match json.StartYear.Number, json.StartMonth.Number, json.StartDay.Number with
match json.StartYear, json.StartMonth, json.StartDay with
| Some y, Some m, Some d -> sprintf "%d/%02d/%02d" y m d
| _ -> ""
Duration = json.DurationString
HomeLink = homeLink
Active = json.Active
HasFinished = json.GradesReleaseDate.JsonValue <> Json.JsonValue.Null || json.CertificatesReady || json.Status = false
HasFinished = json.GradesReleaseDate.IsSome || json.CertificatesReady || json.Status = false
Topic = topic
LectureSections = getLectureSections id topic.Name homeLink }

Expand Down
11 changes: 11 additions & 0 deletions LearnOnTheGo/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.3.5.1" newVersion="2.3.5.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
2 changes: 1 addition & 1 deletion LearnOnTheGo/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FSharp.Data" version="2.0.0-alpha" targetFramework="portable-net45+sl50+win+MonoAndroid10+MonoTouch10" />
<package id="FSharp.Data" version="2.0.0-rc-a1403090010" targetFramework="portable-net45+sl50+win+MonoAndroid10+MonoTouch10" />
<package id="HtmlAgilityPack-PCL" version="1.4.6" targetFramework="portable-win+net45+sl50" />
<package id="Zlib.Portable" version="1.9.2" targetFramework="portable-net45+sl50+win+MonoAndroid10+MonoTouch10" />
</packages>
8,105 changes: 8,102 additions & 3 deletions LearnOnTheGo/topics.json

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions Trains.WP8/Trains.WP8.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@
<Reference Include="Microsoft.Phone.Controls.Toolkit">
<HintPath>..\packages\WPtoolkit.4.2013.08.16\lib\wp8\Microsoft.Phone.Controls.Toolkit.dll</HintPath>
</Reference>
<Reference Include="SharpGIS.GZipWebClient">
<HintPath>..\packages\SharpGIS.GZipWebClient.1.4.0.0\lib\wp71\SharpGIS.GZipWebClient.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Page Include="LiveProgressPage.xaml">
Expand Down
5 changes: 2 additions & 3 deletions Trains/LiveDepartures.IE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ open HtmlAgilityPack
open HtmlAgilityPack.FSharp
open FSharp.Control
open FSharp.Data
open FSharp.Net
open Trains

//http://api.irishrail.ie/realtime/index.htm
Expand Down Expand Up @@ -47,7 +46,7 @@ let private getJourneyDetails trainCode trainDate = async {

let getDepartures() =
try
xmlT.GetObjTrainMovements()
xmlT.ObjTrainMovements
|> Seq.filter (fun xml -> xml.LocationType <> LocationType.TimingPoint.ToString())
|> Seq.map xmlToJourneyElement
|> Seq.toArray
Expand Down Expand Up @@ -106,7 +105,7 @@ let private getDeparturesOrArrivals forDepartures mapper getOutput (departuresAn
let getDeparturesOrArrivals callingAtFilter xml extraFilter =
try
let xmlT = StationDataXmlT.Parse xml
xmlT.GetObjStationDatas()
xmlT.ObjStationDatas
|> Seq.filter (fun xml -> xml.Locationtype <> (if forDepartures then LocationType.Destination else LocationType.Origin).ToString())
|> Seq.map (mapper callingAtFilter)
|> extraFilter
Expand Down
5 changes: 3 additions & 2 deletions Trains/LiveDepartures.UK.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ open System.Threading
open HtmlAgilityPack
open HtmlAgilityPack.FSharp
open FSharp.Control
open FSharp.Net
open FSharp.Data
open FSharp.Data.HttpRequestHeaders
open Trains

let wp8UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)"

let private asyncRequestString (url:string) =
Http.AsyncRequestString(url, headers = ["User-Agent", wp8UserAgent])
Http.AsyncRequestString(url, headers = [ UserAgent wp8UserAgent ])

let private getStatus due (str:string) =
match trimEnd "*" str with
Expand Down
4 changes: 2 additions & 2 deletions Trains/Stations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module Stations =
use stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("UKStations.csv")
let csvFile = CsvProvider<"UKStations.csv", Schema="Latitude=float,Longitude=float">.Load stream
#endif
csvFile.Data
csvFile.Rows
|> Seq.groupBy (fun station -> station.CrsCode)
|> Seq.map (fun (code, stations) ->
let station =
Expand All @@ -65,7 +65,7 @@ module Stations =
use stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("IrelandStations.xml")
let xml = XmlProvider<"IrelandStations.xml">.Load stream
#endif
xml.GetObjStations()
xml.ObjStations
|> Seq.distinctBy (fun station -> station.StationDesc) // there's two different Adamstown
|> Seq.map (fun station ->
{ Code = station.StationCode
Expand Down
3 changes: 2 additions & 1 deletion Trains/Trains.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@
<Compile Include="LiveDepartures.UK.fs" />
<Compile Include="LiveDeparturesExtensions.fs" />
<Compile Include="SampleData.fs" />
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="FSharp.Core">
<HintPath>$(MSBuildExtensionsPath32)\..\Reference Assemblies\Microsoft\FSharp\.NETPortable\$(TargetFSharpCoreVersion)\FSharp.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FSharp.Data">
<HintPath>..\packages\FSharp.Data.2.0.0-alpha\lib\portable-net40+sl5+wp8+win8\FSharp.Data.dll</HintPath>
<HintPath>..\packages\FSharp.Data.2.0.0-rc-a1403090010\lib\portable-net40+sl5+wp8+win8\FSharp.Data.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="HtmlAgilityPack-PCL">
Expand Down
11 changes: 11 additions & 0 deletions Trains/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.3.5.1" newVersion="2.3.5.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
2 changes: 1 addition & 1 deletion Trains/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FSharp.Data" version="2.0.0-alpha" targetFramework="portable-net45+sl50+win+MonoAndroid10+MonoTouch10" />
<package id="FSharp.Data" version="2.0.0-rc-a1403090010" targetFramework="portable-net45+sl50+win+MonoAndroid10+MonoTouch10" />
<package id="HtmlAgilityPack-PCL" version="1.4.6" targetFramework="portable-win+net45+sl50" />
<package id="Zlib.Portable" version="1.9.2" targetFramework="portable-net45+sl50+win+MonoAndroid10+MonoTouch10" />
</packages>

0 comments on commit 783daa4

Please sign in to comment.