/* All user scripts should derive from the base "Application" class */ require ("Application"); /* Get the Gamma library functions and methods for ODBC and/or * Windows programming. Uncomment either or both. */ //require ("WindowsSupport"); //require ("ODBCSupport"); /* Applications share the execution thread and the global name * space, so we create a class that contains all of the functions * and variables for the application. This does two things: * 1) creates a private name space for the application, and * 2) allows you to re-load the application to create either * a new unique instance or multiple instances without * damaging an existing running instance. */ class CSVTagRead Application { //The name and location of the file to read (User-dependent value, change to meet application as needed) filename = "C:\\Program Files\\Cogent\\Cogent DataHub\\scripts\\CSVTagWrite.csv"; //this tag is our File Pointer once the file is opened fp; } /* Use methods to create functions outside the 'main line'. */ method CSVTagRead.fileread () { //opens the file to the first line and checks to see that the .csv is not empty if ((fp = open(.filename, "r", nil)) != nil); { //holds the current location within file local line; //conrtols the number of lines read (for loop) local count = 0; //holds the entire contents of one line in the .csv local lineArray; //hold the .csv values local Domain; local TagName; local TagValue; //loop through each line of the file while((line = read_line(fp)) != _eof_) { //if we are at the beginning of the file we want to skip //of the header and read the second line. if(count == 0) { line = read_line(fp); count++; } //split the comma separated line we read in and place it //into an array lineArray = list_to_array(string_split(line, ",", 0)); //store the Domain Domain = lineArray[0]; //store the TagName TagName = lineArray[1]; //store the TagValue TagValue = lineArray[2]; //.AddRecord(Domain, TagName, TagValue); datahub_write(string(Domain, ":", TagName), TagValue); } //once we have read the entire file we need to close the file. close(fp); } } /* Write the 'main line' of the program here. */ method CSVTagRead.constructor () { .fileread(); //initiates the fileread method } /* Any code to be run when the program gets shut down. */ method CSVTagRead.destructor () { } /* Start the program by instantiating the class. If your * constructor code does not create a persistent reference to * the instance (self), then it will be destroyed by the * garbage collector soon after creation. If you do not want * this to happen, assign the instance to a global variable, or * create a static data member in your class to which you assign * 'self' during the construction process. ApplicationSingleton() * does this for you automatically. */ ApplicationSingleton (CSVTagRead);