Skip to content

Instantly share code, notes, and snippets.

@lenadroid
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save lenadroid/ba302764e2bca5290a52 to your computer and use it in GitHub Desktop.

Select an option

Save lenadroid/ba302764e2bca5290a52 to your computer and use it in GitHub Desktop.
let directory = cluster.StoreClient.FileStore.Directory.Create()
let songFileNames = [|...|] // url addresses to the lyrics of the songs
let download (url : string) = async {
let http = new System.Net.WebClient()
return! http.AsyncDownloadString(Uri url)
}
// to create new cloud file storing song's lyrics
let songCloudFile (song:string) (dir: CloudDirectory) = cloud {
let songName = song.Substring(0, song.IndexOf("\n") - 1).Trim().Replace("\"", "")
let fileName = Path.Combine(dir.Path, songName)
do! CloudFile.Delete fileName
return! CloudFile.WriteAllText(song, path = fileName)
}
// process to start the cloud files creation
let songCloudFilesProcess =
songFileNames
|> Array.map (fun i -> cloud {
let! text = download i |> Cloud.OfAsync
return! songCloudFile text directory
})
|> Cloud.Parallel
|> cluster.Run
// to display the contents of previously saved file
let displayLyrics (song: string) (dir: CloudDirectory) = cloud {
let fileName = Path.Combine(dir.Path, song)
return! CloudFile.ReadAllText fileName
}
// process to display lyrics of some song
let songLyrics = displayLyrics "Smells Like Teen Spirit" directory
|> cluster.Run
// remove all cloud files within the directory and the directory itself
let clearDirectory (dir: string) = cloud {
do! CloudDirectory.Delete dir
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment