/// <summary>Stops the timer corresponding to MGData passed with the interval specified in seconds.</summary> /// <param name="mgData">MgData object</param> /// <param name="seconds">Timer interval</param> /// <param name="isIdle">Is idle timer or not</param> static internal void StopTimer(MGData mgData, int milliseconds, bool isIdle) { List <RCTimer> timers = null; if (TimerObjectCollection.MgDataToTimerObjList.ContainsKey(mgData)) { timers = TimerObjectCollection.MgDataToTimerObjList[mgData]; foreach (RCTimer rcTimer in timers) { if (rcTimer != null) { if ((rcTimer._timerIntervalMilliSeconds == milliseconds) && (rcTimer._isIdle == isIdle)) { //Placing STOP_TIMER command in queue. Commands.addAsync(CommandType.STOP_TIMER, rcTimer); timers.Remove(rcTimer); break; } } } Commands.beginInvoke(); if (timers.Count == 0) { TimerObjectCollection.MgDataToTimerObjList.Remove(mgData); } } }
/// <summary> /// add MGData object to the table /// </summary> /// <param name = "mgd">the MGData object to add</param> /// <param name = "idx">the index within the table for the new MGData</param> internal void addMGData(MGData mgd, int idx, bool isStartup) { if (idx < 0 || idx > getSize()) { throw new ApplicationException("Illegal MGData requested"); } if (isStartup) { StartupMgData = mgd; } if (idx == getSize()) { _mgDataTab.Add(mgd); } else { MGData oldMgd = getMGData(idx); if (oldMgd != null && !oldMgd.IsAborting) { oldMgd.getFirstTask().stop(); oldMgd.abort(); } _mgDataTab[idx] = mgd; } }
/// <summary>Stops all the timers.</summary> /// <param name="MgData"></param> internal static void StopAll(MGData mgData) { List <RCTimer> timers = null; //Checking for the entry of the timer objects list for the respective key. if (TimerObjectCollection.MgDataToTimerObjList.ContainsKey(mgData)) { timers = TimerObjectCollection.MgDataToTimerObjList[mgData]; } if (timers != null) { foreach (RCTimer rcTimer in timers) { if (rcTimer != null) { //Placing STOP_TIMER command in queue. Commands.addAsync(CommandType.STOP_TIMER, rcTimer); } } Commands.beginInvoke(); //Clearing the list, after all the timers are stopped. timers.Clear(); //Removing the key from the hash table, after the list of timer objects are cleared. TimerObjectCollection.MgDataToTimerObjList.Remove(mgData); } }
/// <summary> /// Gets the MGData that holds/should hold the startup program. /// The method takes into consideration whether the application uses MDI or not. /// </summary> /// <returns></returns> internal MGData GetMGDataForStartupProgram() { Debug.Assert(_mgDataTab.Count > 0, "The main program must be processed before invoking this method."); Task mainProg = GetMainProgByCtlIdx(0); Debug.Assert(mainProg != null, "The main program must be processed before invoking this method."); Debug.Assert(mainProg.getMgdID() == 0, "Main program is expected to be on MGData 0. Is this an error?"); // if the main program does not have MDI frame, the startup MGData index is 0. if (!mainProg.HasMDIFrame) { return(_mgDataTab[0]); } // If the main program has MDI, the startup MGData index is 1. If it already exists, // return it. if (_mgDataTab.Count >= 2) { return(_mgDataTab[1]); } // The startup MGData is 1, but it does not exist yet, so create it. MGData mgd = new MGData(1, null, false); addMGData(mgd, 1, true); return(mgd); }
/// <summary> Stops the specified task and all the tasks which are invoked by it. </summary> /// <param name="task"></param> /// <returns></returns> private bool StopTaskTree(Task task) { bool taskStopped = false; if (task.hasSubTasks()) { for (int i = 0; i < task.SubTasks.getSize();) { //If the task was not stopped, then only increment the counter, because, if //the task was stopped, it is removed from task.SubTasks and so, the next //task is available at the same index. if (!StopTaskTree(task.SubTasks.getTask(i))) { i++; } } } //Do not execute abort command for the subform. Subform task are stopped //when its container task will be aborted. if (!task.IsSubForm) { MGData mgData = task.getMGData(); IClientCommand abortCommand = CommandFactory.CreateAbortCommand(task.getTaskTag()); mgData.CmdsToClient.Add(abortCommand); // execute the command mgData.CmdsToClient.Execute(null); taskStopped = true; } return(taskStopped); }
/// <summary> /// returns MGData object by its index /// </summary> internal MGData getMGData(int idx) { MGData mgd = null; if (idx >= 0 && idx < getSize()) { mgd = _mgDataTab[idx]; } return(mgd); }
/// <summary> Removes all the pending server commands </summary> internal void RemoveServerCommands() { for (int i = 0; i < getSize(); i++) { MGData mgd = getMGData(i); if (mgd != null) { mgd.CmdsToServer.clear(); } } }
/// <summary> constructor </summary> /// <param name="MgData"></param> /// <param name="milliseconds">time interval, in milliseconds</param> /// <param name="isIdle"></param> internal RCTimer(MGData mgData, int milliseconds, bool isIdle) : base(milliseconds) { _mgData = mgData; IsIdleTimer = isIdle; if (!TimerObjectCollection.MgDataToTimerObjList.ContainsKey(_mgData)) { TimerObjectCollection.MgDataToTimerObjList.Add(_mgData, new List <RCTimer>()); } TimerObjectCollection.MgDataToTimerObjList[_mgData].Add(this); }
/// <summary> /// build XML string of the MGDataTABLE object, /// ALL MGData in the table /// </summary> /// <param name="message">a message being prepared.</param> /// <param name="serializeTasks">if true, tasks in the current execution will also be serialized.</param> internal void buildXML(StringBuilder message, Boolean serializeTasks) { for (int i = 0; i < getSize(); i++) { MGData mgd = getMGData(i); if (mgd != null && !mgd.IsAborting) { mgd.buildXML(message, serializeTasks); } } FlowMonitorQueue.Instance.buildXML(message); }
/// <summary> Stops all the non-offline tasks and its children. </summary> internal void StopNonOfflineTasks() { for (int i = 0; i < _mgDataTab.Count; i++) { MGData mgData = _mgDataTab[i]; if (mgData != null && !mgData.IsAborting) { Task firstTask = mgData.getFirstTask(); if (!firstTask.isMainProg() && !firstTask.IsOffline) { StopTaskTree(mgData.getFirstTask()); } } } }
/// <summary> /// perform any data error recovery action on all dataviews /// </summary> internal void processRecovery() { for (int i = 0; i < getSize(); i++) { MGData mgd = getMGData(i); if (mgd != null) { for (int j = 0; j < mgd.getTasksCount(); j++) { Task task = mgd.getTask(j); if (task != null) { ((DataView)task.DataView).processRecovery(); } } } } }
/// <summary> /// searches all the MGData objects till it finds the task with the given id /// </summary> /// <param name = "id">the id of the requested task</param> public ITask GetTaskByID(String id) { Task task = null; for (int i = 0; i < getSize() && task == null; i++) { MGData mgd = getMGData(i); if (mgd == null) { // the window connected to the MGData was closed continue; } task = mgd.getTask(id); } return(task); }
/// <summary> /// searches all the MGData objects till it finds a main program with the given ctl idx /// </summary> /// <param name = "contextID"></param> /// <param name = "ctlIdx">the idx of the requested component</param> public ITask GetMainProgByCtlIdx(Int64 contextID, int ctlIdx) { Task task = null; for (int i = 0; i < getSize() && task == null; i++) { MGData mgd = getMGData(i); if (mgd == null) { // the window connected to the MGData was closed continue; } task = mgd.getMainProg(ctlIdx); } return(task); }
private bool _timersStarted; // TRUE if the timers have already been started /// <summary> /// CTOR /// </summary> /// <param name = "id">the id of this mgdata object</param> /// <param name = "parent">the parent MGData</param> /// <param name = "isModal">true for modal windows</param> internal MGData(int id, MGData parent, bool isModal) { CmdsToServer = new CommandsTable(); CmdsToClient = new CommandsTable(); _timerHandlers = new HandlersTable(); _expHandlers = new HandlersTable(); _mprgTab = new TasksTable(); _tasksTab = new TasksTable(); _id = id; _parent = parent; if (ClientManager.Instance.EventsManager.getCompMainPrgTab() == null) { var compMainPrgTab = new CompMainPrgTable(); ClientManager.Instance.EventsManager.setCompMainPrgTab(compMainPrgTab); } IsModal = isModal; }
/// <summary> /// Start task,parsing /// </summary> private bool initInnerObjects(String foundTagName, MGData mgdata, OpeningTaskDetails openingTaskDetails) { if (foundTagName == null) { return(false); } if (foundTagName.Equals(XMLConstants.MG_TAG_TASK)) { var task = new Task(); ClientManager.Instance.TasksNotStartedCount++; _tasks.Add(task); task.fillData(mgdata, openingTaskDetails); } else { return(false); } return(true); }
/// <summary> /// get the next task using the tasks iterator /// </summary> internal Task getNextTask() { Task task = null; MGData mgd = getMGData(_iteratorMgdIdx); if (mgd == null) { return(null); } task = mgd.getTask(_iteratorTaskIdx); if (task == null) { do { _iteratorMgdIdx++; } while (_iteratorMgdIdx < getSize() && getMGData(_iteratorMgdIdx) == null); _iteratorTaskIdx = 0; return(getNextTask()); } _iteratorTaskIdx++; return(task); }
/// set modality of command and task according to task form type and the force-modal info /// </summary> /// <param name="task"></param> void SetIsModal(Task task) { MGData mgdata = task.getMGData(); if (mgdata.ForceModal) { // force the task to run modal mgdata.IsModal = true; // change the form type to be modal if (task.getForm() != null) { task.getForm().ConcreteWindowType = WindowType.Modal; } } else { // set the IsModel according to the calculated window type if (!task.IsSubForm && task.getForm() != null) { mgdata.IsModal = (task.getForm().ConcreteWindowType == WindowType.Modal); } } }
/// <summary> /// To allocate and fill inner objects of the class /// </summary> /// <param name = "foundTagName">possible tag name, name of object, which need be allocated</param> /// <param name="openingTaskDetails">additional information of opening task</param> /// <returns> xmlParser.getCurrIndex(), the found object tag and ALL its subtags finish</returns> private bool initInnerObjects(XmlParser parser, String foundTagName, OpeningTaskDetails openingTaskDetails) { if (foundTagName == null) { return(false); } switch (foundTagName) { case XMLConstants.MG_TAG_XML: parser.setCurrIndex( parser.getXMLdata().IndexOf(XMLConstants.TAG_CLOSE, parser.getCurrIndex()) + 1); // do // nothing break; case ConstInterface.MG_TAG_DATAVIEW: if (!insertDataView(parser)) { // the task of insert data view not found -> set parsers counter to the // end of the data view // the data view, got from server and there is no task to the data view , yet. int endContext = parser.getXMLdata().IndexOf('/' + ConstInterface.MG_TAG_DATAVIEW, parser.getCurrIndex()); parser.setCurrIndex(endContext); parser.setCurrIndex2EndOfTag(); } break; // read DataViewContent that received as a response of GetDataViewContent Command. case ConstInterface.MG_TAG_COMPLETE_DV: { Task task = null; int endContext = parser.getXMLdata().IndexOf(XMLConstants.TAG_CLOSE, parser.getCurrIndex()); int index = parser.getXMLdata().IndexOf(ConstInterface.MG_TAG_COMPLETE_DV, parser.getCurrIndex()) + ConstInterface.MG_TAG_COMPLETE_DV.Length; List <String> tokensVector = XmlParser.getTokens(parser.getXMLdata().Substring(index, endContext - index), "\""); // get task id string attribute = (tokensVector[0]); String valueStr; if (attribute.Equals(XMLConstants.MG_ATTR_TASKID)) { valueStr = (tokensVector[1]); String taskId = valueStr; task = getTask(taskId) ?? (Task)MGDataCollection.Instance.GetTaskByID(taskId); } int start = endContext + 1; endContext = parser.getXMLdata().IndexOf(XMLConstants.END_TAG + ConstInterface.MG_TAG_COMPLETE_DV, parser.getCurrIndex()); String dataViewContent = parser.getXMLdata().Substring(start, endContext - start); task.dataViewContent = dataViewContent; parser.setCurrIndex(endContext); parser.setCurrIndex2EndOfTag(); } break; case XMLConstants.MG_TAG_TREE: { int start = parser.getCurrIndex(); int endContext = parser.getXMLdata().IndexOf('/' + XMLConstants.MG_TAG_TREE, parser.getCurrIndex()); parser.setCurrIndex(endContext); parser.setCurrIndex2EndOfTag(); String treeData = parser.getXMLdata().Substring(start, parser.getCurrIndex() - start); //read tree data using sax parser try { var mgSAXParser = new MgSAXParser(new TreeSaxHandler()); mgSAXParser.parse(Encoding.UTF8.GetBytes(treeData)); } catch (Exception e) { Logger.Instance.WriteExceptionToLog(e); Misc.WriteStackTrace(e, Console.Error); } break; } case ConstInterface.MG_TAG_CONTEXT: { int endContext = parser.getXMLdata().IndexOf(XMLConstants.TAG_TERM, parser.getCurrIndex()); if (endContext != -1 && endContext < parser.getXMLdata().Length) { // last position of its tag String tag = parser.getXMLsubstring(endContext); parser.add2CurrIndex(tag.IndexOf(ConstInterface.MG_TAG_CONTEXT) + ConstInterface.MG_TAG_CONTEXT.Length); parser.setCurrIndex(endContext + XMLConstants.TAG_TERM.Length); // to delete "/>" too } break; } case XMLConstants.MG_TAG_RECOMPUTE: var recompTab = new RecomputeTable(); recompTab.fillData(); break; case ConstInterface.MG_TAG_COMMAND: Logger.Instance.WriteDevToLog("goes to command"); CmdsToClient.fillData(); break; case ConstInterface.MG_TAG_LANGUAGE: Logger.Instance.WriteDevToLog("goes to language data"); ClientManager.Instance.getLanguageData().fillData(); break; case ConstInterface.MG_TAG_KBDMAP_URL: Logger.Instance.WriteDevToLog("goes to keyBoard"); ClientManager.Instance.getEnvironment().fillFromUrl(foundTagName); break; case ConstInterface.MG_TAG_KBDMAP: Logger.Instance.WriteDevToLog("goes to keyBoard"); int kbdStartIdx = parser.getCurrIndex(); int kbdEndIdx = parser.getXMLdata().IndexOf('/' + ConstInterface.MG_TAG_KBDMAP, parser.getCurrIndex()); parser.setCurrIndex(kbdEndIdx); parser.setCurrIndex2EndOfTag(); String kbdData = parser.getXMLdata().Substring(kbdStartIdx, parser.getCurrIndex() - kbdStartIdx); ClientManager.Instance.getKbdMap().fillKbdMapTable(Encoding.UTF8.GetBytes(kbdData)); break; case ConstInterface.MG_TAG_COLORTABLE_URL: Logger.Instance.WriteDevToLog("goes to color"); ClientManager.Instance.getEnvironment().fillFromUrl(foundTagName); break; case XMLConstants.MG_TAG_COLORTABLE: { Logger.Instance.WriteDevToLog("goes to color"); int colorStartIdx = parser.getCurrIndex(); int colorEndIdx = parser.getXMLdata().IndexOf('/' + XMLConstants.MG_TAG_COLORTABLE, parser.getCurrIndex()); parser.setCurrIndex(colorEndIdx); parser.setCurrIndex2EndOfTag(); String colorData = parser.getXMLdata().Substring(colorStartIdx, parser.getCurrIndex() - colorStartIdx); Manager.GetColorsTable().FillFrom(Encoding.UTF8.GetBytes(colorData)); break; } case ConstInterface.MG_TAG_FONTTABLE_URL: Logger.Instance.WriteDevToLog("goes to font"); ClientManager.Instance.getEnvironment().fillFromUrl(foundTagName); break; case ConstInterface.MG_TAG_FONTTABLE: Logger.Instance.WriteDevToLog("goes to font"); int startIdx = parser.getCurrIndex(); int endIdx = parser.getXMLdata().IndexOf('/' + ConstInterface.MG_TAG_FONTTABLE, parser.getCurrIndex()); parser.setCurrIndex(endIdx); parser.setCurrIndex2EndOfTag(); String fontData = parser.getXMLdata().Substring(startIdx, parser.getCurrIndex() - startIdx); Manager.GetFontsTable().FillFrom(Encoding.UTF8.GetBytes(fontData)); break; case ConstInterface.MG_TAG_COMPMAINPRG: Logger.Instance.WriteDevToLog("goes to compmainprg"); ClientManager.Instance.EventsManager.getCompMainPrgTab().fillData(); break; case ConstInterface.MG_TAG_EVENTS_QUEUE: Logger.Instance.WriteDevToLog("goes to eventsqueue"); fillEventsQueue(parser); break; case ConstInterface.MG_TAG_TASKURL: ClientManager.Instance.ProcessTaskURL(); break; case XMLConstants.MG_TAG_TASK: Logger.Instance.WriteDevToLog("goes to task"); int taskCountBefore = _mprgTab.getSize(); _mprgTab.fillData(this, openingTaskDetails); // QCR #759911: mprg must belong to the main application's MGData. // This ensures it will not be discarded until the end of execution. // There could be more then 1 mprgs that are added (Qcr #168549) if (_id != 0) { int taskCountAfter = _mprgTab.getSize(); MGData mgd0 = MGDataCollection.Instance.getMGData(0); // check all the new main prgs. for (int taskIndex = taskCountBefore; taskIndex < taskCountAfter; taskIndex++) { Task newTask = _mprgTab.getTask(taskIndex); if (newTask.isMainProg() && mgd0._mprgTab.getTask(newTask.getTaskTag()) == null) { mgd0._mprgTab.addTask(newTask); mgd0.addTask(newTask); } } } break; case ConstInterface.MG_TAG_ENV: Logger.Instance.WriteDevToLog("goes to environment"); ClientManager.Instance.getEnvironment().fillData(); break; case ConstInterface.MG_TAG_FLWMTR_CONFIG: FlowMonitorQueue.Instance.fillData(); break; case XMLConstants.MG_TAG_XML_END: parser.setCurrIndex2EndOfTag(); return(false); case ConstInterface.MG_TAG_USER_RIGHTS: ClientManager.Instance.fillUserRights(); break; case ConstInterface.MG_TAG_DBH_REAL_IDXS: ClientManager.Instance.fillDbhRealIdxs(); break; case ConstInterface.MG_TAG_GLOBALPARAMSCHANGES: Logger.Instance.WriteDevToLog("applying global params changes from the server (Set/GetParams)"); ClientManager.Instance.getGlobalParamsTable().fillData(); break; case ConstInterface.MG_TAG_GLOBALPARAMS: Logger.Instance.WriteDevToLog("processing base64 encoded image of all global params from the server"); ClientManager.Instance.fillGlobalParams(); break; case ConstInterface.MG_TAG_CACHED_FILES: RemoteCommandsProcessor.GetInstance().ServerFileToClientHelper.RequestedForFolderOrWildcard = true; parser.setCurrIndex(parser.getXMLdata().IndexOf(XMLConstants.TAG_CLOSE, parser.getCurrIndex()) + 1); break; case ConstInterface.MG_TAG_CACHED_FILES_END: parser.setCurrIndex(parser.getXMLdata().IndexOf(XMLConstants.TAG_CLOSE, parser.getCurrIndex()) + 1); break; case ConstInterface.MG_TAG_CACHED_FILE: ClientManager.Instance.fillCacheFilesMap(); break; case ConstInterface.MG_TAG_ENV_PARAM_URL: Logger.Instance.WriteDevToLog("goes to env params name "); ClientManager.Instance.getEnvironment().fillFromUrl(foundTagName); break; case ConstInterface.MG_TAG_ENV_PARAM: Logger.Instance.WriteDevToLog("goes to env params name "); ClientManager.Instance.getEnvParamsTable().fillData(); break; case ConstInterface.MG_TAG_USER_DETAILS: UserDetails.Instance.fillData(); break; case ConstInterface.MG_TAG_DBHS: ClientManager.Instance.LocalManager.ApplicationDefinitions.DataSourceDefinitionManager.FillData(); break; case ConstInterface.MG_TAG_DATABASE_URL: // If data includes only file url ClientManager.Instance.LocalManager.ApplicationDefinitions.DatabaseDefinitionsManager.FillUrl(); break; case ConstInterface.MG_TAG_DATABASES_HEADER: ClientManager.Instance.LocalManager.ApplicationDefinitions.DatabaseDefinitionsManager.FillData(); break; case ConstInterface.MG_TAG_TASKDEFINITION_IDS_URL: Logger.Instance.WriteDevToLog("goes to task definition ids"); ClientManager.Instance.LocalManager.ApplicationDefinitions.TaskDefinitionIdsManager.FillFromUrl(foundTagName); break; case ConstInterface.MG_TAG_OFFLINE_SNIPPETS_URL: ClientManager.Instance.LocalManager.ApplicationDefinitions.OfflineSnippetsManager.FillFromUrl(foundTagName); break; case ConstInterface.MG_TAG_STARTUP_PROGRAM: CommandsProcessorManager.GetCommandsProcessor().ParseStartupProgram(parser); break; case ConstInterface.MG_TAG_CONTEXT_ID: { String ctxId; int ctxEndIdx; parser.setCurrIndex(parser.getXMLdata().IndexOf(XMLConstants.TAG_CLOSE, parser.getCurrIndex()) + 1); ctxEndIdx = parser.getXMLdata().IndexOf(XMLConstants.TAG_OPEN, parser.getCurrIndex()); ctxId = parser.getXMLsubstring(ctxEndIdx).Trim(); parser.setCurrIndex(ctxEndIdx); parser.setCurrIndex2EndOfTag(); ClientManager.Instance.RuntimeCtx.ContextID = Int64.Parse(ctxId); } break; case ConstInterface.MG_TAG_HTTP_COMMUNICATION_TIMEOUT: { uint httpCommunicationTimeout; // communication-level timeout (i.e. the access to the web server, NOT the entire request/response round-trip), in seconds. int httpCommunicationTimeoutIdx; parser.setCurrIndex(parser.getXMLdata().IndexOf(XMLConstants.TAG_CLOSE, parser.getCurrIndex()) + 1); httpCommunicationTimeoutIdx = parser.getXMLdata().IndexOf(XMLConstants.TAG_OPEN, parser.getCurrIndex()); httpCommunicationTimeout = uint.Parse(parser.getXMLsubstring(httpCommunicationTimeoutIdx)); parser.setCurrIndex(httpCommunicationTimeoutIdx); parser.setCurrIndex2EndOfTag(); HttpManager.GetInstance().HttpCommunicationTimeoutMS = httpCommunicationTimeout * 1000; } break; default: Logger.Instance.WriteExceptionToLog( "There is no such tag name in MGData, add case to MGData.initInnerObjects and case to while of MGData.FillData " + foundTagName); return(false); } return(true); }
/// <summary> /// CTOR to be used when running offline tasks - hold the command to enable right setting of modality /// </summary> /// <param name="id"></param> /// <param name="parent"></param> /// <param name="isModal"></param> /// <param name="forceModal"></param> public MGData(int id, MGData parent, bool isModal, bool forceModal) : this(id, parent, isModal) { ForceModal = forceModal; }
/// <summary> /// returns the index of MGData in MGDataTable /// </summary> /// <param name = "mgd">to find into table</param> internal int getMgDataIdx(MGData mgd) { return(_mgDataTab.IndexOf(mgd)); }
/// <summary> /// parse a set of tasks /// </summary> /// <param name = "mgdata">to parent -> MGData </param> /// <param name="openingTaskDetails">additional information of opening task</param> internal void fillData(MGData mgdata, OpeningTaskDetails openingTaskDetails) { while (initInnerObjects(ClientManager.Instance.RuntimeCtx.Parser.getNextTag(), mgdata, openingTaskDetails)) { } }