예제 #1
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(true);
                    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);
        }
예제 #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);
        }
예제 #3
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);
        }
예제 #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);
        }