Monthly Archives: July 2011 - Page 3

F# Console Application Template

Carl Nolan has posted another great online template:

 

If you are like me and often use console applications for a variety of purposes you would have found the F# template not much use (in fact a blank code file). As such I decided to put together a more complete Project Template that I could use.

The template can be found on the Visual Studio Gallery:

http://visualstudiogallery.msdn.microsoft.com/031891a9-06c3-47db-9c7d-8c9d4a32546a

When the template is installed you get the following template added to your F# folder when creating a new F# project:

image

The Project Template creates a Windows Console Application with the following components:

  • Program.fs: The application entry point defined
  • Arguments.fs: A simple command line parser placing all arguments into a dictionary
  • MyConsole.fs: A separate module for the custom console application code

The application entry point is quite simple:

module Program =  

     [<EntryPoint>]
     let Main(args) =

         MyConsole.Run args

         // main entry point return
         0

The custom console application handles the argument parsing, in addition to providing a TODO for the custom code:

module MyConsole =
        
     let Run args =

         // Define what arguments are expected
         let defs = [
             {ArgInfo.Command="a1"; Description="Argument 1"; Required=true };
             {ArgInfo.Command="a2"; Description="Argument 2"; Required=false } ]

         // Parse Arguments into a Dictionary
         let parsedArgs = Arguments.ParseArgs args defs
        
         // TODO add your code here
         Arguments.DisplayArgs parsedArgs
         Console.ReadLine() |> ignore

If one does not wish to use the argument parsing module the ArgInfo list can be removed. This list provides a simple means for ensuring that the start-up arguments are as expected. The returned parsed parameters is merely a Dictionary of the found arguments.

If one so desires one could map this over to the argument parsing provided in the FSharp PowerPack.

For completeness here is the argument parsing code:

module Arguments =

     // Type for simple argument checking
     type ArgInfo = { Command:string; Description:string; Required:bool }

     // Displays the help arguments
     let DisplayHelp (defs:ArgInfo list) =
         match defs with
         | [] -> Console.WriteLine “No help text defined.”
         | _ ->
             Console.WriteLine “Command Arguments:”
             defs
             |> List.iter (fun def ->
                 let helpText = sprintf “-%s (Required=%b) : %s” def.Command def.Required def.Description
                 Console.WriteLine helpText )

     // Displays the found arguments
     let DisplayArgs (args:Dictionary<string, string>) =
         match args.Keys.Count with
         | 0 -> Console.WriteLine “No arguments found.”
         | _ ->
             Console.WriteLine “Arguments Found:”
             for arg in args.Keys do
                 if String.IsNullOrEmpty(args.[arg]) then
                     Console.WriteLine (sprintf “-%s” arg)
                 else
                     Console.WriteLine (sprintf “-%s ‘%s’” arg args.[arg])

     // Parse the input arguments
     let ParseArgs (args:string array) (defs:ArgInfo list) =

         let parsedArgs = new Dictionary<string, string>()

         // Ensure help is supported if defintions provided
         let fullDefs =
             if not (List.exists (fun def -> String.Equals(def.Command, “help”)) defs) then
                 {ArgInfo.Command=“help”; Description=“Display Help Text”; Required=false } :: defs
             else
                 defs

         // Report errors
         let reportError errorText =       
             DisplayArgs parsedArgs
             DisplayHelp fullDefs
             let errMessage = sprintf “Error occured: %A” errorText
             Console.Error.WriteLine errMessage
             Console.Error.Flush()
             Environment.Exit(1)

         // Capture variables
         let captureArg command value =
             match defs with
             | [] -> parsedArgs.Add(command, value)
             | _ ->               
                 if not (List.exists (fun def -> String.Equals(def.Command, command)) fullDefs) then
                     reportError (sprintf “Command ‘%s’ Not in definition list.” command)
                 else
                     parsedArgs.Add(command, value)           

         let (|IsCommand|_|) (command:string) =           
             let m = Regex.Match(command, “^(?:-{1,2}|\/)(?<command>.*)$”, RegexOptions.IgnoreCase)
             if m.Success then Some(m.Groups.["command"].Value.ToLower()) else None

         let rec loop (argList:string list) =
             match argList with
             | [] -> ()
             | head::tail ->
                 match head with
                 | IsCommand command ->
                     match tail with
                     | [] -> captureArg command String.Empty
                     | iHead::iTail ->
                         match iHead with
                         | IsCommand iCommand ->
                             captureArg command String.Empty
                             loop tail
                         | _ ->
                             captureArg command iHead
                             loop iTail
                 | _ -> reportError (sprintf “Expected a command but got ‘%s’” head)
         loop (Array.toList args)
        
         // Look to see if help has been requested if not check for required
         if (parsedArgs.ContainsKey(“help”)) then
             DisplayHelp defs
         else
             defs
             |> List.filter (fun def -> def.Required)
             |> List.iter ( fun def ->
                 if not (parsedArgs.ContainsKey(def.Command)) then
                     reportError (sprintf “Command ‘%s’ found but in argument list.” def.Command))
                  
         parsedArgs

As always, hopefully you will find this template useful.

Written by Carl Nolan

F# Console Application Template

Carl Nolan has posted another great online template:

 

If you are like me and often use console applications for a variety of purposes you would have found the F# template not much use (in fact a blank code file). As such I decided to put together a more complete Project Template that I could use.

The template can be found on the Visual Studio Gallery:

http://visualstudiogallery.msdn.microsoft.com/031891a9-06c3-47db-9c7d-8c9d4a32546a

When the template is installed you get the following template added to your F# folder when creating a new F# project:

image

The Project Template creates a Windows Console Application with the following components:

  • Program.fs: The application entry point defined
  • Arguments.fs: A simple command line parser placing all arguments into a dictionary
  • MyConsole.fs: A separate module for the custom console application code

The application entry point is quite simple:

module Program =  

     [<EntryPoint>]
     let Main(args) =

         MyConsole.Run args

         // main entry point return
         0

The custom console application handles the argument parsing, in addition to providing a TODO for the custom code:

module MyConsole =
        
     let Run args =

         // Define what arguments are expected
         let defs = [
             {ArgInfo.Command="a1"; Description="Argument 1"; Required=true };
             {ArgInfo.Command="a2"; Description="Argument 2"; Required=false } ]

         // Parse Arguments into a Dictionary
         let parsedArgs = Arguments.ParseArgs args defs
        
         // TODO add your code here
         Arguments.DisplayArgs parsedArgs
         Console.ReadLine() |> ignore

If one does not wish to use the argument parsing module the ArgInfo list can be removed. This list provides a simple means for ensuring that the start-up arguments are as expected. The returned parsed parameters is merely a Dictionary of the found arguments.

If one so desires one could map this over to the argument parsing provided in the FSharp PowerPack.

For completeness here is the argument parsing code:

module Arguments =

     // Type for simple argument checking
     type ArgInfo = { Command:string; Description:string; Required:bool }

     // Displays the help arguments
     let DisplayHelp (defs:ArgInfo list) =
         match defs with
         | [] -> Console.WriteLine “No help text defined.”
         | _ ->
             Console.WriteLine “Command Arguments:”
             defs
             |> List.iter (fun def ->
                 let helpText = sprintf “-%s (Required=%b) : %s” def.Command def.Required def.Description
                 Console.WriteLine helpText )

     // Displays the found arguments
     let DisplayArgs (args:Dictionary<string, string>) =
         match args.Keys.Count with
         | 0 -> Console.WriteLine “No arguments found.”
         | _ ->
             Console.WriteLine “Arguments Found:”
             for arg in args.Keys do
                 if String.IsNullOrEmpty(args.[arg]) then
                     Console.WriteLine (sprintf “-%s” arg)
                 else
                     Console.WriteLine (sprintf “-%s ‘%s’” arg args.[arg])

     // Parse the input arguments
     let ParseArgs (args:string array) (defs:ArgInfo list) =

         let parsedArgs = new Dictionary<string, string>()

         // Ensure help is supported if defintions provided
         let fullDefs =
             if not (List.exists (fun def -> String.Equals(def.Command, “help”)) defs) then
                 {ArgInfo.Command=“help”; Description=“Display Help Text”; Required=false } :: defs
             else
                 defs

         // Report errors
         let reportError errorText =       
             DisplayArgs parsedArgs
             DisplayHelp fullDefs
             let errMessage = sprintf “Error occured: %A” errorText
             Console.Error.WriteLine errMessage
             Console.Error.Flush()
             Environment.Exit(1)

         // Capture variables
         let captureArg command value =
             match defs with
             | [] -> parsedArgs.Add(command, value)
             | _ ->               
                 if not (List.exists (fun def -> String.Equals(def.Command, command)) fullDefs) then
                     reportError (sprintf “Command ‘%s’ Not in definition list.” command)
                 else
                     parsedArgs.Add(command, value)           

         let (|IsCommand|_|) (command:string) =           
             let m = Regex.Match(command, “^(?:-{1,2}|\/)(?<command>.*)$”, RegexOptions.IgnoreCase)
             if m.Success then Some(m.Groups.["command"].Value.ToLower()) else None

         let rec loop (argList:string list) =
             match argList with
             | [] -> ()
             | head::tail ->
                 match head with
                 | IsCommand command ->
                     match tail with
                     | [] -> captureArg command String.Empty
                     | iHead::iTail ->
                         match iHead with
                         | IsCommand iCommand ->
                             captureArg command String.Empty
                             loop tail
                         | _ ->
                             captureArg command iHead
                             loop iTail
                 | _ -> reportError (sprintf “Expected a command but got ‘%s’” head)
         loop (Array.toList args)
        
         // Look to see if help has been requested if not check for required
         if (parsedArgs.ContainsKey(“help”)) then
             DisplayHelp defs
         else
             defs
             |> List.filter (fun def -> def.Required)
             |> List.iter ( fun def ->
                 if not (parsedArgs.ContainsKey(def.Command)) then
                     reportError (sprintf “Command ‘%s’ found but in argument list.” def.Command))
                  
         parsedArgs

As always, hopefully you will find this template useful.

Written by Carl Nolan

F# Console Application Template

Carl Nolan has posted another great online template:

 

If you are like me and often use console applications for a variety of purposes you would have found the F# template not much use (in fact a blank code file). As such I decided to put together a more complete Project Template that I could use.

The template can be found on the Visual Studio Gallery:

http://visualstudiogallery.msdn.microsoft.com/031891a9-06c3-47db-9c7d-8c9d4a32546a

When the template is installed you get the following template added to your F# folder when creating a new F# project:

image

The Project Template creates a Windows Console Application with the following components:

  • Program.fs: The application entry point defined
  • Arguments.fs: A simple command line parser placing all arguments into a dictionary
  • MyConsole.fs: A separate module for the custom console application code

The application entry point is quite simple:

module Program =  

     [<EntryPoint>]
     let Main(args) =

         MyConsole.Run args

         // main entry point return
         0

The custom console application handles the argument parsing, in addition to providing a TODO for the custom code:

module MyConsole =
        
     let Run args =

         // Define what arguments are expected
         let defs = [
             {ArgInfo.Command="a1"; Description="Argument 1"; Required=true };
             {ArgInfo.Command="a2"; Description="Argument 2"; Required=false } ]

         // Parse Arguments into a Dictionary
         let parsedArgs = Arguments.ParseArgs args defs
        
         // TODO add your code here
         Arguments.DisplayArgs parsedArgs
         Console.ReadLine() |> ignore

If one does not wish to use the argument parsing module the ArgInfo list can be removed. This list provides a simple means for ensuring that the start-up arguments are as expected. The returned parsed parameters is merely a Dictionary of the found arguments.

If one so desires one could map this over to the argument parsing provided in the FSharp PowerPack.

For completeness here is the argument parsing code:

module Arguments =

     // Type for simple argument checking
     type ArgInfo = { Command:string; Description:string; Required:bool }

     // Displays the help arguments
     let DisplayHelp (defs:ArgInfo list) =
         match defs with
         | [] -> Console.WriteLine “No help text defined.”
         | _ ->
             Console.WriteLine “Command Arguments:”
             defs
             |> List.iter (fun def ->
                 let helpText = sprintf “-%s (Required=%b) : %s” def.Command def.Required def.Description
                 Console.WriteLine helpText )

     // Displays the found arguments
     let DisplayArgs (args:Dictionary<string, string>) =
         match args.Keys.Count with
         | 0 -> Console.WriteLine “No arguments found.”
         | _ ->
             Console.WriteLine “Arguments Found:”
             for arg in args.Keys do
                 if String.IsNullOrEmpty(args.[arg]) then
                     Console.WriteLine (sprintf “-%s” arg)
                 else
                     Console.WriteLine (sprintf “-%s ‘%s’” arg args.[arg])

     // Parse the input arguments
     let ParseArgs (args:string array) (defs:ArgInfo list) =

         let parsedArgs = new Dictionary<string, string>()

         // Ensure help is supported if defintions provided
         let fullDefs =
             if not (List.exists (fun def -> String.Equals(def.Command, “help”)) defs) then
                 {ArgInfo.Command=“help”; Description=“Display Help Text”; Required=false } :: defs
             else
                 defs

         // Report errors
         let reportError errorText =       
             DisplayArgs parsedArgs
             DisplayHelp fullDefs
             let errMessage = sprintf “Error occured: %A” errorText
             Console.Error.WriteLine errMessage
             Console.Error.Flush()
             Environment.Exit(1)

         // Capture variables
         let captureArg command value =
             match defs with
             | [] -> parsedArgs.Add(command, value)
             | _ ->               
                 if not (List.exists (fun def -> String.Equals(def.Command, command)) fullDefs) then
                     reportError (sprintf “Command ‘%s’ Not in definition list.” command)
                 else
                     parsedArgs.Add(command, value)           

         let (|IsCommand|_|) (command:string) =           
             let m = Regex.Match(command, “^(?:-{1,2}|\/)(?<command>.*)$”, RegexOptions.IgnoreCase)
             if m.Success then Some(m.Groups.["command"].Value.ToLower()) else None

         let rec loop (argList:string list) =
             match argList with
             | [] -> ()
             | head::tail ->
                 match head with
                 | IsCommand command ->
                     match tail with
                     | [] -> captureArg command String.Empty
                     | iHead::iTail ->
                         match iHead with
                         | IsCommand iCommand ->
                             captureArg command String.Empty
                             loop tail
                         | _ ->
                             captureArg command iHead
                             loop iTail
                 | _ -> reportError (sprintf “Expected a command but got ‘%s’” head)
         loop (Array.toList args)
        
         // Look to see if help has been requested if not check for required
         if (parsedArgs.ContainsKey(“help”)) then
             DisplayHelp defs
         else
             defs
             |> List.filter (fun def -> def.Required)
             |> List.iter ( fun def ->
                 if not (parsedArgs.ContainsKey(def.Command)) then
                     reportError (sprintf “Command ‘%s’ found but in argument list.” def.Command))
                  
         parsedArgs

As always, hopefully you will find this template useful.

Written by Carl Nolan

F# Console Application Template

Carl Nolan has posted another great online template:

 

If you are like me and often use console applications for a variety of purposes you would have found the F# template not much use (in fact a blank code file). As such I decided to put together a more complete Project Template that I could use.

The template can be found on the Visual Studio Gallery:

http://visualstudiogallery.msdn.microsoft.com/031891a9-06c3-47db-9c7d-8c9d4a32546a

When the template is installed you get the following template added to your F# folder when creating a new F# project:

image

The Project Template creates a Windows Console Application with the following components:

  • Program.fs: The application entry point defined
  • Arguments.fs: A simple command line parser placing all arguments into a dictionary
  • MyConsole.fs: A separate module for the custom console application code

The application entry point is quite simple:

module Program =  

     [<EntryPoint>]
     let Main(args) =

         MyConsole.Run args

         // main entry point return
         0

The custom console application handles the argument parsing, in addition to providing a TODO for the custom code:

module MyConsole =
        
     let Run args =

         // Define what arguments are expected
         let defs = [
             {ArgInfo.Command="a1"; Description="Argument 1"; Required=true };
             {ArgInfo.Command="a2"; Description="Argument 2"; Required=false } ]

         // Parse Arguments into a Dictionary
         let parsedArgs = Arguments.ParseArgs args defs
        
         // TODO add your code here
         Arguments.DisplayArgs parsedArgs
         Console.ReadLine() |> ignore

If one does not wish to use the argument parsing module the ArgInfo list can be removed. This list provides a simple means for ensuring that the start-up arguments are as expected. The returned parsed parameters is merely a Dictionary of the found arguments.

If one so desires one could map this over to the argument parsing provided in the FSharp PowerPack.

For completeness here is the argument parsing code:

module Arguments =

     // Type for simple argument checking
     type ArgInfo = { Command:string; Description:string; Required:bool }

     // Displays the help arguments
     let DisplayHelp (defs:ArgInfo list) =
         match defs with
         | [] -> Console.WriteLine “No help text defined.”
         | _ ->
             Console.WriteLine “Command Arguments:”
             defs
             |> List.iter (fun def ->
                 let helpText = sprintf “-%s (Required=%b) : %s” def.Command def.Required def.Description
                 Console.WriteLine helpText )

     // Displays the found arguments
     let DisplayArgs (args:Dictionary<string, string>) =
         match args.Keys.Count with
         | 0 -> Console.WriteLine “No arguments found.”
         | _ ->
             Console.WriteLine “Arguments Found:”
             for arg in args.Keys do
                 if String.IsNullOrEmpty(args.[arg]) then
                     Console.WriteLine (sprintf “-%s” arg)
                 else
                     Console.WriteLine (sprintf “-%s ‘%s’” arg args.[arg])

     // Parse the input arguments
     let ParseArgs (args:string array) (defs:ArgInfo list) =

         let parsedArgs = new Dictionary<string, string>()

         // Ensure help is supported if defintions provided
         let fullDefs =
             if not (List.exists (fun def -> String.Equals(def.Command, “help”)) defs) then
                 {ArgInfo.Command=“help”; Description=“Display Help Text”; Required=false } :: defs
             else
                 defs

         // Report errors
         let reportError errorText =       
             DisplayArgs parsedArgs
             DisplayHelp fullDefs
             let errMessage = sprintf “Error occured: %A” errorText
             Console.Error.WriteLine errMessage
             Console.Error.Flush()
             Environment.Exit(1)

         // Capture variables
         let captureArg command value =
             match defs with
             | [] -> parsedArgs.Add(command, value)
             | _ ->               
                 if not (List.exists (fun def -> String.Equals(def.Command, command)) fullDefs) then
                     reportError (sprintf “Command ‘%s’ Not in definition list.” command)
                 else
                     parsedArgs.Add(command, value)           

         let (|IsCommand|_|) (command:string) =           
             let m = Regex.Match(command, “^(?:-{1,2}|\/)(?<command>.*)$”, RegexOptions.IgnoreCase)
             if m.Success then Some(m.Groups.["command"].Value.ToLower()) else None

         let rec loop (argList:string list) =
             match argList with
             | [] -> ()
             | head::tail ->
                 match head with
                 | IsCommand command ->
                     match tail with
                     | [] -> captureArg command String.Empty
                     | iHead::iTail ->
                         match iHead with
                         | IsCommand iCommand ->
                             captureArg command String.Empty
                             loop tail
                         | _ ->
                             captureArg command iHead
                             loop iTail
                 | _ -> reportError (sprintf “Expected a command but got ‘%s’” head)
         loop (Array.toList args)
        
         // Look to see if help has been requested if not check for required
         if (parsedArgs.ContainsKey(“help”)) then
             DisplayHelp defs
         else
             defs
             |> List.filter (fun def -> def.Required)
             |> List.iter ( fun def ->
                 if not (parsedArgs.ContainsKey(def.Command)) then
                     reportError (sprintf “Command ‘%s’ found but in argument list.” def.Command))
                  
         parsedArgs

As always, hopefully you will find this template useful.

Written by Carl Nolan

F# Console Application Template

Carl Nolan has posted another great online template:

 

If you are like me and often use console applications for a variety of purposes you would have found the F# template not much use (in fact a blank code file). As such I decided to put together a more complete Project Template that I could use.

The template can be found on the Visual Studio Gallery:

http://visualstudiogallery.msdn.microsoft.com/031891a9-06c3-47db-9c7d-8c9d4a32546a

When the template is installed you get the following template added to your F# folder when creating a new F# project:

image

The Project Template creates a Windows Console Application with the following components:

  • Program.fs: The application entry point defined
  • Arguments.fs: A simple command line parser placing all arguments into a dictionary
  • MyConsole.fs: A separate module for the custom console application code

The application entry point is quite simple:

module Program =  

     [<EntryPoint>]
     let Main(args) =

         MyConsole.Run args

         // main entry point return
         0

The custom console application handles the argument parsing, in addition to providing a TODO for the custom code:

module MyConsole =
        
     let Run args =

         // Define what arguments are expected
         let defs = [
             {ArgInfo.Command="a1"; Description="Argument 1"; Required=true };
             {ArgInfo.Command="a2"; Description="Argument 2"; Required=false } ]

         // Parse Arguments into a Dictionary
         let parsedArgs = Arguments.ParseArgs args defs
        
         // TODO add your code here
         Arguments.DisplayArgs parsedArgs
         Console.ReadLine() |> ignore

If one does not wish to use the argument parsing module the ArgInfo list can be removed. This list provides a simple means for ensuring that the start-up arguments are as expected. The returned parsed parameters is merely a Dictionary of the found arguments.

If one so desires one could map this over to the argument parsing provided in the FSharp PowerPack.

For completeness here is the argument parsing code:

module Arguments =

     // Type for simple argument checking
     type ArgInfo = { Command:string; Description:string; Required:bool }

     // Displays the help arguments
     let DisplayHelp (defs:ArgInfo list) =
         match defs with
         | [] -> Console.WriteLine “No help text defined.”
         | _ ->
             Console.WriteLine “Command Arguments:”
             defs
             |> List.iter (fun def ->
                 let helpText = sprintf “-%s (Required=%b) : %s” def.Command def.Required def.Description
                 Console.WriteLine helpText )

     // Displays the found arguments
     let DisplayArgs (args:Dictionary<string, string>) =
         match args.Keys.Count with
         | 0 -> Console.WriteLine “No arguments found.”
         | _ ->
             Console.WriteLine “Arguments Found:”
             for arg in args.Keys do
                 if String.IsNullOrEmpty(args.[arg]) then
                     Console.WriteLine (sprintf “-%s” arg)
                 else
                     Console.WriteLine (sprintf “-%s ‘%s’” arg args.[arg])

     // Parse the input arguments
     let ParseArgs (args:string array) (defs:ArgInfo list) =

         let parsedArgs = new Dictionary<string, string>()

         // Ensure help is supported if defintions provided
         let fullDefs =
             if not (List.exists (fun def -> String.Equals(def.Command, “help”)) defs) then
                 {ArgInfo.Command=“help”; Description=“Display Help Text”; Required=false } :: defs
             else
                 defs

         // Report errors
         let reportError errorText =       
             DisplayArgs parsedArgs
             DisplayHelp fullDefs
             let errMessage = sprintf “Error occured: %A” errorText
             Console.Error.WriteLine errMessage
             Console.Error.Flush()
             Environment.Exit(1)

         // Capture variables
         let captureArg command value =
             match defs with
             | [] -> parsedArgs.Add(command, value)
             | _ ->               
                 if not (List.exists (fun def -> String.Equals(def.Command, command)) fullDefs) then
                     reportError (sprintf “Command ‘%s’ Not in definition list.” command)
                 else
                     parsedArgs.Add(command, value)           

         let (|IsCommand|_|) (command:string) =           
             let m = Regex.Match(command, “^(?:-{1,2}|\/)(?<command>.*)$”, RegexOptions.IgnoreCase)
             if m.Success then Some(m.Groups.["command"].Value.ToLower()) else None

         let rec loop (argList:string list) =
             match argList with
             | [] -> ()
             | head::tail ->
                 match head with
                 | IsCommand command ->
                     match tail with
                     | [] -> captureArg command String.Empty
                     | iHead::iTail ->
                         match iHead with
                         | IsCommand iCommand ->
                             captureArg command String.Empty
                             loop tail
                         | _ ->
                             captureArg command iHead
                             loop iTail
                 | _ -> reportError (sprintf “Expected a command but got ‘%s’” head)
         loop (Array.toList args)
        
         // Look to see if help has been requested if not check for required
         if (parsedArgs.ContainsKey(“help”)) then
             DisplayHelp defs
         else
             defs
             |> List.filter (fun def -> def.Required)
             |> List.iter ( fun def ->
                 if not (parsedArgs.ContainsKey(def.Command)) then
                     reportError (sprintf “Command ‘%s’ found but in argument list.” def.Command))
                  
         parsedArgs

As always, hopefully you will find this template useful.

Written by Carl Nolan

WinForms HTML Editor

A few years ago I wrote a WinForms HTML Editor. As I have been working in WinForms again it seemed appropriate to post the code up to a new location:

http://code.msdn.microsoft.com/WinForms-HTML-Editor-01dbce1a

The purpose of the Html Editor is to provide Html Editing capabilities within a WinForms control; satisfying the requirements of input for rich text layouts and simple portal type information. Examples of the former are case where the Rich Text control would normally be utilized; documentation, complex descriptions where text formatting is required, correspondences, bulletins, etc. Examples of the latter case are such items as dashboards; news clips, announcements, company references, etc. These are defined by cases where complex layouts are required that may include images and links.

The control emulates the operations that are available within a Rich Text control, but have information persisted and restored using an Html BODY element.

A sample of it being used within a Form is provided with the code download; as shown here:

image

WinForms HTML Editor

A few years ago I wrote a WinForms HTML Editor. As I have been working in WinForms again it seemed appropriate to post the code up to a new location:

http://code.msdn.microsoft.com/WinForms-HTML-Editor-01dbce1a

The purpose of the Html Editor is to provide Html Editing capabilities within a WinForms control; satisfying the requirements of input for rich text layouts and simple portal type information. Examples of the former are case where the Rich Text control would normally be utilized; documentation, complex descriptions where text formatting is required, correspondences, bulletins, etc. Examples of the latter case are such items as dashboards; news clips, announcements, company references, etc. These are defined by cases where complex layouts are required that may include images and links.

The control emulates the operations that are available within a Rich Text control, but have information persisted and restored using an Html BODY element.

A sample of it being used within a Form is provided with the code download; as shown here:

image

Submitting the Windows Phone application to the Marketplace

The last several weeks have been quite busy at work. However, I finally found the time to publish my application to the market place and it now now live there, with a few downloads reported too! In this post I will walk you through the steps involved in submissions, and share with you my experience.

Registering at the App Hub

Before you can submit an app to the market place, you first need to register for “App Hub” membership. You do this by going to http://create.msdn.com. This essentially is a vibrant community of app and game developers for both Windows Phone and XBOX live games. The hub provides free tools, information, and the community you need to create and publish beautiful apps and games that reach every Windows Phone user and XBOX live members worldwide. Here’s how the home screen looks before you sign up

You first need to register for an annual subscription of USD that gives you the following privileges for both the world of phone apps and XBOX.

image

The registration itself is a 5 step process as noted below and is quite simple. I show some of the screens below as well

imageclip_image002

clip_image002[11]clip_image002[13]

Once signed up, the App Hub home screen now looks like the following. Notice the advertisement for the next version of Windows Phone, code named Mango! I can’t wait to upgrade my phone, and have been waiting to finish this tutorial and getting my application published!. My next app will be on Mango!

Also notice that the action on the App Hub are different now – for example, you get the option of “Submitting for Windows Phone”

image

The App Submission flow

The following diagram captures the flow involved in the app submission process

 

image

We have of course so far been focusing on the first step of the process – creating the application in Visual Studio. I have also been developing using the Emulator. Before submitting the application it is of course also very important to test on an actual device. To do this however you will need to “Unlock” the phone. To do this, connect a phone device to your laptop using the USB (charging) cable, and the run the “Windows Phone Developer Registration” application from the Windows Start menu (this application gets installed on your system when you download the phone development tool kit). The application looks like the following – it takes in your Live ID and then “Unlocks” the phone device so that Visual Studio can deploy the phone application binary directly onto the phone device.

image

In Visual Studio you can select the “Windows Phone 7 Device” as the target for the publishing as shown in the Visual Studio Menu bar below. Now when you build and publish, the application will be deployed on the device and you can do your pre-certification device testing there. The application of course worked well for me there.

image

The Certification Process

The certification process is of course the most important part of the submission. The goal is to ensure that before any application or game is taken into the market place, it is certified that the application is reliable, it makes efficient use of device resources, the do not adversely interfere with the device functionality, and that they are free of any malicious software.

The full certification and submission process is as outlined below.

image

image

The flow through the certification process

The following screen shots show the flow, as I proceeded with each step of the certification process.

image

The submission process starts with the “Upload” step where you select the name of the application, give it a version number, and point to the .XAP file in the bin\release directory where Visual Studio builds the application. Note that the entire application is contained in single binary manifest file of extension XAP. This is shown below.

On hitting next on this screen, the submission process found one error – that my application did not have the locale information marked correctly. At this point I had to add the following lines to the MainPage.xaml.cs to mark the locale as “English”, recompile the application to regenerate the XAP file, test it, and redo the application submission process.

image

The next step is to describe the application by providing information that will later show up in the application market place.image

This information will help potential buyers decide whether they want to try or buy your application or not. Here you choose to describe the category that best describes what the application does, a detailed description, and also key words that will lead an application search to your application. This essentially is your “marketing” collateral for your app.

image

As part of this step, you are also needed to provide various icons and art work that are used in various places in the market place. Here note that the Large Mobile Tile app is really a mandatory image (as I would learn later) though it is not marked as such. This icon is used when you pin your application to the start page. Likewise the “Background Art” image is mandatory too – it will be used when your application shows up in the market place. You can also submit a set of screen shots for the application and these will further describe and “market” your app when listed in the market place. The most convenient place to capture the screenshots of course is when you test your application on the Emulator. You can use the Windows Snipping tool to capture the screen shots – however, be sure to avoid including any of the Emulator “chrome” in the screen shot – this too I found out later.

image

The next step is to select the price for your application, and also decide which market placed the app would be listed in. There are three different geographical regions as you see in the image below. Select carefully and check out the defaults – or your application may not show up in the right marketplaces. (Note, each phone user provides a Live ID when they configure their phone for us. The country the Live ID is associated with then becomes the default market place for the “Marketplace” application on the phone.

image

The next step is to call out a set of testing instructions that will be carried out in the “backend” to make a final validation that the application works as designed. You can also select the publishing option – for example, you can select that the app be published as soon as the validation and certification is done, without any further interventions from you.

image

The last step then is to click the “Submit” button and submit the application.

image

You can track the state of the submission on the “My Dashboard” page at “App Hub”. For example, a couple of days later I noticed that my submission had run into issues.

image

image

As shown above, the certification had run into errors, and clicking on the “View Error” page leads you to a PDF file with details about the errors. The PDF files looked as follows

image

In my case all of the errors were related to the images and iconography. I was missing the large mobile tile app, and the background art image, and the application screenshot included the chrome of the Emulator. Also, it called out that one of the icons in my application was still the generic Windows Sunburst icon. I then proceeded to fix the errors and in the process created my own custom icon and images (using Microsoft Paint, and saving them as .PNG files of the different dimensions necessary, as called out in the submission process).

I also had to select the “United States” market place, as apparently in the last submission I had not selected it.

The submission goes through

This time the submission went through without errors – a couple of days later, it was nice to see on the “Dashboard” that the process had worked, the app was in the Marketplace and it showed there were a few downloads too. The dashboard provides you several reports and statistics of your application.

image

image

image

The App shows up in the Marketplace

It was exciting to then checkout the Marketplace on my phone, search for “AmitC”, and have the app show up – and I could install it from there! To capture an image of the app in the market place, I launched the Zune application and searched for the app there – and there it was!

 

image

It felt great to build, blog, and publish about this simple Windows Phone application. I hope it has spurred some of the readers to write and publish your own application. I really liked the Visual Studio tooling experience and felt proud of my team which has developed this tooling!

On now to the Mango version of Windows Phone!

Cheers!

Submitting the Windows Phone application to the Marketplace

The last several weeks have been quite busy at work. However, I finally found the time to publish my application to the market place and it now now live there, with a few downloads reported too! In this post I will walk you through the steps involved in submissions, and share with you my experience.

Registering at the App Hub

Before you can submit an app to the market place, you first need to register for “App Hub” membership. You do this by going to http://create.msdn.com. This essentially is a vibrant community of app and game developers for both Windows Phone and XBOX live games. The hub provides free tools, information, and the community you need to create and publish beautiful apps and games that reach every Windows Phone user and XBOX live members worldwide. Here’s how the home screen looks before you sign up

You first need to register for an annual subscription of USD that gives you the following privileges for both the world of phone apps and XBOX.

image

The registration itself is a 5 step process as noted below and is quite simple. I show some of the screens below as well

imageclip_image002

clip_image002[11]clip_image002[13]

Once signed up, the App Hub home screen now looks like the following. Notice the advertisement for the next version of Windows Phone, code named Mango! I can’t wait to upgrade my phone, and have been waiting to finish this tutorial and getting my application published!. My next app will be on Mango!

Also notice that the action on the App Hub are different now – for example, you get the option of “Submitting for Windows Phone”

image

The App Submission flow

The following diagram captures the flow involved in the app submission process

 

image

We have of course so far been focusing on the first step of the process – creating the application in Visual Studio. I have also been developing using the Emulator. Before submitting the application it is of course also very important to test on an actual device. To do this however you will need to “Unlock” the phone. To do this, connect a phone device to your laptop using the USB (charging) cable, and the run the “Windows Phone Developer Registration” application from the Windows Start menu (this application gets installed on your system when you download the phone development tool kit). The application looks like the following – it takes in your Live ID and then “Unlocks” the phone device so that Visual Studio can deploy the phone application binary directly onto the phone device.

image

In Visual Studio you can select the “Windows Phone 7 Device” as the target for the publishing as shown in the Visual Studio Menu bar below. Now when you build and publish, the application will be deployed on the device and you can do your pre-certification device testing there. The application of course worked well for me there.

image

The Certification Process

The certification process is of course the most important part of the submission. The goal is to ensure that before any application or game is taken into the market place, it is certified that the application is reliable, it makes efficient use of device resources, the do not adversely interfere with the device functionality, and that they are free of any malicious software.

The full certification and submission process is as outlined below.

image

image

The flow through the certification process

The following screen shots show the flow, as I proceeded with each step of the certification process.

image

The submission process starts with the “Upload” step where you select the name of the application, give it a version number, and point to the .XAP file in the bin\release directory where Visual Studio builds the application. Note that the entire application is contained in single binary manifest file of extension XAP. This is shown below.

On hitting next on this screen, the submission process found one error – that my application did not have the locale information marked correctly. At this point I had to add the following lines to the MainPage.xaml.cs to mark the locale as “English”, recompile the application to regenerate the XAP file, test it, and redo the application submission process.

image

The next step is to describe the application by providing information that will later show up in the application market place.image

This information will help potential buyers decide whether they want to try or buy your application or not. Here you choose to describe the category that best describes what the application does, a detailed description, and also key words that will lead an application search to your application. This essentially is your “marketing” collateral for your app.

image

As part of this step, you are also needed to provide various icons and art work that are used in various places in the market place. Here note that the Large Mobile Tile app is really a mandatory image (as I would learn later) though it is not marked as such. This icon is used when you pin your application to the start page. Likewise the “Background Art” image is mandatory too – it will be used when your application shows up in the market place. You can also submit a set of screen shots for the application and these will further describe and “market” your app when listed in the market place. The most convenient place to capture the screenshots of course is when you test your application on the Emulator. You can use the Windows Snipping tool to capture the screen shots – however, be sure to avoid including any of the Emulator “chrome” in the screen shot – this too I found out later.

image

The next step is to select the price for your application, and also decide which market placed the app would be listed in. There are three different geographical regions as you see in the image below. Select carefully and check out the defaults – or your application may not show up in the right marketplaces. (Note, each phone user provides a Live ID when they configure their phone for us. The country the Live ID is associated with then becomes the default market place for the “Marketplace” application on the phone.

image

The next step is to call out a set of testing instructions that will be carried out in the “backend” to make a final validation that the application works as designed. You can also select the publishing option – for example, you can select that the app be published as soon as the validation and certification is done, without any further interventions from you.

image

The last step then is to click the “Submit” button and submit the application.

image

You can track the state of the submission on the “My Dashboard” page at “App Hub”. For example, a couple of days later I noticed that my submission had run into issues.

image

image

As shown above, the certification had run into errors, and clicking on the “View Error” page leads you to a PDF file with details about the errors. The PDF files looked as follows

image

In my case all of the errors were related to the images and iconography. I was missing the large mobile tile app, and the background art image, and the application screenshot included the chrome of the Emulator. Also, it called out that one of the icons in my application was still the generic Windows Sunburst icon. I then proceeded to fix the errors and in the process created my own custom icon and images (using Microsoft Paint, and saving them as .PNG files of the different dimensions necessary, as called out in the submission process).

I also had to select the “United States” market place, as apparently in the last submission I had not selected it.

The submission goes through

This time the submission went through without errors – a couple of days later, it was nice to see on the “Dashboard” that the process had worked, the app was in the Marketplace and it showed there were a few downloads too. The dashboard provides you several reports and statistics of your application.

image

image

image

The App shows up in the Marketplace

It was exciting to then checkout the Marketplace on my phone, search for “AmitC”, and have the app show up – and I could install it from there! To capture an image of the app in the market place, I launched the Zune application and searched for the app there – and there it was!

 

image

It felt great to build, blog, and publish about this simple Windows Phone application. I hope it has spurred some of the readers to write and publish your own application. I really liked the Visual Studio tooling experience and felt proud of my team which has developed this tooling!

On now to the Mango version of Windows Phone!

Cheers!

C9::GoingNative

C9::GoingNative is a monthly show on Channel 9 focused on native development with an emphasis on C++. Each episode will have a segment including an interview with a native dev in his/her native habitat (office) where we’ll talk about what they do and how they use native code and associated toolchains, as well as get their insights and wisdom—geek out. There will be a small news component or segment, but the show will primarily focus on technical tips and conversations with active C/C++ coders, demonstrations…(read more)