public void Execute(object param)
        {
            IAdvancedLoggingService advlog = LifetimeService.Instance.Container.Resolve<IAdvancedLoggingService>(); ;//01May2015
            advlog.RefreshAdvancedLogging();
            AdvancedLogging = AdvancedLoggingService.AdvLog;//01May2015
            bool reloaddiskfiledata = false;
            //26Jun2014 isXmlTemplateDefined = false;
            parameter = param;////set Global var
            selectedForDump = false; //this parameter is only for Analytics(or non-Analytics)commands exected from Syntax Editor
            OnPreExecute(parameter);
            if (!canExecute)
            {
                canExecute = true;//06Nov2012.Fixed. if no dataset loaded.run one smpl. then load dataset. cant run one sampl now.
                return;
            }

            //for getting dialog xaml filename in logs.
            logService.WriteToLogLevel("XAML name : " + TemplateFileName, LogLevelEnum.Info);

            object obj = null;
            string dialogkey = string.Empty;//13Feb2013
            bool isOldDialog = false;//13Feb2013
            try
            {
                //Added by Aaron 06/15/2014
                BSkyCanvas.applyBehaviors = false;

                /// TemplateFilename /// for XAML filename
                dialogkey = TemplateFileName + UIController.GetActiveDocument().FileName + UIController.GetActiveDocument().Name;
                //if obj is already in dictionary for particular dataset which is currently open
                //then load obj from dictionary
                if (sdc.SessionDialogList.ContainsKey(dialogkey))
                {
                    obj = sdc.SessionDialogList[dialogkey];//gets the exisiting dialog
                    isOldDialog = true;
                }
                else//else use XAML dialog file and create obj and then store obj in dictionary with dataset name.
                {

                    //Added by Aaron 06/15/2014
                    string CurrentDatasetName = UIController.GetActiveDocument().Name;
                    string changedxaml = string.Empty;

                    changedxaml = FixRadioGroupNameUsingFiling(TemplateFileName, CurrentDatasetName + Path.GetFileName(TemplateFileName));
                    /////////////////////////////

                    XmlReader xmlReader = XmlReader.Create(new StringReader(changedxaml));
                    obj = System.Windows.Markup.XamlReader.Load(xmlReader);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not create template from " + TemplateFileName);
                logService.WriteToLogLevel("Could not create template from " + TemplateFileName, LogLevelEnum.Error, ex);
                //GenerateOutputTablesForNonXAML(param);
                return;
            }

            BSkyCanvas cs = obj as BSkyCanvas;
            BSkyCanvas.applyBehaviors = true;
            BSkyCanvas.first = cs;
            var converter = new System.Windows.Media.BrushConverter();

            cs.Background = (Brush)converter.ConvertFrom("#FFEEefFf");

            cmd = new CommandRequest();//set Global var
            element = obj as FrameworkElement;////set Global var
            window = new BaseOptionWindow();////set Global var
            window.Template = element;
            element.DataContext = this; // loading vars in left listbox(source)


            // If a form is displayed as modal, the code following the ShowDialog method is not executed  
            // until the dialog box is closed. However, when a form is shown as modeless, the code following 
            // the Show method is executed immediately after the form is displayed.
            if (!cs.Command)//26Jun2014 !isCommandOnlyDialog)
                window.ShowDialog();
            //Added by Aaron 07/20/2014
            //If GetOverwrittenVars returns true tells me that a user has selected a dataset or variable to be created by the analytical command but that 
            //variable already exists. Hence the command should not be executed.
            if (window.GetOverwrittenVars()) return;
            /////13Feb2013 Store obj in dictionary if not already there ////
            if (!isOldDialog)
            {
                sdc.SessionDialogList.Add(dialogkey, obj);
            }

            commandwindow = element;

            OutputHelper.Reset();
            OutputHelper.UpdateMacro("%DATASET%", UIController.GetActiveDocument().Name);
            //OutputHelper.UpdateMacro("%DATASET%", "bskyCurrentDatasetSplitSliceObj"); //09Jun2014 in case of split slice name is Dataset name

            if ((window.DialogResult.HasValue && window.DialogResult.Value) || cs.Command)
            {
                BSkyCanvas canvas = element as BSkyCanvas;

                if (canvas != null && !string.IsNullOrEmpty(canvas.CommandString))
                {
                    //following is important as its substituting params with values.
                    cmd.CommandSyntax = OutputHelper.GetCommand(canvas.CommandString, element);// can be used for "Paste" for syntax editor
                    if (cmd.CommandSyntax.Contains("BSkyReloadDataset("))// if its relaod dataset commmand then prepare some parameter before executing the command
                    {
                        reloaddiskfiledata = true;
                        SubstituteFilenameAndType();//get filename and file type of disk file that is supposed to get reloaded.

                    }
                    CollectDialogProperties(canvas); // get all dialog properties

                    ShowMouseBusy();

                    #region Loading Dialog's required R Packages //30Apr2015
                    //following single line just for testing. Comment it and uncomment next line for production.
                    //string pkgs = "zoo;sem;aa;;nlme;bb;class;"; 
                    string pkgs = dlgprop.RequiredRPacakges;
                    if (!string.IsNullOrEmpty(pkgs))
                    {
                        bool packageMissing = false;
                        string statmsg = LoadDialogRPacakges(pkgs, out packageMissing);//pass semi colon separated list of R packages.
                        if (statmsg.Trim().Length > 0 && (statmsg.ToLower().Contains("error") || packageMissing))
                        {
                            // statmsg has message like : XYZ package not found. Please install it from CRAN
                            string lastmsg = "\nPlease install the above mentioned R package(s).\nGo To Tools -> Package -> Install package from CRAN.\nInstall missing R packages and execute the dialog again.";
                            MessageBox.Show(canvas.Title + " needs the following R package(s):\n\n" + statmsg + lastmsg, "Error: Missing R Package(s)", MessageBoxButton.OK, MessageBoxImage.Stop);
                            logService.WriteToLogLevel("Dialog's required R package loading error:\n" + statmsg, LogLevelEnum.Error);
                            if (window != null)
                                window.Template = null; //13Feb2013 release the XAML object. ie obj is no more child of window.
                            HideMouseBusy();
                            return;//Skip dialog execution further.(as all required packages failed to load. And dialog commands will not execute properly)
                        }
                    }
                    #endregion

                    #region PASTE clicked on the dialog
                    //Check if OK or Syntax was clicked
                    if (window.Tag != null && window.Tag.ToString().Equals("Syntax"))//21Jan2013
                    {
                        PasteInOutputSyntax();//06May2015 PasteSyntax();
                    }
                    #endregion

                    #region OK clicked on the dialog
                    if ((window.Tag != null && window.Tag.ToString().Equals("Ok")) || dlgprop.IsCommandOnly)//26Jun2014 isCommandOnlyDialog)//21Jan2013 Dont use else if is Syntax stay dialog workaround is in use.
                    {
                        dialogTitle = (window.Title != null) ? window.Title : string.Empty;
                        string batchcommtitle = dialogTitle;

                        dsvs = UIController.GetActiveDocument().Variables;//list of exisiting vars in active dataset

                        try
                        {
                            string dlgcommands = string.Join(";", dlgprop.Commands);
                            if (dlgcommands.Contains("BSkyIndSmTTest") || dlgcommands.Contains("BSkyOneSmTTest") || dlgcommands.Contains("BSkyCrossTable"))
                            {
                                //30Apr2015 This is block is probably needed because 3 of our Template based dialogs have internal split handler.
                                cmd.CommandSyntax = GetSliceSubstitutedCommands(dlgprop.Commands, 1);
                                PrintDialogTitle(dialogTitle);//30Apr2015

                                if(AdvancedLogging)logService.WriteToLogLevel("ExtraLogs: before executing in Syntax.", LogLevelEnum.Info);


                                ExecuteInSyntaxEditor(true, dialogTitle);

                                if(AdvancedLogging)logService.WriteToLogLevel("ExtraLogs: after executing in Syntax.", LogLevelEnum.Info);


                            }
                            else
                            {
                                if(AdvancedLogging)logService.WriteToLogLevel("ExtraLogs: before executing as BatchCommand.", LogLevelEnum.Info);


                                //this can handle template based dialogs but split handling may get tricky. To make it
                                //work here, probably, turn off split handling from within these template based dialogs.
                                //this is just ahint, we nned to try and make sure.
                                ExecuteBatch(dlgprop.Commands); //Execute single and multiple commands as batch commands(ie..execute in Syntax)

                                if(AdvancedLogging)logService.WriteToLogLevel("ExtraLogs: after executing as BatchCommand.", LogLevelEnum.Info);


                            }

                            //15Jan2015
                            //Following was the original code.But 'if/else' was introduced above just to resctrict XML templated 
                            //dialog to run differently in case of split set.
                            if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: successful execution.", LogLevelEnum.Info);


                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Couldn't Execute the command");
                            logService.WriteToLogLevel("Couldn't Execute the command", LogLevelEnum.Error, e);
                            if (window != null)
                                window.Template = null; //25Mar2013 release the XAML object. ie obj is no more child of window.
                            return;
                        }
                        //save current dialog in 'History' menu
                        SaveInHistory();
                    }
                    #endregion

                    HideMouseBusy();
                }
            }

            // if its relaod dataset commmand then we need to refresh grid and status bar
            if (reloaddiskfiledata)// (cmd.CommandSyntax.Contains("BSkyReloadDataset("))
            {
                RefreshGridAndStatus();//uncomment this line if executing in Syntax. Comment it if executing using old method.
            }

            window.Template = null; //13Feb2013 release the XAML object. ie obj is no more child of window.
            OnPostExecute(parameter);
        }