-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStockTickerViewController.fs
More file actions
66 lines (54 loc) · 2.36 KB
/
Copy pathStockTickerViewController.fs
File metadata and controls
66 lines (54 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
namespace StockTicker
open Agents
open MonoTouch.Foundation
open MonoTouch.UIKit
open System
open System.Drawing
open Steema.TeeChart
[<Register("StockTickerViewController")>]
type StockTickerViewController() =
inherit UIViewController()
let mutable AgentState = Stop
let appleLine = new Styles.FastLine(Title = "Apple")
let msLine = new Styles.FastLine(Title = "Microsoft")
let googleLine = new Styles.FastLine(Title = "Google")
let rec DrawLine n agentState stock (stockLine:Styles.FastLine) (stockPriceAgent:MailboxProcessor<Message>) =
match agentState with
| Start ->
let stockAsync = stockPriceAgent.PostAndAsyncReply id
Async.StartWithContinuations(stockAsync,
(fun reply ->
printfn "%s %i %f" stock n reply
stockLine.Add reply |> ignore
do DrawLine (n+1) AgentState stock stockLine stockPriceAgent),
(fun _ -> ()), // exception
(fun _ -> ())) // cancellation
| Stop -> ()
let StartStopSlider =
let s = new UISegmentedControl(RectangleF(85.f, 350.f, 150.f, 50.f))
s.InsertSegment("Start", 0, false)
s.InsertSegment("Stop", 1, false)
s.SelectedSegment <- 1
let HandleSegmentChanged =
new EventHandler(fun sender _ ->
let s = sender :?> UISegmentedControl
match s.SelectedSegment with
| 0 -> AgentState <- Start
| 1 -> AgentState <- Stop
| _ -> failwith "No such segment!"
DrawLine 0 AgentState "apple" appleLine AppleStockPriceAgent
DrawLine 0 AgentState "ms" msLine MSStockPriceAgent
DrawLine 0 AgentState "google" googleLine GoogleStockPriceAgent
)
s.ValueChanged.AddHandler HandleSegmentChanged
s
override this.ViewDidLoad() =
base.ViewDidLoad()
let stockView = new UIView(this.View.Bounds, BackgroundColor = UIColor.White)
let chart = new TChart(Frame = RectangleF(10.f, 10.f, 300.f, 300.f))
chart.Series.Add appleLine |> ignore
chart.Series.Add msLine |> ignore
chart.Series.Add googleLine |> ignore
stockView.AddSubview chart
stockView.AddSubview StartStopSlider
this.View.AddSubview stockView