Please enable JavaScript to view this site.

CORE HL7 API

Online Help - Region 1: [CORE HL7 API Basic]

Other CORE HL7 API Help Regions

Download the API Libraries


 

Object: COREFolderAnalyzer

License Required: No. Publicly accessible constructors.

Creation code (C#)  

var cfa = new COREFolderAnalyzer();

//or

var cfa = new COREFolderAnalyzer("<fullpath>", "*.hl7", 10);

 

COREFolderAnalyzer Object

COREFolderAnalyzer Object

 

The COREFolderAnalyzer reads a Directory and presents you with a list of files in that folder. So What? Retrieving a list of files from a Directory in Windows is really a very simple operation in almost every programming language. What we have found over the years is that it's really too simple, and that every process we would create that needed to do this always, always needed additional code, sometimes a little, and sometimes a lot, so we came up with the COREFolderAnalyzer object. This object will look at a folder and give you a snapshot of the files in that folder in a manner that you KNOW you can work with. For instance the folder analyzer will automatically:

 

Ignore Zero Byte files.

Ignore FUTURE DATED files. Yes, this still happens when people don't have their system clocks synched correctly on their network. We get at least 1 call per year from a customer who says "It's not working. My files just sit in the folder and then they randomly disappear!". We tell them to check the files and voila, they have a date time stamp in the future. So we say "That file is a time traveler and won't technically exist for another <xx>minutes."

Ignore files NEWER than a value you configure (the MinimumSecondsOld property set in the constructor). Need to archive log files after they are 1 day old, no problem see the Example Code below.

MOST IMPORTANTLY, it will deliver the files to you sorted by the LastModified date which can be critically important.

 

We use this object extensively in all of our commercial software which require any type of folder polling operations.

 

 

 

 

Public Properties:

 

Property Name

Data Type

ExceptionHandling

Uses the Standard Exceptions Interface

Count

int (read only) - The number of items in FilesList.

CurrentState

ENUM AnalyzerStateEnum (read only) - The current state of the object.

FilesList

SortedList<string, COREFolderFileInfo> - Will return true if the internal HL7FileAnalyzer object is holding (locking) a data file open.

MinimumSecondsOld

double (read only) - Set in either the constructor or the Reset() method. To be included in FilesList a file must have a LastModified date older than DateTime.Now - MinimumSecondsOld

MyPath

string (read only) - The windows path to the folder to be polled. Set either in the constructor or the Reset() method. A trailing backslash ( \ ) will be added automatically if you don't provide one

MySearchPattern

string (read only) - Set in either the constructor or the Reset() method. The Search Pattern to use when polling MyPath. Follows the same rules as System.IO.Directory.GetFiles().

Tag

CORETag object - General purpose Tag object for custom programming code

TotalFolderFilesCount

int (read only) - After each PollFolder() operation this number will be the TOTAL number of files in MyPath that match MySearchPattern.

TotalFolderFilesExcluded

int (read only) - After each PollFolder() operation this number will be the number of files in MyPath that match MySearchPattern that were not added to FilesList.

TotalZeroByteFiles

int (read only) - After each PollFolder() operation this number will be the number of files in MyPath that match MySearchPattern that have zero bytes (this number is part of TotalFolderFilesExcluded)

 

 

 

Public Static Methods:

 

Method

Return Value

TotalSecondsPerHour()

double - The total number of seconds in 1 hour.

TotalSecondsPerDay()

double - The total number of seconds in 24 hours.

TotalSecondsPerWeek()

double - The total number of seconds in 7 days.

TotalSecondsPerYear()

double - The total number of seconds in 365 days.

 

Public Methods:

 

Method

Return Value

ExceptionHandling

Uses the Standard Exceptions Interface

Clear()

void - Clears the object. NOTE: Clear() is always called internally at the start of any analysis operation.

PollFolder()

bool - Returns true if MyPath is successfully polled for MySearchPattern files. Returns false and sets LastException if an error occurs or it is cancelled.

Reset(string path, string pattern, double minimumSecondsOld = 1) Returns bool. Takes the same parameters as the constructor. Calls Clear() and then resets MyPath, MySearchPattern, and MinimumSecondsOld for the next call to PollFolder(). Using this method allows you to reuse the same COREFolderAnalyzer object over and over again to look at different folders with different patterns and file age requirements.

 

Scenario: I need to look at My logs folder and every log file in that folder more than 1 day old I need to add to a ZIP file in the Archives folder for each week where they will be kept for 1 year. Then I need to look at the Archives folder for zip files more than 1 year old and delete them.

 

Example Code (C#):

 

      private void ArchiveAndPurge()

       {

          //I'll create a new analyzer. I COULD pass the

          //parameters in to the constructor but we want to

          //show the Reset() method here.

           COREFolderAnalyzer fa = new COREFolderAnalyzer();

          //First my logs folder. I want files named *.log that are

          //more than 1 day old. I'll call one of the handy Static methods

          double daysOld = COREFolderAnalyzer.TotalSecondsPerDay();

          //When comparing file age the folder analyzer always uses

          //SECONDS (or partial seconds as decimals are allowed)

 

          //Call the Reset Method

          if (fa.Reset("C:\\Log Files", "*.log", daysOld))

           {

               fa.PollFolder();

              for (int i = 0; i < fa.FilesList.Count; i++)

               {

                   COREFolderFileInfo fi = fa.FilesList.Values[i];

                  string fName = fa.MyPath + fi.FileTitle;

                  /*

                    * ...Code to add to zip file in Archives

                    */

               }

           }

          //Now I need to look at the archives folder and delete any zip files in there that

          //are more than 1 year old.

          //I will create a COREUtilities object here

           COREUtilities utils = new COREUtilities();

           daysOld = COREFolderAnalyzer.TotalSecondsPerYear();

 

          if (fa.Reset("C:\\Archived Log Files", "*.zip", daysOld))

           {

               fa.PollFolder();

              for (int i = 0; i < fa.FilesList.Count; i++)

               {

                   COREFolderFileInfo fi = fa.FilesList.Values[i];

                  string fName = fa.MyPath + fi.FileTitle;

                   utils.KillAFile(fName);

               }

           }

          //And I'm done. Call this function every so often like every hour or so

          //and be completely current

       }

 

 

 

Events

 

Event

public event EventHandler<COREFolderAnalysisArgs> Working;

 

NOTE: This event will be fired every SECOND that passes in a PollFolder() operation. This means that you will likely only ever see this event being fired IF you are polling a folder with thousands and thousands of file in it. Programming example can be seen in the example code at the top of this page.

 

See Also: COREFolderAnalysisArgs

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

Keyboard Navigation

F7 for caret browsing
Hold ALT and press letter

This Info: ALT+q
Nav Header: ALT+n
Page Header: ALT+h
Topic Header: ALT+t
Topic Body: ALT+b
Exit Menu/Up: ESC