Example #1
0
        // Make Full Pass Through Processing.
        public int Run(int pass = 0, bool logBeat = false)
        {
            int rc = 0;

            // Determine what we are currently processing!
            eventStatus = getDictionaryEntry("ProcessEvents", "Y").Equals("Y");
            commandStatus = getDictionaryEntry("ProcessCommands", "Y").Equals("Y");
            dataStatus = getDictionaryEntry("ProcessData", "Y").Equals("Y");
            maxEventFileSize = Convert.ToInt32(getDictionaryEntry("MaxEventFileSize", "1024000"));

            // Validate Connection.
            if (validateConnection(MasterConnection))
            {
                exCount_XML = 0;
                // Populate activeEvents from XDB.
                switch (pass)
                {
                    // Pass 0:  Parse the XLator Configs.
                    case 0:
                        if (eventStatus)
                        {
                            if ((!bConfigLoaded) | (XTRMObject.getDictionaryEntry("ReloadConfig", "Y").Equals("Y")))
                            {
                                // Get the XLator Event Folder (from the dictionary).
                                //string strPendingEventFolder = XLib.XDB_Objects.XObject.getDictionaryEntry("XLatorPendingEventFolder");
                                // May be a list of config files!
                                //string strPendingEventFolder = myConfigLoader.configFile;
                                myConfigLoaders.Clear();
                                foreach (string thisConfig in myConfigs)
                                {
                                    XTRMRoot thisLoader = new XTRMRoot(ResolveText(thisConfig, XDictionary));
                                    thisLoader.ParseConfig(2, true);
                                    myConfigLoaders.Add(thisLoader);
                                }
                                bConfigLoaded = true;
                            }
                            // Commit.
                        }
                        break;
                    // Pass 2:  Process all active XDB events against each of the loaders.
                    case 2:
                        if (eventStatus)
                        {
                            // Loop through all XDB events
                            // Run query to get active XDB events.
                            rc = LoadActiveEvents();
                            if (rc < 0)
                            {
                                XLogger(1102, -1, string.Format("Run::LoadActiveEvents() Failure; Pass={0}; rc={1}", pass, rc));
                            }
                            XTRMEvent thisEvent = new XTRMEvent(false);
                            // For each event:
                            foreach (int thisEventSerial in activeEvents)
                            {
                                int eventState = 0;
                                //XEvent thisEvent = new XEvent();
                                rc = thisEvent.Initialize(thisEventSerial);
                                // For each loader:
                                if (rc >= 0)
                                {
                                    // XEvent Retrieved Successfully!
                                    foreach (XTRMRoot thisLoader in myConfigLoaders)
                                    {
                                        XTRMMatchMaker myEventChecker = new XTRMMatchMaker();
                                        rc = myEventChecker.ProcessActiveEvent(thisLoader, thisEvent);
                                        if (rc >= 0)
                                        {
                                            eventState += rc;
                                        }
                                        else
                                        {
                                            XLogger(1103, -1, string.Format("Run::XTRMEvent.ProcessActiveEvent() Failure; Pass={0}; UUID={1}; rc={2}", pass, thisEvent.eventUUID, rc));
                                        }
                                    }
                                    thisEvent.eventState = eventState;
                                    rc = thisEvent.Save();
                                    if (rc >= 0)
                                    {
                                        XLogger(1124, eventState, string.Format("Event={0}; {1}", rc, thisEvent.banner), thisEvent.eventUser);
                                    }
                                    else
                                    {
                                        XLogger(1123, -1, string.Format("Unable to Save() Active Event; rc={2}", pass, thisEvent.eventUUID, rc));
                                    }
                                }
                                else
                                {
                                    // Error!
                                    XLogger(1104, -1, string.Format("Run::XEvent.Initialize() Failure; Pass={0}; UUID={1}; rc={2}", pass, thisEvent.eventUUID, rc));
                                }
                                thisEvent.Clear();
                            }
                        }
                        break;
                }
            }
            else
            {
                myLog.WriteEntry("Master XDB Connection Failure");
            }
            return rc;
        }
Example #2
0
        // Overall Flow:
        //
        //  Run through eack XLator config file (loading events).
        //  Query XDB for events whose state is 0 (not processed).
        //  For each XLator config, run each event against the corresponding XLator config rules generating jobs as indicated (use event-tagging on the job).
        //  When generating a job update the Event_Processed time stamp.
        //  After processing all events against each relevant XLator config, then mark event state as 1 (processed).
        //
        // Process Pending Events in XLator/Events Folder.
        public int ProcessPendingEvents(string strPendingEventFolder)
        {
            int rc = 0;
            bool bError = false;
            XTRMEvent eventTester = new XTRMEvent(false);
            // For Each File in the folder, need to consume into XEvent(s).
            //Directory.GetFiles(strPendingEventFolder);
            try
            {
                //Directory.GetFiles(strPendingEventFolder, "*.dll").Select(fn => new FileInfo(fn)).
                //string[] fileEntries = Directory.GetFiles(strPendingEventFolder).Select(fn => new FileInfo(fn)).OrderBy(f => f.CreationTime).ToList();
                string[] fileEntries = Directory.GetFiles(strPendingEventFolder);
                foreach (string fileName in fileEntries)
                {
                    bError = false;
                    try
                    {
                        // Only process file if it is less than 100KB.
                        FileInfo myInfo = new FileInfo(fileName);
                        if (myInfo.Length <= maxEventFileSize)
                        {
                            //ParseConfig(fileName);
                            XTRMRoot myEventLoader = new XTRMRoot(fileName);
                            //myEventLoader.Clear();
                            myEventLoader.ParseConfig(2, true);
                            // This will result in 0 or more XEvents to process.
                            foreach (XTRMEvent thisEvent in myEventLoader.events)
                            {
                                try
                                {
                                    // Check to see if the UUID already exists!
                                    if (eventTester.Initialize(thisEvent.eventUUID) <= 0)
                                    {
                                        // Persist the XEvent to XDB.
                                        rc = thisEvent.Save();
                                        if (rc < 0)
                                        {
                                            bError = true;
                                            XLogger(1105, -1, string.Format("ProcessPendingEvents::XEvent.Save() Failure; Folder={0}; UUID={1}; rc={2}", strPendingEventFolder, thisEvent.eventUUID, rc));
                                        }
                                    }
                                    else
                                    {
                                        XLogger(1128, -1, string.Format("Duplicate Event Skipped; Folder={0}; UUID={1}; File={2}; rc={3}", strPendingEventFolder, thisEvent.eventUUID, thisEvent.eventParm1, rc));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    XLogger(1106, rc, string.Format("Caught Event Loader Exception; Folder={0}; UUID={1}; Message={2}", strPendingEventFolder, thisEvent.eventUUID, ex.Message));
                                }
                            }
                        }
                        else
                        {
                            XLogger(1129, -1, string.Format("Event File Too Large; Folder={0}; File={1}; rc={2}", strPendingEventFolder, fileName, rc));
                        }
                    }
                    catch (Exception ex)
                    {
                        XLogger(1130, -1, string.Format("ParseConfig Exception; Folder={0}; File={1}; rc={2}", strPendingEventFolder, fileName, rc));
                    }
                    // Now Move the File Containing the Event(s) to the OK Folder.
                    try
                    {
                        FileInfo myFileInfo = new FileInfo(fileName);
                        string shortName = myFileInfo.Name;
                        //File.Move();
                        DirectoryInfo myParentDirInfo = Directory.GetParent(strPendingEventFolder);
                        string myParentDir = myParentDirInfo.FullName;
                        // REWORK the following moves.

                        if (bError)
                        {
                            //File.Move();
                            bool bExists = Directory.Exists(myParentDir + "\\Discard\\");
                            if (!bExists)
                            {
                                Directory.CreateDirectory(myParentDir + "\\Discard\\");
                            }
                            File.Move(strPendingEventFolder + "\\" + shortName, myParentDir + "\\Discard\\" + shortName);
                        }
                        else
                        {
                            //File.Move();
                            bool bExists = Directory.Exists(myParentDir + "\\OK\\");
                            if (!bExists)
                            {
                                Directory.CreateDirectory(myParentDir + "\\OK\\");
                            }
                            File.Move(strPendingEventFolder + "\\" + shortName, myParentDir + "\\OK\\" + shortName);
                        }
                        // Whether can move or not, must delete!
                        File.Delete(strPendingEventFolder + "\\" + shortName);
                    }
                    catch (Exception ex)
                    {
                        XLogger(1107, -1, string.Format("ProcessPendingEvents::Move Files Exception; Folder={0}; Message={1}", strPendingEventFolder, ex.Message));
                    }
                }
            }
            catch (Exception ex)
            {
                XLogger(1108, -1, string.Format("ProcessPendingEvents::Get Files Exception; Folder={0}; Message={1}", strPendingEventFolder, ex.Message));
            }
            return rc;
        }
Example #3
0
        public static new XTRMObject consumeXML(Dictionary<String, String> existingConfig, string XmlFragment, int lVariant = 0, bool bDeep = false)
        {
            //XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
            //myDictionaryLoader.Augment();
            //
            // Consume XML to create the XComponent object.
            // if bDeep is false, then ONLY do this object.
            // if bDeep is true, then also do recursive objects.
            XmlTextReader reader = null;
            XmlParserContext context = null;
            Dictionary<String, String> myConfig = new Dictionary<string, string>(existingConfig);
            XTRMEvent thisEvent = null;
            if (lVariant == 1)
            {
                thisEvent = new XTRMEvent();
                thisEvent.Initialize(-1);
            }
            else
            {
                thisEvent = new XTRMEvent();
            }
            thisEvent.variant = lVariant;

            try
            {
                // Load the reader with the data file and ignore all white space nodes.
                context = new XmlParserContext(null, null, null, XmlSpace.None);
                reader = new XmlTextReader(XmlFragment, XmlNodeType.Element, context);
                reader.WhitespaceHandling = WhitespaceHandling.None;
                // Parse the file and display each of the nodes.
                bool bResult = reader.Read();
                string outerXML;
                int lElementType = 0;
                XDictionaryLoader myDictionaryLoader = new XDictionaryLoader();
                Dictionary<String, String> elementAttributes;
                while (bResult)
                {
                    bool bProcessed = false;
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            string elementName = reader.Name;
                            switch (elementName.ToUpper())
                            {
                                case "THENJOB": // XTRMJob
                                    outerXML = reader.ReadOuterXml();
                                    XTRMJob thisJob = (XTRMJob)XTRMJob.consumeXML(myConfig, outerXML, 0, true);
                                    thisEvent.eventJobs.Add(thisJob);
                                    bProcessed = true;
                                    break;
                                case "BASECONFIG":
                                    outerXML = reader.ReadOuterXml();
                                    myDictionaryLoader = new XDictionaryLoader();
                                    myConfig = new Dictionary<string, string>();
                                    myDictionaryLoader.Augment(myConfig, outerXML);
                                    bProcessed = true;
                                    break;
                                //   Add to the current dictionary!
                                // XConfig
                                case "WITHCONFIG":
                                    outerXML = reader.ReadOuterXml();
                                    //myDictionaryLoader = new XDictionaryLoader();
                                    myDictionaryLoader.Augment(myConfig, outerXML);
                                    bProcessed = true;
                                    break;
                            }
                            if (!bProcessed)
                            {
                                // May wish to get all the attributes here for new elements!
                                elementAttributes = new Dictionary<String, String>();
                                if (reader.HasAttributes)
                                {
                                    reader.MoveToFirstAttribute();
                                    for (int i = 0; i < reader.AttributeCount; i++)
                                    {
                                        //reader.GetAttribute(i);
                                        elementAttributes.Add(reader.Name, reader.Value);
                                        reader.MoveToNextAttribute();
                                    }
                                    // Check to see if ID is supplied!
                                    //if (elementAttributes["ID"] != null)
                                    if (elementAttributes.ContainsKey("Serial"))
                                    {
                                        // Try to instantiate the XTRMEvent Object!
                                        int myEventID = Convert.ToInt32(elementAttributes["Serial"]);
                                        thisEvent.Initialize(myEventID);
                                    }
                                    if (elementAttributes.ContainsKey("Action"))
                                    {
                                        thisEvent.eventAction = elementAttributes["Action"];
                                    }
                                    if (elementAttributes.ContainsKey("Source"))
                                    {
                                        thisEvent.eventSource = elementAttributes["Source"];
                                    }
                                    reader.MoveToElement();
                                }
                                // Need to see if we are interested in this element!
                                //string elementName = reader.Name;
                                switch (elementName.ToUpper())
                                {
                                    case "SERIAL": // Serial
                                        lElementType = 1;
                                        bResult = reader.Read();
                                        break;
                                    case "SOURCE": // Source
                                        lElementType = 2;
                                        bResult = reader.Read();
                                        break;
                                    case "ACTION": // Action
                                        lElementType = 3;
                                        bResult = reader.Read();
                                        break;
                                    //case "NORMALPATH": // NormalPath
                                    //    lElementType = 4;
                                    //    bResult = reader.Read();
                                    //    break;
                                    case "SUFFIX": // Suffix
                                        lElementType = 5;
                                        bResult = reader.Read();
                                        break;
                                    case "REGEX": // Regex
                                        lElementType = 6;
                                        bResult = reader.Read();
                                        break;
                                    case "UUID": // UUID
                                        lElementType = 7;
                                        bResult = reader.Read();
                                        break;
                                    case "NORMALPATH": // Parm1
                                    case "NORMALNAME":
                                    case "PRISMFULLNAME":
                                    case "P4FULLNAME":
                                    case "PARM1":
                                        lElementType = 8;
                                        bResult = reader.Read();
                                        break;
                                    case "PRISMPATH":
                                    case "P4VERSION":  // P4Version
                                    case "PARM2": // Parm2
                                        lElementType = 9;
                                        bResult = reader.Read();
                                        break;
                                    case "PRISMNAME":
                                    case "P4CHANGELIST":
                                    case "PARM3": // Parm3
                                        lElementType = 10;
                                        bResult = reader.Read();
                                        break;
                                    case "PRISMVERSION":
                                    case "P4TYPE":
                                    case "PARM4": // Parm4
                                        lElementType = 11;
                                        bResult = reader.Read();
                                        break;
                                    case "PRISMBRANCH":
                                    case "P4SIZE":
                                    case "PARM5": // Parm5
                                        lElementType = 12;
                                        bResult = reader.Read();
                                        break;
                                    case "P4CLIENT":
                                    case "PRISMLOCALNAME":
                                    case "PARM6": // Parm6
                                        lElementType = 13;
                                        bResult = reader.Read();
                                        break;
                                    case "PRISMTIME":
                                    case "P4TIME":
                                    case "PARM7": // Parm7
                                        lElementType = 14;
                                        bResult = reader.Read();
                                        break;
                                    case "PARM8": // Parm8
                                        lElementType = 15;
                                        bResult = reader.Read();
                                        break;
                                    case "PARM9": // Parm9
                                        lElementType = 16;
                                        bResult = reader.Read();
                                        break;
                                    case "PARM10": // Parm10
                                        lElementType = 17;
                                        bResult = reader.Read();
                                        break;
                                    case "USER": // User
                                        lElementType = 18;
                                        bResult = reader.Read();
                                        break;
                                    case "PIN": // PIN
                                        lElementType = 19;
                                        bResult = reader.Read();
                                        break;
                                    case "TAG": // Tag
                                        lElementType = 20;
                                        bResult = reader.Read();
                                        break;
                                    case "DATESTAMP": // Date
                                        lElementType = 21;
                                        bResult = reader.Read();
                                        break;
                                    case "EVENTDATE": // Date (new format that imports directly).
                                        lElementType = 22;
                                        bResult = reader.Read();
                                        break;
                                    case "STATUS": // Date (new format that imports directly).
                                        lElementType = 23;
                                        bResult = reader.Read();
                                        break;
                                    case "PATH": // Date (new format that imports directly).
                                        lElementType = 24;
                                        bResult = reader.Read();
                                        break;
                                    case "DESC": // Date (new format that imports directly).
                                        lElementType = 25;
                                        bResult = reader.Read();
                                        break;
                                    //case "THENJOB": // XTRMJob
                                    //    outerXML = reader.ReadOuterXml();
                                    //    XTRMJob thisJob = (XTRMJob)XTRMJob.consumeXML(myConfig, outerXML, 0, true);
                                    //    thisEvent.eventJobs.Add(thisJob);
                                    //    break;
                                    // Reset Dictionary!
                                    // XConfig
                                    //case "BASECONFIG":
                                    //    outerXML = reader.ReadOuterXml();
                                    //    myDictionaryLoader = new XDictionaryLoader();
                                    //    myConfig = new Dictionary<string, string>();
                                    //    myDictionaryLoader.Augment(myConfig, outerXML);
                                    //    break;
                                    //   Add to the current dictionary!
                                    // XConfig
                                    //case "WITHCONFIG":
                                    //    outerXML = reader.ReadOuterXml();
                                    //    //myDictionaryLoader = new XDictionaryLoader();
                                    //    myDictionaryLoader.Augment(myConfig, outerXML);
                                    //    break;
                                    default:
                                        bResult = reader.Read();
                                        break;
                                }
                            }
                            break;
                        case XmlNodeType.XmlDeclaration:
                        case XmlNodeType.ProcessingInstruction:
                            //writer.WriteProcessingInstruction(reader.Name, reader.Value);
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.Comment:
                            //writer.WriteComment(reader.Value);
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.EndElement:
                            //writer.WriteFullEndElement();
                            bResult = reader.Read();
                            break;
                        case XmlNodeType.Text:
                            //Console.Write(reader.Value);
                            switch (lElementType)
                            {
                                case 1:     // Serial
                                    thisEvent.eventSerial = Convert.ToInt16(reader.Value);
                                    break;
                                case 2:     // Source
                                    thisEvent.eventSource = reader.Value;
                                    break;
                                case 3:     // Action
                                    thisEvent.eventAction = reader.Value;
                                    break;
                                case 4:     // NormalPath
                                    thisEvent.normalPath.Add(reader.Value);
                                    break;
                                case 5:     // Suffix
                                    thisEvent.suffix.Add(reader.Value);
                                    break;
                                case 6:     // Regex
                                    thisEvent.regex.Add(reader.Value);
                                    break;
                                case 7:     // eventUUID
                                    thisEvent.eventUUID = reader.Value;
                                    break;
                                case 8:     // eventParm1
                                    thisEvent.eventParm1 = reader.Value;
                                    thisEvent.normalPath.Add(reader.Value);
                                    break;
                                case 9:     // eventParm2
                                    thisEvent.eventParm2 = reader.Value;
                                    break;
                                case 10:     // eventParm3
                                    thisEvent.eventParm3 = reader.Value;
                                    break;
                                case 11:     // eventParm4
                                    thisEvent.eventParm4 = reader.Value;
                                    break;
                                case 12:     // eventParm5
                                    thisEvent.eventParm5 = reader.Value;
                                    break;
                                case 13:     // eventParm6
                                    thisEvent.eventParm6 = reader.Value;
                                    break;
                                case 14:     // eventParm7
                                    thisEvent.eventParm7 = reader.Value;
                                    break;
                                case 15:     // eventParm8
                                    thisEvent.eventParm8 = reader.Value;
                                    break;
                                case 16:     // eventParm9
                                    thisEvent.eventParm9 = reader.Value;
                                    break;
                                case 17:     // eventParm10
                                    thisEvent.eventParm10 = reader.Value;
                                    break;
                                case 18:     // eventUser
                                    thisEvent.eventUser = reader.Value;
                                    break;
                                case 19:     // eventPIN
                                    thisEvent.eventPIN = reader.Value;
                                    break;
                                case 20:     // eventTag
                                    thisEvent.eventTag = reader.Value;
                                    break;
                                case 21:     // eventDate
                                    string inputDate = reader.Value;
                                    int year, month, day, hour, min, sec;
                                    DateTime dateStamp;
                                    // If contains "/", then use method 2!
                                    if (inputDate.Contains("/"))
                                    {
                                        //year = Convert.ToInt16(inputDate.Substring(6, 4));
                                        //month = Convert.ToInt16(inputDate.Substring(0, 2));
                                        //day = Convert.ToInt16(inputDate.Substring(3, 2));
                                        //hour = Convert.ToInt16(inputDate.Substring(11, 2));
                                        //min = Convert.ToInt16(inputDate.Substring(14, 2));
                                        //sec = Convert.ToInt16(inputDate.Substring(17, 2));
                                        dateStamp = DateTime.Parse(inputDate, System.Globalization.CultureInfo.InvariantCulture);

                                    }
                                    else
                                    {
                                        year = Convert.ToInt16(inputDate.Substring(0, 4));
                                        month = Convert.ToInt16(inputDate.Substring(4, 2));
                                        day = Convert.ToInt16(inputDate.Substring(6, 2));
                                        hour = Convert.ToInt16(inputDate.Substring(9, 2));
                                        min = Convert.ToInt16(inputDate.Substring(12, 2));
                                        sec = Convert.ToInt16(inputDate.Substring(15, 2));
                                        dateStamp = new DateTime(year, month, day, hour, min, sec);
                                    }
                                    //inputDate = "6/7/2012 06:00:00";
                                    //thisEvent.eventDate = dateStamp.ToString();
                                    //thisEvent.eventDate = inputDate;
                                    break;
                                case 22:     // eventDate (mm/dd/yyyy hh24:mi:ss)
                                    thisEvent.eventDate = reader.Value;
                                    break;
                                case 23:     // Status
                                    //thisEvent. = reader.Value;
                                    break;
                                case 24:     // Path
                                    //thisEvent = reader.Value;
                                    break;
                                case 25:     // Description
                                    //thisEvent.eventDate = reader.Value;
                                    break;
                                case 26:     // eventHost
                                    thisEvent.eventHost = reader.Value;
                                    break;
                                default:
                                    break;
                            }
                            lElementType = 0;
                            bResult = reader.Read();
                            break;
                        default:
                            bResult = reader.Read();
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                exCount_XML++;
                XLogger(2210, -1, string.Format("XML={0}; Message={1}", XmlFragment, ex.Message));
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
            thisEvent.config = myConfig;
            return thisEvent;
        }
Example #4
0
        public int ProcessEvents()
        {
            int rc = 0;
            string tempstr = "";
            try
            {
                _pool.WaitOne();
                // Process Everything in XFileList
                XFileAction thisAction;
                while (ChangesQueue.TryDequeue(out thisAction))
                //foreach (XFileAction thisAction in XFileList)
                {
                    XTRMFSEntity thisEntity = findEntity(thisAction);
                    XTRMEvent thisEvent = new XTRMEvent();
                    thisEvent.Initialize(-1);
                    //  <XEvent ID="626">
                    //		<Source>P4V</Source>
                    //		<Action>edit</Action>
                    //		<DateStamp>20120103 19:23:03</DateStamp>
                    //		<User>shlori</User>
                    //		<PIN>A342158B864EE75025C6F08F42C9544A</PIN>
                    //		<Status>0</Status>
                    //		<Path>//depot/main/product/doc/Portable/English/*</Path>
                    //		<Desc>Fixed page/line breaks.</Desc>
                    //		<!-- Parm1 = {Depot File} -->
                    //		<Parm1>//depot/main/product/doc/Portable/English/Basic Analysis and Graphing.pdf</Parm1>
                    //		<!-- Parm2 = {Depot Version} -->
                    //		<Parm2>56</Parm2>
                    //		<!-- Parm3 = {Change List} -->
                    //		<Parm3>83234</Parm3>
                    //		<!-- Parm4 = {File Type} -->
                    //		<Parm4>binary+lm</Parm4>
                    //		<!-- Parm5 = {File Size} -->
                    //		<Parm5>4216714</Parm5>
                    //		<!-- Parm6 = {Client} -->
                    //		<Parm6>shlori-Win</Parm6>
                    //		<!-- Parm7 = {SCM Time} -->
                    //		<Parm7>1325636582</Parm7>
                    //	</XEvent>
                    thisEvent.eventAction = thisAction.ChangeType.ToString();
                    thisEvent.eventDate = DateTime.Now.ToString();
                    thisEvent.eventState = -1;
                    thisEvent.eventParm1 = thisAction.FullPath;
                    string thisEventPath = "";
                    if (thisEntity == null)
                    {
                        // Use Defaults.
                        thisEvent.eventTag = agentTag;
                        thisEvent.eventSource = agentSource;
                        thisEvent.eventUser = agentUser;
                        //thisEventPath = agentEventPath;
                        thisEvent.meta.eventPath = agentEventPath;
                        thisEvent.meta.holdTime = 0;
                    }
                    else
                    {
                        // Use this entity, then defaults.
                        if (thisEntity.entityTag.Equals(""))
                        {
                            thisEvent.eventTag = agentTag;
                        }
                        else
                        {
                            thisEvent.eventTag = thisEntity.entityTag;
                        }
                        if (thisEntity.entitySource.Equals(""))
                        {
                            thisEvent.eventSource = agentSource;
                        }
                        else
                        {
                            thisEvent.eventSource = thisEntity.entitySource;
                        }
                        if (thisEntity.entityUser.Equals(""))
                        {
                            thisEvent.eventUser = agentUser;
                        }
                        else
                        {
                            thisEvent.eventUser = thisEntity.entityUser;
                        }
                        if (thisEntity.entityTag.Equals(""))
                        {
                            thisEvent.eventTag = agentTag;
                        }
                        else
                        {
                            thisEvent.eventTag = thisEntity.entityTag;
                        }
                        if (thisEntity.entityEventPath.Equals(""))
                        {
                            //thisEventPath = agentEventPath;
                            thisEvent.meta.eventPath = agentEventPath;
                        }
                        else
                        {
                            //thisEventPath = thisEntity.entityEventPath;
                            thisEvent.meta.eventPath = thisEntity.entityEventPath;
                        }
                        if (thisEntity.entityHoldTime.Equals(""))
                        {
                            thisEvent.meta.holdTime = 0;
                        }
                        else
                        {
                            thisEvent.meta.holdTime = thisEntity.entityHoldTime;
                        }
                    }

                    //thisEvent.eventDate = DateTime.Now.ToString();
                    thisEvent.eventDate = thisAction.actionTime.ToString();

                    // Add Event to Dictionaries (by time and by path::action).
                    thisEvent.eventPath = thisEventPath;
                    string eventKey = string.Format("{0}::{1}", thisEvent.eventParm1, thisEvent.eventAction);
                    // Are we holding this event already?
                    if (eventOrder.ContainsKey(eventKey).Equals(false))
                    {
                        //eventInventory.Add(eventKey);
                        //eventOrder.Add(DateTime.Now, thisEvent);
                        eventOrder.Add(eventKey, thisEvent);
                    }
                }
                //XFileList.Clear();
            }
            catch (Exception ex)
            {
                tempstr = string.Format("FileSystemWatcher Exception : {0}", ex.Message);
                myLog.WriteEntry(tempstr);
            }
            finally
            {
                _pool.Release();
            }
            return rc;
        }
Example #5
0
        public int Traverse(string candidatePath, string filePattern, string WorkspacePrefix, string DepotPrefix)
        {
            int rc = -1;

            try
            {
                XLogger(51002, 0, string.Format("Execute XTroll.exe"));

                myConfigs = XTRMObject.getDictionaryEntries("XTRMRootConfigFile");
                myConfigLoaders.Clear();
                foreach (string thisConfig in myConfigs)
                {
                    XTRMRoot thisLoader = new XTRMRoot(ResolveText(thisConfig, XDictionary));
                    thisLoader.ParseConfig(2, true);
                    myConfigLoaders.Add(thisLoader);
                }
                var fileEntries = Directory.EnumerateFiles(candidatePath, filePattern, SearchOption.AllDirectories);
                foreach (string sourceFile in fileEntries)
                {
                    string thisFile = sourceFile.Replace(WorkspacePrefix, DepotPrefix);
                    thisFile = thisFile.Replace(@"\", @"/");
                    //if (stopFlag.Equals(1))
                    //{
                    //    throw new Exception("EggTimer Expired!");
                    //}
                    // Try to Validate the Component and Element.
                    // If Element is valid, then skip (only looking for new elements).
                    // Fabricate Event Object for Element.
                    // Instantiate and Call Monitor to Identify Jobs.
                    //XMonitorCore myMonitor = new XMonitorCore();
                    XTRMMatchMaker myEventChecker = new XTRMMatchMaker();
                    // XTRMEvent Retrieved Successfully!
                    XTRMEvent thisEvent = new XTRMEvent();
                    thisEvent.Initialize(-1);
                    //  <XTRMEvent ID="626">
                    //		<Source>P4V</Source>
                    //		<Action>edit</Action>
                    //		<DateStamp>20120103 19:23:03</DateStamp>
                    //		<User>shlori</User>
                    //		<PIN>A342158B864EE75025C6F08F42C9544A</PIN>
                    //		<Status>0</Status>
                    //		<Path>//depot/main/product/doc/Portable/English/*</Path>
                    //		<Desc>Fixed page/line breaks.</Desc>
                    //		<!-- Parm1 = {Depot File} -->
                    //		<Parm1>//depot/main/product/doc/Portable/English/Basic Analysis and Graphing.pdf</Parm1>
                    //		<!-- Parm2 = {Depot Version} -->
                    //		<Parm2>56</Parm2>
                    //		<!-- Parm3 = {Change List} -->
                    //		<Parm3>83234</Parm3>
                    //		<!-- Parm4 = {File Type} -->
                    //		<Parm4>binary+lm</Parm4>
                    //		<!-- Parm5 = {File Size} -->
                    //		<Parm5>4216714</Parm5>
                    //		<!-- Parm6 = {Client} -->
                    //		<Parm6>shlori-Win</Parm6>
                    //		<!-- Parm7 = {SCM Time} -->
                    //		<Parm7>1325636582</Parm7>
                    //	</XTRMEvent>
                    thisEvent.eventAction = "edit";
                    thisEvent.eventDate = DateTime.Now.ToString();
                    thisEvent.eventSource = "P4V";
                    thisEvent.eventUser = "******";
                    thisEvent.eventState = -1;
                    thisEvent.eventParm1 = thisFile;
                    int eventState = 0;
                    bool eventFlag = false;
                    foreach (XTRMRoot thisLoader in myConfigLoaders)
                    {
                        //rc = myMonitor.EvaluateEvent(thisLoader, thisEvent);
                        List<XTRMJob> theseJobs = new List<XTRMJob>();
                        rc = myEventChecker.FindXMatch(thisLoader, thisEvent, out theseJobs);
                        if (rc > 0)
                        {
                            if (theseJobs.Count > 0)
                            {
                                foreach (XTRMJob thisJob in theseJobs)
                                {
                                    Dictionary<string, string> jobData = new Dictionary<string, string>();
                                    try
                                    {
                                        foreach (KeyValuePair<string, string> kvp in thisJob.config)
                                        {
                                            //saveJobData(jobSerial, kvp.Key.ToString().ToUpper(), kvp.Value);
                                            jobData[kvp.Key.ToString().ToUpper()] = kvp.Value;
                                        }
                                        foreach (KeyValuePair<string, string> kvp in myEventChecker.dynConfig)
                                        {
                                            //saveJobData(jobSerial, kvp.Key.ToString().ToUpper(), kvp.Value);
                                            jobData[kvp.Key.ToString().ToUpper()] = kvp.Value;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        XLogger(1157, -1, string.Format("Saving Job Data; Message={0}", ex.Message));
                                    }
                                    try
                                    {
                                        if (validateInventory())
                                        {
                                            eventFlag = true;
                                        }
                                    }
                                    catch(Exception)
                                    {
                                        eventFlag = false;
                                    }
                                }
                            }
                        }
                        if (rc >= 0)
                        {
                            eventState += rc;
                        }
                        else
                        {
                            XLogger(1103, -1, string.Format("Execute::XTRMEvent.EvaluateEvent() Failure; UUID={1}; rc={2}", thisEvent.eventUUID, rc));
                        }
                    }
                    // If no jobs, then skip.
                    if (eventFlag)
                    {
                        // Creating the event will result in the Monitor processing against the production Config Loaders.
                        rc = thisEvent.Save();
                        if (rc < 0)
                        {
                            // Error!
                        }
                    }
                    // Otherwise, try to Validate the Component and Element Again.
                    // If Element is valid, then skip (only looking for new elements).
                    // Call Monitor to Create Jobs.
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                XLogger(51003, -1, string.Format("XTroll Exception in Execute(); Message={0}.", ex.Message));
            }
            return rc;
        }
Example #6
0
        // Check EventTag (now does)
        // Check EventHost should feed into JobHost (new)
        private bool CheckEvent(XTRMEvent thisEvent, XTRMEvent thisFilter)
        {
            bool bResult = true;
            //dynConfig.Clear();
            // For test, return 1.
            // thisEvent is the real incoming event
            // thisFilter is for comparison

            try
            {
                // User
                if (bResult = CheckEventAttribute(thisEvent.eventUser, thisFilter.eventUser))
                {
                    bResult = CheckEventAttribute(thisEvent.eventTag, thisFilter.eventTag);
                }
                // Source/Action Dependent Checks
                // EventSource
                if (bResult)
                {
                    thisEvent.banner = thisEvent.eventParm1;
                    // Source
                    if (bResult = CheckEventAttribute(thisEvent.eventSource, thisFilter.eventSource))
                    {
                        // Action
                        if (bResult = CheckEventAttribute(thisEvent.eventAction, thisFilter.eventAction))
                        {
                            // Parm1
                            if (bResult = CheckNormalPath(thisEvent.eventParm1, thisFilter.normalPath))
                            {
                                // Parm2
                                if (bResult = CheckEventAttribute(thisEvent.eventParm2, thisFilter.eventParm2))
                                {
                                    // Parm3
                                    if (bResult = CheckEventAttribute(thisEvent.eventParm3, thisFilter.eventParm3))
                                    {
                                        // Parm4
                                        if (bResult = CheckEventAttribute(thisEvent.eventParm4, thisFilter.eventParm4))
                                        {
                                            // Parm5
                                            if (bResult = CheckEventAttribute(thisEvent.eventParm5, thisFilter.eventParm5))
                                            {
                                                // Parm6
                                                if (bResult = CheckEventAttribute(thisEvent.eventParm6, thisFilter.eventParm6))
                                                {
                                                    // Parm7
                                                    if (bResult = CheckEventAttribute(thisEvent.eventParm7, thisFilter.eventParm7))
                                                    {
                                                        // Parm8
                                                        if (bResult = CheckEventAttribute(thisEvent.eventParm8, thisFilter.eventParm8))
                                                        {
                                                            // Parm9
                                                            if (bResult = CheckEventAttribute(thisEvent.eventParm9, thisFilter.eventParm9))
                                                            {
                                                                // Parm10
                                                                bResult = CheckEventAttribute(thisEvent.eventParm10, thisFilter.eventParm10);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                XLogger(1120, -1, string.Format("CheckEventAttribute::Exception Checking Event; Value={0}; Expression={1}; Message={2}", thisEvent.eventSerial, thisFilter.eventTag, ex.Message));
            }
            finally
            {
            }
            return bResult;
        }
Example #7
0
 // Process Active Events in XDB.
 // Check for Completed Jobs.
 public int ProcessActiveEvent(XTRMRoot thisLoader, XTRMEvent thisEvent)
 {
     List<XTRMJob> theseJobs = new List<XTRMJob>();
     int rc = FindXMatch(thisLoader, thisEvent, out theseJobs);
     switch (rc)
     {
         case -1:
             // Failed Event Filter.
             // Update event status (to Initial State).
             break;
         case 0:
             // No Jobs Identified.
             // Update event status.
             break;
         default:
             if (rc > 0)
             {
                 // One or more Jobs Identified.
                 // Create Job(s); XExecutive will process asynchronously.
                 // Update event status.
             }
             else
             {
                 // Other negative values are ignored (at present)!
             }
             break;
     }
     //rc = theseJobs.Count;
     if (theseJobs.Count > 0)
     {
         foreach (XTRMJob thisJob in theseJobs)
         {
             rc = CreateJob(thisJob, thisEvent, dynConfig);
         }
     }
     return theseJobs.Count;
 }
Example #8
0
        public int FindXMatch(XTRMRoot thisLoader, XTRMEvent thisEvent, out List<XTRMJob> myJobs)
        {
            // rc == -1     EventFilter Not Satisfied.
            // rc >= 0      Number of matching jobs.
            int rc = 0;
            bool bResult = true;
            myJobs = new List<XTRMJob>();
            dynConfig.Clear();

            // If there is a match, it will be (a) job(s) from one of (XWorkflow, XToolkit, XComponent, XElement).
            // All matches will be returned in a list of jobs to run.
            // List<XTRMJob> is Returned.

            // Check to see if the Event Filter(s) <is/are all> satisfied; if not, set return code to -1 and exit.
            foreach (XTRMEvent thisEventFilter in thisLoader.eventFilters)
            {
                if (CheckEvent(thisEvent, thisEventFilter) == false)
                {
                    return -1;
                }
            }

            // Traverse XTRMRoot structures for XWorkflow, XToolkit, XComponent, XElement looking for matches.
            foreach (XTRMWorkFlow candidate in thisLoader.workflows)
            {
                try
                {
                    foreach (XTRMEvent thisFilter in candidate.workflowEvents)
                    {
                        try
                        {
                            // If we match the filter, then create the job(s).
                            // Check the active event against the event filter.
                            if (bResult = CheckEvent(thisEvent, thisFilter))
                            {
                                // Add to List of Job(s).
                                foreach (XTRMJob thisJob in thisFilter.eventJobs)
                                {
                                    thisJob.containingWorkflow = candidate.name;
                                    myJobs.Add(thisJob);
                                    rc++;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            XLogger(1118, -1, string.Format("FindXMatch::Exception(workflow); Serial={0}; Expression={1}; Message={2}", thisEvent.eventSerial, thisFilter.eventTag, ex.Message));
                        }
                    }
                }
                catch (Exception ex)
                {
                    XLogger(1119, -1, string.Format("FindXMatch::Exception(candidate workflow); Serial={0}; Message={1}", thisEvent.eventSerial, ex.Message));
                }
            }
            return rc;
        }
Example #9
0
        public int CheckEvents(string strPendingEventFolder)
        {
            int rc = 0;
            int maxEventFileSize = 100000;
            string[] fileEntries = { strPendingEventFolder };
            XTRMEvent eventTester = new XTRMEvent();
            List<string> myConfigs = new List<string>();
            // We load each XTRMRoot Config File (once) and hold on to it for repeated use both in the loading of events (from XML) and in the evaluation of XDB events.
            List<XTRMRoot> myConfigLoaders = new List<XTRMRoot>();
            XmlWriter myCheckedEvent;
            // For Each File in the folder, need to consume into XTRMEvent(s).
            try
            {
                if (File.Exists(strPendingEventFolder))
                {
                    //fileEntries = strPendingEventFolder;
                }
                else if (Directory.Exists(strPendingEventFolder))
                {
                    fileEntries = Directory.GetFiles(strPendingEventFolder);
                }
                else
                {
                    //Error
                    rc = -1;
                }
            }
            catch (Exception ex)
            {
            }

            try
            {
                myConfigs = XTRMObject.getDictionaryEntries("XTRMRootConfigFile");
                myConfigLoaders.Clear();
                foreach (string thisConfig in myConfigs)
                {
                    XTRMRoot thisLoader = new XTRMRoot(ResolveText(thisConfig, XDictionary));
                    thisLoader.ParseConfig(2, true);
                    myConfigLoaders.Add(thisLoader);
                }
            }
            catch (Exception ex)
            {

            }
            try
            {
                foreach (string fileName in fileEntries)
                {
                    try
                    {
                        // Only process file if it is less than 100KB.
                        FileInfo myInfo = new FileInfo(fileName);
                        if (myInfo.Length <= maxEventFileSize)
                        {
                            //ParseConfig(fileName);
                            XTRMRoot myEventLoader = new XTRMRoot(fileName);
                            //myEventLoader.Clear();
                            myEventLoader.ParseConfig(2, true);
                            // Going to write the same file with comments.
                            // OK, proceed!
                            XmlWriterSettings settings = new XmlWriterSettings();
                            settings.OmitXmlDeclaration = false;
                            settings.ConformanceLevel = ConformanceLevel.Document;
                            settings.CloseOutput = true;
                            settings.Indent = true;
                            settings.Encoding = Encoding.Unicode;
                            myCheckedEvent = XmlWriter.Create(fileName, settings);
                            myCheckedEvent.WriteStartDocument();
                            myCheckedEvent.WriteStartElement("XTRMRoot");
                            // This will result in 0 or more XTRMEvents to process.
                            foreach (XTRMEvent thisEvent in myEventLoader.events)
                            {
                                try
                                {
                                    myCheckedEvent.WriteStartElement("XTRMEvent");
                                    myCheckedEvent.WriteAttributeString("ID", thisEvent.eventSerial.ToString());
                                    myCheckedEvent.WriteWhitespace("\n");

                                    // Check the Event!
                                    foreach (XTRMRoot thisLoader in myConfigLoaders)
                                    {
                                        List<XTRMJob> theseJobs = new List<XTRMJob>();
                                        rc = FindXMatch(thisLoader, thisEvent, out theseJobs);
                                        if (rc > 0)
                                        {
                                            if (theseJobs.Count > 0)
                                            {
                                                foreach (XTRMJob thisJob in theseJobs)
                                                {
                                                    myCheckedEvent.WriteComment(string.Format("CONFIG = {0} ------ FOLLOWING JOB MATCHED ------", thisLoader.name));
                                                    myCheckedEvent.WriteWhitespace("\n");
                                                    if (thisLoader.configFile.Length > 0)
                                                    {
                                                        myCheckedEvent.WriteComment(string.Format("FILE = {0}", thisLoader.configFile));
                                                        myCheckedEvent.WriteWhitespace("\n");
                                                    }
                                                    if (thisLoader.includeFile.Length > 0)
                                                    {
                                                        myCheckedEvent.WriteComment(string.Format("INCLUDE = {0}", thisLoader.includeFile));
                                                        myCheckedEvent.WriteWhitespace("\n");
                                                    }
                                                    // Display the Job Information and other info (job data) depending upon detail requested.
                                                    // Add to XML Output as Comments.
                                                    if (thisJob.containingComponent.Length > 0)
                                                    {
                                                        myCheckedEvent.WriteComment(string.Format("XComponent = {0}", thisJob.containingComponent));
                                                        myCheckedEvent.WriteWhitespace("\n");
                                                    }
                                                    if (thisJob.containingElement.Length > 0)
                                                    {
                                                        myCheckedEvent.WriteComment(string.Format("XElement = {0}", thisJob.containingElement));
                                                        myCheckedEvent.WriteWhitespace("\n");
                                                    }
                                                    if (thisJob.containingToolkit.Length > 0)
                                                    {
                                                        myCheckedEvent.WriteComment(string.Format("XToolkit = {0}", thisJob.containingToolkit));
                                                        myCheckedEvent.WriteWhitespace("\n");
                                                    }
                                                    if (thisJob.containingWorkflow.Length > 0)
                                                    {
                                                        myCheckedEvent.WriteComment(string.Format("XWorkflow = {0}", thisJob.containingWorkflow));
                                                        myCheckedEvent.WriteWhitespace("\n");
                                                    }
                                                    string strComment = "Job Name :\t";
                                                    strComment += thisJob.jobName;
                                                    myCheckedEvent.WriteComment(strComment);
                                                    myCheckedEvent.WriteWhitespace("\n");
                                                    foreach (XTRMTask thisTask in thisJob.tasks)
                                                    {
                                                        strComment = string.Format("\tTask Name : \t {0}", thisTask.taskName);
                                                        myCheckedEvent.WriteComment(strComment);
                                                        myCheckedEvent.WriteWhitespace("\n");
                                                        strComment = string.Format("\tTask Exec : \t {0}", thisTask.taskExecutable);
                                                        myCheckedEvent.WriteComment(strComment);
                                                        myCheckedEvent.WriteWhitespace("\n");
                                                        int count = 1;
                                                        foreach (string thisParm in thisTask.parms)
                                                        {
                                                            strComment = string.Format("\t\t<Parm{0}>\t = \t {1} ", count++, thisParm);
                                                            myCheckedEvent.WriteComment(strComment);
                                                            myCheckedEvent.WriteWhitespace("\n");
                                                        }
                                                    }

                                                    Dictionary<string, string> jobData = new Dictionary<string, string>();
                                                    try
                                                    {
                                                        myCheckedEvent.WriteComment("STATIC JOB DATA ------");
                                                        myCheckedEvent.WriteWhitespace("\n");

                                                        foreach (KeyValuePair<string, string> kvp in thisJob.config)
                                                        {
                                                            //saveJobData(jobSerial, kvp.Key.ToString().ToUpper(), kvp.Value);
                                                            jobData[kvp.Key.ToString().ToUpper()] = kvp.Value;
                                                            strComment = string.Format("\t\t<{0}>\t=\t{1} ", kvp.Key.ToString().ToUpper(), kvp.Value);
                                                            myCheckedEvent.WriteComment(strComment);
                                                            myCheckedEvent.WriteWhitespace("\n");
                                                        }

                                                        myCheckedEvent.WriteComment("DYNAMIC JOB DATA ------");
                                                        myCheckedEvent.WriteWhitespace("\n");

                                                        foreach (KeyValuePair<string, string> kvp in dynConfig)
                                                        {
                                                            //saveJobData(jobSerial, kvp.Key.ToString().ToUpper(), kvp.Value);
                                                            jobData[kvp.Key.ToString().ToUpper()] = kvp.Value;
                                                            strComment = string.Format("\t\t<{0}>\t=\t{1} ", kvp.Key.ToString().ToUpper(), kvp.Value);
                                                            myCheckedEvent.WriteComment(strComment);
                                                            myCheckedEvent.WriteWhitespace("\n");
                                                        }

                                                        myCheckedEvent.WriteComment("------------------------------------------------------------------");
                                                        myCheckedEvent.WriteWhitespace("\n");
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        XLogger(1157, -1, string.Format("Saving Job Data; Message={0}", ex.Message));
                                                    }
                                                }
                                                myCheckedEvent.WriteComment("*** END MATCHES ------");
                                                myCheckedEvent.WriteWhitespace("\n");
                                            }
                                            else
                                            {
                                                myCheckedEvent.WriteComment("NO JOBS MATCHED ------");
                                                myCheckedEvent.WriteWhitespace("\n");
                                            }
                                        }
                                        else
                                        {
                                            myCheckedEvent.WriteComment("NO MATCHES ------");
                                            myCheckedEvent.WriteWhitespace("\n");
                                        }
                                    }
                                    myCheckedEvent.WriteStartElement("Source");
                                    myCheckedEvent.WriteString(thisEvent.eventSource);
                                    myCheckedEvent.WriteEndElement();
                                    myCheckedEvent.WriteWhitespace("\n");
                                    myCheckedEvent.WriteStartElement("Action");
                                    myCheckedEvent.WriteString(thisEvent.eventAction);
                                    myCheckedEvent.WriteEndElement();
                                    myCheckedEvent.WriteWhitespace("\n");
                                    myCheckedEvent.WriteStartElement("DateStamp");
                                    myCheckedEvent.WriteString(thisEvent.eventDate);
                                    myCheckedEvent.WriteEndElement();
                                    myCheckedEvent.WriteWhitespace("\n");
                                    myCheckedEvent.WriteStartElement("User");
                                    myCheckedEvent.WriteString(thisEvent.eventUser);
                                    myCheckedEvent.WriteEndElement();
                                    myCheckedEvent.WriteWhitespace("\n");
                                    myCheckedEvent.WriteStartElement("PIN");
                                    myCheckedEvent.WriteString(thisEvent.eventUUID);
                                    myCheckedEvent.WriteEndElement();
                                    myCheckedEvent.WriteWhitespace("\n");
                                    myCheckedEvent.WriteStartElement("Status");
                                    myCheckedEvent.WriteString("0");
                                    myCheckedEvent.WriteEndElement();
                                    myCheckedEvent.WriteWhitespace("\n");
                                    if (thisEvent.eventParm1 != null)
                                    {
                                        if (thisEvent.eventParm1.Length > 0)
                                        {
                                            myCheckedEvent.WriteStartElement("Parm1");
                                            myCheckedEvent.WriteString(thisEvent.eventParm1);
                                            myCheckedEvent.WriteEndElement();
                                            myCheckedEvent.WriteWhitespace("\n");
                                        }
                                    }
                                    if (thisEvent.eventParm2 != null)
                                    {
                                        if (thisEvent.eventParm2.Length > 0)
                                        {
                                            myCheckedEvent.WriteStartElement("Parm2");
                                            myCheckedEvent.WriteString(thisEvent.eventParm2);
                                            myCheckedEvent.WriteEndElement();
                                            myCheckedEvent.WriteWhitespace("\n");
                                        }
                                    }
                                    if (thisEvent.eventParm3 != null)
                                    {
                                        if (thisEvent.eventParm3.Length > 0)
                                        {
                                            myCheckedEvent.WriteStartElement("Parm3");
                                            myCheckedEvent.WriteString(thisEvent.eventParm3);
                                            myCheckedEvent.WriteEndElement();
                                            myCheckedEvent.WriteWhitespace("\n");
                                        }
                                    }
                                    if (thisEvent.eventParm4 != null)
                                    {
                                        if (thisEvent.eventParm4.Length > 0)
                                        {
                                            myCheckedEvent.WriteStartElement("Parm4");
                                            myCheckedEvent.WriteString(thisEvent.eventParm4);
                                            myCheckedEvent.WriteEndElement();
                                            myCheckedEvent.WriteWhitespace("\n");
                                        }
                                    }
                                    if (thisEvent.eventParm5 != null)
                                    {
                                        if (thisEvent.eventParm5.Length > 0)
                                        {
                                            myCheckedEvent.WriteStartElement("Parm5");
                                            myCheckedEvent.WriteString(thisEvent.eventParm5);
                                            myCheckedEvent.WriteEndElement();
                                            myCheckedEvent.WriteWhitespace("\n");
                                        }
                                    }
                                    if (thisEvent.eventParm6 != null)
                                    {
                                        if (thisEvent.eventParm6.Length > 0)
                                        {
                                            myCheckedEvent.WriteStartElement("Parm6");
                                            myCheckedEvent.WriteString(thisEvent.eventParm6);
                                            myCheckedEvent.WriteEndElement();
                                            myCheckedEvent.WriteWhitespace("\n");
                                        }
                                    }
                                    if (thisEvent.eventParm7 != null)
                                    {
                                        if (thisEvent.eventParm7.Length > 0)
                                        {
                                            myCheckedEvent.WriteStartElement("Parm7");
                                            myCheckedEvent.WriteString(thisEvent.eventParm7);
                                            myCheckedEvent.WriteEndElement();
                                            myCheckedEvent.WriteWhitespace("\n");
                                        }
                                    }
                                    if (thisEvent.eventParm8 != null)
                                    {
                                        if (thisEvent.eventParm8.Length > 0)
                                        {
                                            myCheckedEvent.WriteStartElement("Parm8");
                                            myCheckedEvent.WriteString(thisEvent.eventParm8);
                                            myCheckedEvent.WriteEndElement();
                                            myCheckedEvent.WriteWhitespace("\n");
                                        }
                                    }
                                    if (thisEvent.eventParm9 != null)
                                    {
                                        if (thisEvent.eventParm9.Length > 0)
                                        {
                                            myCheckedEvent.WriteStartElement("Parm9");
                                            myCheckedEvent.WriteString(thisEvent.eventParm9);
                                            myCheckedEvent.WriteEndElement();
                                            myCheckedEvent.WriteWhitespace("\n");
                                        }
                                    }
                                    if (thisEvent.eventParm10 != null)
                                    {
                                        if (thisEvent.eventParm10.Length > 0)
                                        {
                                            myCheckedEvent.WriteStartElement("Parm10");
                                            myCheckedEvent.WriteString(thisEvent.eventParm10);
                                            myCheckedEvent.WriteEndElement();
                                            myCheckedEvent.WriteWhitespace("\n");
                                        }
                                    }
                                    myCheckedEvent.WriteEndElement();   // XTRMEvent
                                }
                                catch (Exception ex)
                                {
                                    XLogger(1106, rc, string.Format("Caught Event Loader Exception; Folder={0}; UUID={1}; Message={2}", strPendingEventFolder, thisEvent.eventUUID, ex.Message));
                                }
                            }
                            myCheckedEvent.WriteEndElement();   // XTRMRoot
                            myCheckedEvent.Flush();
                        }
                        else
                        {
                            XLogger(1129, -1, string.Format("Event File Too Large; Folder={0}; File={1}; rc={2}", strPendingEventFolder, fileName, rc));
                        }
                    }
                    catch (Exception ex)
                    {
                        XLogger(1130, -1, string.Format("ParseConfig Exception; Folder={0}; File={1}; rc={2}", strPendingEventFolder, fileName, rc));
                    }
                }
            }
            catch (Exception ex)
            {
                XLogger(1108, -1, string.Format("ProcessPendingEvents::Get Files Exception; Folder={0}; Message={1}", strPendingEventFolder, ex.Message));
            }
            return rc;
        }
Example #10
0
        public string ResolveParm(string rawParm, XTRMEvent thisEvent, Dictionary<string, string> thisConfig, int taskSerial = 0, int jobSerial = -1, int depth = 0)
        {
            string resolvedParm = rawParm;
            string name;

            // @"\{\{(?i:(.*?))\}\}"
            // @"((?<name>.*?(?=\s*=)))(.*?)(?<value>(?<=\().+(?=\)))"
            MatchCollection matchSymbol = XTRMUtil.GetRegexMatches(rawParm, @"\{\{(?<name>(.*?))\}\}");
            if (matchSymbol != null)
            {
                if (matchSymbol.Count > 0)
                {
                    // Report on each match.
                    foreach (Match match in matchSymbol)
                    {
                        string test = match.Value;
                        GroupCollection groups = match.Groups;
                        name = groups["name"].Value;
                        // Dictionary Lookup.
                        // Substitute into rawParm.
                        string result = "";
                        switch (name)
                        {
                            case "JobSerial":
                                result = jobSerial.ToString();
                                break;
                            case "TaskSerial":
                                result = taskSerial.ToString();
                                break;
                            case "EventSerial":
                                result = thisEvent.eventSerial.ToString();
                                break;
                            case "EventSource":
                                result = thisEvent.eventSource;
                                break;
                            case "EventAction":
                                result = thisEvent.eventAction;
                                break;
                            case "EventDate":
                                result = thisEvent.eventDate.ToString();
                                break;
                            case "EventState":
                                result = thisEvent.eventState.ToString();
                                break;
                            case "EventUser":
                                result = thisEvent.eventUser;
                                break;
                            case "EventPIN":
                                result = thisEvent.eventPIN;
                                break;
                            case "EventUUID":
                                result = thisEvent.eventUUID;
                                break;
                            case "EventProcessed":
                                result = thisEvent.eventProcessed.ToString();
                                break;
                            case "EventParm1":
                                result = thisEvent.eventParm1;
                                break;
                            case "EventParm2":
                                result = thisEvent.eventParm2;
                                break;
                            case "EventParm3":
                                result = thisEvent.eventParm3;
                                break;
                            case "EventParm4":
                                result = thisEvent.eventParm4;
                                break;
                            case "EventParm5":
                                result = thisEvent.eventParm5;
                                break;
                            case "EventParm6":
                                result = thisEvent.eventParm6;
                                break;
                            case "EventParm7":
                                result = thisEvent.eventParm7;
                                break;
                            case "EventParm8":
                                result = thisEvent.eventParm8;
                                break;
                            case "EventParm9":
                                result = thisEvent.eventParm9;
                                break;
                            case "EventParm10":
                                result = thisEvent.eventParm10;
                                break;
                            case "EventTag":
                                result = thisEvent.eventTag;
                                break;
                            default:
                                //result = thisEvent.config.getDictionaryEntry(name);
                                //result = getConfig(thisEvent.config, name);
                                result = getConfig(thisConfig, name);
                                // If empty, then use name as the value.
                                break;
                        }
                        resolvedParm = resolvedParm.Replace(match.Value, result);
                    }
                }
            }
            if (!resolvedParm.Equals(rawParm))
            {
                if (depth < 10)
                {
                    // THIS IS A RECURSIVE CALL!
                    resolvedParm = ResolveParm(resolvedParm, thisEvent, thisConfig, taskSerial, jobSerial, depth++);
                }
            }
            return resolvedParm;
        }
Example #11
0
        public int CreateJob(XTRMJob thisJob, XTRMEvent thisEvent, Dictionary<string, string> dynConfig = null)
        {
            int rc = 0;
            int jobSerial = -1;
            int taskSerial = -1;
            XTRMJob newJob = new XTRMJob();
            XTRMTask newTask = new XTRMTask();
            newJob.Initialize(-1);
            newJob.jobType = thisJob.jobType;
            newJob.jobEvent = thisEvent.eventSerial;
            newJob.jobSequence = 0;
            newJob.jobLimit = -1;
            newJob.jobDisplay = "TEST";
            //newJob.jobName = thisJob.jobName + " - " + thisEvent.eventParm1;
            newJob.jobName = ResolveParm(thisJob.jobName, thisEvent, thisJob.config, taskSerial) + " - " + thisEvent.eventParm1;
            newJob.jobStatus = -99;
            newJob.jobResult = 0;
            jobSerial = newJob.Save();
            if (jobSerial >= 0)
            {
                XLogger(1128, 0, string.Format("Created Job Serial={0}; Name={1}", jobSerial, newJob.jobName));

                // Write job config to WorkJobData!
                try
                {
                    foreach (KeyValuePair<string, string> kvp in thisJob.config)
                    {
                        saveJobData(jobSerial, kvp.Key.ToString().ToUpper(), kvp.Value);
                    }
                    if (dynConfig != null)
                    {
                        foreach (KeyValuePair<string, string> kvp in dynConfig)
                        {
                            saveJobData(jobSerial, kvp.Key.ToString().ToUpper(), kvp.Value);
                        }
                    }
                }
                catch (Exception ex)
                {
                    XLogger(1157, -1, string.Format("Saving Job Data; Message={0}", ex.Message));
                }

                int position = 0;
                foreach (XTRMTask thisTask in thisJob.tasks)
                {
                    rc = newTask.Initialize(-1);
                    newTask.jobSerial = jobSerial;
                    newTask.taskSerial = -1;
                    newTask.taskSequence = position++;
                    //newTask.taskName = thisTask.taskName;
                    newTask.taskName = ResolveParm(thisTask.taskName, thisEvent, thisTask.config, taskSerial);
                    newTask.taskPath = ResolveParm(thisTask.taskPath, thisEvent, thisTask.config, taskSerial);
                    //newTask.taskExecutable = thisTask.taskExecutable;
                    newTask.taskExecutable = ResolveParm(thisTask.taskExecutable, thisEvent, thisTask.config, taskSerial);
                    newTask.taskPID = -1;
                    newTask.taskStatus = 0;
                    newTask.taskResult = 0;
                    newTask.taskEvent = thisEvent.eventSerial;
                    //newTask.taskStart = DateTime.Now;
                    //newTask.taskStop = DateTime.Now;
                    taskSerial = newTask.Save();
                    if (taskSerial >= 0)
                    {
                        // Must do Parameters!
                        // Need to resolve {{x}} parms!
                        if (thisTask.parms != null)
                        {
                            newTask.parms.Add(newTask.taskName);
                            foreach (string thisParm in thisTask.parms)
                            {
                                //string resolvedParm = ResolveParm(thisParm, thisEvent, thisTask.config);
                                newTask.parms.Add(ResolveParm(thisParm, thisEvent, thisTask.config, taskSerial, jobSerial));
                            }
                        }
                        //newTask.taskStart = DateTime.Now;
                        //newTask.taskStop = DateTime.Now;
                        taskSerial = newTask.Save();
                        if (taskSerial >= 0)
                        {
                            XLogger(1125, 0, string.Format("Created Task Serial={0}; Name={1}; Path={2}", taskSerial, newTask.taskName, newTask.taskPath));
                        }
                        else
                        {
                            XLogger(1126, -1, string.Format("Unable To Create Task; rc={0}", taskSerial));
                        }
                    }
                    else
                    {
                        XLogger(1155, -1, string.Format("Unable To Create Task; rc={0}", taskSerial));
                    }
                }
                newJob.jobStatus = 0;   // Activate Job!
                jobSerial = newJob.Save();
                if (jobSerial < 0)
                {
                    XLogger(1156, -1, string.Format("Unable To Activate (save) Job; rc={0}", jobSerial));
                }
            }
            else
            {
                XLogger(1127, -1, string.Format("Unable To Create Job; rc={0}", jobSerial));
            }
            return rc;
        }