Sunday, September 16, 2012

BIML WmiEventWatcher wait for file to arrive

How to execute a sequence container after a file has arrived, using BIML
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Connections>
        <WmiConnection
            Name="WmiConnection"
            ServerName="\\localhost"
            UseWindowsAuthentication="true"
            Namespace="\root\cimv2" />
    </Connections>
    <Annotations>
        <Annotation>
            File: WmiEventWatcher.WaitForFile.biml
            Demo biml using the WmiEventWatcher to
            wait for a file to arrive before execution
            Enviroment:
            DB: MS-SQL2012
            BIML: 1.6 VS2010 BIDS Helper
            (c) John Minkjan biml101.blogspot.com
        </Annotation>
    </Annotations>
    <Packages>       
        <Package Name="WmiEventWatcher.WaitForFile" ConstraintMode="Linear">
            <Variables>
                <Variable
                    Name="DirectoryToWatch"
                    DataType ="String">C:\\\\FileRecieve</Variable>
                <!--Note the really should be 4 backslashes -->
            </Variables>
            <Tasks>
                <FileSystem
                    Name="FT Create Watch Dir"
                    Operation="CreateDirectory"
                    OverwriteDestination="true">
                        <VariableInput VariableName ="User.DirectoryToWatch"></VariableInput>
                </FileSystem>
                <WmiEventWatcher
                    Name="WMI CheckForNewFile"
                    NumberOfEvents="1"
                    ConnectionName="WmiConnection">
                    <DirectInput>
                        SELECT * FROM __InstanceCreationEvent WITHIN 10
                        WHERE TargetInstance ISA "CIM_DirectoryContainsFile"
                        and TargetInstance.GroupComponent= "Win32_Directory.Name=\"C:\\\\test1\""                                           
                    </DirectInput>
                    <Expressions>
                        <Expression
                            PropertyName="WqlQuerySource">"SELECT * FROM __InstanceCreationEvent
                            WITHIN 10 WHERE TargetInstance ISA \"CIM_DirectoryContainsFile\"
                            and TargetInstance.GroupComponent= \"Win32_Directory.Name=\\\""
                            + @[User::DirectoryToWatch] + "\\\"\""
                        </Expression>
                    </Expressions>
                </WmiEventWatcher>
                <Container
                    Name="SEQ Stuff to do when file has arived"
                    ConstraintMode="Linear">                   
                </Container>
            </Tasks>
        </Package>
    </Packages>
</Biml>
Gives you:
image
Till Next Time

No comments:

Post a Comment