protected static void Alert(string subject, string text) { // Send email to XBot Admin. string contact = XTRMObject.getDictionaryEntry("AdminMail", "*****@*****.**"); XTRMObject.Notify(contact, null, subject, text); }
public static bool IsDictionaryLoaded() { bool bValid = false; if (XTRMObject.getDictionaryEntry("LoadDisposition").Equals("1")) { bValid = true; Console.Write("\nConfig ID={0}.\n", getDictionaryEntry("ConfigID")); } return(bValid); }
public int Initialize() { int rc = -99; try { SetLogID(1); myConfigs = XTRMObject.getDictionaryEntries("XLatorConfigFile"); rc = myConfigs.Count; } catch (Exception ex) { XLogger(1175, -1, string.Format("Exception in Initialize(); message={0}", ex.Message)); rc = -1; } return(rc); }
//static String odbcConnectionString = XTRMObject.getDictionaryEntry("ODBCConnectString"); static public SqlConnection connectXDB(string connectString = "") { SqlConnection thisConnection = null; if (connectString.Equals("")) { connectString = XTRMObject.getDictionaryEntry("TaskConnectString"); } try { thisConnection = new SqlConnection(connectString); } catch (SqlException) { } catch (Exception) { } return(thisConnection); }
public bool Initialize(string filename = "") { bool bExists = false; try { string defaultFile = filename; if (defaultFile.Length == 0) { // Try to get from the environment! defaultFile = Environment.GetEnvironmentVariable("XDB_DICTIONARY"); } if (File.Exists(defaultFile)) { // If exists as specified, then use it! bExists = true; dictionaryFile = defaultFile; } else { // Otherwise, must go look for it! dictionaryFile = XTRMObject.FindMyDictionaryFile(defaultFile); // Does the file exist? bExists = File.Exists(dictionaryFile); if (!bExists) { dictionaryFile = defaultFile; bExists = File.Exists(dictionaryFile); if (!bExists) { // Cannot Find. dictionaryFile = ""; } } } } catch (Exception) { } finally { } return(bExists); }
public int Initialize() { int rc = -99; try { //int rc = 0; SetLogID(1); //string XLatorConfigFile = XLib.XDB_Objects.XObject.getDictionaryEntry("XLatorConfigFile"); myConfigs = XTRMObject.getDictionaryEntries("XLatorConfigFile"); //myConfigLoader.ParseConfig(XLatorConfigFile, 2, true); rc = myConfigs.Count; } catch (Exception ex) { XLogger(1175, -1, string.Format("Exception in Initialize(); message={0}", ex.Message)); rc = -1; } return(rc); }
public int Initialize() { int rc = 0; _pool = new Semaphore(1, 1); Clear(); SetLogID(3); myConfigs = XTRMObject.getDictionaryEntries("XAgentConfigFile"); // Read file, call parseConfig, then iterate around addPath(). foreach (string thisAgentFile in myConfigs) { // Read each file ParseConfig(ResolveText(thisAgentFile, XDictionary), true); //ParseConfig(thisAgentFile, true); } foreach (XTRMFSEntity thisEntity in entities) { // addEntity addEntity(thisEntity); } return(rc); }
public Dictionary <String, String> Augment(Dictionary <String, String> existDictionary, string XmlFragment, bool bUpper = false) { XmlParserContext context = null; int count = 0; bool bRC = true; if (bRC) { try { // Load the reader with the data file and ignore all white space nodes. // Check the file first! //Create the XmlParserContext. context = new XmlParserContext(null, null, null, XmlSpace.None); reader = new XmlTextReader(XmlFragment, XmlNodeType.Element, context); int lElementType = 0; Dictionary <String, String> elementAttributes = new Dictionary <String, String>(); existDictionary["LoadDisposition"] = "1"; // Load the reader with the data file and ignore all white space nodes. reader.WhitespaceHandling = WhitespaceHandling.None; // Parse the file and display each of the nodes. bool bResult = reader.Read(); while (bResult) { switch (reader.NodeType) { case XmlNodeType.Element: string elementName = reader.Name; // 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++) { elementAttributes.Add(reader.Name, reader.Value); reader.MoveToNextAttribute(); } reader.MoveToElement(); } // Need to see if we are interested in this element! lElementType = 0; switch (elementName) { case "Variable": // Variable lElementType = 1; bResult = reader.Read(); break; default: bResult = reader.Read(); break; } break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: bResult = reader.Read(); break; case XmlNodeType.Comment: bResult = reader.Read(); break; case XmlNodeType.EndElement: bResult = reader.Read(); break; case XmlNodeType.Text: switch (lElementType) { case 1: // Variable // thisTask.parms.Add(reader.Value); string name = elementAttributes["Name"]; if (name != null) { string value = reader.Value; if (value != null) { if (bUpper) { name = name.ToUpper(); value = value.ToUpper(); } existDictionary[name] = value; } } break; default: break; } bResult = reader.Read(); break; default: bResult = reader.Read(); break; } } } catch (FileNotFoundException) { Console.Write("Use Local File"); } catch (Exception) { existDictionary["LoadDisposition"] = "-1"; } finally { if (reader != null) { reader.Close(); } existDictionary["LoadCount"] = Convert.ToString(count); existDictionary["RootFolder"] = XTRMObject.GetRootFolder(); } } else { // Cannot load dictionary. existDictionary["LoadedCount"] = "0"; existDictionary["LoadDisposition"] = "0"; existDictionary["RootFolder"] = XTRMObject.GetRootFolder(); } return(existDictionary); }
// Make Full Pass Through Processing. public int Run(int pass = 0, bool logBeat = false) { int rc = 0; bool initiatorStatus = getDictionaryEntry("ProcessJobs", "Y").Equals("Y"); // Validate Connection. if (validateConnection(MasterConnection)) { switch (pass) { // Pass 1: Evaluate current run states. // Review Active Jobs. case 1: //myLog.WriteEntry("Starting Pass 0"); if (CheckStatus() >= 0) //Initialize(); //if (bInitialized) { // Inspect each running job. //XLogger(1200, 0, string.Format("Jobs Executing={0}; Allowed={1}", runningJobs.Count, jobsAllowed)); foreach (XTRMJob thisJob in runningJobs) { //rc = thisJob.Initialize(thisJob.jobSerial); //if (rc >= 0) //{ if (thisJob.jobStatus == 1) { int lActiveTasks = 0; // Inspect each running task (should be one at most). foreach (XTRMTask thisTask in thisJob.tasks) { // Refresh Task. //rc = thisTask.Initialize(thisTask.taskSerial); //if (rc >= 0) //{ /* * if (thisTask.taskStatus > 9) * { * // Done. * // Start next one if no other active tasks. * //thisJob.tasks.Remove(thisTask); * } */ if (thisTask.taskStatus == 1) { lActiveTasks++; if (false) { // If not original task object, then let's check closer. // This can happen if XExecutive gets re-initialized with running jobs. if (!thisTask.taskOriginator) { if (thisTask.taskPID != -1) { // Future, Check the [time]-limit? // Check the PID; If exists, then wait. try { Process thisProcess = Process.GetProcessById(thisTask.taskPID); if (thisProcess.HasExited) { thisTask.taskStatus = 95; // Complete; disposition unknown. rc = thisTask.Save(); } } catch (Exception ex) { // Mark the task as complete. thisTask.taskStatus = 91; // Complete; disposition unknown. rc = thisTask.Save(); } } } } } else { // Other status values ignored (for now) - should not be pending! //XLogger(1201, 0, string.Format("Unexpected TaskStatus Value={0}", thisTask.taskStatus)); // If result < 0, then mark job for termination! if (thisTask.taskResult < 0) { XLogger(1201, 0, string.Format("Job #{0} Terminated Due to Task #{1} Result={2}.", thisJob.jobSerial, thisTask.taskSerial, thisTask.taskResult)); thisJob.jobStatus = 98; // Terminated. thisJob.jobStop = DateTime.Now.ToString(); lActiveTasks = 1; rc = thisJob.Save(); if (rc < 0) { XLogger(1227, 0, string.Format("thisJob.Save() Failed; rc={0}", rc)); } // Send email to XBot Admin. string contact = XTRMObject.getDictionaryEntry("AdminMail", "*****@*****.**"); Notify(contact, null, string.Format("Job #{0}/{1} Failed {2}", thisJob.jobSerial, thisTask.taskSerial, thisJob.jobName), string.Format("Exec={0}; Path={1}; Result={2}.", thisTask.taskExecutable, thisTask.taskPath, thisTask.taskResult)); } } //} //else //{ // Error on Initialize() of XTask. // XLogger(1202, 0, string.Format("XTask.Initialize() Failure; rc={0}", rc)); //} } //if (thisJob.tasks.Count == 0) if (lActiveTasks == 0) { // Look for next task (within this job). List <int> pendingTaskSerials = InventoryPendingTasks(thisJob); if (pendingTaskSerials.Count <= 0) { // Job Complete thisJob.jobStatus = 99; thisJob.jobStop = DateTime.Now.ToString(); rc = thisJob.Save(); if (rc < 0) { XLogger(1203, 0, string.Format("thisJob.Save() Failed; rc={0}", rc)); } //runningJobs.Remove(thisJob); } else { XTRMTask pendingTask = new XTRMTask(false); if (pendingTaskSerials[0] < 1) { // Error XLogger(1204, 0, "No Pending TaskSerials"); } rc = pendingTask.Initialize(pendingTaskSerials[0]); if (rc >= 0) { //thisJob.tasks.Add(pendingTask); //runningTasks.Add(pendingTask); rc = pendingTask.Start(); if (rc < 0) { XLogger(1205, 0, string.Format("pendingTask.Start() Failed; Serial={0}; rc={1}", pendingTask.taskSerial, rc)); // Send email to XBot Admin. string contact = XTRMObject.getDictionaryEntry("AdminMail", "*****@*****.**"); Notify(contact, null, string.Format("Job Task #{0}/{1} {2} Could Not Start", thisJob.jobSerial, pendingTask.taskSerial, pendingTask.taskName), string.Format("Exec={0}; Path={1}.", pendingTask.taskExecutable, pendingTask.taskPath)); } else { XLogger(1206, 0, string.Format("Task #{0} Started", pendingTask.taskSerial)); } //thisJob.tasks.Add(pendingTask); } else { // Error XLogger(1207, 0, string.Format("XTask.Initialize() Failure for Pending Task; rc={0}", rc)); } } } else { // Wait for other pending task(s) - should not happen! //XLogger(1208, 0, "Waiting for Job Task(s) to Complete."); } //} //else //{ // Error on Initialize() of XJob. // XLogger(1209, 0, string.Format("XJob.Initialize() Failure; rc={0}", rc)); //} } } // Purge Jobs that have completed! jobStatus >= 9 bool purgeFlag = true; while (purgeFlag) { purgeFlag = false; foreach (XTRMJob thisJob in runningJobs) { if (thisJob.jobStatus >= 9) { runningJobs.Remove(thisJob); purgeFlag = true; break; } } } } else { // Error! XLogger(1210, 0, "Executive Not Initialized in Pass 0"); } break; // Pass 0: Start New Jobs. // Review Pending Jobs. // Spawn Candidate Jobs. case 0: if (initiatorStatus) { //myLog.WriteEntry("Starting Pass 1"); // If we are under the MPR, then start a new job. if (runningJobs.Count < jobsAllowed) { rc = LoadCandidateJobs(); if (rc >= 0) { foreach (int thisJobSerial in candidateJobs) { // Mark the Job as Started. XTRMJob newJob = new XTRMJob(false); if (runningJobs.Count < jobsAllowed) { rc = newJob.Initialize(thisJobSerial); if (rc >= 0) { newJob.jobStatus = 1; newJob.jobStart = DateTime.Now.ToString(); //newJob.jobStop = DBNull.Value.ToString(); rc = newJob.Save(); if (rc >= 0) { // Job Started; first task will start in next call to case 0: runningJobs.Add(newJob); XLogger(1222, 0, string.Format("Job #{0} Started; Executing={1}; Allowed={2}", newJob.jobSerial, runningJobs.Count, jobsAllowed)); } else { // Error XLogger(1211, 0, string.Format("newJob.Save() Failure; rc={0}", rc)); } } else { // Initialize Error (XJob). XLogger(1212, 0, string.Format("newJob.Initialize() Failure; rc = {0}", rc)); } } else { XLogger(1213, 0, "Waiting for Runnng Jobs To Complete"); break; } } } else { // Error XLogger(1214, 0, string.Format("Failure in LoadCandidateJobs(); rc={0}", rc)); } } else { //XLogger(1215, 0, "Waiting for Capacity"); // Wait for capacity. } } break; } } else { myLog.WriteEntry("Master XDB Connection Failure"); } return(rc); }
/* * public bool OKtoExit() * { * int rc = 0; * bool bResult = false; * runningJobs = new List<XJob>(); * //rc = InventoryRunningJobs(runningJobs); * //if (rc >= 0) * //{ * if (runningJobs.Count == 0) * { * bResult = true; * } * //} * return bResult; * } * */ public int XLogger(int result, string logtext, int ID = 9900) { return(XTRMObject.XLogger(ID, result, logtext)); }
public static string GetConfigID() { return(XTRMObject.getDictionaryEntry("ConfigID")); }
public int ParseConfig(string configFile, bool bDeep = false) { // // Consume XML to create the XFSEntity objects. // if bDeep is false, then ONLY do this object. // if bDeep is true, then also do recursive objects. XmlTextReader reader = null; int rc = -1; string connectString = XTRMObject.getDictionaryEntry("TaskConnectString"); string outerXML; int lElementType = 0; XDictionaryLoader myDictionaryLoader = new XDictionaryLoader(); Dictionary <String, String> elementAttributes; entities.Clear(); try { // Load the reader with the data file and ignore all white space nodes. reader = new XmlTextReader(configFile); reader.WhitespaceHandling = WhitespaceHandling.None; // Parse the file and display each of the nodes. bool bResult = reader.Read(); while (bResult) { bool bProcessed = false; switch (reader.NodeType) { case XmlNodeType.Element: string elementName = reader.Name; switch (elementName.ToUpper()) { case "XFSENTITY": outerXML = reader.ReadOuterXml(); XTRMFSEntity thisEntity = (XTRMFSEntity)XTRMFSEntity.consumeXML(outerXML, 1, true); entities.Add(thisEntity); 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(); } if (elementAttributes.ContainsKey("Tag")) { agentTag = elementAttributes["Tag"]; } if (elementAttributes.ContainsKey("Source")) { agentSource = elementAttributes["Source"]; } if (elementAttributes.ContainsKey("User")) { agentUser = elementAttributes["User"]; } if (elementAttributes.ContainsKey("EventPath")) { agentEventPath = elementAttributes["EventPath"]; } reader.MoveToElement(); } // Need to see if we are interested in this element! //string elementName = reader.Name; switch (elementName.ToUpper()) { case "XFILEAGENTCONFIG": // Advance into Elements! reader.MoveToContent(); bResult = reader.Read(); 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) { default: break; } bResult = reader.Read(); break; default: bResult = reader.Read(); break; } } } catch (Exception ex) { exCount_XML++; XLogger(2400, -1, string.Format("XTRMFileAgent::parseConfig(); ConfigFile={0}; Message={1}", configFile, ex.Message)); } finally { if (reader != null) { reader.Close(); } } return(rc); }
// 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); }
/* * public int startIteration() * { * int rc = 0; * int interval = 60; * try * { * XObject.XDictionary = createDictionary(); * myConfigs = XLib.XDB_Objects.XObject.getDictionaryEntries("XLatorConfigFile"); * interval = Convert.ToInt32(getConfig(XObject.XDictionary, "MonitorInterval", "60")); * } * catch (Exception ex) * { * interval = 60; * } * return interval; * } * */ // 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")); //Process execProcess = Process.GetCurrentProcess(); /* * if (logBeat) * { * XLogger(1131, 0, string.Format("Heartbeat: Current={0}; Peak={1}; WSS={2}; TotProc={3};", execProcess.VirtualMemorySize64, execProcess.PeakVirtualMemorySize64, execProcess.WorkingSet64, execProcess.TotalProcessorTime)); * } * * // Check memory. * // Check registry. * if (execProcess.VirtualMemorySize64 > 500000000) * { * XLogger(1137, 0, string.Format("Forcing Garbage Collection: Current={0}; Peak={1}; WSS={2}; TotProc={3};", execProcess.VirtualMemorySize64, execProcess.PeakVirtualMemorySize64, execProcess.WorkingSet64, execProcess.TotalProcessorTime)); * GC.Collect(); * XLogger(1138, 0, string.Format("After Garbage Collection: Current={0}; Peak={1}; WSS={2}; TotProc={3};", execProcess.VirtualMemorySize64, execProcess.PeakVirtualMemorySize64, execProcess.WorkingSet64, execProcess.TotalProcessorTime)); * if (execProcess.VirtualMemorySize64 > 300000000) * { * XLogger(1139, 0, string.Format("Re-Instantiating: Current={0}; Peak={1}; WSS={2}; TotProc={3};", execProcess.VirtualMemorySize64, execProcess.PeakVirtualMemorySize64, execProcess.WorkingSet64, execProcess.TotalProcessorTime)); * * return -1; * } * } * */ // 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 1: Process any pending events referenced by any of the loaders. case 1: if (eventStatus) { foreach (XTRMRoot thisLoader in myConfigLoaders) { //myConfigLoader.ParseConfig(thisConfig, 2, true); foreach (string strPendingEventFolder in thisLoader.eventFolders) { rc = ProcessPendingEvents(strPendingEventFolder); if (rc < 0) { XLogger(1100, -1, string.Format("Run::ProcessPendingEvents() Failure; Pass={0}; rc={1}; folder={2}", pass, rc, strPendingEventFolder)); } } //myConfigLoaders.Add(myConfigLoader); } if (exCount_XML > 0) { //Console.Write("XML Parser Exceptions\n"); XLogger(1101, exCount_XML, string.Format("Run::XML Parser xceptions > 0; Pass={0}; rc={1}", pass, rc)); } } break; } } else { myLog.WriteEntry("Master XDB Connection Failure"); } return(rc); }
public int CheckEvents(string strPendingEventFolder) { int rc = 0; int maxEventFileSize = 100000; string[] fileEntries = { strPendingEventFolder }; XTRMEvent eventTester = new XTRMEvent(false); 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); }
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); }
public int IncludeConfig(string inFile, Dictionary <String, String> myConfig, int lVariant = 0, bool bDeep = false) { // // Consume XML to create the XLator object. // if bDeep is false, then ONLY do this object. // if bDeep is true, then also do recursive objects. int rc = -1; XmlTextReader reader = null; string connectString = XTRMObject.getDictionaryEntry("TaskConnectString"); string outerXML; int lElementType = 0; XDictionaryLoader myDictionaryLoader = new XDictionaryLoader(); Dictionary <String, String> elementAttributes; try { // Load the reader with the data file and ignore all white space nodes. reader = new XmlTextReader(inFile); reader.WhitespaceHandling = WhitespaceHandling.None; // Parse the file and display each of the nodes. bool bResult = reader.Read(); while (bResult) { bool bProcessed = false; switch (reader.NodeType) { case XmlNodeType.Element: string elementName = reader.Name; switch (elementName.ToUpper()) { case "BASECONFIG": outerXML = reader.ReadOuterXml(); myDictionaryLoader = new XDictionaryLoader(); myConfig = myDictionaryLoader.Augment(myConfig, outerXML); bProcessed = true; break; case "WITHCONFIG": outerXML = reader.ReadOuterXml(); myDictionaryLoader.Augment(myConfig, outerXML); bProcessed = true; break; case "EVENTFILTER": outerXML = reader.ReadOuterXml(); XTRMEvent thisFilter = (XTRMEvent)XTRMEvent.consumeXML(myConfig, outerXML, 2, true); eventFilters.Add(thisFilter); bProcessed = true; break; case "XTRMEVENT": outerXML = reader.ReadOuterXml(); XTRMEvent thisEvent = (XTRMEvent)XTRMEvent.consumeXML(myConfig, outerXML, 1, true); events.Add(thisEvent); bProcessed = true; break; case "XTRMWORKFLOW": outerXML = reader.ReadOuterXml(); XTRMWorkFlow thisFlow = (XTRMWorkFlow)XTRMWorkFlow.consumeXML(myConfig, outerXML, 1, true); workflows.Add(thisFlow); 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++) { elementAttributes.Add(reader.Name, reader.Value); reader.MoveToNextAttribute(); } if (elementAttributes.ContainsKey("Name")) { // Try to instantiate the XEvent Object! name = elementAttributes["Name"]; } reader.MoveToElement(); } // Need to see if we are interested in this element! //string elementName = reader.Name; switch (elementName.ToUpper()) //switch (reader.Name) { case "EVENTFOLDER": lElementType = 1; bResult = reader.Read(); break; case "XTRM": // Advance into Elements! reader.MoveToContent(); bResult = reader.Read(); break; default: bResult = reader.Read(); break; } } break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: bResult = reader.Read(); break; case XmlNodeType.Comment: bResult = reader.Read(); break; case XmlNodeType.EndElement: bResult = reader.Read(); break; case XmlNodeType.Text: switch (lElementType) { case 1: // EventFolder eventFolders.Add(ResolveText(reader.Value, XDictionary)); break; default: break; } bResult = reader.Read(); break; default: bResult = reader.Read(); break; } } } catch (Exception ex) { exCount_XML++; XLogger(2402, -1, string.Format("XLator::IncludeConfig(); ConfigFile={0}; Message={1}", configFile, ex.Message)); } finally { if (reader != null) { reader.Close(); } } return(rc); }