3 Replies Latest reply: May 15, 2014 10:01 AM by Bill Tilghman RSS

    Holidays. how to

    Bill Tilghman

      Now can I set up a list of holidays and NOT run a project on those days...????

       

       

      Thanks,

        • Holidays. how to
          Bill Watson

          Funnily enough I was working on something similar but not quite the same so here is something to try and see if it works for you. This should definitely work for DP 8 or above. If the date being checked is a holiday or a weekend the process will return "Process Prerequisites Failed" and the process will stop. The only way I can see of stopping a process

          from running is using "return false" in the code (I think this was something that Gareth Horton posted in response to another query).

           

          Of course you could combine the code below with the info I posted on using one process to kick off another url=http://www.monarchforums.com/showpost.php?p=9340&postcount=7here[/url] and this would result in much cleaner logging i.e no error returned as the process wouldn't even run. Just a thought.

           

          Anyway here goes:

           

          Step 1[/B] Create a text file with the dates of holidays for the next year (or so!) (each date on a seperate line (These are UK Bank Holidays):

           

          25/12/2007

          26/12/2007

          01/01/2008

          21/03/2008

          24/03/2008

          05/05/2008

          26/05/2008

          25/08/2008

          25/12/2008

          26/12/2008

          01/01/2009

          10/04/2009

          13/04/2009

          04/05/2009

          25/05/2009

          31/08/2009

          25/12/2009

          28/12/2009

          01/01/2010

          /code

           

          Step 2[/B] In your Datapump Process go to Script > References and Imports[/B] and add System.IO[/B] in the Imports section.

           

          Step 3[/B] In your Pre Process /B tab add the following script:

          Dim dtnow as datetime = Now '<current date/time

          Dim holiday As Boolean = false '<default to not being a holiday

           

          dtNow = DateTime.Parse((dtnow.day).tostring()"/"(dtnow.month).tostring()"/"(dtnow.year).tostring(), Globalization.CultureInfo.CreateSpecificCulture("en-GB"))  '<force date to common format for country)

           

          Log.AddEvent("Today: "+dtnow.tostring())

          'check if weekend, if so do nothing else, if not check for holidays

          If dtnow.DayOfWeek = DayOfWeek.Sunday or dtnow.DayOfWeek = DayOfWeek.Saturday Then

               holiday = true

          else

               Dim objStreamReader as StreamReader   '<prepare to read text file

               objStreamReader = File.OpenText("C:\Data\HolidayList.TXT") '<open text file (change path to yours)

               Dim line as String = objStreamReader.ReadLine() '<get first line

               Log.AddEvent("Checking: "+line)

               Do While Not line is Nothing '<loop through all holiday file lines

                    'if today is in holiday file do nothing else, else keep checking

                    if dtnow = DateTime.Parse(line, Globalization.CultureInfo.CreateSpecificCulture("en-GB")) then

                         holiday = true

                         Log.AddEvent("Date Matched")     

                         exit do

                    else

                         line = objStreamReader.ReadLine()

                         Log.AddEvent("Checking: "+line)

                    end if

               Loop

               objstreamreader.close() '<close text file

          End If

           

           

          if holiday = true then '<if holiday do not run process

               Log.AddEvent("Weekend or Holiday. Process Halting.")

               return false

          else '<if not holiday continue with process

               Log.AddEvent("Not A Weekend or Holiday. Process Continuing.")

               return true

          end if

          /code