This is a little rewrite of GUI.

Antonio

#light

open System

open System.Windows.Forms

open System.Xml

open System.Reflection

open System.IO

open System.Text

// Ref to schemabase

let schemaPropertyName = "XmlContent"

let btsSchemas file =

if (not (string.IsNullOrEmpty(file))) then

let btsAssembly = Assembly.LoadFile(file)

let types = btsAssembly.GetTypes()

let schemabaseType = typeof<SchemaBase>

let btsSchemaTypes = types |> Array.filter (fun x -> schemabaseType.IsAssignableFrom(x))

btsSchemaTypes

else

[||]

let tbDllFile = new TextBox()

let btnBrowse = new Button(Text="Browse...")

let btnExtract = new Button(Text="Extract")

let label1 = new Label(Text="Assembly")

let progressBar1 = new ProgressBar(Minimum=0,Step=0,Value=0)

let openFileDialog1 = new OpenFileDialog(Title="Select an assembly",CheckFileExists=true,Filter="Assemblies (*.exe; *.dll)|*.exe;*.dll|All files|*.*")

let form = new Form(Text="Extract Biz schemas")

btnBrowse.Click.Add(fun _ ->

if (DialogResult.OK = openFileDialog1.ShowDialog()) then

tbDllFile.Text <- openFileDialog1.FileName

)

btnExtract.Click.Add(fun e ->

let justTheFileName = tbDllFile.Text

if File.Exists(justTheFileName) then

let temp = btsSchemas justTheFileName

if temp.Length > 0 then

progressBar1.Maximum <- temp.Length

temp |> Array.iter (fun typ ->

let instance = Activator.CreateInstance(typ) :?> SchemaBase

let xsd = instance.XmlContent

let curAssm = Assembly.GetExecutingAssembly()

let curDir = Path.GetDirectoryName(curAssm.Location)

let fullFileName = Path.Combine(curDir, typ.Name + ".xsd")

progressBar1.Increment(1)

using(new StreamWriter(fullFileName, false, Encoding.Unicode)) (fun sw -> sw.Write(xsd))

)

form.Dispose()

else

MessageBox.Show(justTheFileName + " does not contain BizTalk schemas") |> ignore

else

MessageBox.Show(justTheFileName + " file does not exist") |> ignore

)

let p = new FlowLayoutPanel()

p.Controls.Add(label1)

p.Controls.Add(tbDllFile)

p.Controls.Add(btnBrowse)

p.Controls.Add(btnExtract)

p.Dock <- DockStyle.Fill

form.Controls.Add(p)

Application.Run(form)

By on 11/8/2007 2:54 AM ()

Hi Antonio,

When writing GUI apps I find it easier to create the UI part using a C# project and then just rewrite this into F# syntax i.e. I would have a "Form1" class containing all the controls as members. Is this advisable?

By on 11/9/2007 1:01 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper