Using F# type provider
For the moment, the NugGet is only on my personal MyGet feed, which can be used as a package source: https://www.myget.org/F/romcyber/api/v2
PM> Install-Package Salesforce.TypeProvider
In this tutorial we will simply try to generate basic stats of our salesforce accounts
Open module and namespaces
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: |
|
We must specify TLS protocol versions to avoid misterious Salesforce authentication errors.
(May cause some problems with MONO :( )
1:
|
|
We can use a JSON file containing authentication informations.
This json contains something like:
1: 2: 3: 4: 5: 6: 7: 8: |
|
If you don't know how to get those infos, then follow this tutorial: https://rflechner.github.io/LinqToSalesforce/getting_started_with_salesforce.html
1: 2: |
|
During the 'Design time' a type provider frequently discovering generated structures.
To reduce risks of exceeding maximum allowed requests per 24 hours, we will use a tiny cache stored in files and shared between 'Design time' and 'Runtime'.
1: 2: 3: |
|
Generate your type (could take 2 minutes the first time if your bandwith is not good)
1: 2: 3: |
|
Now instanciate your generated type with authentication informations
1: 2: |
|
Exploring data
You can create a script like LinqToSalesforce.TpExample\Script.fsx
.
I suggest you use it with Atom and ionide.io ( cf. http://tomasp.net/blog/2016/fslab-ionide/ )
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: |
|
The result is cool
Sending data to Salesforce
You can update an entity
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: |
|
You can also add a new one
1: 2: 3: |
|
namespace FSharp
--------------------
namespace Microsoft.FSharp
static val DefaultNonPersistentConnectionLimit : int
static val DefaultPersistentConnectionLimit : int
static member CertificatePolicy : ICertificatePolicy with get, set
static member CheckCertificateRevocationList : bool with get, set
static member DefaultConnectionLimit : int with get, set
static member DnsRefreshTimeout : int with get, set
static member EnableDnsRoundRobin : bool with get, set
static member EncryptionPolicy : EncryptionPolicy
static member Expect100Continue : bool with get, set
static member FindServicePoint : address:Uri -> ServicePoint + 2 overloads
...
Full name: System.Net.ServicePointManager
| Ssl3 = 48
| Tls = 192
Full name: System.Net.SecurityProtocolType
static member CommandLine : string
static member CurrentDirectory : string with get, set
static member Exit : exitCode:int -> unit
static member ExitCode : int with get, set
static member ExpandEnvironmentVariables : name:string -> string
static member FailFast : message:string -> unit + 1 overload
static member GetCommandLineArgs : unit -> string[]
static member GetEnvironmentVariable : variable:string -> string + 1 overload
static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
static member GetFolderPath : folder:SpecialFolder -> string + 1 overload
...
nested type SpecialFolder
nested type SpecialFolderOption
Full name: System.Environment
type LiteralAttribute =
inherit Attribute
new : unit -> LiteralAttribute
Full name: Microsoft.FSharp.Core.LiteralAttribute
--------------------
new : unit -> LiteralAttribute
Full name: Using_type_provider.authfile
Full name: Using_type_provider.cacheFolder
Full name: Using_type_provider.slidingExpiration
Full name: Using_type_provider.TS
Full name: Using_type_provider.authJson
static member AppendAllLines : path:string * contents:IEnumerable<string> -> unit + 1 overload
static member AppendAllText : path:string * contents:string -> unit + 1 overload
static member AppendText : path:string -> StreamWriter
static member Copy : sourceFileName:string * destFileName:string -> unit + 1 overload
static member Create : path:string -> FileStream + 3 overloads
static member CreateText : path:string -> StreamWriter
static member Decrypt : path:string -> unit
static member Delete : path:string -> unit
static member Encrypt : path:string -> unit
static member Exists : path:string -> bool
...
Full name: System.IO.File
File.ReadAllText(path: string, encoding: Text.Encoding) : string
Full name: Using_type_provider.sf
type TimeSpan =
struct
new : ticks:int64 -> TimeSpan + 3 overloads
member Add : ts:TimeSpan -> TimeSpan
member CompareTo : value:obj -> int + 1 overload
member Days : int
member Duration : unit -> TimeSpan
member Equals : value:obj -> bool + 1 overload
member GetHashCode : unit -> int
member Hours : int
member Milliseconds : int
member Minutes : int
...
end
Full name: System.TimeSpan
--------------------
TimeSpan()
TimeSpan(ticks: int64) : unit
TimeSpan(hours: int, minutes: int, seconds: int) : unit
TimeSpan(days: int, hours: int, minutes: int, seconds: int) : unit
TimeSpan(days: int, hours: int, minutes: int, seconds: int, milliseconds: int) : unit
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.query
Calls Linq.QueryBuilder.Select
from Microsoft.FSharp.Collections
Full name: Microsoft.FSharp.Collections.Seq.toList
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member GetSlice : startIndex:int option * endIndex:int option -> 'T list
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
Full name: Microsoft.FSharp.Collections.List.groupBy
type CultureInfo =
new : name:string -> CultureInfo + 3 overloads
member Calendar : Calendar
member ClearCachedData : unit -> unit
member Clone : unit -> obj
member CompareInfo : CompareInfo
member CultureTypes : CultureTypes
member DateTimeFormat : DateTimeFormatInfo with get, set
member DisplayName : string
member EnglishName : string
member Equals : value:obj -> bool
...
Full name: System.Globalization.CultureInfo
--------------------
Globalization.CultureInfo(name: string) : unit
Globalization.CultureInfo(culture: int) : unit
Globalization.CultureInfo(name: string, useUserOverride: bool) : unit
Globalization.CultureInfo(culture: int, useUserOverride: bool) : unit
Full name: Microsoft.FSharp.Collections.List.map
static member Area : data:seq<#seq<'a1 * 'a2>> -> PlotlyChart (requires 'a1 :> key and 'a2 :> value)
static member Area : data:seq<#key * #value> -> PlotlyChart
static member Area : data:seq<#value> -> PlotlyChart
static member Bar : data:seq<#seq<'a1 * 'a2>> -> PlotlyChart (requires 'a1 :> key and 'a2 :> value)
static member Bar : data:seq<#key * #value> -> PlotlyChart
static member Bar : data:seq<#value> -> PlotlyChart
static member Bubble : data:seq<#key * #value * #value> -> PlotlyChart
static member Column : data:seq<#seq<'a1 * 'a2>> -> PlotlyChart (requires 'a1 :> key and 'a2 :> value)
static member Column : data:seq<#key * #value> -> PlotlyChart
static member Column : data:seq<#value> -> PlotlyChart
...
Full name: XPlot.Plotly.Chart
static member Chart.Line : data:seq<#seq<'a1 * 'a2>> -> PlotlyChart (requires 'a1 :> key and 'a2 :> value)
static member Chart.Line : data:seq<#key * #value> -> PlotlyChart
static member Chart.Line : data:seq<#value> -> PlotlyChart
--------------------
static member Chart.Line : data:Series<'K,#value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Drawing.Color * ?XTitle:string * ?YTitle:string -> ChartTypes.GenericChart (requires equality and 'K :> key)
static member Chart.Line : data:seq<#value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Drawing.Color * ?XTitle:string * ?YTitle:string -> ChartTypes.GenericChart
static member Chart.Line : data:seq<#key * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Drawing.Color * ?XTitle:string * ?YTitle:string -> ChartTypes.GenericChart
module Layout
from XPlot.Plotly
--------------------
type Layout =
new : unit -> Layout
member ShouldSerializeangularaxis : unit -> bool
member ShouldSerializeannotations : unit -> bool
member ShouldSerializeautosize : unit -> bool
member ShouldSerializebargap : unit -> bool
member ShouldSerializebargroupgap : unit -> bool
member ShouldSerializebarmode : unit -> bool
member ShouldSerializeboxmode : unit -> bool
member ShouldSerializedirection : unit -> bool
member ShouldSerializedragmode : unit -> bool
...
Full name: XPlot.Plotly.Layout.Layout
--------------------
new : unit -> Layout
static member Chart.WithLegend : enabled:bool -> chart:PlotlyChart -> PlotlyChart
--------------------
static member Chart.WithLegend : ?Enabled:bool * ?Title:string * ?Background:ChartTypes.Background * ?FontName:string * ?FontSize:float * ?FontStyle:Drawing.FontStyle * ?Alignment:Drawing.StringAlignment * ?Docking:ChartTypes.Docking * ?InsideArea:bool * ?TitleAlignment:Drawing.StringAlignment * ?TitleFont:Drawing.Font * ?TitleColor:Drawing.Color * ?BorderColor:Drawing.Color * ?BorderWidth:int * ?BorderDashStyle:ChartTypes.DashStyle -> ('a0 -> 'a0) (requires 'a0 :> ChartTypes.GenericChart)
Full name: Using_type_provider.industryCounts
type String =
new : value:char -> string + 7 overloads
member Chars : int -> char
member Clone : unit -> obj
member CompareTo : value:obj -> int + 1 overload
member Contains : value:string -> bool
member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
member EndsWith : value:string -> bool + 2 overloads
member Equals : obj:obj -> bool + 2 overloads
member GetEnumerator : unit -> CharEnumerator
member GetHashCode : unit -> int
...
Full name: System.String
--------------------
String(value: nativeptr<char>) : unit
String(value: nativeptr<sbyte>) : unit
String(value: char []) : unit
String(c: char, count: int) : unit
String(value: nativeptr<char>, startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int) : unit
String(value: char [], startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : unit
static member Chart.Area : data:seq<#seq<'a1 * 'a2>> -> PlotlyChart (requires 'a1 :> key and 'a2 :> value)
static member Chart.Area : data:seq<#key * #value> -> PlotlyChart
static member Chart.Area : data:seq<#value> -> PlotlyChart
--------------------
static member Chart.Area : data:Series<'K,#value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Drawing.Color * ?XTitle:string * ?YTitle:string -> ChartTypes.GenericChart (requires equality and 'K :> key)
static member Chart.Area : data:seq<#value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Drawing.Color * ?XTitle:string * ?YTitle:string -> ChartTypes.GenericChart
static member Chart.Area : data:seq<#key * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Drawing.Color * ?XTitle:string * ?YTitle:string -> ChartTypes.GenericChart
module Series
from Deedle
--------------------
type Series =
static member ofNullables : values:seq<Nullable<'a0>> -> Series<int,'a0> (requires default constructor and value type and 'a0 :> ValueType)
static member ofObservations : observations:seq<'c * 'd> -> Series<'c,'d> (requires equality)
static member ofOptionalObservations : observations:seq<'K * 'a1 option> -> Series<'K,'a1> (requires equality)
static member ofValues : values:seq<'a> -> Series<int,'a>
Full name: Deedle.F# Series extensions.Series
--------------------
type Series<'K,'V (requires equality)> =
interface IFsiFormattable
interface ISeries<'K>
new : pairs:seq<KeyValuePair<'K,'V>> -> Series<'K,'V>
new : keys:'K [] * values:'V [] -> Series<'K,'V>
new : keys:seq<'K> * values:seq<'V> -> Series<'K,'V>
new : index:IIndex<'K> * vector:IVector<'V> * vectorBuilder:IVectorBuilder * indexBuilder:IIndexBuilder -> Series<'K,'V>
member After : lowerExclusive:'K -> Series<'K,'V>
member Aggregate : aggregation:Aggregation<'K> * observationSelector:Func<DataSegment<Series<'K,'V>>,KeyValuePair<'TNewKey,OptionalValue<'R>>> -> Series<'TNewKey,'R> (requires equality)
member Aggregate : aggregation:Aggregation<'K> * keySelector:Func<DataSegment<Series<'K,'V>>,'TNewKey> * valueSelector:Func<DataSegment<Series<'K,'V>>,OptionalValue<'R>> -> Series<'TNewKey,'R> (requires equality)
member AsyncMaterialize : unit -> Async<Series<'K,'V>>
...
Full name: Deedle.Series<_,_>
--------------------
new : pairs:seq<Collections.Generic.KeyValuePair<'K,'V>> -> Series<'K,'V>
new : keys:seq<'K> * values:seq<'V> -> Series<'K,'V>
new : keys:'K [] * values:'V [] -> Series<'K,'V>
new : index:Indices.IIndex<'K> * vector:IVector<'V> * vectorBuilder:Vectors.IVectorBuilder * indexBuilder:Indices.IIndexBuilder -> Series<'K,'V>
Full name: Using_type_provider.account1
Calls Linq.QueryBuilder.Take
Full name: Microsoft.FSharp.Collections.Seq.head
Full name: Using_type_provider.na