private void treeViewTraces_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            object tagObject = e.Node.Tag;

            if (tagObject is DebugTracePanel)
            {
                DebugTracePanel tracePanel = tagObject as DebugTracePanel;
                string          radName    = tracePanel.RADName;
                string          panelName  = tracePanel.PanelInfo.PanelName;
                RADPanel        radPanel   = GetRADPanel(radName, panelName);
                if (radPanel != null)
                {
                    tracePanel.PanelInfo = radPanel;
                }
                string formatName = tracePanel.PanelInfo.Format;

                Format        format        = GetFormatInfo(formatName, "en");
                FormatControl formatControl = new FormatControl(format);
                formatControl.DebugTrace = tracePanel;
                panelRADDetail.Controls.Clear();
                panelRADDetail.Controls.Add(formatControl);
                PopulateFormData(tracePanel.PanelInfo, formatControl);

                ShowContext(tracePanel);
            }
        }
        private void PopulateChildData(RADPanel panelData, Control childControl, Dictionary <string, string> fieldMappings)
        {
            string controlName = childControl.Name;

            if (fieldMappings.ContainsKey(controlName))
            {
                string         targetPropertyName = fieldMappings[controlName];
                PropertyInfo[] properties         = typeof(RADPanel).GetProperties(BindingFlags.Public | BindingFlags.Instance);
                PropertyInfo   targetProperty     = null;
                foreach (PropertyInfo temProperty in properties)
                {
                    if (temProperty.Name == targetPropertyName)
                    {
                        targetProperty = temProperty;
                        break;
                    }
                }
                if (targetProperty != null)
                {
                    object propertyValue = targetProperty.GetValue(panelData, null);
                    if (propertyValue != null)
                    {
                        if (childControl is TextBox)
                        {
                            if (propertyValue.GetType() == typeof(int) || propertyValue.GetType() == typeof(string))
                            {
                                (childControl as TextBox).Text = propertyValue.ToString();
                            }
                            else //Collection<string>
                            {
                                (childControl as TextBox).Text = (propertyValue as Collection <string>)[0];
                            }
                        }
                        else if (childControl is RichTextBox)
                        {
                            if (propertyValue.GetType() == typeof(int) || propertyValue.GetType() == typeof(string))
                            {
                                (childControl as RichTextBox).Text = propertyValue.ToString();
                            }
                            else //Collection<string>
                            {
                                RichTextBox         richTextBox = childControl as RichTextBox;
                                Collection <string> values      = propertyValue as Collection <string>;

                                foreach (string itemValue in values)
                                {
                                    richTextBox.Text = richTextBox.Text + itemValue + "\r\n";
                                }
                            }
                        }
                    }
                }
            }
            foreach (Control subControl in childControl.Controls)
            {
                PopulateChildData(panelData, subControl, fieldMappings);
            }
        }
        private void PopulateFormData(RADPanel panelData, FormatControl formatControl)
        {
            Dictionary <string, string> fieldMappings = new Dictionary <string, string>();

            fieldMappings.Add("application", "RADName");
            fieldMappings.Add("label", "PanelName");
            fieldMappings.Add("comments", "Comments");
            fieldMappings.Add("normal", "Normal");
            fieldMappings.Add("error", "Error");
            fieldMappings.Add("format", "Format");
            fieldMappings.Add("file", "File");
            fieldMappings.Add("all_null", "AllNull");
            fieldMappings.Add("key_null", "KeyNull");
            fieldMappings.Add("key_dupl", "KeyDupl");
            fieldMappings.Add("second_file", "SecondFile");
            fieldMappings.Add("target_file", "TargetFile");
            fieldMappings.Add("record", "Record");
            fieldMappings.Add("query", "Query");
            fieldMappings.Add("name", "Name");
            fieldMappings.Add("names", "Names");
            fieldMappings.Add("values", "Values");
            fieldMappings.Add("prompt", "Prompt");
            fieldMappings.Add("condition", "Conditions");
            fieldMappings.Add("option", "Option");
            fieldMappings.Add("description", "Description");
            fieldMappings.Add("exit", "Exit");
            fieldMappings.Add("empty", "Empty");
            fieldMappings.Add("one_rec", "OneRec");
            fieldMappings.Add("text", "Text");
            fieldMappings.Add("statements", "Statements");
            fieldMappings.Add("cond_input", "CondInput");
            fieldMappings.Add("sort", "Sort");
            fieldMappings.Add("types", "Types");
            fieldMappings.Add("levels", "Levels");
            fieldMappings.Add("numbers", "Numbers");
            fieldMappings.Add("number1", "Number1");
            fieldMappings.Add("string1", "String1");
            fieldMappings.Add("time1", "Time1");
            fieldMappings.Add("boolean1", "Boolean1");
            fieldMappings.Add("times", "Times");
            fieldMappings.Add("expressions", "Expressions");
            fieldMappings.Add("comments_more", "CommentsMore");
            fieldMappings.Add("file_variables", "FileVariables");
            fieldMappings.Add("second_record", "SecondRecord");
            fieldMappings.Add("booleans", "Booleans");
            fieldMappings.Add("table", "Table");
            fieldMappings.Add("tables", "Tables");

            foreach (Control subControl in formatControl.Controls)
            {
                PopulateChildData(panelData, subControl, fieldMappings);
            }
        }
 /// <summary>
 /// Get RAD panel from SM server.
 /// </summary>
 /// <param name="radName"></param>
 /// <param name="panel"></param>
 /// <returns></returns>
 private RADPanel GetRADPanel(string radName, string panel)
 {
     using (DataBus dataBus = GetDataBus())
     {
         JSCodeRunner codeRunner = new JSCodeRunner();
         codeRunner.Include("JSCode\\JsonEncode.js");
         codeRunner.Include("JSCode\\GetRADInfo.js");
         string   codeToRun = " return GetRADInfo(\"" + radName + "\",\"" + panel + "\");";
         RADPanel radPanel  = codeRunner.Run <RADPanel>(dataBus, codeToRun);
         return(radPanel);
     }
 }
        private RADPanel GetRADPanel(string radName, string panel)
        {
            string sessionId           = textBoxCookieId.Text.Trim();
            string authorizationString = textBoxAuthorization.Text.Trim();

            ConnectionInfo    currentConnectionInfo = comboBoxServer.SelectedItem as ConnectionInfo;
            SessionCache      sessionCache          = new SessionCache();
            ConnectionSession connectionSession     = sessionCache[currentConnectionInfo];
            DataBus           dataBus = connectionSession.GetDataBus(sessionId, authorizationString);

            JSCodeRunner codeRunner = new JSCodeRunner();

            codeRunner.Include("JSCode\\JsonEncode.js");
            codeRunner.Include("JSCode\\GetRADInfo.js");
            string   codeToRun = " return GetRADInfo(\"" + radName + "\",\"" + panel + "\");";
            RADPanel radPanel  = codeRunner.Run <RADPanel>(dataBus, codeToRun);

            return(radPanel);
        }
        public void AddTrace(Execute excuteObject)
        {
            ClientRequest clientRequest = excuteObject.ClientRequestEntity;

            if (clientRequest != null)
            {
                for (int i = clientRequest.Messages.Messages.Count - 1; i >= 0; i--)
                //for (int i = 0; i < clientRequest.Messages.Messages.Count ; i++)
                {
                    MessageItem messageItem  = clientRequest.Messages.Messages[i];
                    string      debugMessage = messageItem.Text.Trim();

                    //rad call.
                    if (radCallReg.IsMatch(debugMessage))
                    {
                        TraceChangedInfo changedInfo = new TraceChangedInfo();
                        changedInfo.OldRad   = currentRAD;
                        changedInfo.OldPanel = currentTrance as DebugTracePanel;

                        Match           radMatch       = radCallReg.Match(debugMessage);
                        GroupCollection groups         = radMatch.Groups;
                        string          threadId       = groups[1].Value;
                        string          currentRADName = groups[2].Value;
                        if (!followingReturn)
                        {
                            DebugTraceRADCall newRadCall = new DebugTraceRADCall();
                            newRadCall.Parent  = currentRAD;
                            newRadCall.RADName = currentRADName;

                            currentRAD.Traces.Add(newRadCall);
                            currentRAD = newRadCall;
                            radStack.Push(currentRADName);

                            currentTrance        = null;
                            changedInfo.NewRad   = currentRAD;
                            changedInfo.NewPanel = null;
                            changedInfo.Type     = TraceChangedType.NewRADCall;
                            if (OnTraceChanged != null)
                            {
                                OnTraceChanged(this, changedInfo);
                            }
                        }
                        else
                        {
                            //Check if current value is the same as the parent rad
                            if (currentRAD.RADName != currentRADName)
                            {
                                do
                                {
                                    radStack.Pop();
                                    currentRAD = currentRAD.Parent as DebugTraceRADCall;
                                }while (currentRADName != currentRAD.RADName);
                                //throw new Exception("RAD stack mismatched...");
                            }
                        }


                        followingReturn = false;
                        //nothing to do
                    }
                    else if (returnReg.IsMatch(debugMessage))
                    {
                        followingReturn = true;
                        TraceChangedInfo changedInfo = new TraceChangedInfo();
                        changedInfo.OldRad   = currentRAD;
                        changedInfo.OldPanel = currentTrance as DebugTracePanel;

                        radStack.Pop();
                        currentRAD = currentRAD.Parent as DebugTraceRADCall;

                        currentTrance        = null;
                        changedInfo.NewRad   = currentRAD;
                        changedInfo.NewPanel = null;
                        changedInfo.Type     = TraceChangedType.RADCallReturn;

                        if (OnTraceChanged != null)
                        {
                            OnTraceChanged(this, changedInfo);
                        }
                    }
                    else if (panelReg.IsMatch(debugMessage))
                    {
                        followingReturn = false;
                        TraceChangedInfo changedInfo = new TraceChangedInfo();
                        changedInfo.OldRad   = currentRAD;
                        changedInfo.OldPanel = currentTrance as DebugTracePanel;


                        Match           radMatch         = panelReg.Match(debugMessage);
                        GroupCollection groups           = radMatch.Groups;
                        string          threadId         = groups[1].Value;
                        string          currentPanelName = groups[2].Value;

                        RADPanel panel = new RADPanel();
                        panel.RADName   = currentRAD.RADName;
                        panel.PanelName = currentPanelName;

                        DebugTracePanel tracePanel = new DebugTracePanel();
                        tracePanel.PanelInfo = panel;
                        tracePanel.Parent    = currentRAD;
                        currentRAD.Traces.Add(tracePanel);
                        currentTrance = tracePanel;

                        changedInfo.NewRad   = currentRAD;
                        changedInfo.NewPanel = currentTrance as DebugTracePanel;
                        changedInfo.Type     = TraceChangedType.NewPanel;
                        if (OnTraceChanged != null)
                        {
                            OnTraceChanged(this, changedInfo);
                        }
                    }
                    else
                    {
                        //followingReturn = false;
                    }
                    //radStack.Push(messageItem);
                }
            }
        }