Exemple #1
0
        /// <summary>
        /// part of the buildXML which deals with the command only - used for command serialization unit test
        /// </summary>
        /// <param name="message"></param>
        /// <param name="execStackExists"></param>
        /// <returns></returns>
        internal void BuildXMLInternal(StringBuilder message, bool execStackExists)
        {
            bool hasChildElements = false;

            message.Append(XMLConstants.START_TAG + ConstInterface.MG_TAG_COMMAND);
            message.Append(" " + XMLConstants.MG_ATTR_TYPE + "=\"");
            switch (Type)
            {
            case ClientCommandType.VerifyCache:
                message.Append(ConstInterface.MG_ATTR_VAL_VERIFY_CACHE);
                break;

            case ClientCommandType.Event:
                message.Append(ConstInterface.MG_ATTR_VAL_EVENT);
                break;

            case ClientCommandType.Recompute:
                message.Append(ConstInterface.MG_ATTR_VAL_RECOMP);
                break;

            case ClientCommandType.Transaction:
                message.Append(ConstInterface.MG_ATTR_VAL_TRANS);
                break;

            case ClientCommandType.Unload:
                message.Append(ConstInterface.MG_ATTR_VAL_UNLOAD);
                break;

            case ClientCommandType.Hibernate:
                message.Append(ConstInterface.MG_ATTR_VAL_HIBERNATE);
                break;

            case ClientCommandType.Resume:
                message.Append(ConstInterface.MG_ATTR_VAL_RESUME);
                break;

            case ClientCommandType.ExecOper:
                message.Append(ConstInterface.MG_ATTR_VAL_EXEC_OPER);
                break;

            case ClientCommandType.Menu:
                message.Append(ConstInterface.MG_ATTR_VAL_MENU);
                break;

            case ClientCommandType.Evaluate:
                message.Append(ConstInterface.MG_ATTR_VAL_EVAL);
                break;

            case ClientCommandType.OpenURL:
                message.Append(ConstInterface.MG_ATTR_VAL_OPENURL);
                break;

            case ClientCommandType.Query:
                message.Append(ConstInterface.MG_ATTR_VAL_QUERY);
                break;

            case ClientCommandType.Expand:
                message.Append(ConstInterface.MG_ATTR_VAL_EXPAND);
                break;

            case ClientCommandType.IniputForceWrite:
                message.Append(ConstInterface.MG_ATTR_VAL_INIPUT_FORCE_WRITE);
                break;

            default:
                Logger.Instance.WriteErrorToLog("in Command.buildXML() no such type: " + Type);
                break;
            }

            message.Append("\"");

            if (TaskTag != null && !execStackExists)
            {
                // QCR #980454 - the task id may change during the task's lifetime, so taskId might
                // be holding the old one - find the task and refetch its current ID.
                String id = MGDataTable.Instance.getTaskIdById(TaskTag);

                message.Append(" " + XMLConstants.MG_ATTR_TASKID + "=\"" + id + "\"");
            }
            if (_oper != 0)
            {
                message.Append(" " + ConstInterface.MG_ATTR_OPER + "=\"" + _oper + "\"");
            }
            if (_fldId != -1)
            {
                message.Append(" " + ConstInterface.MG_ATTR_FIELDID + "=\"" + _fldId + "\"");
            }
            if (_ignoreSubformRecompute)
            {
                message.Append(" " + ConstInterface.MG_ATTR_IGNORE_SUBFORM_RECOMPUTE + "=\"" + 1 + "\"");
            }
            if (_handlerId != null && !execStackExists)
            {
                message.Append(" " + ConstInterface.MG_ATTR_HANDLERID + "=\"" + _handlerId + "\"");
            }
            if (MagicEvent != 0)
            {
                message.Append(" " + ConstInterface.MG_ATTR_MAGICEVENT + "=\"" + MagicEvent + "\"");
            }
            if (rollbackType != RollbackEventCommand.RollbackType.NONE)
            {
                message.Append(" " + ConstInterface.MG_ATTR_ROLLBACK_TYPE + "=\"" + (char)rollbackType + "\"");
            }
            if (_exitByMenu)
            {
                message.Append(" " + ConstInterface.MG_ATTR_EXIT_BY_MENU + "=\"" + "=\"1\"");
            }
            if (_operIdx > Int32.MinValue && !execStackExists)
            {
                message.Append(" " + ConstInterface.MG_ATTR_OPER_IDX + "=\"" + _operIdx + "\"");
            }
            if (_ditIdx > Int32.MinValue)
            {
                message.Append(" " + XMLConstants.MG_ATTR_DITIDX + "=\"" + _ditIdx + "\"");
            }
            if (_val != null)
            {
                message.Append(" " + XMLConstants.MG_ATTR_VALUE + "=\"" + XmlParser.escape(_val) + "\"");
            }
            if (_expIdx > Int32.MinValue)
            {
                message.Append(" " + ConstInterface.MG_ATTR_EXP_IDX + "=\"" + _expIdx + "\"");
            }
            if (_expType != StorageAttribute.NONE)
            {
                String maxDigits = "";
                if (_lengthExpVal > 0)
                {
                    maxDigits += _lengthExpVal;
                }

                message.Append(" " + ConstInterface.MG_ATTR_EXP_TYPE + "=\"" + (char)_expType + maxDigits + "\"");
            }
            if (!_reversibleExit)
            {
                message.Append(" " + ConstInterface.MG_ATTR_REVERSIBLE + "=\"0\"");
            }

            if (_varList != null)
            {
                message.Append(" " + ConstInterface.MG_ATTR_ARGLIST + "=\"");
                _varList.buildXML(message);
                message.Append("\"");
            }

            if (_generation != null)
            {
                message.Append(" " + ConstInterface.MG_ATTR_GENERATION + "=\"" + _generation + "\"");
            }

            if (_taskVarList != null)
            {
                message.Append(" " + ConstInterface.MG_ATTR_TASKVARLIST + "=\"" + _taskVarList + "\"");
            }

            if (Obj != null)
            {
                message.Append(" " + ConstInterface.MG_ATTR_OBJECT + "=\"" + Obj + "\"");
            }

            if (_mprgCreator != null)
            {
                message.Append(" " + ConstInterface.MG_ATTR_MPRG_SOURCE + "=\"" + _mprgCreator.getTaskTag() + "\"");
            }

            if (_level != 0)
            {
                message.Append(" " + ConstInterface.MG_ATTR_TRANS_LEVEL + "=\"" + _level + "\"");
            }

            if (_key != null)
            {
                message.Append(" " + ConstInterface.MG_ATTR_KEY + "=\"" + _key + "\"");
            }

            if (RefreshMode != 0)
            {
                message.Append(" " + ConstInterface.MG_ATTR_REALREFRESH + "=\"" + (int)RefreshMode + "\"");
            }
            //this tag value alway when sent equals to 1

            if (_keepUserSort)
            {
                message.Append(" " + ConstInterface.MG_ATTR_KEEP_USER_SORT + "=\"1\"");
            }

            if (SubformTaskTag != null)
            {
                message.Append(" " + ConstInterface.MG_ATTR_SUBFORM_TASK + "=\"" + SubformTaskTag + "\"");
            }
            //this tag value always when sent does not equal to 0

            if (_menuUid > Int32.MinValue)
            {
                message.Append(" " + ConstInterface.MG_ATTR_MNUUID + "=\"" + _menuUid + "\"");
            }

            if (MenuComp > Int32.MinValue)
            {
                message.Append(" " + ConstInterface.MG_ATTR_MNUCOMP + "=\"" + MenuComp + "\"");
            }

            if (_closeSubformOnly)
            {
                message.Append(" " + ConstInterface.MG_ATTR_CLOSE_SUBFORM_ONLY + "=\"1\"");
            }

            if (_checkOnly)
            {
                message.Append(" " + ConstInterface.MG_ATTR_CHECK_ONLY + "=\"1\"");
            }

            if (_treePath != null)
            {
                message.Append(" " + ConstInterface.MG_ATTR_PATH + "=\"" + _treePath + "\"");
            }

            if (_treeValues != null)
            {
                message.Append(" " + ConstInterface.MG_ATTR_VALUES + "=\"" + _treeValues + "\"");
            }

            if (_treeIsNulls != null)
            {
                message.Append(" " + ConstInterface.MG_ATTR_TREE_IS_NULLS + "=\"" + _treeIsNulls + "\"");
            }

            if (_direction != -1)
            {
                message.Append(" " + ConstInterface.MG_ATTR_DIRECTION + "=\"" + _direction + "\"");
            }

            if (_incrmentalSearchString != null)
            {
                message.Append(" " + ConstInterface.MG_ATTR_SEARCH_STR + "=\"" + _incrmentalSearchString + "\"");
            }

            if (_resetIncrementalSearch)
            {
                message.Append(" " + ConstInterface.MG_ATTR_RESET_SEARCH + "=\"1\"");
            }

            if (_accessedCacheFiles != null && _accessedCacheFiles.Count > 0)
            {
                hasChildElements = true;
                message.Append(" " + ConstInterface.MG_ATTR_SHOULD_PRE_PROCESS + "=\"Y\"");
                message.Append(XMLConstants.TAG_CLOSE + "\n");

                foreach (KeyValuePair <string, string> cachedFileInfo in _accessedCacheFiles)
                {
                    message.Append(XMLConstants.XML_TAB + XMLConstants.XML_TAB + XMLConstants.TAG_OPEN);
                    message.Append(ConstInterface.MG_TAG_CACHE_FILE_INFO + " ");
                    message.Append(ConstInterface.MG_ATTR_SERVER_PATH + "=\"" + cachedFileInfo.Key + "\" ");
                    message.Append(ConstInterface.MG_ATTR_TIMESTAMP + "=\"" + cachedFileInfo.Value + "\"");
                    message.Append(XMLConstants.TAG_TERM + "\n");
                }

                message.Append(XMLConstants.XML_TAB + XMLConstants.END_TAG + ConstInterface.MG_TAG_COMMAND);
            }

            switch (Type)
            {
            case ClientCommandType.Query:
                message.Append(" " + ConstInterface.MG_ATTR_VAL_QUERY_TYPE + "=\"");
                switch (_queryType)
                {
                case QueryType.GLOBAL_PARAMS:
                    message.Append(ConstInterface.MG_ATTR_VAL_QUERY_GLOBAL_PARAMS);
                    break;

                default:
                    message.Append(ConstInterface.MG_ATTR_VAL_QUERY_CACHED_FILE);
                    message.Append("\" ");
                    message.Append(ConstInterface.MG_ATTR_FILE_PATH);
                    message.Append("=\"");
                    message.Append(_text);
                    break;
                }

                message.Append("\"");
                break;

            case ClientCommandType.IniputForceWrite:
                _text = XmlParser.escape(_text);
                message.Append(" " + ConstInterface.MG_ATTR_VAL_INIPUT_PARAM + "=\"" + _text + "\"");
                break;

            default:
                try
                {
                    MGData currMGData      = MGDataTable.Instance.getCurrMGData();
                    int    length          = currMGData.getTasksCount();
                    bool   titleExist      = false;
                    Task   currFocusedTask = ClientManager.Instance.getLastFocusedTask();

                    for (int i = 0;
                         i < length;
                         i++)
                    {
                        Task task = currMGData.getTask(i);
                        var  ctrl = (MgControl)task.getLastParkedCtrl();
                        if (ctrl != null && task.KnownToServer && !task.IsOffline)
                        {
                            if (!titleExist)
                            {
                                message.Append(" " + ConstInterface.MG_ATTR_FOCUSLIST + "=\"");
                                titleExist = true;
                            }
                            else
                            {
                                message.Append('$');
                            }
                            message.Append(task.getTaskTag() + ",");
                            message.Append((task.getLastParkedCtrl()).getDitIdx());
                        }
                    }

                    if (titleExist)
                    {
                        message.Append("\"");
                    }

                    if (currFocusedTask != null && !currFocusedTask.IsOffline)
                    {
                        message.Append(" " + ConstInterface.MG_ATTR_FOCUSTASK + "=\"" + currFocusedTask.getTaskTag() + "\"");
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.WriteErrorToLog(ex);
                }
                break;
            }

            if (hasChildElements)
            {
                message.Append(XMLConstants.TAG_CLOSE);
            }
            else
            {
                message.Append(XMLConstants.TAG_TERM);
            }
        }