Skip to content

Instantly share code, notes, and snippets.

@TahaHachana
Last active December 21, 2015 15:29
Show Gist options
  • Save TahaHachana/6326968 to your computer and use it in GitHub Desktop.
Save TahaHachana/6326968 to your computer and use it in GitHub Desktop.
#r "WindowsBase.dll"
#r "PresentationFramework.dll"
#r "PresentationCore.dll"
#r "System.Xaml.dll"
#r "Tsunami.IDEDesktop.exe"
#r "System.Xml.Linq"
#r "cache:http://tsunami.io/assemblies/FunScript.dll"
#r "cache:http://tsunami.io/assemblies/FunScript.TypeScript.dll"
#r "cache:http://tsunami.io/assemblies/FunScript.TypeScript.Interop.dll"
#r "ActiproSoftware.Docking.Wpf.dll"
#r "ActiproSoftware.Ribbon.Wpf.dll"
#r "ActiproSoftware.DataGrid.Contrib.Wpf.dll"
#r "ActiproSoftware.SyntaxEditor.Wpf.dll"
#r "ActiproSoftware.Shared.Wpf.dll"
#r "UIAutomationTypes.dll"
open FunScript
open System.IO
open System.Net
open Tsunami.IDE
open Tsunami.Utilities
open Tsunami.Server.AsyncHTTP
open System.Windows
open System.Windows.Controls
module Browser =
let ui = Threading.DispatcherSynchronizationContext UI.Instances.ApplicationMenu.Dispatcher
let browser =
async {
do! Async.SwitchToContext ui
let browser = new WebBrowser()
return browser
} |> Async.RunSynchronously
type BrowserControl() as this =
inherit UserControl()
do this.Content <- browser
SimpleUI.addControlToNewDocument("Browser", fun _ -> new BrowserControl() :> UIElement)
let refresh() =
async {
do! Async.SwitchToContext ui
browser.Refresh()
} |> Async.RunSynchronously
module Server =
module Model =
let mutable client =
html5Page
[
title "Highcharts Example"
]
[
div (attrs(["id","chart"]))
JQuery.jquery1_9_1
script (src "http://code.highcharts.com/highcharts.js")
script (src "http://code.highcharts.com/modules/exporting.js")
script (src "app.js")
]
let mutable js = ""
let routing : AsyncParser<HTTPState,string,string,string> =
[
getPath "/" -!> okDynamic (fun _ -> Model.client)
getPath "/app.js" -!> okDynamicWithMimeType "application/javascript" (fun _ -> Model.js)
notFound
]
|> disjoin
|> respondWeb
let chatServer() = webserver "Server" IPAddress.Any 4503 routing None
let server = chatServer()
async {
do! Async.SwitchToContext Browser.ui
Browser.browser.Navigate "http://127.0.0.1:4503/"
} |> Async.RunSynchronously
// JavaScript
module JS =
type HTP = TypeScript.Api<"https://github.com/borisyankov/DefinitelyTyped/raw/master/highcharts/highcharts.d.ts">
[<FunScript.JS>]
module Charts =
[<JSEmit("return new {0}({1});")>]
let clone (obj : 'T, args : 'A) : 'T = failwith "never"
let line() =
let options = HTP.HighchartsOptions()
options.chart <- HTP.HighchartsChartOptions(renderTo = "chart", ``type`` = "pie")
let titleOptions = HTP.HighchartsTitleOptions()
titleOptions.AsHighchartsSubtitleOptions().text <- "Visitors By Browser"
options.title <- titleOptions
let series =
let options = HTP.HighchartsSeriesOptions()
options.``type`` <- "pie"
options.name <- "Visitors"
options.data <- [|[|box "Chrome"; box 606|]; [|box "Firefox"; box 450|]; [|box "IE"; box 342|]|]
[|options|]
options.series <- series
clone(HTP.Highcharts.Chart, options) |> ignore
let components = FunScript.Interop.Components.all
let js = FunScript.Compiler.Compiler.Compile(<@ Charts.line() @>, components=components, noReturn = true)
Server.Model.js <- js
Browser.refresh()
//Server.server.Dispose()
@Vijesh2
Copy link

Vijesh2 commented Aug 25, 2013

I get this error message in the shell window of Tsunami when trying to run this:
stdin(28,1): error FS3031: The type provider 'cache:http://tsunami.io/assemblies/FunScript.TypeScript.dll' reported an error: Assembly attribute 'TypeProviderAssemblyAttribute' refers to a designer assembly 'FunScript.TypeScript' which cannot be loaded or doesn't exist. scheme for cache:http://tsunami.io/assemblies/FunScript.TypeScript.dll unrecognized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment