public void ExecuteSyntaxEditor(object param, bool SelectedForDump)
{
parameter = param;//set Global var.
selectedForDump = SelectedForDump;//set Global var
OnPreExecute(param);
if (!canExecute) return;
object obj = null;
string dialogcommandstr = null;
string HistMenuText = string.Empty;//29Mar2013
try
{
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: dialog xaml:" + TemplateFileName, LogLevelEnum.Info);
//here TemplateFileName xaml will have same name as the analysis command function name
// say- function called frm SynEdtr was 'bsky.my.func()' then in bin\Config\
// dialog xaml, 'bsky.my.func.xaml' and
// output template file 'bsky.my.func.xml' must exist
// ie.. func name = xaml name = xml name
XmlReader xmlr = XmlReader.Create(TemplateFileName);
xmlr.ReadToFollowing("BSkyCanvas");
//Following commented code can be used to Add command to "History" menu when executed from Syntax Editor
//But "Title" from XAML may not same as "text" attr from menu.xml
//So the same command executed from Syntax Editor and Main App's menu will show duplicate
////xmlr.MoveToAttribute("Title");//29Mar2013 For "History" Text
////HistMenuText = xmlr.Value;//29Mar2013 For "History" Text
////UAMenuCommand uam = (UAMenuCommand)param;
////uam.text = HistMenuText;
////parameter = uam;//set Global var
xmlr.MoveToAttribute("CommandString");
dialogcommandstr = xmlr.Value.Replace(" ", string.Empty).Replace('\"', '\'');
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: dialog command string:" + dialogcommandstr, LogLevelEnum.Info);
xmlr.Close();
obj = System.Windows.Markup.XamlReader.Load(XmlReader.Create(TemplateFileName));
}
catch (Exception ex)
{
//18Aug2014 Supressing this message box as we dont need it. But we still pass message in log.
//MessageBox.Show("XAML missing or has improper format! Could not create template from " + TemplateFileName);
logService.WriteToLogLevel("SynEdtr:Could not create template from " + TemplateFileName, LogLevelEnum.Error, ex);
GenerateOutputTablesForNonXAML(param);
return;
}
//obj = GetSessionDialog(); // same dialog cant be used as its child of the another parent in AUAnalysisCommandBase
element = obj as FrameworkElement;
window = new BaseOptionWindow();
window.Template = element;
element.DataContext = this; // loading vars in left listbox(source)
///window.ShowDialog();
commandwindow = element;
{
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Dialog controls value mapping.", LogLevelEnum.Info);
////////////test///////
//// take two strings and then try to make merged dictionary. remove extra spaces. replace " with '
//string bksytemplate="bsky.CrossTable(x=c({Rows}),y=c({columns}),layers=c({layers}),datasetname='{%DATASET%}',chisq={chisq})";
//string bskycommand="bsky.CrossTable(x=c('store','contact'),y='regular',layers=c('gender'),datasetname='Dataset1',chisq=FALSE)";
//string dialogcommandstr = "bsky.one.sm.t.test(vars=c({SelectedVars}),mu={testValue},conf.level=0.89,datasetname='{%DATASET%}',missing=0)";
string bskycommand = ((UAMenuCommand)parameter).bskycommand.Replace(" ", string.Empty);//"bsky.one.sm.t.test(vars=c('tg0','tg2','tg3'),mu=30,conf.level=0.89,datasetname='Dataset1',missing=0)";
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Command:" + bskycommand, LogLevelEnum.Info);
Dictionary<string, string> dialogkeyvalpair = new Dictionary<string, string>();//like: key=mu, val= {testValue}
Dictionary<string, string> bskycommandkeyvalpair = new Dictionary<string, string>();//like: key=mu, val= 30
Dictionary<string, string> merged = new Dictionary<string, string>();//like: key=testValue, val = 30
OutputHelper.getArgumentSetDictionary(dialogcommandstr, dialogkeyvalpair);
OutputHelper.getArgumentSetDictionary(bskycommand, bskycommandkeyvalpair);
OutputHelper.MergeTemplateCommandDictionary(dialogkeyvalpair, bskycommandkeyvalpair, merged);
foreach (KeyValuePair<string, string> pair in merged)
{
if (AdvancedLogging)
{
string mapping = "Element:" + element.Name + ". Key:" + pair.Key + ". Value:" + pair.Value;
logService.WriteToLogLevel("ExtraLogs:\n" + mapping, LogLevelEnum.Info);
}
if (!pair.Key.Contains("%"))// This should only skip macros(words enclosed within %) and not other formats.
{
OutputHelper.SetValueFromSynEdt(element, pair.Key, pair.Value); //Filling dialog with values
}
}
}
//foreach (Match m in mc)
//{
// //Console.WriteLine(s.Index + " : " + s.ToString());// {SelectedVars} {testValue} {%DATASET%}
// if (!m.ToString().Contains("%"))
// {
// args = OutputHelper.getArgument(bskycommand, m.Index);
// uiElementName = m.ToString().Replace('{', ' ').Replace('}', ' ').Trim();
// OutputHelper.SetValueFromSynEdt(element, uiElementName, args);
// }
//}
//OutputHelper.SetValueFromSynEdt(element, "SelectedVars");
//OutputHelper.SetValueFromSynEdt(element, "testValue");
//For Chisq check box only
//FrameworkElement chkElement = element.FindName("chisq") as FrameworkElement;
if (true)//window.DialogResult.HasValue && window.DialogResult.Value)
{
//analytics can be sent from parent function(in SyntaxEditorWindow)
cmd = new CommandRequest();
OutputHelper.Reset();
OutputHelper.UpdateMacro("%DATASET%", UIController.GetActiveDocument().Name);
///////////for chisq //// 29Mar2012 ///
//if ((chkElement != null) && (bool)((chkElement as CheckBox).IsChecked))
// OutputHelper.UpdateMacro("%CHISQ%", "chisq");
/////////////for chisq //// 29Mar2012 ///
BSkyCanvas canvas = element as BSkyCanvas;
if (canvas != null && !string.IsNullOrEmpty(canvas.CommandString))
{
UAMenuCommand command = (UAMenuCommand)parameter;
cmd.CommandSyntax = command.commandformat;//OutputHelper.GetCommand(canvas.CommandString, element);// can be used for "Paste" for syntax editor
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Getting DOM", LogLevelEnum.Info);
retval = analytics.Execute(cmd); //ExecuteBSkyCommand(true);
ExecuteXMLDefinedDialog(cmd.CommandSyntax);//no need to pass parameters here. Just to match func signature
}
//16Apr2013 till this point command has already been executed. So now we store this command for "History"
// moved here from common function ExecuteBSkyCommand b'coz for command batch dialog SaveHistory should execute once.
//SaveInHistory(); // not sure if needed to be commented
}
//OnPostExecute(parameter);
//Cleanup. Remove Canvas children and make it null. then make Window.templace null
BSkyCanvas canv = element as BSkyCanvas;
int count = canv.Children.Count;
canv.Children.RemoveRange(0, count);
window.Template = null;
}