Skip to content

Commit 20f74e1

Browse files
author
Steven Taylor
committed
added a shortcut to bring up test.fsx in VS
added simple .cmds for debugging test.fsx script from either the IDE or the command line added diagnostic lines appended todo / bug / done / fixed / notes sections. Just a simple in-file co-ordination mechanism. added basic .gitignore
1 parent 23e6d31 commit 20f74e1

File tree

5 files changed

+99
-28
lines changed

5 files changed

+99
-28
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FtpProvider/FtpProvider/bin/Debug/FSharp.Core.dll
2+
FtpProvider/FtpProvider/bin/Debug/FSharp.Core.xml
3+
FtpProvider/FtpProvider/bin/Debug/FtpTypeProvider.dll
4+
FtpProvider/FtpProvider/bin/Debug/FtpTypeProvider.pdb
5+
FtpProvider/FtpProvider/bin/Debug/TestTypeProvider.XML
6+
FtpProvider/FtpProvider/obj/Debug/FtpTypeProvider.dll
7+
FtpProvider/FtpProvider/obj/Debug/FtpTypeProvider.fsproj.FileListAbsolute.txt
8+
FtpProvider/FtpProvider/obj/Debug/FtpTypeProvider.pdb
9+
FtpProvider/packages/FSharp.TypeProviders.StarterPack.1.1.3.67/FSharp.TypeProviders.StarterPack.1.1.3.67.nupkg
10+
FtpProvider/packages/FSharp.TypeProviders.StarterPack.1.1.3.67/content/DebugProvidedTypes.fs
11+
FtpProvider/packages/FSharp.TypeProviders.StarterPack.1.1.3.67/content/ProvidedTypes.fs
12+
FtpProvider/packages/FSharp.TypeProviders.StarterPack.1.1.3.67/content/ProvidedTypes.fsi

FtpProvider/FtpProvider/FtpProvider.fs

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ open System.Reflection
77
open ProviderImplementation.ProvidedTypes
88
open Microsoft.FSharp.Core.CompilerServices
99

10+
[<Literal>]
11+
let diag=true // TODO.4 TODO.5
12+
1013
/// Get the directories and files in an FTP site using anonymous login
1114
let getFtpDirectory (site:string, user:string, pwd:string) =
1215
let request =
@@ -38,40 +41,64 @@ let getFtpDirectory (site:string, user:string, pwd:string) =
3841

3942
// getFtpDirectory "ftp://ftp.ncbi.nlm.nih.gov/"
4043

41-
4244
[<TypeProvider>]
4345
type FtpProviderImpl(config : TypeProviderConfig) as this =
4446
inherit TypeProviderForNamespaces ()
4547
let nameSpace = "FSharp.Management"
4648
let asm = Assembly.GetExecutingAssembly()
4749

4850
// Recursive, on-demand adding of types
49-
let createTypes (typeName, site, user, pwd) =
51+
let createTypes (typeName, site, user, pwd:string) =
5052
let rec addTypes (site:string, td:ProvidedTypeDefinition) =
51-
53+
5254
td.AddMembersDelayed(fun () ->
55+
// TODO.6
56+
if diag then printfn "debug: getting site: %s, user: %s, pwd: %s" site user (String.replicate (pwd.Length) "#")
5357
let files, dirs = getFtpDirectory (site, user, pwd)
5458

55-
[ for dir in dirs do
56-
let nestedType = ProvidedTypeDefinition(dir, Some typeof<obj>)
57-
addTypes(site + dir + "/", nestedType)
58-
yield nestedType :> MemberInfo
59-
60-
for file in files do
61-
//let nestedType = ProvidedTypeDefinition(file, Some typeof<obj>)
62-
let myProp = ProvidedLiteralField("Contents", typeof<string>, site + file)
63-
(*
64-
GetterCode = (fun args ->
65-
<@@ let request = WebRequest.Create(site + file) :?> FtpWebRequest
66-
request.Method <- WebRequestMethods.Ftp.DownloadFile
67-
request.Credentials <- new NetworkCredential ("anonymous","[email protected]");
68-
let response = request.GetResponse() :?> FtpWebResponse
69-
use responseStream = response.GetResponseStream()
70-
use reader = new StreamReader(responseStream)
71-
reader.ReadToEnd() @@>))
72-
*)
73-
//nestedType.AddMember myProp
74-
yield myProp :> MemberInfo ] )
59+
[
60+
if diag then printfn "- debug: list dirs and files"
61+
for dir in dirs do
62+
let nestedType = ProvidedTypeDefinition(dir, Some typeof<obj>)
63+
addTypes(site + dir + "/", nestedType)
64+
yield nestedType :> MemberInfo
65+
66+
for file in files do
67+
68+
// BUG.1
69+
70+
let nestedType = ProvidedTypeDefinition(file, Some typeof<obj>)
71+
72+
let contentsProperty =
73+
ProvidedProperty("Contents", typeof<obj>,
74+
GetterCode =
75+
(fun args ->
76+
<@@
77+
if diag then printfn "debug: getting %s%s" site file
78+
let request = WebRequest.Create(site + file) :?> FtpWebRequest
79+
80+
if diag then printf " - debug: 1)getting"
81+
request.Method <- WebRequestMethods.Ftp.DownloadFile
82+
request.Credentials <- new NetworkCredential(user, pwd)
83+
let response = request.GetResponse() :?> FtpWebResponse // TODO.2
84+
85+
if diag then printf ",2)streaming"
86+
use responseStream = response.GetResponseStream()
87+
use reader = new StreamReader(responseStream)
88+
89+
if diag then printf ",3)reading"
90+
let r = reader.ReadToEnd() :> obj
91+
if diag then printfn ",4)returning info"
92+
r
93+
94+
// TODO.3
95+
96+
@@>))
97+
nestedType.AddMember contentsProperty
98+
99+
yield nestedType :> MemberInfo
100+
]
101+
)
75102
let actualType = ProvidedTypeDefinition(asm, nameSpace, typeName, Some typeof<obj>)
76103
addTypes(site, actualType)
77104
actualType
@@ -80,7 +107,7 @@ type FtpProviderImpl(config : TypeProviderConfig) as this =
80107
let topType = ProvidedTypeDefinition(asm, nameSpace, "FtpProvider", Some typeof<obj>)
81108
let siteParam =
82109
let p = ProvidedStaticParameter("Url",typeof<string>)
83-
p.AddXmlDoc("The URL of the FTP site, including ftp://")
110+
p.AddXmlDoc(sprintf "The URL of the FTP site, including ftp://")
84111
p
85112
let userParam =
86113
let p = ProvidedStaticParameter("User",typeof<string>, "anonymous")
@@ -93,10 +120,34 @@ type FtpProviderImpl(config : TypeProviderConfig) as this =
93120
let staticParams = [ siteParam; userParam; pwdParam ]
94121
topType.DefineStaticParameters(staticParams, (fun typeName args ->
95122
let site = args.[0] :?> string
96-
let user = args.[1] :?> string
97-
let pwd = args.[2] :?> string
123+
let user = args.[1] :?> string |> fun s -> if String.IsNullOrEmpty(s) then "anonymous" else s // TODO.1
124+
let pwd = args.[2] :?> string |> fun s -> if String.IsNullOrEmpty(s) then "[email protected]" else s
98125
createTypes(typeName, site, user, pwd)))
99126
this.AddNamespace(nameSpace, [topType])
100127

101128
[<assembly:TypeProviderAssembly>]
102-
do ()
129+
do ()
130+
131+
// TODO
132+
// ----
133+
134+
// TODO.1: pick up FTP courtesy details from environment variables?
135+
// TODO.2: add progress updates via intellisense? ie. | | and |**** underneath for a text based left to right gauge
136+
// TODO.3: return `notfound or exception on error
137+
// TODO.4: consider having a verbose and diagnostic modes to std out? ie. consider actually keeping them after testing is complete
138+
// TODO.5: allow this to be set through type provider instantiation param <>
139+
// TODO.6: add diag info to intellisense to cover command line + also IDE support (ie. so that it's transparent irrespective of usage style)
140+
141+
// BUG
142+
// ---
143+
// BUG.1: file identifiers are never defined. Is this because of an error in the quotation? Why?
144+
145+
// DONE
146+
// ----
147+
148+
// FIXED
149+
// -----
150+
151+
// NOTES
152+
// -----
153+
// NB. possibly the original example Don translated to F# live? https://msdn.microsoft.com/en-us/library/ms229711%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

FtpProvider/ide.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@REM it's better to load .fsx files in a different process, because when you are in a compile->test->compile loop, it's easier to kill off any references
2+
@REM the VS IDE might make on your behalf just by having the .fsx file open. Saves you getting caught out asking intermittantly, 'why isn't it copying after compiling okay?'
3+
devenv test.fsx

FtpProvider/test.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@fsc will compile and run test.fsx (ie. emulate fsi / VS Intellisense "interpreting" the dotted-into sub phrases)
2+
@This way there are no side effects for the VS IDE. It's a cleaner way to test, because the process will die after being run and release any .dll file locks it may have so that you can compile again afterwards.
3+
fsc.exe test.fsx

FtpProvider/test.fsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
type F = FSharp.Management.FtpProvider<"ftp://ftp.ncbi.nlm.nih.gov/">
44

5-
F.genomes.Drosophila_melanogaster.``RELEASE_4.1``.CHR_2.``NT_033778.faa``.Contests
5+
F.genomes.Drosophila_melanogaster.``RELEASE_4.1``.CHR_2.``NT_033778.faa`` // see: FtpProvider.fs -> BUG.1
6+
7+
// F.genomes.Drosophila_melanogaster.``RELEASE_4.1``.CHR_2.``NT_033778.faa``.Contents // ie. we're not getting to the .Contents
68

79
// F.genomes.Buceros_rhinoceros_silvestris.RNA.``Gnomon.mRNA.fsa.gz``

0 commit comments

Comments
 (0)