BlueSky.CommandExecutionHelper.ExeuteSingleCommandWithtoutXML C# (CSharp) Method

ExeuteSingleCommandWithtoutXML() public method

public ExeuteSingleCommandWithtoutXML ( string command = "" ) : void
command string
return void
        public void ExeuteSingleCommandWithtoutXML(string command = "")
        {
            if (command != null && command.Length > 0)
            {
                cmd = new CommandRequest();
                cmd.CommandSyntax = command;
            }
            if (cmd.CommandSyntax == null || cmd.CommandSyntax.Length < 1)
            {
                cmd = new CommandRequest();
                cmd.CommandSyntax = "print('No command to execute')";
            }

            if (cmd.CommandSyntax.Contains("BSkyReloadDataset("))// if its relaod dataset commmand then prepare some parameter before executing the command
            {
                DataSource tempds = UIController.GetActiveDocument();
                string filename = tempds.FileName.Replace("\\", "/");
                string filetype = tempds.FileType;
                string temp = new string(cmd.CommandSyntax.ToCharArray());

                cmd.CommandSyntax = temp.Replace("fullpathfilename", "fullpathfilename='" + filename + "'").Replace("filetype", "filetype='" + filetype + "'"); ;

                //Restting split if all data and attributes are loaded 
                int idx = temp.IndexOf("=", temp.IndexOf("loaddataonly")); // index of  '=' after 'loaddataonly'
                int idxcomma = temp.IndexOf(",", temp.IndexOf("loaddataonly")); // index of  ',' after 'loaddataonly'
                string boolvalue = temp.Substring(idx + 1, idxcomma - idx - 1).Trim();
                if (boolvalue.Equals("FALSE"))//loaddataonly = false then we need to reset SPLIT in C# also
                {
                    OutputHelper.DeleteGlobalObject(string.Format("GLOBAL.{0}.SPLIT", UIController.GetActiveDocument().Name));
                }
            }
            //retval = analytics.Execute(cmd);
            if (bdt != null)
                if (!bdt.IsBatchCommand && bdt.IsCommandOnly && !bdt.IsXMLDefined && !cmd.CommandSyntax.Contains("BSkySetDataFrameSplit("))
                {
                    SendToOutputWindow(dialogTitle, cmd.CommandSyntax);
                    ExecuteInSyntaxEditor(true, dialogTitle);//GenerateOutputTablesForNonXAML(null);// ExecuteXMLDefinedDialog();
                }

            if (cmd.CommandSyntax.Contains("BSkySortDataframe(") || cmd.CommandSyntax.Contains("BSkyComputeExpression(") ||
                         cmd.CommandSyntax.Contains("BSkyRecode("))
            {
                retval = analytics.Execute(cmd);
                OutputHelper.AnalyticsData.Result = retval;//putting latest DOM
                string[,] ew = OutputHelper.GetBSkyErrorsWarning(1, "normal");//08Nov2014

                if (cmd.CommandSyntax.Contains("BSkySortDataframe")) //11Apr2014 putting sort icon
                {
                    //single column logic
                    //int startidx = cmd.CommandSyntax.IndexOf("'");
                    //int endidx= cmd.CommandSyntax.IndexOf("'", startidx+1);
                    //int leng = endidx - startidx-1;
                    //string colname = cmd.CommandSyntax.Substring(startidx+1, leng);

                    //sort order 14Apr2014
                    string srtodr = string.Empty;
                    // descending=TRUE in command. There is just 1 boolean in sort so this 'if' will work
                    if (cmd.CommandSyntax.Contains("TRUE"))
                        srtodr = "desc";
                    else
                        srtodr = "asc";

                    //mulitiple col logic
                    List<string> collst = new List<string>();
                    int startidx = cmd.CommandSyntax.IndexOf("c(");
                    if (startidx == -1) //no items in target listbox. No need of this if sort dialog has OK disabled when no items in target
                    {
                        return;
                    }
                    int endidx = cmd.CommandSyntax.IndexOf(")", startidx + 1);
                    int leng = endidx - startidx - 1;
                    string selcols = cmd.CommandSyntax.Substring(startidx + 2, leng - 1).Replace("'", "");// +2 is the length of "c(", -1 for )
                    string[] cols = selcols.Split(',');
                    for (int j = 0; j < cols.Length; j++) //string s in cols)
                    {
                        collst.Add(cols[j]);
                    }
                    RefreshGrids(collst, srtodr);
                }
                else
                {
                    //testing something. If success, we dont need this. RefreshGrids();
                }

                //16Apr2014
                //must be excuted at the end after data is reloaded otherwise split is not refresh in statusbar. 
                if (cmd.CommandSyntax.Contains("BSkyReloadDataset("))
                {
                    Refresh_Statusbar();
                }

                ////Finally show messages in output
                //SendToOutputWindow(dialogTitle, cmd.CommandSyntax);
                //Show errors if any 08Nov2014
                if (ew != null && ew[0, 0] != null)
                {
                    //SendToOutputWindow("", ew[0, 2]);
                    CommandOutput ewmsg = new CommandOutput();
                    ewmsg.NameOfAnalysis = "Errors/Warnings";
                    ewmsg.IsFromSyntaxEditor = false;

                    AUParagraph ewtypeaup = new AUParagraph();
                    ewtypeaup.FontSize = BSkyStyler.BSkyConstants.TEXT_FONTSIZE;//App.TEXT_FONTSIZE;
                    ewtypeaup.Text = (ew[0, 0] != null)?ew[0, 0]:"no type info";
                    ewtypeaup.ControlType = "Type:";
                    ewmsg.Add(ewtypeaup);

                    AUParagraph usrmsgaup = new AUParagraph();
                    usrmsgaup.FontSize = BSkyStyler.BSkyConstants.TEXT_FONTSIZE;//App.TEXT_FONTSIZE;
                    usrmsgaup.Text = (ew[0, 1] != null) ? ew[0, 1] : "no user message info";
                    usrmsgaup.ControlType = "User Message:";
                    ewmsg.Add(usrmsgaup);

                    AUParagraph rmsgaup = new AUParagraph();
                    rmsgaup.FontSize = BSkyStyler.BSkyConstants.TEXT_FONTSIZE;//App.TEXT_FONTSIZE;
                    rmsgaup.Text = (ew[0, 2] != null) ? ew[0, 2] : "no R message info";
                    rmsgaup.ControlType = "R Message:";
                    ewmsg.Add(rmsgaup);

                    AddToSyntaxSession(ewmsg);
                }
            }
        }

Usage Example

        private void ExecuteOtherCommand(OutputWindow ow, string stmt)
        {

            if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Before Executing in R.", LogLevelEnum.Info);


            #region Check open close brackets before executing
            string unbalmsg;
            if (!AreBracketsBalanced(stmt, out unbalmsg))//if unbalanced brackets
            {
                CommandRequest errmsg = new CommandRequest();
                string fullmsg = "Error : " + unbalmsg;
                errmsg.CommandSyntax = "write(\"" + fullmsg.Replace("<", "&lt;").Replace('"', '\'') + "\",fp)";//
                analytics.ExecuteR(errmsg, false, false); //for printing command in file
                return;
            }
            #endregion
            ///if command is for loading dataset //
            if (stmt.Contains("UAloadDataset"))
            {
                int indexofopening = stmt.IndexOf('(');
                int indexofclosing = stmt.IndexOf(')');
                string[] parameters = stmt.Substring(indexofopening + 1, indexofclosing - indexofopening - 2).Split(',');
                string filename = string.Empty;
                foreach (string s in parameters)
                {
                    if (s.Contains('/') || s.Contains('\\'))
                        filename = s.Replace('\"', ' ').Replace('\'', ' ');
                }
                if (filename.Contains("="))
                {
                    filename = filename.Substring(filename.IndexOf("=") + 1);
                }
                FileOpenCommand fo = new FileOpenCommand();
                fo.FileOpen(filename.Trim());
                return;
            }

            object o = null;
            CommandRequest cmd = new CommandRequest();

            if (stmt.Contains("BSkySortDataframe(") ||
                stmt.Contains("BSkyComputeExpression(") || stmt.Contains("BSkyRecode("))
            {
                CommandExecutionHelper auacb = new CommandExecutionHelper();
                UAMenuCommand uamc = new UAMenuCommand();
                uamc.bskycommand = stmt;
                uamc.commandtype = stmt;
                auacb.ExeuteSingleCommandWithtoutXML(stmt);//auacb.ExecuteSynEdtrNonAnalysis(uamc);
                auacb.Refresh_Statusbar();
                //auacb = null;
            }
            else
            {

                if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Executing in R.", LogLevelEnum.Info);

 
                 isVariable(ref stmt);///for checking if its variable then it must be enclosed within print();
                                      
                //27May2015 check if command is graphic and get its height width and then reopen graphic device with new dimensions
                 if (lastcommandwasgraphic)//listed graphic
                 {
                     if (imgDim!=null && imgDim.overrideImgDim)
                     {
                         CloseGraphicsDevice();
                         OpenGraphicsDevice(imgDim.imagewidth, imgDim.imageheight); // get image dimenstion from external source for this particular graphic.
                     }
                 }


                cmd.CommandSyntax = stmt;// command 
                o = analytics.ExecuteR(cmd, false, false);   //// get Direct Result and write in sink file

                CommandRequest cmdprn = new CommandRequest();
                if (o != null && o.ToString().Contains("Error"))//for writing some of the errors those are not taken care by sink.
                {
                    cmdprn.CommandSyntax = "write(\"" + o.ToString() + "\",fp)";// http://www.w3schools.com/xml/xml_syntax.asp
                    o = analytics.ExecuteR(cmdprn, false, false); /// for printing command in file
                    
                    ///if there is error in assignment, like RHS caused error and LHS var is never updated
                    ///Better make LHS var null.
                    string lhvar = string.Empty;
                    GetLeftHandVar(stmt, out lhvar);
                    if (lhvar != null)
                    {
                        cmd.CommandSyntax = lhvar+" <- NULL";// assign null 
                        o = analytics.ExecuteR(cmd, false, false);
                    }
                }
            }

            if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: After Executing in R.", LogLevelEnum.Info);

            
        }