Skip to content

Commit

Permalink
Refactoring towards #27
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Sep 3, 2014
1 parent 4667c46 commit 4fc519b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
26 changes: 0 additions & 26 deletions src/Paket/Hashing.fs
@@ -1,35 +1,9 @@
module Hashing

open System.Security.Cryptography
open System.Xml.Linq
open System.Net
open System
open System.IO

/// Gets hash value and algorithm from Nuget.
let getDetailsFromNuget name version =
async {
use wc = new WebClient()
let! data = sprintf "https://www.nuget.org/api/v2/Packages(Id='%s',Version='%s')" name version
|> wc.DownloadStringTaskAsync
|> Async.AwaitTask
let data = XDocument.Parse data

let getAttribute =
let rootNs = XName.Get("entry", "http://www.w3.org/2005/Atom")
let propertiesNs =
XName.Get("properties", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata")
let attributesNs attribute =
XName.Get(attribute, "http://schemas.microsoft.com/ado/2007/08/dataservices")

let properties =
rootNs
|> data.Element
|> fun entry -> entry.Element(propertiesNs)
fun attribute -> properties.Element(attributesNs attribute).Value
return (getAttribute "PackageHash", getAttribute "PackageHashAlgorithm")
}

let private getAlgorithm algorithmName =
match algorithmName with
| "SHA512" -> Some(SHA512.Create() :> HashAlgorithm)
Expand Down
27 changes: 26 additions & 1 deletion src/Paket/Nuget.fs
Expand Up @@ -7,6 +7,7 @@ open System.Net
open System.Xml
open Newtonsoft.Json
open Ionic.Zip
open System.Xml.Linq

/// Gets versions of the given package.
let getAllVersions(nugetURL,package) =
Expand Down Expand Up @@ -61,6 +62,30 @@ let getDependencies nugetURL package version =
|> Array.toList
return packages
}

/// Gets hash value and algorithm from Nuget.
let getDetailsFromNuget name version =
async {
use wc = new WebClient()
let! data = sprintf "https://www.nuget.org/api/v2/Packages(Id='%s',Version='%s')" name version
|> wc.DownloadStringTaskAsync
|> Async.AwaitTask
let data = XDocument.Parse data

let getAttribute =
let rootNs = XName.Get("entry", "http://www.w3.org/2005/Atom")
let propertiesNs =
XName.Get("properties", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata")
let attributesNs attribute =
XName.Get(attribute, "http://schemas.microsoft.com/ado/2007/08/dataservices")

let properties =
rootNs
|> data.Element
|> fun entry -> entry.Element(propertiesNs)
fun attribute -> properties.Element(attributesNs attribute).Value
return (getAttribute "PackageHash", getAttribute "PackageHashAlgorithm")
}

/// The NuGet cache folder.
let CacheFolder =
Expand Down Expand Up @@ -89,7 +114,7 @@ let DownloadPackage(source, name, version, force) =
do! client.DownloadFileTaskAsync(Uri url, targetFileName)
|> Async.AwaitIAsyncResult
|> Async.Ignore
let! hashDetails = Hashing.getDetailsFromNuget name version
let! hashDetails = getDetailsFromNuget name version
match hashDetails |> Hashing.compareWith name targetFile with
| Some error ->
// TODO: File.Delete targetFileName
Expand Down

0 comments on commit 4fc519b

Please sign in to comment.