private List <ControlObject> GetControls(BSkyCanvas canvas) { List <ControlObject> lst = new List <ControlObject>(); foreach (Object obj in canvas.Children) { if (obj is IBSkyInputControl) { IBSkyInputControl ib = obj as IBSkyInputControl; lst.Add(new ControlObject() { Name = ib.Name, Type = ib.GetType().Name }); } if (obj is BSkyButton) { FrameworkElement fe = obj as FrameworkElement; BSkyCanvas cs = fe.Resources["dlg"] as BSkyCanvas; if (cs != null) { List <ControlObject> lstTemp = GetControls(cs); foreach (ControlObject co in lstTemp) { co.Parent = ((BSkyButton)obj).Text; } lst.AddRange(lstTemp); } } } return(lst); }
private void dlgexpander_Expanded(object sender, RoutedEventArgs e) { this.Width = this.Width + expanderWidth; dlgexpander.BorderBrush = Brushes.Black; object obj = this.Template; BSkyCanvas cs = obj as BSkyCanvas; dialoghelptext.Html = cs.HelpText; }
private bool checkDuplicateNameInRdGrp(BSkyCanvas canvas, string name) { string message; foreach (Object obj in canvas.Children) { // if (obj is IBSkyControl && obj != selectedElement) if (obj is IBSkyControl) { IBSkyControl ib = obj as IBSkyControl; //if (ib.Name == e.ChangedItem.Value.ToString()) if (ib.Name == name) { message = string.Format(BSky.GlobalResources.Properties.Resources.PlzEnterUniqueName, name); MessageBox.Show(message); // this.OptionsPropertyGrid.ResetSelectedProperty(); return(true); } } //05/18/2013 //Added by Aaron //Code below checks the radio buttons within each radiogroup looking for duplicate names if (obj is BSkyRadioGroup) { BSkyRadioGroup ic = obj as BSkyRadioGroup; StackPanel stkpanel = ic.Content as StackPanel; foreach (object obj1 in stkpanel.Children) { BSkyRadioButton btn = obj1 as BSkyRadioButton; if (btn.Name == name) { message = string.Format(BSky.GlobalResources.Properties.Resources.PlzEnterUniqueName, name); MessageBox.Show(message); return(true); } } } if (obj is BSkyButton) { FrameworkElement fe = obj as FrameworkElement; BSkyCanvas cs = fe.Resources["dlg"] as BSkyCanvas; if (cs != null) { if (checkDuplicateNameInRdGrp(cs, name)) { return(true); } } } } return(false); }
//Added by Aaron //01/15/2014 //Added by Aaron 05/06/2014 //When I am inspecting a dialog definition or previewing a dialog in dialog editor. I want to click on the HELP button and access the Help files //However the help files are not in the bin/config directory //Its only whenI install the dialog that the help files are in the binn/config directory //Also when you install the help files, we rename the help files to dialogname_1, dialogname_2. This ensures that we don't //accidently overide the help files of another command //This means when I am in the main application, I want the Help button to work differently for 2 cases //Case 1: click help on the dialog definition when inspecting the command. Here I launch the help files with their original name //from the temp directory //Case 2: click help on dialog displayed when executing an installed command //Here I launch the help files from the bin/config directory //This also allows me to use the same code to create the sub dialog mode in the execution of the dialog and the inspection //Case 3: //When I am in dialog editor and I am previewing a dialog definition, I just created //The help files need to be loaded from the original llocation where they exist private void help_Click(object sender, RoutedEventArgs e) { //System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:\Users\Aiden\Documents\Gipin.jpg"); //img.Tag = @"C:\Users\Aiden\Documents\Gipin.jpg"; //System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(); //info.FileName = ("mspaint.exe"); //info.Arguments = img.Tag.ToString(); // returns full path and name //System.Diagnostics.Process p1 = System.Diagnostics.Process.Start(info); BSkyCanvas cs = Template as BSkyCanvas; string path = null; if (BSkyCanvas.previewinspectMode == true) { if (cs.Helpfile != "urlOrUri") { path = Path.GetTempPath() + Path.GetFileName(cs.Helpfile); } else { path = cs.Helpfile; } try { System.Diagnostics.Process p1 = System.Diagnostics.Process.Start(path); } catch (System.ComponentModel.Win32Exception ex) { System.Windows.MessageBox.Show(ex.Message); } } else { //string path="c:\aaron\ab.bc"; if (cs.internalhelpfilename != "urlOrUri") { path = Path.GetFullPath(@".\Config\") + cs.internalhelpfilename; } else { path = cs.Helpfile; } // System.Diagnostics.Process p1 = System.Diagnostics.Process.Start(path); try { System.Diagnostics.Process p1 = System.Diagnostics.Process.Start(path); } catch (System.ComponentModel.Win32Exception ex) { System.Windows.MessageBox.Show(ex.Message); } } }
//public FrameworkElement Template //{ // get // { // if (Host.Children.Count > 0) // return Host.Children[0] as FrameworkElement; // else // return null; // } // set // { // if (value == null) // { // Host.Children.Clear();//13Feb2013 Delete all children. for testing and developing dialog session logic // return; // } // BSkyCanvas canvas = value as BSkyCanvas; // // canvas.CanExecuteChanged += new EventHandler<BSkyBoolEventArgs>(canvas_CanExecuteChanged); // if (canvas == null) // return; // if (!string.IsNullOrEmpty(canvas.Title)) // this.Title = canvas.Title; // else // this.Title = "Untitled Dialog"; // if (value.Width != double.NaN) // { // this.Host.Width = value.Width + 10; // this.Width = value.Width + 30; // } // if (value.Height != double.NaN) // { // this.Host.Height = value.Height + 25; // this.Height = value.Height + 85; // } // Host.Children.Add(value); // //Added 01/15/2014 // //This disables the help button on the canvas when the help file is empty // // if (canvas.Helpfile == null || canvas.Helpfile == string.Empty) help.IsEnabled = false; // } //} public void setSizeOfPropertyGrid() { BSkyCanvas cs = CanvasHost.Child as BSkyCanvas; int width = Convert.ToInt32(cs.Width); // int height = 100; CanvasPropertyGrid.Width = width; // CanvasPropertyGrid.Height = 200; // CanvasPropertyGrid.Size = new System.Drawing.Size(width,height ); // CanvasPropertyGrid.Width = width; }
//BSkyDependentListBox rg = selectedElement as BSkyDependentListBox; //// StackPanel sp = rg.Content as StackPanel; //DependentListBoxValueCollection col = w.ListBoxEntries; //int count = col.Count; //rg.Items.Clear(); //int i = 0; //foreach (DependentListBoxEntry entry in col) // rg.Items.Add(entry.entryName); //if (col.Count > 0) rg.SelectedIndex = 1; //05/18/2013 //Added by Aaron //Code below works as follows //Step 1: Outer loop, for each item in radio group, loop through the rest of the radio group, looking for a //duplicate name. If not found, look through the entire dialog and all sub-dialogs looking for a duplicate name. //If a duplicate name is found, show an error message and revert to the original state of the radiogroup. //Note: THIS FUNCTION STOPS PROCESSING AS SOON AS A DUPLICATE IS FOUND. THIS MEANS IF YOU HAVE ENTERED 6, VALUES AND THE //6TH VALUE IS A DUPLICATE, 5 VALUES WILL BE SAVED. //IF THE 1ST VALUE IS A DUPLICATE, ALL 6 VALUES ENTERED WILL BE LOST AND YOU WILL HAVE TO REENTER // for (i = 0; i < count; i++) //// foreach (object obj in col) // { // int j = 0; // j = i; // string message; // BSkyRadioButton tmp = col[i] as BSkyRadioButton; // while(j <count -1) // { // BSkyRadioButton tmp2 = col[j + 1] as BSkyRadioButton; // if (tmp.Name == tmp2.Name) // { // message = string.Format("You have already created a control with the name \"{0}\", please enter a unique name", tmp.Name); // MessageBox.Show(message); // // this.OptionsPropertyGrid.ResetSelectedProperty(); // return oldValue; // } // j = j + 1; // } // tmp.Margin = new Thickness(2); // tmp.GroupName = rg.Name; // if (!checkDuplicateNameInRdGrp(BSky.Controls.Window1.firstCanvas, tmp.Name)) // sp.Children.Add(tmp); // else return oldValue; // } // rg.Height = sp.Children.Count * 30 + 20; //private bool checkDuplicateNameInRdGrp(BSkyCanvas canvas, string name) //{ // string message; // foreach (Object obj in canvas.Children) // { // // if (obj is IBSkyControl && obj != selectedElement) // if (obj is IBSkyControl) // { // IBSkyControl ib = obj as IBSkyControl; // //if (ib.Name == e.ChangedItem.Value.ToString()) // if (ib.Name == name) // { // message = string.Format("You have already created a control with the name \"{0}\", please enter a unique name", name); // MessageBox.Show(message); // // this.OptionsPropertyGrid.ResetSelectedProperty(); // return true; // } // } // //05/18/2013 // //Added by Aaron // //Code below checks the radio buttons within each radiogroup looking for duplicate names // if (obj is BSkyRadioGroup) // { // BSkyRadioGroup ic = obj as BSkyRadioGroup; // StackPanel stkpanel = ic.Content as StackPanel; // foreach (object obj1 in stkpanel.Children) // { // BSkyRadioButton btn = obj1 as BSkyRadioButton; // if (btn.Name == name) // { // message = string.Format("You have already created a control with the name \"{0}\", please enter a unique name", name); // MessageBox.Show(message); // return true; // } // } // } // if (obj is BSkyButton) // { // FrameworkElement fe = obj as FrameworkElement; // BSkyCanvas cs = fe.Resources["dlg"] as BSkyCanvas; // if (cs != null) // { // if (checkDuplicateNameInRdGrp(cs, name)) return true; // } // } // } // return false; //} public FrameworkElement GetResource(BSkyMasterListBox selection, string name) { BSkyCanvas canvas = UIHelper.FindVisualParent <BSkyCanvas>(selection); foreach (FrameworkElement fe in canvas.Children) { if (fe.Name == name) { return(fe); } } return(null); }
public string GetCommand(BSkyCanvas canvas) { mylist.ItemsSource = GetControls(canvas); string val = txtCommand.Text; this.ShowDialog(); if (this.DialogResult.HasValue && this.DialogResult.Value) { return(txtCommand.Text); } else { return(val); } }
private void rhelpbutton_Click(object sender, RoutedEventArgs e) { object obj = this.Template; BSkyCanvas cs = obj as BSkyCanvas; string rhelp = cs.RHelpText; //in future, this can be semicolon separated list( if help on multiple functions is required). //now try launching R help if (!BSkyCanvas.dialogMode)//if not a dialog designer mode. ( Dialog is in execution rather than creation mode) { IAnalyticsService analytics = LifetimeService.Instance.Container.Resolve <IAnalyticsService>(); CommandRequest comreq = new CommandRequest(); comreq.CommandSyntax = "print(" + rhelp + ")";//"print(help(library))";// analytics.ExecuteR(comreq, false, false); } }
//Added by Aaron //01/15/2014 //Code below launches the help file in the default application for the Help file //Added by Aaron 05/06/2014 //When I am inspecting a dialog definition or previewing a dialog in dialog editor. I want to click on the HELP button and access the Help files //However the help files are not in the bin/config directory //Its only whenI install the dialog that the help files are in the binn/config directory //Also when you install the help files, we rename the help files to dialogname_1, dialogname_2. This ensures that we don't //accidently overide the help files of another command //This means when I am in the main application, I want the Help button to work differently for 2 cases //Case 1: click help on the dialog definition when inspecting the command. Here I launch the help files with their original name //from the temp directory //Case 2: click help on dialog displayed when executing an installed command //Here I launch the help files from the bin/config directory //This also allows me to use the same code to create the sub dialog mode in the execution of the dialog and the inspection //Case 3: //When I am in dialog editor and I am previewing a dialog definition, I just created //The help files need to be loaded from the original llocation where they exist private void help_Click(object sender, RoutedEventArgs e) { BSkyCanvas cs = Template as BSkyCanvas; string path = null; if (BSkyCanvas.previewinspectMode == true) { if (cs.Helpfile != "urlOrUri") { path = Path.GetTempPath() + Path.GetFileName(cs.Helpfile); } else { path = cs.Helpfile; } try { System.Diagnostics.Process p1 = System.Diagnostics.Process.Start(path); } catch (System.ComponentModel.Win32Exception ex) { System.Windows.MessageBox.Show(ex.Message); } } else { //string path="c:\aaron\ab.bc"; if (cs.internalhelpfilename != "urlOrUri") { //23Apr2015 path = Path.GetFullPath(@".\Config\") + cs.internalhelpfilename; path = Path.GetFullPath(string.Format(@"{0}", BSkyAppDir.RoamingUserBSkyConfigL18nPath)) + cs.internalhelpfilename;//23Apr2015 } else { path = cs.Helpfile; } try { System.Diagnostics.Process p1 = System.Diagnostics.Process.Start(path); } catch (System.ComponentModel.Win32Exception ex) { System.Windows.MessageBox.Show(ex.Message); } } }
private void Ok_Click(object sender, RoutedEventArgs e) { this.Tag = "Ok"; this.DialogResult = true; object obj = this.Template; BSkyCanvas cs = obj as BSkyCanvas; overwrittenvars = CheckForOverwrittenVars(cs); // string varnames = ""; // List<DataSourceVariable> varlst = UIController.GetActiveDocument().Variables; //// List<DataSourceVariable> varlst = UIController. // foreach (DataSourceVariable dsv in varlst) // { // varnames = varnames +", "+ dsv.Name; // } // MessageBox.Show("Variables:\n" + varnames); this.Close(); }
private void rhelpbutton_Click(object sender, RoutedEventArgs e) { object obj = this.Template; BSkyCanvas cs = obj as BSkyCanvas; string rhelp = cs.RHelpText; //in future, this can be semicolon separated list( if help on multiple functions is required). //27Sep2016 //First make sure therespective R package is loaded. If its not, the help wont work string pkgs = cs.RPackages; LoadDialogRPacakges(pkgs); //now try launching R help CommandRequest comreq = new CommandRequest(); comreq.CommandSyntax = "print(" + rhelp + ")";//"print(help(library))";// analytics.ExecuteR(comreq, false, false); }
private void Help_Click(object sender, RoutedEventArgs e) { string path; BSkyCanvas cs = CanvasHost.Child as BSkyCanvas; //string path="c:\aaron\ab.bc"; if (cs.Helpfile != "urlOrUri") { path = Path.GetTempPath() + Path.GetFileName(cs.Helpfile); } else { path = cs.Helpfile; } try { System.Diagnostics.Process p1 = System.Diagnostics.Process.Start(path); } catch (System.ComponentModel.Win32Exception ex) { System.Windows.MessageBox.Show(ex.Message); } }
////// 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; }
protected void CollectDialogProperties(BSkyCanvas canvas) { dlgprop = new BSkyDialogProperties(); dlgprop.RequiredRPacakges = canvas.RPackages;//30Apr2015 dlgprop.HandleSplits = true;// canvas.PROPERTYFORSPLITHERE; //if true handle splits for command only dialog, else not dlgprop.IsCommandOnly = canvas.Command; // command(no dialog) or dialog dlgprop.IsGraphic = false; dlgprop.IsGridRefresh = true; dlgprop.IsMacroUpdate = true; dlgprop.IsStatusBarRefresh = true; dlgprop.IsXMLDefined = (canvas.OutputDefinition != null && canvas.OutputDefinition.Length > 0) ? true : false; //string[] commands = cmd.CommandSyntax.Replace('\n', ';').Split(';'); if (cmd.CommandSyntax == null) cmd.CommandSyntax = string.Empty; dlgprop.Commands = cmd.CommandSyntax.Replace('\n', ';').Split(';'); dlgprop.DialogTitle = canvas.Title; CommandCountInBatch = dlgprop.Commands.Length; dlgprop.IsBatchCommand = (CommandCountInBatch > 1) ? true : false; }
void InspectBinding_Executed() { CommonFunctions cf = new CommonFunctions(); InspectDialog window = new InspectDialog(); System.Windows.Forms.DialogResult result; //Added by Aaron 05/11/2014 //Clearing up chainopen canvas as we are starting from a Blank Slate when ever we are inspecting a dialog //We alsodo it when we finish inspecting the dialog BSkyCanvas.chainOpenCanvas.Clear(); System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog(); dialog.Filter = "Xaml Document (*.bsky)|*.bsky"; result = dialog.ShowDialog(); object obj; string nameOfFile; if (result == System.Windows.Forms.DialogResult.OK) { string xamlfile = string.Empty, outputfile = string.Empty; cf.SaveToLocation(@dialog.FileName, Path.GetTempPath(), out xamlfile, out outputfile); if (!string.IsNullOrEmpty(xamlfile)) { FileStream stream = System.IO.File.Open(Path.Combine(Path.GetTempPath(), Path.GetFileName(xamlfile)), FileMode.Open); //FileStream stream = File.Open(Path.Combine(Path.GetTempPath(), xamlfile,FileMode.Open); try { //Added by Aaron 11/24/2013 //The line below is important as when the dialog editor is launched for some reason and I DONT know why //BSKYCanvas is invoked from the controlfactor and hence dialogMode is true, we need to reset BSkyCanvas.dialogMode = false; obj = XamlReader.Load(stream); //Added by Aaron 04/13/2014 //There are 3 conditions here, when I launch dialog editor //1. The first thing I do is open an existing dialog. Chainopencanvas.count=0 //2. I have an existing dialog open and I click open again. Chainopencanvas.count=2. The first dialog is empty as I clean the existing canvas and open a new one //3. I hit new the first time I open dialogeditor and then I hit open. Again,Chainopencanvas.count=2. The first dialog is empty as I clean the existing canvas and open a new one //The chainopencanvas at this point has 2 entries, one with an empty canvas as we have removed all the children //the other with the dialog we just opened //we remove the empty one //if (BSkyCanvas.chainOpenCanvas.Count > 1) // BSkyCanvas.chainOpenCanvas.RemoveAt(0); // 11/18/2012, code inserted by Aaron to display the predetermined variable list BSkyCanvas canvasobj; canvasobj = obj as BSkyCanvas; BSkyCanvas.chainOpenCanvas.Add(canvasobj); BSkyCanvas.previewinspectMode = true; //Added by Aaron 12/08/2013 //if (canvasobj.Command == true) c1ToolbarStrip1.IsEnabled = false; //else c1ToolbarStrip1.IsEnabled = true; //Added by Aaron 11/21/2013 //Added line below to enable checking of properties in behaviour.cs i.e. propertyname and control name in dialog //editor mode to make sure that the property names are generated correctly // BSkyCanvas.dialogMode = true; //Added 04/07/2013 //The properties like outputdefinition are not set for firstCanvas //The line below sets it // firstCanvas = canvasobj; foreach (UIElement child in canvasobj.Children) { // Code below has to be written as we have saved BSKYvariable list with rendervars=False. //BSKyvariablelist has already been created with the default constructore and we need to //do some work to point the itemsource properties to the dummy variables we create if (child.GetType().Name == "BSkyVariableList") { List <DataSourceVariable> preview = new List <DataSourceVariable>(); DataSourceVariable var1 = new DataSourceVariable(); var1.Name = "var1"; var1.DataType = DataColumnTypeEnum.Numeric; var1.Width = 4; var1.Decimals = 0; var1.Label = "var1"; var1.Alignment = DataColumnAlignmentEnum.Left; var1.Measure = DataColumnMeasureEnum.Scale; var1.ImgURL = "../Resources/scale.png"; // var1.ImgURL = "C:/Users/Aiden/Downloads/Client/libs/BSky.Controls/Resources/scale.png"; DataSourceVariable var2 = new DataSourceVariable(); var2.Name = "var2"; var2.DataType = DataColumnTypeEnum.Character; var2.Width = 4; var2.Decimals = 0; var2.Label = "var2"; var2.Alignment = DataColumnAlignmentEnum.Left; var2.Measure = DataColumnMeasureEnum.Nominal;; var2.ImgURL = "../Resources/nominal.png"; DataSourceVariable var3 = new DataSourceVariable(); var3.Name = "var3"; var3.DataType = DataColumnTypeEnum.Character; var3.Width = 4; var3.Decimals = 0; var3.Label = "var3"; var3.Alignment = DataColumnAlignmentEnum.Left; var3.Measure = DataColumnMeasureEnum.Ordinal; var3.ImgURL = "../Resources/ordinal.png"; preview.Add(var1); preview.Add(var2); preview.Add(var3); BSkyVariableList temp; temp = child as BSkyVariableList; // 12/25/2012 //renderVars =TRUE meanswe will render var1, var2 and var3 as listed above. This means that we are in the Dialog designer temp.renderVars = false; temp.ItemsSource = preview; } //Added by Aaron 04/06/2014 //Code below ensures that when the dialog is opened in dialog editor mode, the IsEnabled from //the base class is set to true. This ensures that the control can never be disabled in dialog editor mode //Once the dialog is saved, the Enabled property is saved to the base ISEnabled property to make sure that //the proper state of the dialog is saved //if (child is IBSkyEnabledControl) //{ // IBSkyEnabledControl bskyCtrl = child as IBSkyEnabledControl; // bskyCtrl.Enabled = bskyCtrl.IsEnabled; // bskyCtrl.IsEnabled = true; //} } // subCanvasCount = GetCanvasObjectCount(obj as BSkyCanvas); // BSkyControlFactory.SetCanvasCount(subCanvasCount); // OpenCanvas(obj); //Aaron 01/12/2013 //This stores the file name so that we don't have to display the file save dialog on file save and we can save to the file directly; nameOfFile = @dialog.FileName; //01/26/2013 Aaron //Setting the title of the window //Title = nameOfFile; //Aaron: Commented this on 12/15 // myCanvas.OutputDefinition = Path.Combine(Path.GetTempPath(), outputfile); //Aaron 01/26/2013 //Making sure saved is set to true as soon as you open the dialog. // saved = true; //Aaron //02/10/2013 //Added code below to ensure that the RoutedUICommand gets fired correctly and the menu items under file and Dialog (top level menu items) //are properly opened and closed // c1ToolbarStrip1.IsEnabled = true; // CanClose = true; // CanSave = true; //this.Focus(); // window.Template = obj as FrameworkElement; BSkyCanvas cs = obj as BSkyCanvas; System.Windows.Forms.PropertyGrid CanvasPropertyGrid; // window.CanvasPropHost = obj as BSkyCanvas; CanvasPropertyGrid = window.CanvasPropHost.Child as System.Windows.Forms.PropertyGrid; // window.CanvasHost.Child = obj as BSkyCanvas; window.Template = cs; CanvasPropertyGrid.SelectedObject = obj as BSkyCanvas; window.setSizeOfPropertyGrid(); window.Width = cs.Width + 20; // window.CanvasHost.Width = cs.Width; // window.CanvasHost.Height = cs.Height; // window.Height = cs.Height + 200+80; //CanvasPropertyGrid.Refresh(); // Aaron //03/05/2012 //Making the preview window a fixed size window // if (obj.GetType().Name == "BSkyCanvas") window.ResizeMode = ResizeMode.NoResize; stream.Close(); window.ShowDialog(); BSkyCanvas.previewinspectMode = false; //Added by Aaron 05/11/2014 //Clearing up chainopen canvas as we are starting from a Blank Slate when ever we are inspecting a dialog //We alsodo it when we finish inspecting the dialog BSkyCanvas.chainOpenCanvas.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show(BSky.GlobalResources.Properties.Resources.CantOpenFile); } // ******************************************************************************************************* //gencopy(); //Aaron 11/25/2012, the line below needs to be uncommented once the serialization issue is addressed with Anil // string xaml = GetXamlforpreview(); //string xaml = GetXaml(); //************************************************************************************************* } }
//This function returns the title of the canvas of the dialog being inspected private string getTitle() { BSkyCanvas cs = CanvasHost.Child as BSkyCanvas; return(cs.Title); }
//This function returns the command string from the canvas of the dialog being inspected private string getCommand() { BSkyCanvas cs = CanvasHost.Child as BSkyCanvas; return(cs.CommandString); }
//Added by Aaron 07/20/2014 //this function looks at all the objects on the canvas recursively (for subdialogs) that contain the Overwrite settings property //The overwrite setting value controls whether the user should be prompted when creating a new variable or dataset and that variable or dataset already exists. public Boolean CheckForOverwrittenVars(BSkyCanvas cs) { System.Windows.Forms.DialogResult result; Boolean stopexecution = false; string message; foreach (object obj in cs.Children) { if (obj.GetType().Name == "BSkyTextBox") { BSkyTextBox tb = obj as BSkyTextBox; if (tb.OverwriteSettings == "PromptBeforeOverwritingVariables") { List <DataSourceVariable> varlst = UIController.GetActiveDocument().Variables; // UIController. //as=UIController.Re // List<DataSourceVariable> varlst = UIController. foreach (DataSourceVariable dsv in varlst) { // varnames = varnames + ", " + dsv.Name; if (dsv.Name == tb.Text) { message = "Do you want to overwrite variable " + tb.Text; result = System.Windows.Forms.MessageBox.Show(message, "Save Changes", System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Question); if (result == System.Windows.Forms.DialogResult.Yes)//save { } if (result == System.Windows.Forms.DialogResult.Cancel)//save { return(stopexecution = true); } if (result == System.Windows.Forms.DialogResult.No)//save { return(stopexecution = true); } } } } if (tb.OverwriteSettings == "PromptBeforeOverwritingDatasets") { // List<DataSourceVariable> varlst = UIController.GetActiveDocument().Variables; // UIController. //as=UIController.Re // List<DataSourceVariable> varlst = UIController. List <string> datasetnames; datasetnames = UIController.GetDatasetNames(); foreach (string dataset in datasetnames) { if (dataset == tb.Text) { message = "Do you want to overwrite dataset " + tb.Text; result = System.Windows.Forms.MessageBox.Show(message, "Save Changes", System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Question); if (result == System.Windows.Forms.DialogResult.Yes)//save { } if (result == System.Windows.Forms.DialogResult.Cancel)//save { return(stopexecution = true); } if (result == System.Windows.Forms.DialogResult.No)//save { return(stopexecution = true); } } } } } else if (obj.GetType().Name == "BSkyButton") { BSkyButton btn = obj as BSkyButton; FrameworkElement fe = obj as FrameworkElement; BSkyCanvas cnvs = fe.Resources["dlg"] as BSkyCanvas; // if (cs != null) ls.AddRange(gethelpfilenames(cs)); stopexecution = CheckForOverwrittenVars(cnvs); } } return(stopexecution); }
////// 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); }