protected override void OnExecute(object param) { //get the reference of output window container. If container is empty, a new output window // will be created by Resolve() [ it was found that its created on the fly, you cant use debug to // step into output window creation ] OutputWindowContainer owc = (LifetimeService.Instance.Container.Resolve <IOutputWindowContainer>()) as OutputWindowContainer; OutputWindow ow = owc.ActiveOutputWindow as OutputWindow; //get currently active window // if 'open' is invoked from specific output window. (it can be active or non-active output window) // Then output needs to thrown to this specific output window only. if (param != null) { UAMenuCommand uamc = (UAMenuCommand)param; if (uamc.commandformat.Length > 0) { ow = owc.GetOuputWindow(uamc.commandformat) as OutputWindow;// get specific output window. } } OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = FileNameFilter; bool?output = openFileDialog.ShowDialog(Application.Current.MainWindow); if (output.HasValue && output.Value) { // Adding analysis from file to the active output window ow.AddAnalyisFromFile(openFileDialog.FileName); } }
protected virtual void OnPreExecute(object param) { PreExecuteSub(); UAMenuCommand command = (UAMenuCommand)param; ///Store command for "History" menu // 04Mar2013 TemplateFileName = command.commandtemplate;// @".\Config\OneSampleCommand.xaml"; }
private void GenerateOutputTablesForNonXAML(object param) { if (param != null) { UAMenuCommand command = (UAMenuCommand)param; cmd = new CommandRequest(); cmd.CommandSyntax = command.commandformat; } retval = analytics.Execute(cmd); //ExecuteBSkyCommand(true); ExecuteAnalysisCommands(); //fixed on 19Apr2014 for list of list formatting using BSkyFormat and BSkyFormat2 }
//Save executed command in History private void SaveInHistory() { ///Store executed command in "History" menu /// 04March2013 UAMenuCommand command = (UAMenuCommand)parameter; Window1 appWindow = LifetimeService.Instance.Container.Resolve <Window1>(); if (ds != null) { appWindow.History.AddCommand(ds.Name, command); } }
public bool ContainsDialog(DashBoardItem di) { UAMenuCommand uamc = (UAMenuCommand)di.CommandParameter; //BlueSky.Services.UAMenuCommand string name = (uamc.commandtemplate != null && uamc.commandtemplate.Length > 1) ? uamc.commandtemplate : uamc.text; if (_dialoglist.Contains(name)) { return(true); } else { return(false); } }
/// <summary> /// Creating clone of Output menu from App's main window. The section that shows names of each output window in current session. /// </summary> private void CreateClone()//List<DashBoardItem> di) { MenuItem output_menu = null; if (allOutputMenus.Count > 0) { output_menu = allOutputMenus[0];//grab the first menu.(this should be from Apps main window) } if (output_menu.Header.ToString() == BSky.GlobalResources.Properties.Resources.OutputMenu) { MenuItem mi1 = null; //Separator spr; foreach (object objmi in output_menu.Items) /// windownames { if (objmi.GetType().Name == "MenuItem") { mi1 = objmi as MenuItem; } //else if (objmi.GetType().Name == "Separator") // spr = objmi as Separator; /// default items are already being created /// if (mi1 != null && (mi1.Header.ToString().Equals(BSky.GlobalResources.Properties.Resources.NewOutputWin) || mi1.Header.ToString().Equals(BSky.GlobalResources.Properties.Resources.OpenOutput) || mi1.Header.ToString().Equals(BSky.GlobalResources.Properties.Resources.SaveOutput)) || (objmi.GetType().Name == "Separator")) { continue; } //////creating clone//// DashBoardItem item = new DashBoardItem(); item.Command = new SelectOutputWindowCommand(); UAMenuCommand uamc = new UAMenuCommand(); //01Aug2012. There was no 'new' before uamc.commandformat = mi1.Header.ToString(); //window name is key. Action shud b taken on this. uamc.commandoutputformat = ""; uamc.commandtemplate = ""; uamc.commandtype = ""; item.CommandParameter = uamc; item.isGroup = false; item.Name = mi1.Header.ToString(); //this should also be the key MenuItem createdmi = CreateItem(item); createdmi.Icon = mi1.Icon; outputmenu.Items.Add(createdmi); } } }
private DashBoardItem CreateItem(XmlNode node) { DashBoardItem item = new DashBoardItem(); item.Name = GetAttributeString(node, "text"); item.isGroup = node.HasChildNodes; if (node.HasChildNodes) { item.Items = new List <DashBoardItem>(); foreach (XmlNode child in node.ChildNodes) { item.Items.Add(CreateItem(child)); } } else { UAMenuCommand cmd = new UAMenuCommand(); cmd.commandtype = GetAttributeString(node, "command"); if (string.IsNullOrEmpty(cmd.commandtype)) { cmd.commandtype = typeof(AUAnalysisCommandBase).FullName; } cmd.commandtemplate = GetAttributeString(node, "commandtemplate"); cmd.commandformat = GetAttributeString(node, "commandformat"); cmd.commandoutputformat = GetAttributeString(node, "commandoutputformat"); cmd.text = GetAttributeString(node, "text"); //04mar2013 //cmd.id = GetAttributeString(node, "id"); //04mar2013 //cmd.owner = GetAttributeString(node, "owner"); //04mar2013 item.Command = CreateCommand(cmd); item.CommandParameter = cmd; #region 11Jun2015 Set icon fullpathfilename item.iconfullpathfilename = GetAttributeString(node, "icon"); string showicon = GetAttributeString(node, "showtoolbaricon"); if (showicon == null || showicon.Trim().Length == 0 || !showicon.ToLower().Equals("true")) { item.showshortcuticon = false; } else { item.showshortcuticon = true; } #endregion } return(item); }
//Add executed command per Dataset public void AddCommand(string DatasetName, UAMenuCommand Command) { //Creating a copy of command for putting it in "History" menu UAMenuCommand uamc = new UAMenuCommand(); // new obj needed, because same obj can't be child at two places. uamc.commandformat = Command.commandformat; uamc.commandoutputformat = Command.commandoutputformat; uamc.commandtemplate = Command.commandtemplate; uamc.commandtype = Command.commandtype; //29Mar2013 //If History Menu text is not present. Dont add this command to "History" menu if (Command.text == null || Command.text.Length < 1) { return; } uamc.text = Command.text;//Command name shown in "History" menu //now create menuitem for each command and add to "History" menu DashBoardItem item = new DashBoardItem(); item.Command = new AUAnalysisCommandBase(); // should point to AUAnalysisCommandBase item.CommandParameter = uamc; item.isGroup = false; item.Name = uamc.text;// MenuName MenuItem newmi = CreateItem(item); //Check if command already in history menu /// bool ExistsInHistory = false; int miIndex = 0; foreach (MenuItem mi in commandhistmenu.Items) { if (mi.Header == newmi.Header)//command already in History { ExistsInHistory = true; break; } miIndex++; } // Adding command with "latest executed on top" in menu /// if (ExistsInHistory) { commandhistmenu.Items.RemoveAt(miIndex); } commandhistmenu.Items.Insert(0, newmi);//Adding to "History" menu }
//this is binding the 'Make Predictions' dialog to 'Score' button in GetModelsControl control. private DashBoardItem ScoreCommand() { DashBoardItem item = new DashBoardItem(); UAMenuCommand cmd = new UAMenuCommand(); cmd.commandtype = "BlueSky.Commands.Analytics.TTest.AUAnalysisCommandBase"; cmd.commandtemplate = BSkyAppData.RoamingUserBSkyConfigL18nPath + "Make Predictions.xaml"; cmd.commandformat = ""; cmd.commandoutputformat = BSkyAppData.RoamingUserBSkyConfigL18nPath + "Make Predictions.xml"; cmd.text = "Make Predictions"; item.Command = CreateCommand(cmd); item.CommandParameter = cmd; return(item); }
private ICommand CreateCommand(UAMenuCommand cmd) { Type commandTypeObject = null; ICommand command = null; try { commandTypeObject = Type.GetType(cmd.commandtype); command = (ICommand)Activator.CreateInstance(commandTypeObject); } catch { //Create new command instance using default command dispatcher logService.WriteToLogLevel("Could not create command. " + cmd.commandformat, LogLevelEnum.Error); } return(command); }
//remove executed command per Dataset public void RemoveCommand(string DatasetName, UAMenuCommand Command) { //Check if command already in history menu /// bool ExistsInHistory = false; int miIndex = 0; foreach (MenuItem mi in commandhistmenu.Items) { if (mi.Header.ToString() == Command.text)//command already in History { ExistsInHistory = true; break; } miIndex++; } // Adding command with "latest executed on top" in menu /// if (ExistsInHistory) { commandhistmenu.Items.RemoveAt(miIndex); } }
/// <summary> /// Creating clone of Output menu from App's main window. The section that shows names of each output window in current session. /// </summary> private void CreateClone()//List<DashBoardItem> di) { MenuItem output_menu = null; if (allOutputMenus.Count > 0) { output_menu = allOutputMenus[0];//grab the first menu.(this should be from Apps main window) } if (output_menu.Header.ToString() == "Output") { foreach (MenuItem mi in output_menu.Items) /// windownames { /// default items are already being created /// if (mi.Header.ToString().Equals("New Output Window") || mi.Header.ToString().Equals("Open Output") || mi.Header.ToString().Equals("Save Output") || mi.Header.GetType() == typeof(Separator)) { continue; } //////creating clone//// DashBoardItem item = new DashBoardItem(); item.Command = new SelectOutputWindowCommand(); UAMenuCommand uamc = new UAMenuCommand(); //01Aug2012. There was no 'new' before uamc.commandformat = mi.Header.ToString(); //window name is key. Action shud b taken on this. uamc.commandoutputformat = ""; uamc.commandtemplate = ""; uamc.commandtype = ""; item.CommandParameter = uamc; item.isGroup = false; item.Name = mi.Header.ToString(); //this should also be the key MenuItem createdmi = CreateItem(item); createdmi.Icon = mi.Icon; outputmenu.Items.Add(createdmi); } } }
//// Adding new output windows //// public void AddOutputMenuItem(string outwindowname) { DashBoardItem item = new DashBoardItem(); item.Command = new SelectOutputWindowCommand(); UAMenuCommand uamc = new UAMenuCommand(); //01Aug2012. There was no 'new' before uamc.commandformat = outwindowname; //window name is key. Action shud b taken on this. uamc.commandoutputformat = ""; uamc.commandtemplate = ""; uamc.commandtype = ""; item.CommandParameter = uamc; item.isGroup = false; item.Name = outwindowname;//this should also be the key foreach (MenuItem output_menu in allOutputMenus) { if (output_menu.Header.ToString() == BSky.GlobalResources.Properties.Resources.OutputMenu) { output_menu.Items.Add(CreateItem(item)); } } CheckOutputMenuItem(outwindowname);//putting a check or alphabet to show which one is active }
protected override void OnPreExecute(object param) { UAMenuCommand command = (UAMenuCommand)param; windowname = command.commandformat;// getting windowname from commandformat }
public const String FileNameFilter = "BSky Format, that can be opened in Output Window later (*.bsoz)|*.bsoz|Comma Seperated (*.csv)|*.csv|HTML (*.html)|*.html|PDF (*.pdf)|*.html"; //BSkyOutput protected override void OnExecute(object param) { /// Get the refrence of the output window container OutputWindowContainer owc = (LifetimeService.Instance.Container.Resolve <IOutputWindowContainer>()) as OutputWindowContainer; OutputWindow ow; if (owc.Count < 1) //28Feb2013 If there is no output window, an error/wrning message must b shown { MessageBox.Show("There is no output window."); return; } ow = owc.ActiveOutputWindow as OutputWindow; //get currently active window //29OCt2013 Saving all output in .bso ////if (!ow.IsOneOrMoreSelected())//24Jan2013 ////{ //// MessageBox.Show("Please select at least one of the output, for saving."); //// ow.BringOnTop(); //// return; ////} // if 'Save' is invoked from specific output window. (it can be active or non-active output window) // Then dump should be performed on this specific output window only. if (param != null) { UAMenuCommand uamc = (UAMenuCommand)param; if (uamc.commandformat.Length > 0) { ow = owc.GetOuputWindow(uamc.commandformat) as OutputWindow;// get specific output window. } } SaveFileDialog saveasFileDialog = new SaveFileDialog(); saveasFileDialog.Filter = FileNameFilter; bool?output = saveasFileDialog.ShowDialog(Application.Current.MainWindow); if (output.HasValue && output.Value) { C1.WPF.FlexGrid.FileFormat fileformat = C1.WPF.FlexGrid.FileFormat.Html; bool extratags = false; // false means dont save extratags.(only for .CSV .HTML) if (saveasFileDialog.FilterIndex == 1) { extratags = true;// save as HTML with extratags (.bso) } else if (saveasFileDialog.FilterIndex == 2) { fileformat = C1.WPF.FlexGrid.FileFormat.Csv; // save as CSV(.csv) } else if (saveasFileDialog.FilterIndex == 3) { fileformat = C1.WPF.FlexGrid.FileFormat.Html; // save as HTML without extratags (.html) } else if (saveasFileDialog.FilterIndex == 4) // save first as HTML and then use 3rd party library to change it to PDF and delte HTML file { fileformat = C1.WPF.FlexGrid.FileFormat.Html; } //following three line for testing only. Remove or comment them later //IConfigService conService = LifetimeService.Instance.Container.Resolve<IConfigService>(); //string myfname=conService.AppSettings.Get("tempfolder"); //saveasFileDialog.FileName = myfname; //23May2015 Delete file if it already exists. We need this because for HTML file format the same file is //opened and more output is appended to it and thus added more HTML and BODY tags to same files, which is //not a valid Html syantax. HTML file must have only one HTML and BODY tags. //Even though HTML browsers may not report this error and may ignore this completely, but in long run //wrong syntax may cause some issues. //If you want to save output to a file and keep appending to it, then you must write some extra logic to //fix this multiple HTML/BODY tag issue. May be edit file yourself before saving it again after appending. //Right now easy option is to delete the file and create a new one. bool fileExists = System.IO.File.Exists(saveasFileDialog.FileName); if (fileExists && saveasFileDialog.OverwritePrompt) { //try deleting file, if allowed( if you have previliges) try { System.IO.File.Delete(saveasFileDialog.FileName); } catch (Exception ex) { logService.WriteToLogLevel("Save output: Deleting existing file error: " + ex.Message, LogLevelEnum.Error); } } //dump currently active window in the choosen format and specified filename ow.DumpAllAnalyisOuput(saveasFileDialog.FileName, fileformat, extratags); //28May2015 for PDF. Save as HTML done above. Now take HTML and convert to PDF using 3rd party dlls //Now delete HTML if (saveasFileDialog.FilterIndex == 4) { //chose right extension (ie.. PDF) string pdfFileName = saveasFileDialog.FileName.Substring(0, saveasFileDialog.FileName.LastIndexOf(".html")) + ".pdf"; if (pdfFileName != null) { HTML2PDF(saveasFileDialog.FileName, pdfFileName); } //delete HTML if (System.IO.File.Exists(saveasFileDialog.FileName)) { try { System.IO.File.Delete(saveasFileDialog.FileName); string imagefilename; for (int i = 1; i <= 100; i++)//delete images if any { imagefilename = saveasFileDialog.FileName + "image" + i + ".png"; if (System.IO.File.Exists(imagefilename)) { System.IO.File.Delete(imagefilename); } else { break; } } } catch (Exception ex) { } } } } }
////// For Analysis Command Execution from Syntax Editor ///// public void ExecuteSyntaxEditor3(object param, bool selectedForDump) { parameter = param; OnPreExecute(parameter); if (!canExecute) { return; } object obj = null; string dialogcommandstr = null; try { //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"); xmlr.MoveToAttribute("CommandString"); dialogcommandstr = xmlr.Value.Replace(" ", string.Empty).Replace('\"', '\''); xmlr.Close(); obj = System.Windows.Markup.XamlReader.Load(XmlReader.Create(TemplateFileName)); } catch (Exception ex) { MessageBox.Show("Could not create template from " + TemplateFileName); logService.WriteToLogLevel("SynEdtr:Could not create template from " + TemplateFileName, LogLevelEnum.Error, ex); return; } element = obj as FrameworkElement; window = new BaseOptionWindow(); window.Template = element; element.DataContext = this; // loading vars in left listbox(source) ///window.ShowDialog(); commandwindow = element; ////////////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)"; 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 (!pair.Key.Contains("%")) { OutputHelper.SetValueFromSynEdt(element, pair.Key, pair.Value); } } //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) //IAnalyticsService analytics = LifetimeService.Instance.Container.Resolve<IAnalyticsService>(); //IConfigService confService = LifetimeService.Instance.Container.Resolve<IConfigService>();//23nov2012 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 UAReturn retval = null; //retval = new UAReturn(); retval.Data = LoadAnalysisBinary(); #region Execute BSky command try { retval = analytics.Execute(cmd); // RService called and DOM returned for Analysis commands cmd.CommandSyntax = command.commandtype; ////for header area ie NOTES //SaveAnalysisBinary(retval.Data); ///Added by Anil///07Mar2012 bool myrun = false; if (cmd.CommandSyntax.Contains("BSkySetDataFrameSplit("))///executes when SPLIT is fired from menu { bool setsplit = false; int startind = 0; if (cmd.CommandSyntax.Contains("col.names")) { startind = cmd.CommandSyntax.IndexOf("c(", cmd.CommandSyntax.IndexOf("col.names"));// index of c( } else { startind = cmd.CommandSyntax.IndexOf("c(");// index of c( } int endind = cmd.CommandSyntax.IndexOf(")", startind); int len = endind - startind + 1; // finding the length of c(......) string str = cmd.CommandSyntax.Substring(startind, len); // this will contain c('tg0','tg1') or just c() string ch = null; if (str.Contains("'")) { ch = "'"; } if (str.Contains('"')) { ch = "\""; } if (ch != null && ch.Length > 0) { int i = str.IndexOf(ch); int j = -1; if (i >= 0) { j = str.IndexOf(ch, i + 1); } if (j < 0) { j = i + 1; } string sub = str.Substring(i + 1, (j - i - 1)).Trim(); if (i < 0) { i = str.IndexOf("'"); } if (i >= 0) { if (sub.Length > 0) { setsplit = true; } } } ////////// Setting/Unsetting Macro for SPLIT ////////// if (setsplit) { OutputHelper.AddGlobalObject(string.Format("GLOBAL.{0}.SPLIT", UIController.GetActiveDocument().Name), element); return;// no need to do any thing further } else // unset split { OutputHelper.DeleteGlobalObject(string.Format("GLOBAL.{0}.SPLIT", UIController.GetActiveDocument().Name)); return;// no need to do any thing further } } //////////////////////////// } catch (Exception ex) { MessageBox.Show("Couldn't Execute the command"); logService.WriteToLogLevel("Couldn't Execute the command", LogLevelEnum.Error, ex); return; } #endregion //UAReturn retval = new UAReturn(); retval.Success = true; AnalyticsData data = new AnalyticsData(); data.SelectedForDump = selectedForDump; //10Jan2013 data.PreparedCommand = cmd.CommandSyntax; //storing command data.Result = retval; data.AnalysisType = cmd.CommandSyntax; //"T-Test"; For Parent Node name 02Aug2012 data.InputElement = element; data.DataSource = ds; data.OutputTemplate = ((UAMenuCommand)parameter).commandoutputformat; UIController.AnalysisComplete(data); } } //OnPostExecute(parameter); }
private DashBoardItem CreateItem(XmlNode node) { DashBoardItem item = new DashBoardItem(); item.ID = GetAttributeString(node, "id");//02Oct2017 item.Name = GetAttributeString(node, "text"); item.isGroup = node.HasChildNodes; if (node.HasChildNodes) { item.Items = new List <DashBoardItem>(); foreach (XmlNode child in node.ChildNodes) { item.Items.Add(CreateItem(child)); } } else { UAMenuCommand cmd = new UAMenuCommand(); cmd.commandtype = GetAttributeString(node, "command"); if (string.IsNullOrEmpty(cmd.commandtype)) { cmd.commandtype = typeof(AUAnalysisCommandBase).FullName; } //09Oct2017 //First we need to convert dialogs for support localization. Say for supporting German (de-DE) first //the source dialogs must be opened in Dialog Designer and saved after changing to German. //Then Using Dialog-Installer user with German locale should install the dialogs by Overwriting the //exisitng ones. This will overwrite the dialogs in 'Config/de-DE' folder replacing US dialogs. //Now about the following code: //During developement and testing phase we need postfix CulterName below But ones the German user overwrite-install //his dialogs the menu.xml will have 'de-DE' included in menu.xml for XAML/XML location (which was not there and //so we postfixed CultureName). Now after overwriting dialogs by German user we do not need CulterName postfixed. //So we can achieve this in two ways: //1) In Develop/Test phase keep the CultureName in following and once German Dialogs are installed/overwritten //then we can drop this CulterName postfix because now menu.xml will inculde 'de-De' for XAML/XML dialog path. //2) In this method we need to check if commandtemplate/commandoutputformat in following have two '/' or three '/' //if there are two '/' that means language foldernames are not yet included, so postfix CultureName. //If there ar three '/' that means language folder name is included and there is not need to postfix with CultureName. // string dialogPath = BSkyAppData.RoamingUserBSkyConfigPath + CultureName; string CmdTemplate = GetAttributeString(node, "commandtemplate"); //if (CountCharacter(CmdTemplate, '/') == 2) //{ // cmd.commandtemplate = GetAttributeString(node, "commandtemplate").Replace("/Config", "/Config/" + CultureName); //} //else //{ // cmd.commandtemplate = GetAttributeString(node, "commandtemplate"); //} //cmd.commandtemplate=cmd.commandtemplate.Replace("./Config", BSkyAppData.RoamingUserBSkyConfigPath); cmd.commandtemplate = string.Format(@"{0}\{1}", dialogPath, CmdTemplate); string CmdOutTemplate = GetAttributeString(node, "commandoutputformat"); //if (CountCharacter(CmdTemplate, '/') == 2) //{ // cmd.commandoutputformat = GetAttributeString(node, "commandoutputformat").Replace("/Config", "/Config/" + CultureName); //} //else //{ // cmd.commandoutputformat = GetAttributeString(node, "commandoutputformat"); //} //cmd.commandoutputformat = cmd.commandoutputformat.Replace("./Config", BSkyAppData.RoamingUserBSkyConfigPath); cmd.commandoutputformat = string.Format(@"{0}\{1}", dialogPath, CmdOutTemplate); //cmd.commandtemplate = GetAttributeString(node, "commandtemplate");//no localization //if-else above cmd.commandtemplate = GetAttributeString(node, "commandtemplate").Replace("/Config", "/Config/"+CultureName); //cmd.commandoutputformat = GetAttributeString(node, "commandoutputformat");//no localization //if-else above cmd.commandoutputformat = GetAttributeString(node, "commandoutputformat").Replace("/Config", "/Config/" + CultureName); cmd.commandformat = GetAttributeString(node, "commandformat"); cmd.text = GetAttributeString(node, "text"); //04mar2013 //cmd.id = GetAttributeString(node, "id"); //04mar2013 //cmd.owner = GetAttributeString(node, "owner"); //04mar2013 item.Command = CreateCommand(cmd); item.CommandParameter = cmd; #region 11Jun2015 Set icon fullpathfilename item.iconfullpathfilename = GetAttributeString(node, "icon"); string showicon = GetAttributeString(node, "showtoolbaricon"); if (showicon == null || showicon.Trim().Length == 0 || !showicon.ToLower().Equals("true")) { item.showshortcuticon = false; } else { item.showshortcuticon = true; } #endregion } return(item); }
////// For Analysis Command Execution from Syntax Editor /////28Mar2013 Using this one and not the other one below this method 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; }