Windows Workflow Foundation (WF4) - Workflow Services and Auto-Start

This sample application demonstrates how you can create a Workflow Service that will automatically start and periodically wake up to do some work. The sample also demonstrates a UI that shows the progress of the work and provides control and query capabilities.

C# (249.0 KB)
 
 
 
 
 
4 Star
(6)
4,302 times
Add to favorites
4/28/2011
E-mail Twitter del.icio.us Digg Facebook
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="BatchWeb.Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <!--The next line of code will refresh the page every 5 minutes-->
    <meta http-equiv="refresh" content="20" />
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Create a Batch Job
    </h2>
    <hr />
    <table cellspacing="5">
        <tr>
            <td>
                Count To:
            </td>
            <td>
                <asp:TextBox ID="TextBoxCount" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxCount"
                    ErrorMessage="* Count is required" ForeColor="Red" Display="Dynamic" />
                <asp:CompareValidator ID="ValidateCountIsNumber" ControlToValidate="TextBoxCount"
                    runat="server" Display="Dynamic" ErrorMessage="* Count must be a number" ForeColor="Red"
                    Operator="DataTypeCheck" Type="Integer"></asp:CompareValidator>
            </td>
        </tr>
        <tr>
            <td>
                Delay (Seconds):
            </td>
            <td>
                <asp:TextBox ID="TextBoxDelay" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="DelayRequired" runat="server" ControlToValidate="TextBoxDelay"
                    ErrorMessage="* Delay is required" ForeColor="Red" Display="Dynamic" />
                <asp:CompareValidator ID="DelayIsNumber" ControlToValidate="TextBoxDelay" runat="server"
                    Display="Dynamic" ErrorMessage="* Delay must be a number" ForeColor="Red" Operator="DataTypeCheck"
                    Type="Integer"></asp:CompareValidator>
            </td>
        </tr>
        <tr>
            <td rowspan="2">
                Start At:
            </td>
            <td>
                <asp:CheckBox ID="CheckBoxNow" runat="server" Text="Now" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:TextBox ID="TextBoxStart" runat="server"></asp:TextBox>
                <asp:CompareValidator ControlToValidate="TextBoxStart" Display="Dynamic" ErrorMessage="* Start must be in the future"
                    ForeColor="Red" ID="ValidateStartIsFuture" Operator="GreaterThanEqual" runat="server"
                    Type="Date" />
            </td>
            <td>
                <asp:TextBox ID="TextBoxTime" runat="server"></asp:TextBox><asp:CustomValidator ID="ValidatorStartTime"
                    runat="server" ErrorMessage="* Invalid Start Time" Display="Dynamic" ControlToValidate="TextBoxTime"
                    OnServerVadliate="ValidateStartTime"></asp:CustomValidator>
            </td>
        </tr>
    </table>
    <p>
        <asp:LinkButton ID="LinkButtonSubmit" OnClick="LinkButtonSubmitClick" runat="server">Submit Batch</asp:LinkButton>
        &nbsp;<asp:LinkButton ID="LinkButtonRefresh" runat="server" OnClick="LinkButtonRefreshClick">Refresh</asp:LinkButton>
    </p>
    <asp:Label ID="LabelMsg" runat="server"></asp:Label>
    <hr />
    <h2>Submitted Jobs</h2>
    <p>
        <asp:GridView ID="GridViewJobs" runat="server" CellPadding="4" 
            ForeColor="#333333" GridLines="None" >
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:HyperLinkField DataNavigateUrlFields="JobId" 
                    DataNavigateUrlFormatString="StopJob.aspx?JobId={0}" 
                    DataTextFormatString="Stop" HeaderText="Command" DataTextField="JobId" />
            </Columns>
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#EFF3FB" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F5F7FB" />
            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
            <SortedDescendingCellStyle BackColor="#E9EBEF" />
            <SortedDescendingHeaderStyle BackColor="#4870BE" />
        </asp:GridView>
       </p>
    <h2>
        Active
        Workflow Instances</h2>
        <p>Note: It may take up to a minute for changes to reflect in tracking data</p>
        <hr />
    <asp:GridView ID="GridViewInstances" runat="server" AutoGenerateColumns="False" 
        CellPadding="4" DataSourceID="WFInstancesEntityDataSource" ForeColor="#333333" 
        GridLines="None">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:BoundField DataField="WorkflowInstanceId" HeaderText="Workflow Instance ID" 
                ReadOnly="True" SortExpression="WorkflowInstanceId" />
            <asp:BoundField DataField="LastEventStatus" HeaderText="Last Event Status" 
                ReadOnly="True" SortExpression="LastEventStatus" />
            <asp:BoundField DataField="LastModifiedTime" HeaderText="Last Modified Time" 
                ReadOnly="True" SortExpression="LastModifiedTime" />
            <asp:BoundField DataField="StartTime" HeaderText="Start Time" ReadOnly="True" 
                SortExpression="StartTime" />
            <asp:HyperLinkField DataNavigateUrlFields="WorkflowInstanceId" 
                DataNavigateUrlFormatString="StopJob.aspx?JobId={0}" 
                DataTextField="WorkflowInstanceId" DataTextFormatString="Stop" 
                HeaderText="Control" />
        </Columns>
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>
        <asp:EntityDataSource ID="WFInstancesEntityDataSource" runat="server" 
        ConnectionString="name=AppFabricMonitoringDBEntities" 
        DefaultContainerName="AppFabricMonitoringDBEntities" EnableFlattening="False" 
        EntitySetName="ASWfInstances" 
        
        Select="it.[WorkflowInstanceId], it.[LastEventStatus], it.[LastModifiedTime], it.[StartTime]" 
        OrderBy="it.[StartTime] DESC"
        Where="it.[LastEventStatus]='Started'" EntityTypeFilter="">
    </asp:EntityDataSource>
        <h2>Batch Job Events</h2>

    <asp:ListView ID="ListView1" runat="server" DataSourceID="BatchEntityDataSource">
        <AlternatingItemTemplate>
            <tr style="background-color: #FFF8DC;">
                <td>
                    <asp:Label ID="CustomRecordNameLabel" runat="server" Text='<%# Eval("CustomRecordName") %>' />
                </td>
            </tr>
        </AlternatingItemTemplate>
        <EmptyDataTemplate>
            <table runat="server" style="background-color: #FFFFFF; border-collapse: collapse;
                border-color: #999999; border-style: none; border-width: 1px;">
                <tr>
                    <td>
                        No data was returned.
                    </td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <ItemTemplate>
            <tr style="background-color: #DCDCDC; color: #000000;">
                <td>
                    <asp:Label ID="CustomRecordNameLabel" runat="server" Text='<%# Eval("CustomRecordName") %>' />
                </td>
            </tr>
        </ItemTemplate>
        <LayoutTemplate>
            <table runat="server">
                <tr runat="server">
                    <td runat="server">
                        <table id="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;
                            border-collapse: collapse; border-color: #999999; border-style: none; border-width: 1px;
                            font-family: Verdana, Arial, Helvetica, sans-serif;">
                            <tr runat="server" id="itemPlaceholder">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr runat="server">
                    <td runat="server" style="text-align: center; background-color: #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;
                        color: #000000">
                        <asp:DataPager ID="DataPager1" runat="server">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False"
                                    ShowPreviousPageButton="False" />
                                <asp:NumericPagerField />
                                <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False"
                                    ShowPreviousPageButton="False" />
                            </Fields>
                        </asp:DataPager>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
    </asp:ListView>
    <asp:EntityDataSource ID="BatchEntityDataSource" runat="server" ConnectionString="name=AppFabricMonitoringDBEntities"
        DefaultContainerName="AppFabricMonitoringDBEntities" EnableFlattening="False"
        EntitySetName="ASWfEvents" Select="it.[CustomRecordName], it.[EventType], it.[ActivityName], it.[TimeCreated]"
        OrderBy="it.[TimeCreated] desc" Where="it.[EventType] == 'CustomTrackingRecord'">
    </asp:EntityDataSource>
</asp:Content>