Silverlight Try F# API Reference

The following sections describe the public API elements exposed by the Microsoft.TryFSharp.ConsoleControl and Microsoft.TryFSharp.App classes. The properties and methods of these classes enable you to manipulate the console control from your F# script and to use JavaScript to access the functionality of the control from your web pages. All properties and methods listed here may be used from your F# scripts. Only those marked as [ScriptableMember] may be accessed via JavaScript from your web pages. For more information, see Building Rich User Interfaces in Tutorials.

Microsoft.TryFSharp.ConsoleControl

Microsoft.TryFSharp.ConsoleControl defines a composite control to interact with F# Interactive in Silverlight. It is comprised of a script editing window, a textual output window, a graphical windows and a toolbar. The control embeds an instance of F# Interactive (FSI), supplying it F# code from the editing text box and capturing output from FSI into the lower output text box.

Public Properties

public Canvas Canvas

Summary

Gets a handle to the canvas instance defined in the main pane of the control.

Remarks

For more information, see Canvas in the API for Silverlight documentation on MSDN.

public CanvasPosition CanvasPosition

Summary

Gets or sets the position of the canvas window.

Remarks

The CanvasPosition type is an enumeration. Use one of the following values to set the position of the canvas.

  • CanvasPosition.Alone - Canvas is the only visible component in the control's main pane.
  • CanvasPosition.Right - Canvas is visible and positioned to the right in the control's main pane.
  • CanvasPosition.Hidden - Canvas is not visible.

public bool IsDirty

Summary

Gets a value indicating whether the content of the script window has changed since it was last saved or loaded.

Remarks

This property is set internally when you place content into the script window by setting the Script property or by calling one of the loader methods. The Script property sets IsDirty to true; the loader methods (LoadFromFile, LoadFromString and LoadFromUrl) set IsDirty to false.

public int LinesToEcho

Summary

Gets or sets the maximum number of lines that are echoed to the output window when a script is sent to F# Interactive for execution.

Remarks

Set this property to zero or less to turn off echoing. The default value is 10.

public string Output

Summary

Gets the content of the output window.

[ScriptableMember]

public string Script

Summary

Gets or sets the content of the script window.

Remarks

Assign this property to load text into the script window of the console control, replacing any existing text. This property does not validate the assigned string in any way.

You can also load text into the script window by calling the LoadFromFile, LoadFromString and LoadFromUrl methods. Calling any of these methods sets IsDirty to false while setting the content of the script window via this property sets IsDirty to true.

Public Methods

[ScriptableMember]

public void Cancel()

Summary

Sends F# Interactive a request to cancel the current computation.

Remarks

With a complex F# program, the F# interactive compiler (FSI) may require a long amount of time to complete the evaluation and run the program. Call this method to interrupt FSI.

[ScriptableMember]

public void ClearCanvas()

Summary

Clears the current content of the canvas window.

Remarks

Call this method to programmatically clear the content of the canvas window. A user can also clear the canvas window by right-clicking on the control, and selecting Clear Canvas.

[ScriptableMember]

public void ClearOutput()

Summary

Clears the current content of the output window.

Remarks

Call this method to programmatically clear the content of the output window. A user can also clear the output window by right-clicking on the control, and selecting Clear Output.

[ScriptableMember]

public void Excecute(string code)

Summary

Sends the specified code to the F# Interactive compiler (FSI) for execution.

Parameters

code

Type: System.String

The code to send to FSI for evaulation and execution.

Remarks

This method sends the specified code to the F# Interactive compiler (FSI) for execution. Results appear in the output window.

[ScriptableMember]

public void LoadFromFile()

Summary

Loads the content of a script file into the script window, replacing any existing text.

Remarks

This method displays a dialog box that enables the user to select a file to load.

You can also load text into the script window by assigning the Script property. When you assign the Script property, the IsDirty property is set to true; when you call this method, IsDirty is set to false.

[ScriptableMember]

public void LoadFromString(string script)

Summary

Loads the specified code in the script window.

Parameters

script

Type: System.String

The text of the script to load.

Remarks

This method loads the specified string into the script window of the console control, replacing any existing text. This method does not validate the string in any way.

You can also load text into the script window by assigning the Script property. When you assign the Script property, the IsDirty property is set to true; when you call this method, IsDirty is set to false.

[ScriptableMember]

public void LoadFromUrl(string url)

Summary

Asynchronously fetches a script file at the specified URL and loads its content in the script window.

Parameters

url

Type: System.String

The URL of the script to load.

Remarks

This method asynchronously loads the content at the specified URL into the script window of the console control, replacing any existing text. If url represents an absolute (rather than a relative) URL, this method displays a dialog box that enables the user to confirm or cancel the request.

When passing a relative URL, this method uses the base address of the web client to calculate the final URL that it uses. In Silverlight, the base address of the web client is the path and file name of the Silverlight control. Your relative URL must adjust accordingly.

For example, if the Silverlight control resides in /ClientBin/TryFSharp.xap and the file that you want to load with this method resides in /Example1.txt, pass the string "../../Example1.txt" to this method. One parent directory specifier (..) is needed to escape the file name of the Silverlight control, and the second is needed to escape the directory name.

You can also load text into the script window by assigning the Script property. When you assign the Script property, the IsDirty property is set to true; when you call this method, IsDirty is set to false.

[ScriptableMember]

public void Reset()

Summary

Resets F# Interactive.

Remarks

Call this method to reset F# Interactive (FSI) to its default state. When you call this method, FSI begins a new session; all previously defined symbols are no longer available.

[ScriptableMember]

public void Save()

Summary

Saves the content of the script window to a file.

Remarks

This method displays a dialog box that enables the user to select the destination file.

Microsoft.TryFSharp.App

Microsoft.TryFSharp.App represents the Try F# Silverlight application. It provides static methods to marshal operations from the F# Interactive thread to the UI thread and a static property to obtain a reference to the application's ConsoleControl object.

Public Fields

public const string ScriptableObjectName = "FsiConsole"

Summary

Name used to register the F# interactive console control with the containing HTML page.

Public Properties

public static ConsoleControl Console

Summary

Gets the instance of the F# console associated with this application.

Public Methods

public static DispatcherOperation Dispatch(Action a)

Summary

Executes the specified delegate asynchronously on the thread the Dispatcher is associated with.

Parameters

a

Type: System.Action

A delegate to a method that takes no arguments and does not return a value, which is pushed onto the Dispatcher event queue.

Returns

An object, which is returned immediately after this method is called, that represents the operation that has been posted to the Dispatcher queue.

Remarks

For more information, see Dispatcher and DispatcherOperation in the API for Silverlight documentation on MSDN.

public static DispatcherOperation Dispatch(Delegate d, params object[] args)

Summary

Executes the specified delegate asynchronously with the specified array of arguments on the thread the Dispatcher is associated with.

Parameters

d

Type: System.Delegate

A delegate to a method that takes multiple arguments, which is pushed onto the Dispatcher event queue.

args

Type: object[]

An array of objects to pass as arguments to the specified method.

Returns

An object, which is returned immediately after this method is called, that represents the operation that has been posted to the Dispatcher queue.

Remarks

For more information, see Dispatcher and DispatcherOperation in the API for Silverlight documentation on MSDN.

Facebook Twitter
Microsoft Research ©2011 Microsoft Corporation. All rights reserved.      Contact Us | About Microsoft Research | Privacy | Terms of Use