Friday, January 28, 2011

Post III – Access with Silverlight & Windows Workflow 4.0

First, I would like to personally thank everyone who has downloaded the CodePlex source code. These posts are forging new ground with Access and .NET. Your interest provides motivation to continue unlocking .NET features into Access.
This new post is focused on some code re-design, exploring Windows Workflow 4.0, showing basic HTML editing with embedded Silverlight and showing WPF in a Task Pane. I’ll find some time to provide more specific code details. For now, the source code contains:
·         How to use Windows Workflow 4.0 in Access. We have a simple example, but more complex WF4 workflows could be used within Access
·         Added EventConverterAttribute to convert ondataavailable HTML DOM event to more specific event such as XmlBridgeChanged event
·         Added XmlBridge() method that returns a schema derived from an ADO.NET DataSet. We considered using a Data Contract, but a DataSet XML Schema is easier to generate and is more in tune with Access. Future versions will use the DataSet schema to send/receive XML messages to/from Silverlight and Access.
·         Added a WPF Task Pane to show how to use WPF with Access
·         Modified Database Form Reflector to support more efficient Access object get and release. Note that the pattern used in Form.Reference.cs files always releases the Access process. See http://msdn.microsoft.com/en-us/library/aa902693(office.12).aspx that discusses this issue.
·         Added a simple SharePoint Client Object Model example.
·         Added a few HTML editor examples that use HTML contentEditable = true
·         Added Silverlight Treeview popup to Sample. Click popup link to show/hide Silverlight Treeview
·         Added more code documentation

Workflow

·         Added an example of how to use Windows Workflow 4.0 in Access. The example executes a custom CodeActivity that implements ITaskActivity. Each CodeActivity gets data from a different data source. Note that this is an example only. Not a very fancy sample, but shows the basic principles.


Access Addin

void WorkflowCommand_Click()
{
    
Cursor.Current = Cursors.WaitCursor;
      String fullFilePath = @"ExampleWorkflow.xaml";

      Activity wf = (Activity)ActivityXamlServices.Load(fullFilePath);

      try
      {

              IDictionary<String, Object> output = WorkflowInvoker.Invoke(
                     wf, new Dictionary<String, Object>
                    {
                        {"ArgTeamCode",  Convert.ToInt32(Tasks.ItemText.Value)},
                    });
       
Tasks.HtmlDocument.getElementById("popup").innerText = output["OriginatedCount"].ToString();
      }
      catch (InvalidOperationException exception)
      {
              MessageBox.Show(exception.Message.ToString());
      }
      finally
      {
              Cursor.Current = Cursors.Default;
      }
}

Example CodeActivity

public sealed class Activity1 : CodeActivity, ITaskActivity
    {
      public InArgument<Int32> TeamCode { get; set; }
      public OutArgument<Int32> CategoryCount { get; set; }
      public OutArgument<Int32> WaitingCount { get; set; }

      protected override void Execute(CodeActivityContext context)
      {
              NorthwindDataSetTableAdapters.CategoriesTableAdapter categories =
              new NorthwindDataSetTableAdapters.CategoriesTableAdapter();

CategoryCount.Set(context, Convert.ToInt32(categories.CategoryCount(TeamCode.Get(context)));

              WaitingCount.Set(context, 10);
      }
    }

interface ItaskActivity
{
       InArgument<Int32> TeamCode { get; set; }
       OutArgument<Int32> OriginatedCount{get; set;}
       OutArgument<Int32> WaitingCount{get; set;}

}

Silverlight

·         MyDocumentPanel changed to WebWidget
·         Added EventConverterAttribute to convert ondataavailable HTML DOM event to more specific event such as XmlBridgeChanged event.

Example:
[EventConverter(“XmlBridgeChanged”)]
Tasks.TreeviewPage.onXmlBridgeChanged += new EventHandler<AsyncEventArgs>(TreeviewPage_onXmlBridgeChanged);
·         Added XmlBridge() method that returns a schema derived from an ADO.NET DataSet. Considered using a Data Contract, but a DataSet XML Schema is easier to generate. Future versions will use the DataSet schema to send/receive XML messages to/from Silverlight and Access.

[ondataavailable, EventConverter("onXmlBridgeChanged")]
public void XmlBridge()
{
          HtmlElement xmlBridge = HtmlPage.Document.GetElementById("xmlBridge");
          if (xmlBridge != null)
          {
              xmlBridge.SetProperty("innerHtml", Resource.XmlSchema.ToString());            

htmlBridge.ondataavailable(new HtmlBridge.AsyncEventArgs("XmlBridge", "TreeviewPage", "XmlBridgeChanged"));
          }
}    

WPF Task Pane

·         Added a WPF Task Pane to show how to use WPF with Access

 Database Form Reflector

·         Modified to support more efficient Access object get and release. Note that the pattern used in Form.Reference always releases the Access process. See http://msdn.microsoft.com/en-us/library/aa902693(office.12).aspx that discusses this issue.

SharePoint

·         Added a simple SharePoint Client Object Model example.

Access Addin

void SharePointCommand_Click()
{

      Cursor.Current = Cursors.WaitCursor;

      ClientContext clientContext = new ClientContext("http://localhost");
      Web site = clientContext.Web;
      clientContext.Load(site);
      clientContext.ExecuteQuery();
      Cursor.Current = Cursors.Default;
      MessageBox.Show(site.Title);
}

Web Browser Control

·         Added a few HTML editor examples that use HTML contentEditable = true

Access Addin

void ItalicCommand_Click()
{
      Tasks.HtmlDocument.execCommand("Italic");
}

void BoldCommand_Click()
{
      Tasks.HtmlDocument.execCommand("Bold");
}

void Heading1Command_Click()
{
      Tasks.HtmlDocument.execCommand("Heading1");
}

Thursday, January 27, 2011

Post III source code is coming in a few days

The source code:
·         How to use Windows Workflow 4.0 in Access. We have a simple example, but more complex WF4 workflows could be used within Access
·         Added EventConverterAttribute to convert ondataavailable HTML DOM event to more specific event such as XmlBridgeChanged event
·         Added XmlBridge() method that returns a schema derived from an ADO.NET DataSet. We considered using a Data Contract, but a DataSet XML Schema is easier to generate and is more in tune with Access. Future versions will use the DataSet schema to send/receive XML messages to/from Silverlight and Access.
·         Added a WPF Task Pane to show how to use WPF with Access
·         Modified Database Form Reflector to support more efficient Access object get and release. Note that the pattern used in Form.Reference.cs files always releases the Access process. See http://msdn.microsoft.com/en-us/library/aa902693(office.12).aspx that discusses this issue.
·         Added a simple SharePoint Client Object Model example.
·         Added a few HTML editor examples that use HTML contentEditable = true
·         Added Silverlight Treeview popup to Sample. Click popup link to show/hide Silverlight Treeview
·         Added more code documentation