3 people like it.

Querying NuGet via OData TypeProvider

Querying NuGet package manager via OData TypeProvider

 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: 
#if INTERACTIVE
#r "FSharp.Data.TypeProviders"
#r "System.Data.Services.Client"
#else
module PackageManager
#endif

type Nuget = Microsoft.FSharp.Data.TypeProviders.ODataService<"https://nuget.org/api/v2">
let NugetConnection = Nuget.GetDataContext()
// NugetConnection.Credentials <- ...

let fetchNugetInfo id version = 
    try
        query { for package in NugetConnection.Packages do
                where (package.Id = id && package.Version = version)
                select (package.Title, package.IsLatestVersion)
                headOrDefault
        } |> Some
    with //Not found:
    | :? System.Data.Services.Client.DataServiceClientException -> None

fetchNugetInfo "EntityFramework" "6.0.0.0" 
|> function 
   | Some(title, true) -> Console.WriteLine(title + " is up-to-date")
   | Some(title, false) -> Console.WriteLine(title + " is outdated")
   | _ -> ignore()
type Nuget =
  static member GetDataContext : unit -> V2FeedContext + 1 overload
  nested type ServiceTypes

Full name: Script.Nuget


<summary>Provides the types to access an OData service</summary><param name="ServiceUri">The Uri for the OData service</param><param name='LocalSchemaFile'>The local .csdl file for the service schema</param><param name='ForceUpdate'>Require that a direct connection to the service be available at design-time and force the refresh of the local schema file (default: true)</param><param name='ResolutionFolder'>The folder used to resolve relative file paths at compile-time (default: folder containing the project or script)</param><param name='DataServiceCollection'>Generate collections derived from DataServiceCollection (default: false)</param>
namespace Microsoft
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Data
namespace Microsoft.FSharp.Data.TypeProviders
type ODataService

Full name: Microsoft.FSharp.Data.TypeProviders.ODataService


<summary>Provides the types to access an OData service</summary><param name="ServiceUri">The Uri for the OData service</param><param name='LocalSchemaFile'>The local .csdl file for the service schema</param><param name='ForceUpdate'>Require that a direct connection to the service be available at design-time and force the refresh of the local schema file (default: true)</param><param name='ResolutionFolder'>The folder used to resolve relative file paths at compile-time (default: folder containing the project or script)</param><param name='DataServiceCollection'>Generate collections derived from DataServiceCollection (default: false)</param>
val NugetConnection : Nuget.ServiceTypes.SimpleDataContextTypes.V2FeedContext

Full name: Script.NugetConnection
Nuget.GetDataContext() : Nuget.ServiceTypes.SimpleDataContextTypes.V2FeedContext


Get a simplified data context for this OData Service. By default, no credentials are set

Nuget.GetDataContext(uri: System.Uri) : Nuget.ServiceTypes.SimpleDataContextTypes.V2FeedContext


Get a simplified data context for this OData Service. By default, no credentials are set
val fetchNugetInfo : id:string -> version:string -> (string * bool) option

Full name: Script.fetchNugetInfo
val id : string
val version : string
val query : Linq.QueryBuilder

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.query
val package : Nuget.ServiceTypes.V2FeedPackage
property Nuget.ServiceTypes.SimpleDataContextTypes.V2FeedContext.Packages: System.Data.Services.Client.DataServiceQuery<Nuget.ServiceTypes.V2FeedPackage>


Gets the 'Packages' entities from the OData Service. This property may be used as the source in a query expression.
custom operation: where (bool)

Calls Linq.QueryBuilder.Where
property Nuget.ServiceTypes.V2FeedPackage.Id: string
property Nuget.ServiceTypes.V2FeedPackage.Version: string
custom operation: select ('Result)

Calls Linq.QueryBuilder.Select
property Nuget.ServiceTypes.V2FeedPackage.Title: string
property Nuget.ServiceTypes.V2FeedPackage.IsLatestVersion: bool
custom operation: headOrDefault

Calls Linq.QueryBuilder.HeadOrDefault
union case Option.Some: Value: 'T -> Option<'T>
namespace System
namespace System.Data
namespace System.Data.Services
namespace System.Data.Services.Client
Multiple items
type DataServiceClientException =
  inherit InvalidOperationException
  new : unit -> DataServiceClientException + 4 overloads
  member GetObjectData : info:SerializationInfo * context:StreamingContext -> unit
  member StatusCode : int

Full name: System.Data.Services.Client.DataServiceClientException

--------------------
System.Data.Services.Client.DataServiceClientException() : unit
System.Data.Services.Client.DataServiceClientException(message: string) : unit
System.Data.Services.Client.DataServiceClientException(message: string, innerException: exn) : unit
System.Data.Services.Client.DataServiceClientException(message: string, statusCode: int) : unit
System.Data.Services.Client.DataServiceClientException(message: string, innerException: exn, statusCode: int) : unit
union case Option.None: Option<'T>
val title : string
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore

More information

Link:http://fssnip.net/pb
Posted:9 years ago
Author:Tuomas Hietanen
Tags: nuget , odata , type provider , typeprovider