private void GetFunctionHelp(string RPkgName, string funcname)
        {
            OutputWindowContainer owc = (LifetimeService.Instance.Container.Resolve <IOutputWindowContainer>()) as OutputWindowContainer;

            BSkyMouseBusyHandler.ShowMouseBusy();
            string commands = string.Empty;

            if (RPkgName != null && RPkgName.Length > 0)
            {
                commands = "require(" + RPkgName + "); help('" + funcname + "'); ";
            }
            else
            {
                commands = "help('" + funcname + "'); ";
            }
            SyntaxEditorWindow sewindow = LifetimeService.Instance.Container.Resolve <SyntaxEditorWindow>();

            sewindow.RunCommands(commands, null);
            sewindow.DisplayAllSessionOutput("R Function Help", (owc.ActiveOutputWindow as OutputWindow));
            BSkyMouseBusyHandler.HideMouseBusy();// HideProgressbar_old();// HideStatusProgressbar();//29Oct2014

            //bring main window in front after file open, instead of output window
            Window1 window = LifetimeService.Instance.Container.Resolve <Window1>();

            window.Activate();
        }
        public void PasteDatasetFromClipboard(string dfName = null, bool loadDFinGrid = false)
        {
            container = LifetimeService.Instance.Container;
            service   = container.Resolve <IDataService>();
            OutputWindowContainer owc = (LifetimeService.Instance.Container.Resolve <IOutputWindowContainer>()) as OutputWindowContainer;

            BSkyMouseBusyHandler.ShowMouseBusy();
            string DSName    = string.IsNullOrEmpty(dfName) ? service.GetUniqueNewDatasetname() : dfName.Trim();
            string sheetname = string.Empty;//no sheetname for empty dataset(new dataset)

            string createCommand     = "CreateDFfromClipboard('" + DSName + "'); ";
            string loadInGridCommand = string.Empty;

            if (loadDFinGrid)
            {
                loadInGridCommand = "BSkyLoadRefreshDataframe(" + DSName + ")";
            }

            string commands = createCommand + loadInGridCommand;
            //PrintDialogTitle("Dataset loaded from the clipboard.");
            SyntaxEditorWindow sewindow = LifetimeService.Instance.Container.Resolve <SyntaxEditorWindow>();

            sewindow.RunCommands(commands, null);
            sewindow.DisplayAllSessionOutput("Dataset loaded from the clipboard.", (owc.ActiveOutputWindow as OutputWindow));
            BSkyMouseBusyHandler.HideMouseBusy();

            //bring main window in front
            Window1 window = LifetimeService.Instance.Container.Resolve <Window1>();

            window.Activate();
        }
Beispiel #3
0
        protected override void OnExecute(object param)
        {
            initGlobalObjects();
            if (!AreDefaultRPackagesLoaded()) //Check before showing file open dialog
            {
                return;
            }


            //Window1 appwindow = LifetimeService.Instance.Container.Resolve<Window1>();

            ///Show first dialog where user selects the SQL database ( MS-SQL, MySQL, PostgreSLQ, Oracle etc..)
            DataSourceSelectorWindow dssw = new DataSourceSelectorWindow();

            dssw.Owner = appwindow;
            dssw.ShowDialog();

            logService.WriteToLogLevel("Done SQL table Loading: Now Grid Takes Over. ", LogLevelEnum.Info);

            //bring dataset window in front
            //MainWindow mwindow = LifetimeService.Instance.Container.Resolve<MainWindow>();
            //mwindow.Activate();
            BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
            appwindow.Activate();

            //This is going to be last tab so we can safely call Focus() on last tab
            //without going deeper in DataSource or UIControllerService
            int     totTabs = appwindow.documentContainer.Items.Count;
            TabItem ti      = (appwindow.documentContainer.Items[totTabs - 1] as TabItem);//zero based index so -1

            ti.Focus();
        }
        private void LoadDatasetFromRPackage(string RPkgName, string DSName, string DSObj)
        {
            OutputWindowContainer owc = (LifetimeService.Instance.Container.Resolve <IOutputWindowContainer>()) as OutputWindowContainer;

            //it was found in R-GUI that loading R pkg is not necessary to load dataset from it
            //LoadRPackage(RPkgName);
            BSkyMouseBusyHandler.ShowMouseBusy();
            //string commands = "TmP=data('" + DSName + "', package='" + RPkgName + "');" +
            //    "eval(parse(text = paste('"+ DSObj + "<- as.data.frame( "+DSObj+")', sep = '')));" +
            //    " BSkyLoadRefreshDataframe("+ DSObj + ")";

            string commands = "BSkyLoadRpkgDataset('" + DSName + "','" + DSObj + "','" + RPkgName + "'); " +
                              "BSkyLoadRefreshDataframe(" + DSObj + ")";

            PrintDialogTitle("Open R package dataset");
            SyntaxEditorWindow sewindow = LifetimeService.Instance.Container.Resolve <SyntaxEditorWindow>();

            sewindow.RunCommands(commands, null);
            sewindow.DisplayAllSessionOutput("Open R package dataset", (owc.ActiveOutputWindow as OutputWindow));
            BSkyMouseBusyHandler.HideMouseBusy();// HideProgressbar_old();// HideStatusProgressbar();//29Oct2014

            //08Apr2015 bring main window in front after file open, instead of output window
            Window1 window = LifetimeService.Instance.Container.Resolve <Window1>();

            window.Activate();
        }
        //Find : finds all occurrences by making R call once. And then selects the grid cell for the first search result
        private void gridfindbutton_Click(object sender, RoutedEventArgs e)
        {
            BSkyMouseBusyHandler.ShowMouseBusy();
            gridfindbutton.IsEnabled = false;
            if (searchModified) //if text was changed (search modified) then run find and make R call
            {
                string findtext         = searchtext.Text;
                bool   matchcase        = (matchcasecheckbox.IsChecked == true) ? true : false;
                int    selectedcolcount = selectedColslistbox.SelectedItems.Count;
                //List<DataSourceVariable> selcolnames = selectedColslistbox.SelectedItems as List<DataSourceVariable>;
                string[] selcolumnnames = new string[selectedcolcount];
                int      i = 0;
                foreach (DataSourceVariable dsv in selectedColslistbox.SelectedItems)
                {
                    selcolumnnames[i] = dsv.RName;
                    i++;
                }
                dp.FindGridText(findtext, selcolumnnames, matchcase);

                searchModified = false;//now until someone types new string or modifies, we will not make R calls. We will do NEXT.

                //Also very first time try to jump to the first match.
                dp.FindNextGridText();
            }
            else // No need to make R call. Rather just loop through the results unless the search is modified.
            {
                dp.FindNextGridText();
            }
            gridfindbutton.IsEnabled = true;
            BSkyMouseBusyHandler.HideMouseBusy();
        }
        protected override void OnExecute(object param)
        {
            BSkyMouseBusyHandler.ShowMouseBusy();//ShowProgressbar_old();
            IUnityContainer container  = LifetimeService.Instance.Container;
            IDataService    service    = container.Resolve <IDataService>();
            IUIController   controller = container.Resolve <IUIController>();


            //Get current filetype from loaded dataset. This is file extension and Filter
            DataSource actds = controller.GetActiveDocument();//06Nov2012

            if (actds == null)
            {
                return;
            }
            string datasetName = "" + actds.Name;//uadatasets$lst$
            //string datasetName = "uadatasets$lst$" + controller.GetActiveDocument().Name;
            //Also try to get the filename of currently loaded file. This is FileName.
            string extension = controller.GetActiveDocument().Extension;
            string filename  = controller.GetActiveDocument().FileName;


            SaveFileDialog saveasFileDialog = new SaveFileDialog();

            saveasFileDialog.Filter = FileNameFilter;
            //CheckBox cbox = new CheckBox();

            //saveasFileDialog.FileName = filename;//////
            Window1 appwin = LifetimeService.Instance.Container.Resolve <Window1>();
            bool?   output = saveasFileDialog.ShowDialog(appwin);//Application.Current.MainWindow);

            if (output.HasValue && output.Value)
            {
                service.SaveAs(saveasFileDialog.FileName, controller.GetActiveDocument()); // #0
                controller.GetActiveDocument().Changed = false;                            //21Mar2014 during close it should not prompt again for saving

                if (saveasFileDialog.FileName.ToLower().EndsWith("sav"))                   //12Feb2018 we dont want to open SaveAs-ed SAV files.
                {
                    MessageBox.Show(BSky.GlobalResources.Properties.Resources.SaveAsSucces + saveasFileDialog.FileName, BSky.GlobalResources.Properties.Resources.Saved, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
                else if (System.IO.File.Exists(saveasFileDialog.FileName))
                {
                    //Close current Dataset on whic Save As was run
                    FileCloseCommand fcc = new FileCloseCommand();
                    fcc.CloseDataset(false);

                    //Open Dataset that was SaveAs-ed.
                    FileOpenCommand fo = new FileOpenCommand();
                    fo.FileOpen(saveasFileDialog.FileName, true);
                }
                else
                {
                    BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
                    MessageBox.Show(BSky.GlobalResources.Properties.Resources.SaveAsFailed + saveasFileDialog.FileName, BSky.GlobalResources.Properties.Resources.InternalError, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
            }
            BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
        }
        public bool ProcessNewDataset(string dfName = null, bool loadDFinGrid = true)
        {
            container    = LifetimeService.Instance.Container;
            service      = container.Resolve <IDataService>();
            UIController = LifetimeService.Instance.Container.Resolve <IUIController>();
            string CurrentDatasetName      = UIController.GetActiveDocument().Name;
            OutputWindowContainer owc      = (LifetimeService.Instance.Container.Resolve <IOutputWindowContainer>()) as OutputWindowContainer;
            SyntaxEditorWindow    sewindow = LifetimeService.Instance.Container.Resolve <SyntaxEditorWindow>();

            string DSName    = CurrentDatasetName; //string.IsNullOrEmpty(dfName) ? service.GetUniqueNewDatasetname() : dfName.Trim();
            string sheetname = string.Empty;       //no sheetname for empty dataset(new dataset)

            string isEmpty     = sewindow.ExecuteBoolCommand("BSkyIsEmptyDataset('" + DSName + "')");
            bool   isProcessed = false;//false:dataset not processed may be it was empty.

            if (!isEmpty.Equals("TRUE"))
            {
                BSkyMouseBusyHandler.ShowMouseBusy();
                string strAsFactor = confService.GetConfigValueForKey("NewDatasetStrToFactor");
                strAsFactor = strAsFactor.ToUpper().Equals("TRUE") ? "TRUE" : "FALSE";
                string createCommand     = "BsKyTeM<-BSkyProcessNewDataset('" + DSName + "', stringAsFactor=" + strAsFactor + "); ";
                string loadInGridCommand = string.Empty;

                if (loadDFinGrid)
                {
                    loadInGridCommand = "BSkyLoadRefreshDataframe(" + DSName + ")";
                }

                string commands = createCommand + loadInGridCommand;
                //PrintDialogTitle("Dataset loaded from the clipboard.");

                sewindow.RunCommands(commands, null);
                sewindow.DisplayAllSessionOutput("Dataset loaded.", (owc.ActiveOutputWindow as OutputWindow));

                BSkyMouseBusyHandler.HideMouseBusy();
                isProcessed = true; //dataset was processed
            }
            //bring main window in front
            Window1 window = LifetimeService.Instance.Container.Resolve <Window1>();

            window.Activate();
            return(isProcessed);
        }
        private void LoadPackageHelp(string RPkgName)
        {
            OutputWindowContainer owc = (LifetimeService.Instance.Container.Resolve <IOutputWindowContainer>()) as OutputWindowContainer;

            BSkyMouseBusyHandler.ShowMouseBusy();

            string commands = "require(" + RPkgName + "); help(package='" + RPkgName + "'); ";

            SyntaxEditorWindow sewindow = LifetimeService.Instance.Container.Resolve <SyntaxEditorWindow>();

            sewindow.RunCommands(commands, null);
            sewindow.DisplayAllSessionOutput("R Package Help", (owc.ActiveOutputWindow as OutputWindow));
            BSkyMouseBusyHandler.HideMouseBusy();// HideProgressbar_old();// HideStatusProgressbar();//29Oct2014

            //bring main window in front after file open, instead of output window
            Window1 window = LifetimeService.Instance.Container.Resolve <Window1>();

            window.Activate();
        }
Beispiel #9
0
        protected override void OnExecute(object param)
        {
            BSkyMouseBusyHandler.ShowMouseBusy();//ShowProgressbar_old();
            IUnityContainer container  = LifetimeService.Instance.Container;
            IDataService    service    = container.Resolve <IDataService>();
            IUIController   controller = container.Resolve <IUIController>();

            if (controller.GetActiveDocument().isUnprocessed)
            {
                NewDatasetProcessor procDS = new NewDatasetProcessor();
                bool isProcessed           = procDS.ProcessNewDataset("", true);
                if (isProcessed)//true:empty rows cols removed successfully. False: whole dataset was empty and nothing was removed.
                {
                    controller.GetActiveDocument().isUnprocessed = false;
                }
                else
                {
                    BSkyMouseBusyHandler.HideMouseBusy();
                    MessageBox.Show("The dataset is empty. Please populate the dataset and save the file.", "Empty Dataset", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
            }

            //Get current filetype from loaded dataset. This is file extension and Filter
            DataSource actds = controller.GetActiveDocument();//06Nov2012

            if (actds == null)
            {
                return;
            }
            string datasetName = "" + actds.Name;//uadatasets$lst$
            //string datasetName = "uadatasets$lst$" + controller.GetActiveDocument().Name;
            //Also try to get the filename of currently loaded file. This is FileName.
            string extension = controller.GetActiveDocument().Extension;
            string filename  = controller.GetActiveDocument().FileName;


            SaveFileDialog saveasFileDialog = new SaveFileDialog();

            saveasFileDialog.Filter = FileNameFilter;
            //CheckBox cbox = new CheckBox();

            //saveasFileDialog.FileName = filename;//////
            Window1 appwin = LifetimeService.Instance.Container.Resolve <Window1>();
            bool?   output = saveasFileDialog.ShowDialog(appwin);//Application.Current.MainWindow);

            if (output.HasValue && output.Value)
            {
                //If the filename provided by user matches to any of the dataset's disk filename, currently open
                // in the grid then we must not let user overwrite
                // and inform him/her to first close the dataset whose filename matches and then try Save-As again.
                //
                //Only thing that may confuse users is, in the first Microsoft-SaveAs dialog they already decided
                //to overwrite an existing file (which happens to be loaded in the grid also) but we prompt them
                //again telling that the file is open in the grid and skip the SaveAs operation with message.
                //
                List <string> dsfnames = controller.GetAllOpenDatasetsInGrid();
                if (dsfnames.Contains(saveasFileDialog.FileName))
                {
                    BSkyMouseBusyHandler.HideMouseBusy();
                    string fullpathfilename = saveasFileDialog.FileName;
                    string filenameonly     = Path.GetFileName(saveasFileDialog.FileName);
                    //The filenameonly dataset (fullpathfilename) is already open in the datagrid. Close the dataset first and then try Save-As again.
                    MessageBox.Show(BSky.GlobalResources.Properties.Resources.The + " \'" + filenameonly + "\' " +
                                    BSky.GlobalResources.Properties.Resources.Dtaset +
                                    " (" + fullpathfilename + ") " +
                                    BSky.GlobalResources.Properties.Resources.OverwritingOpenDatasetNotallowed,
                                    BSky.GlobalResources.Properties.Resources.SaveAsFailed,
                                    MessageBoxButton.OK, MessageBoxImage.Asterisk);
                    return;
                }

                service.SaveAs(saveasFileDialog.FileName, controller.GetActiveDocument()); // #0
                controller.GetActiveDocument().Changed = false;                            //21Mar2014 during close it should not prompt again for saving

                if (saveasFileDialog.FileName.ToLower().EndsWith("sav"))                   //12Feb2018 we dont want to open SaveAs-ed SAV files.
                {
                    MessageBox.Show(BSky.GlobalResources.Properties.Resources.SaveAsSucces + saveasFileDialog.FileName, BSky.GlobalResources.Properties.Resources.Saved, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
                else if (System.IO.File.Exists(saveasFileDialog.FileName))
                {
                    //Close current Dataset on whic Save As was run
                    FileCloseCommand fcc = new FileCloseCommand();
                    fcc.CloseDataset(false);

                    //Open Dataset that was SaveAs-ed.
                    FileOpenCommand fo = new FileOpenCommand();
                    fo.FileOpen(saveasFileDialog.FileName, true);
                }
                else
                {
                    BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
                    MessageBox.Show(BSky.GlobalResources.Properties.Resources.SaveAsFailed + saveasFileDialog.FileName, BSky.GlobalResources.Properties.Resources.InternalError, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
            }
            BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
        }
        ////Send executed command to output window. So, user will know what he executed
        //protected override void SendToOutputWindow(string command, string title)//13Dec2013
        //{
        //    #region Get Active output Window
        //    //////// Active output window ///////
        //    OutputWindowContainer owc = (LifetimeService.Instance.Container.Resolve<IOutputWindowContainer>()) as OutputWindowContainer;
        //    OutputWindow ow = owc.ActiveOutputWindow as OutputWindow; //get currently active window
        //    #endregion
        //    ow.AddMessage(command, title);
        //}

        public bool OpenDataframe(string dframename, string fname)
        {
            initGlobalObjects();
            AdvancedLogging = AdvancedLoggingService.AdvLog;//08Aug2016

            Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();

            if (!AreDefaultRPackagesLoaded())
            {
                stopwatch.Stop();
                return(false);
            }
            stopwatch.Stop();

            long elapsed = stopwatch.ElapsedMilliseconds;

            if (AdvancedLogging)
            {
                logService.WriteToLogLevel("PERFORMANCE:Are Req Package loaded: Time taken: " + elapsed, LogLevelEnum.Info);
            }

            BSkyMouseBusyHandler.ShowMouseBusy();// ShowProgressbar_old();//ShowStatusProgressbar();//29Oct2014

            bool       isSuccess = false;
            string     filename = null, sheetname = null;
            DataSource tempds = controller.GetActiveDocument();

            if (tempds != null)
            {
                filename = tempds.FileName;
                //For Excel
                sheetname = UtilFunctions.GetSheetname(tempds);
            }
            if (filename == null)
            {
                filename = string.Empty;
            }
            if (sheetname == null)
            {
                sheetname = string.Empty;
            }
            // if dataset was already loaded last time then this time we want to refresh it
            bool isDatasetNew = service.isDatasetNew(dframename /*+ sheetname*/);

            try
            {
                stopwatch.Restart();
                if (fname.Length == 0)
                {
                    /// It is difficult to diffeneretiate between
                    ///(1) BSkyLoadRefreshDataframe(housing) which is a part of 'Compute' analysis on housing dataset and
                    ///(2) BSkyLoadRefreshDataframe(housing) which is a part of 'Aggregate to dataset' on iris dataset.
                    /// Ideally, first one should keep the Housing.Rdata filename in DataSource as well as on TabItem
                    /// TabItem should be "Housing.RData(housing)"
                    /// And the second on should replace the Housing.Rdata filename in Datasource and TabItem with
                    /// 'housing'. TabItem should be "housing(housing)"
                    ///
                    ///Since we do not have a way to differentiate the two loadRefresh so A.R. and A.D. decided to
                    ///leave the filename in DataSource as well as on TabItem in both cases.
                    if (isDatasetNew)//new dataset may not have filename so R dataset obj name(DatasetX or mydf) is used.
                    {
                        fname = dframename;
                    }
                    else
                    {
                        fname = service.FindDataSourceFromDatasetname(dframename).FileName;//filename;//existing dataframe should retain original filename.
                    }
                }
                if (!(fname.ToLower().EndsWith(".xls") || fname.ToLower().EndsWith(".xlsx")))
                {
                    sheetname = string.Empty;
                }
                DataSource ds = service.OpenDataframe(dframename, sheetname, fname);
                //ds.FileName = fname;
                stopwatch.Stop();
                elapsed = stopwatch.ElapsedMilliseconds;
                if (AdvancedLogging)
                {
                    logService.WriteToLogLevel("PERFORMANCE:Open Dataset in R: Time taken: " + elapsed, LogLevelEnum.Info);
                }

                string errormsg = string.Empty;

                if (ds != null && ds.Message != null && ds.Message.Length > 0) //message that is related to error
                {
                    errormsg = "\n" + ds.Message;
                    ds       = null;                      //making it null so that we do execute further
                }
                if (ds != null && ds.Variables.Count > 0) //07Aug2016 added count condition to not open dataset if there are no variables //03Dec2012
                {
                    logService.WriteToLogLevel("Start Loading Dataframe: " + ds.Name, LogLevelEnum.Info);
                    if (isDatasetNew)
                    {
                        stopwatch.Restart();
                        controller.Load_Dataframe(ds);
                        stopwatch.Stop();
                        elapsed = stopwatch.ElapsedMilliseconds;
                        if (AdvancedLogging)
                        {
                            logService.WriteToLogLevel("PERFORMANCE:Grid loading: Time taken: " + elapsed, LogLevelEnum.Info);
                        }
                    }
                    else
                    {
                        stopwatch.Restart();
                        controller.RefreshBothGrids(ds);//23Jul2015 .RefreshGrids(ds);//.RefreshDataSet(ds);
                        stopwatch.Stop();
                        elapsed = stopwatch.ElapsedMilliseconds;
                        if (AdvancedLogging)
                        {
                            logService.WriteToLogLevel("PERFORMANCE:Grid loading: Time taken: " + elapsed, LogLevelEnum.Info);
                        }
                        ActivateDatagrid(ds);
                    }
                    //ds.Changed = true; // keep track of change made, so that it can prompt for saving while closing dataset tab.
                    logService.WriteToLogLevel("Finished Loading Dataframe: " + ds.Name, LogLevelEnum.Info);
                    //recentfiles.AddXMLItem(dframename);//adding to XML file for recent docs
                    isSuccess = true;
                }
                else
                {
                    BSkyMouseBusyHandler.HideMouseBusy();// HideProgressbar_old();

                    //MessageBox.Show(appwindow, "Unable to open '" + dframename + "'..." +
                    //    "\nReasons could be one or more of the following:" +
                    //    "\n1. Not a data frame object." +
                    //    "\n2. File format not supported (or corrupt file or duplicate column names)." +
                    //    "\n3. Dataframe does not have row(s) or column(s)." +
                    //    "\n4. R.Net server from the old session still running (use task manager to kill it)." +
                    //    "\n5. Some issue on R side (like: required library not loaded, incorrect syntax).",
                    //    "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    //SendToOutputWindow("Error Opening Dataset.(probably not a data frame)", dframename + errormsg);

                    MessageBox.Show(appwindow, BSky.GlobalResources.Properties.Resources.cantopen + " '" + dframename + "'" +
                                    "\n" + BSky.GlobalResources.Properties.Resources.reasonsAre +
                                    "\n" + BSky.GlobalResources.Properties.Resources.NotDataframe2 +
                                    "\n" + BSky.GlobalResources.Properties.Resources.FormatNotSupported2 +
                                    "\n" + BSky.GlobalResources.Properties.Resources.NoRowsColsPresent +
                                    "\n" + BSky.GlobalResources.Properties.Resources.OldSessionRunning2 +
                                    "\n" + BSky.GlobalResources.Properties.Resources.RSideIssue2,
                                    BSky.GlobalResources.Properties.Resources.warning, MessageBoxButton.OK, MessageBoxImage.Warning);
                    SendToOutputWindow(BSky.GlobalResources.Properties.Resources.ErrOpeningDataset2, dframename + errormsg);
                }
            }
            catch (Exception ex)
            {
                logService.WriteToLogLevel("Error:" + ex.Message, LogLevelEnum.Error);
            }
            finally
            {
                //18OCt2013 move up for using in msg box   Window1 appwindow = LifetimeService.Instance.Container.Resolve<Window1>();//for refeshing recent files list
                //appwindow.RefreshRecent();
                BSkyMouseBusyHandler.HideMouseBusy();// HideProgressbar_old();//HideStatusProgressbar();//29Oct2014
            }

            //if (isSuccess)
            //{
            //08Apr2015 bring main window in front after file open, instead of output window
            //Window1 window = LifetimeService.Instance.Container.Resolve<Window1>();
            //window.Activate();
            //}
            return(isSuccess);
        }
        //this is common. Called from FileOpen and OnExecute, only after checking default R packages
        private void OpenDataset(string filename, bool afterSaveAs = false)
        {
            AdvancedLogging = AdvancedLoggingService.AdvLog; //08Aug2016
            // Start Some animation for loading dataset ///
            BSkyMouseBusyHandler.ShowMouseBusy();            // ShowProgressbar_old();//ShowStatusProgressbar();//29Oct2014

            string showRDataWarningStr = confService.GetConfigValueForKey("RDataOpenWarning");
            bool   showRDataWarning    = showRDataWarningStr.ToLower().Equals("true") ? true : false;

            string               errormsg = string.Empty;
            DataSource           ds       = null;
            IOpenDataFileOptions csvo     = new OpenDataFileOptions(); //
            bool removeSpacesSPSS         = false;                     //for SPSS files.

            if (filename != null && filename.Length > 0)
            {
                if (System.IO.File.Exists(filename))
                {
                    //23Oct2016(2) Blank not working in the following.
                    string sheetname = "";                                       //23Oct2016(1) null replaced by empty. File>recent opens aonther grid tab if the current grid has become null

                    if (filename.EndsWith(".xls") || filename.EndsWith(".xlsx")) //27Jan2014
                    {
                        object tbls = service.GetOdbcTableList(filename);

                        if (tbls != null)
                        {
                            SelectTableWindow stw   = new SelectTableWindow();
                            string[]          tlist = null;

                            if (tbls.GetType().Name.Equals("String"))
                            {
                                tlist    = new string[1];
                                tlist[0] = tbls as string;
                            }
                            else if (tbls.GetType().Name.Equals("String[]"))
                            {
                                tlist = tbls as string[];
                            }

                            stw.FillList(tlist);
                            BSkyMouseBusyHandler.HideMouseBusy();// HideProgressbar_old();
                            stw.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            stw.ShowDialog();
                            BSkyMouseBusyHandler.ShowMouseBusy();     // ShowProgressbar_old();
                            if (stw.SelectedTableName == null)        //cancel clicked
                            {
                                BSkyMouseBusyHandler.HideMouseBusy(); // HideProgressbar_old();//HideStatusProgressbar();//29Oct2014
                                return;
                            }
                            else
                            {
                                sheetname = stw.SelectedTableName;
                            }
                        }
                    }
                    else if (filename.ToLower().EndsWith(".rdata") && showRDataWarning && !afterSaveAs)  //dont show warning if file is auto opened after 'SaveAs'
                    {
                        if (!appwindow.RDataShowWarningDialogCheck)                                      //for first time and also when checkbox is not checked
                        {
                            string s1 = BSky.GlobalResources.Properties.Resources.OpenRDataWarnMsgLine1; //Not in use. Replaced by s1a, s1b
                            string s2 = "\n\n" + BSky.GlobalResources.Properties.Resources.OpenRDataWarnMsgLine2;
                            string s3 = "\n" + BSky.GlobalResources.Properties.Resources.OpenRDataWarnMsgLine3;
                            string s4 = "\n\n" + BSky.GlobalResources.Properties.Resources.OpenRDataWarnMsgLine4;
                            string s5 = "\n\n" + BSky.GlobalResources.Properties.Resources.OpenRDataWarnMsgLine5;
                            string s6 = "\n\n" + BSky.GlobalResources.Properties.Resources.OpenRDataWarnMsgLine6;
                            string s7 = "\n\n" + BSky.GlobalResources.Properties.Resources.OpenRDataWarnMsgLine7;

                            //string s1 = "Loading RDATA file may overwrite your current variables/objects in memory if variables/objects with the same name are already present in the RDATA file.";
                            string s1a = BSky.GlobalResources.Properties.Resources.OpenRDataWarnMsgLine1a;  //
                            string s1b = BSky.GlobalResources.Properties.Resources.OpenRDataWarnMsgLine1b;; //

                            //string s2 = "\n\nYou can cancel out of here and save your all your current variables/objects which you can load later if required.";
                            //string s3 = "\nTo save/load your current variables/object run following commands from BlueSky R command editor.";
                            //string s4 = "\n\nTo save:  save.image(file='filename.rdata') # filename.rdata is the file name where objects will be saved.";
                            //string s5 = "\n\nTo load:  load(file='filename.rdata') # filename.rdata is the file name from which objects will be loaded.";
                            //string s6 = "\n\n'filename.rdata' is filename with forward slashed path e.g. 'C:/myfolder/myobjects.rdata' ";
                            //string s7 = "\n\nDo you want to proceed? [Variables with matching names will be overwritten].";
                            //MessageBoxResult messageBoxResult = MessageBox.Show(s1a + s1b + s2 + s3 + s4 + s5 + s6 + s7, "Please Confirm...", MessageBoxButton.YesNo, MessageBoxImage.Question);
                            //if (messageBoxResult == MessageBoxResult.Yes)
                            //{
                            //    //MessageBox.Show("You selected to proceed");
                            //}
                            //else
                            //{
                            //    //MessageBox.Show("You selected to cancel");
                            //    BSkyMouseBusyHandler.HideMouseBusy();
                            //    return;
                            //}

                            RDataWarningMessageBox rdataMBox = new RDataWarningMessageBox();
                            rdataMBox.Msg    = s1a;
                            rdataMBox.AdvMsg = s1b + s2 + s3 + s4 + s5 + s6 + s7;
                            BSkyMouseBusyHandler.HideMouseBusy();
                            rdataMBox.ShowDialog();
                            BSkyMouseBusyHandler.ShowMouseBusy();
                            if (rdataMBox.NotShowCheck)//do not show the checkbox again
                            {
                                appwindow.RDataShowWarningDialogCheck = true;
                            }
                            if (rdataMBox.ButtonClicked == "Cancel")
                            {
                                BSkyMouseBusyHandler.HideMouseBusy();
                                return;
                            }
                        }
                    }
                    else if (filename.ToLower().EndsWith(".r"))// its R script
                    {
                        //errormsg = "To open a R script, you need to switch to the 'Output and Syntax' window.\n" +
                        //    "Go to the right hand pane of the 'Output and Syntax' window and click File -> Open in the 'R Command Editor'.";

                        errormsg = BSky.GlobalResources.Properties.Resources.OpenRScriptInSynWin + "\n" +
                                   BSky.GlobalResources.Properties.Resources.OpenRScriptMenuPath;
                        ds = null;

                        BSkyMouseBusyHandler.HideMouseBusy();// HideProgressbar_old();
                        MessageBox.Show(errormsg, BSky.GlobalResources.Properties.Resources.ErrOpeningFile + "(" + filename + ")", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                        SendToOutputWindow(BSky.GlobalResources.Properties.Resources.ErrOpeningDataset, filename + errormsg);
                        return;
                    }
                    else if (filename.ToLower().EndsWith(".txt") || filename.ToLower().EndsWith(".csv") || filename.ToLower().EndsWith(".dat"))
                    {
                        OpenCSVTXTOptionsWindow csvopwin = new OpenCSVTXTOptionsWindow();
                        csvopwin.Owner = appwindow;
                        csvopwin.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                        BSkyMouseBusyHandler.HideMouseBusy();
                        csvopwin.ShowDialog();
                        //get all parameters
                        csvo = csvopwin.csvtxtOptions;
                        if (csvo == null)//user clicked cancel
                        {
                            return;
                        }

                        BSkyMouseBusyHandler.ShowMouseBusy();
                        //do further processing by passing it into service.open()
                    }
                    else if (filename.EndsWith(".sav"))
                    {
                        OpenSPSSoptionsWindow spssOpt = new OpenSPSSoptionsWindow();
                        spssOpt.Owner = appwindow;
                        BSkyMouseBusyHandler.HideMouseBusy();
                        spssOpt.ShowDialog();
                        BSkyMouseBusyHandler.ShowMouseBusy();
                        removeSpacesSPSS = spssOpt.TrimSpaces;
                    }
                    logService.WriteToLogLevel("Setting DataSource: ", LogLevelEnum.Info);

                    Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();
                    long      elapsed   = 0;

                    // if RData file then get all the data.frame and tbl_df objects.
                    //Give users choice to load one or more of available data.frames in the grid.
                    if (filename.ToLower().EndsWith(".rdata")) //&& !afterSaveAs)
                    {
                        bool     isSingleDFinFile = false;     //if there is a single data.frame object in a file and no other obj.
                        bool     isOneBlank       = false;
                        string[] selectedDF       = null;
                        //get list of data.frame or tbl_df objects from R
                        object tbls = service.GetRDataDataframeObjList(filename);
                        if (tbls != null && !tbls.ToString().Equals("No Result - Check Command"))
                        {
                            string[] tlist = null;

                            if (tbls.GetType().Name.Equals("String"))
                            {
                                tlist            = new string[1];
                                tlist[0]         = tbls as string;
                                isSingleDFinFile = true;
                            }
                            else if (tbls.GetType().Name.Equals("String[]"))
                            {
                                tlist = tbls as string[];
                                if (tlist.Length == 2)
                                {
                                    if (tlist[1].Trim().Length == 0)//blank entry. Also represent there are other objs in Rdata
                                    {
                                        isOneBlank = true;
                                        //remove blank entry
                                        string tempentry = tlist[0];
                                        tlist    = new string[1];
                                        tlist[0] = tempentry;
                                    }
                                }
                            }

                            if (tlist != null && tlist.Length > 1)
                            {
                                BSkyMouseBusyHandler.HideMouseBusy();
                                SelectRdataDataframesWindow srdataw = new SelectRdataDataframesWindow();
                                srdataw.LoadListbox(tlist);
                                srdataw.ShowDialog();
                                string DlgRes = srdataw.DlgResult;
                                if (DlgRes.Equals("Ok"))
                                {
                                    BSkyMouseBusyHandler.ShowMouseBusy();
                                    selectedDF = srdataw.SelectedDFList;
                                }
                                else // 'Cancel' clicked
                                {
                                    //no code here. User aborted the loading in the grid but he already have RData file loaded.
                                    return;
                                }
                            }
                            else if (tlist != null && tlist.Length == 1)
                            {
                                selectedDF = tlist;
                            }

                            #region Load seleted data.frames
                            if (selectedDF != null || selectedDF.Length > 0)
                            {
                                string title = "RData file loaded : " + filename;
                                //SendToOutputWindow("", title, false);
                                PrintTitle(title);

                                //load all the selected dataframes
                                StringBuilder sb = new StringBuilder();
                                StringBuilder selectedDSnames = new StringBuilder("Loaded ");
                                int           selidx          = 1;
                                foreach (string s in selectedDF)
                                {
                                    if (s.Equals("UAObj$obj")) //if it is old RData BSky proprietary format.
                                    {
                                        string RDataFilename = Path.GetFileNameWithoutExtension(filename);
                                        //remove special chars if any in the RDataFilename.
                                        RDataFilename = RemoveSplChars(RDataFilename);

                                        sb.Append(RDataFilename + " <- as.data.frame(" + s + ") ;");
                                        sb.Append("BSkyLoadRefreshDataframe(" + RDataFilename + ");");
                                        selectedDSnames.Append(RDataFilename);
                                    }
                                    else
                                    {
                                        sb.Append("BSkyLoadRefreshDataframe(" + s + ");"); //s must be data.frame name and not the nested data.frame obj.
                                        selectedDSnames.Append(s);
                                        if (selidx < selectedDF.Length)
                                        {
                                            selectedDSnames.Append(", ");
                                            selidx++;
                                        }
                                    }
                                }
                                selectedDSnames.Append("Data frames.");

                                string             commands = sb.ToString();
                                SyntaxEditorWindow sewindow = LifetimeService.Instance.Container.Resolve <SyntaxEditorWindow>();
                                if (isSingleDFinFile)
                                {
                                    sewindow.RunCommands(commands, null, filename);
                                }
                                else
                                {
                                    sewindow.RunCommands(commands, null);
                                }

                                //sewindow.SendCommandToOutput("RData file loaded :: " + filename, "RData Loaded");
                                sewindow.DisplayAllSessionOutput("Load RData file");
                                //SendToOutputWindow(filename + " loaded", selectedDSnames.ToString(), false);
                                recentfiles.AddXMLItem(filename);//adding to XML file for recent docs
                                appwindow.RefreshRecent();
                                return;
                            }
                            #endregion
                        }
                        //else
                        //{
                        //    MessageBox.Show("Data frame object not found!");
                        //    SendToOutputWindow(BSky.GlobalResources.Properties.Resources.ErrOpeningDataset, filename + errormsg);
                        //}
                    }
                    else
                    {
                        ds = service.Open(filename, sheetname, removeSpacesSPSS, csvo);
                        stopwatch.Stop();
                        elapsed = stopwatch.ElapsedMilliseconds;

                        if (AdvancedLogging)
                        {
                            logService.WriteToLogLevel("PERFORMANCE:Both Dataset Opened and Col Attributes read: Time taken: " + elapsed, LogLevelEnum.Info);
                        }
                    }

                    if (ds != null && ds.Message != null && ds.Message.Length > 0) //message that is related to error
                    {
                        errormsg = "\n" + ds.Message;
                        ds       = null;//making it null so that we stop executing further

                        // errormsg = BSky.GlobalResources.Properties.Resources.OpenRScriptInSynWin + "\n"+
                        //     BSky.GlobalResources.Properties.Resources.OpenRScriptMenuPath;
                        // ds = null;
                    }

                    if (ds != null && ds.Variables.Count > 0)//07Aug2016 added count condition to not open dataset if there are no variables //03Dec2012
                    {
                        logService.WriteToLogLevel("Start Loading: " + ds.Name, LogLevelEnum.Info);
                        //controller.LoadNewDataSet(ds);

                        stopwatch = System.Diagnostics.Stopwatch.StartNew();

                        if (ds.Replace)//if dataset became NULL(dataset exists in UI grid) and now we want to replace it by reading data from file
                        {
                            controller.RefreshBothGrids(ds);
                        }
                        else
                        {
                            controller.LoadNewDataSet(ds);
                        }
                        stopwatch.Stop();
                        elapsed = stopwatch.ElapsedMilliseconds;
                        if (AdvancedLogging)
                        {
                            logService.WriteToLogLevel("PERFORMANCE:Creating virtual-Class and grid stuff: Time taken: " + elapsed, LogLevelEnum.Info);
                        }

                        logService.WriteToLogLevel("Finished Loading: " + ds.Name, LogLevelEnum.Info);
                        recentfiles.AddXMLItem(filename);//adding to XML file for recent docs
                        ActivateDatagrid(ds);
                    }
                    else
                    {
                        BSkyMouseBusyHandler.HideMouseBusy();// HideProgressbar_old();

                        //Following block is not needed
                        //StringBuilder sb = new StringBuilder();
                        //List<string> defpacklist = defaultpackges.RecentFileList;
                        //foreach(string s in defpacklist)
                        //{
                        //    sb.Append(s+", ");
                        //}
                        //sb.Remove(sb.Length - 1, 1);//removing last comma
                        //string defpkgs = sb.ToString();

                        //MessageBox.Show(errormsg, "Unable to open the file(" + filename + ")", MessageBoxButton.OK, MessageBoxImage.Warning);
                        //SendToOutputWindow("Error Opening Dataset", filename + errormsg);

                        MessageBox.Show(errormsg, BSky.GlobalResources.Properties.Resources.ErrOpeningFile + "(" + filename + ")", MessageBoxButton.OK, MessageBoxImage.Warning);
                        SendToOutputWindow(BSky.GlobalResources.Properties.Resources.ErrOpeningDataset, filename + errormsg);
                    }
                }
                else
                {
                    BSkyMouseBusyHandler.HideMouseBusy();// HideProgressbar_old();
                    MessageBox.Show(filename + " " + BSky.GlobalResources.Properties.Resources.DoesNotExist,
                                    BSky.GlobalResources.Properties.Resources.FileNotFound, MessageBoxButton.OK, MessageBoxImage.Warning);
                    //If file does not exist. It should be removed from the recent files list.
                    recentfiles.RemoveXMLItem(filename);
                }
                //18OCt2013 move up for using in msg box   Window1 appwindow = LifetimeService.Instance.Container.Resolve<Window1>();//for refeshing recent files list
                appwindow.RefreshRecent();
            }
            BSkyMouseBusyHandler.HideMouseBusy();// HideProgressbar_old();// HideStatusProgressbar();//29Oct2014

            //08Apr2015 bring main window in front after file open, instead of output window
            Window1 window = LifetimeService.Instance.Container.Resolve <Window1>();
            window.Activate();
        }
                                             "|R Object (*.RData)|*.RData";//"Excel 2003 (*.xls)|*.xls " +

        protected override void OnExecute(object param)
        {
            BSkyMouseBusyHandler.ShowMouseBusy();//ShowProgressbar_old();
            IUnityContainer container  = LifetimeService.Instance.Container;
            IDataService    service    = container.Resolve <IDataService>();
            IUIController   controller = container.Resolve <IUIController>();

            //Get current filetype from loaded dataset. This is file extension and Filter
            DataSource actds = controller.GetActiveDocument();//06Nov2012

            if (actds == null)
            {
                return;
            }
            string datasetName = "" + actds.Name;//uadatasets$lst$
            //string datasetName = "uadatasets$lst$"+controller.GetActiveDocument().Name;
            //Also try to get the filename of currently loaded file. This is FileName.
            string extension = controller.GetActiveDocument().Extension.ToLower();
            string filename  = controller.GetActiveDocument().FileName;
            string filter    = null;

            switch (extension)
            {
            case "csv": filter = "Comma Seperated (*.csv)|*.csv"; break;

            case "xls": filter = "Excel 2003 (*.xls)|*.xls"; break;

            case "xlsx": filter = "Excel 2007-2010 (*.xlsx)|*.xlsx"; break;

            case "dbf": filter = "DBF (*.dbf)|*.dbf"; break;

            case "rdata": filter = "R Object (*.RData)|*.RData"; break;

            default: filter = "All Files(*.*)|*.*"; break;
            }

            if (extension.Equals("sav") || extension.Trim().Length == 0)//show save-as dialog if current loaded file is SPSS file or memory dataframe(RData file)
            {
                SaveFileDialog saveasFileDialog = new SaveFileDialog();
                saveasFileDialog.Filter = FileNameFilter;
                Window1 appwin = LifetimeService.Instance.Container.Resolve <Window1>();
                bool?   output = saveasFileDialog.ShowDialog(appwin);//Application.Current.MainWindow);
                if (output.HasValue && output.Value)
                {
                    service.SaveAs(saveasFileDialog.FileName, controller.GetActiveDocument()); // #0
                    controller.GetActiveDocument().Changed = false;                            //21Mar2014 during close it should not prompt again for saving

                    if (saveasFileDialog.FileName.ToLower().EndsWith("sav"))                   //12Feb2018 we dont want to open SaveAs-ed SAV files.
                    {
                        MessageBox.Show(BSky.GlobalResources.Properties.Resources.SaveAsSucces + saveasFileDialog.FileName, BSky.GlobalResources.Properties.Resources.Saved, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                    }
                    else if (System.IO.File.Exists(saveasFileDialog.FileName))
                    {
                        //Close current Dataset on whic Save As was run
                        FileCloseCommand fcc = new FileCloseCommand();
                        fcc.CloseDataset(false);

                        //Open Dataset that was SaveAs-ed.
                        FileOpenCommand fo = new FileOpenCommand();
                        fo.FileOpen(saveasFileDialog.FileName, true);
                    }
                    else
                    {
                        BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
                        MessageBox.Show(BSky.GlobalResources.Properties.Resources.SaveAsFailed + saveasFileDialog.FileName, BSky.GlobalResources.Properties.Resources.InternalError, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                    }
                }
            }
            else if (extension.Equals("xls"))//we are using write.xlsx() from openxlsx package so we can save to XLSX format only and not to XLS.
            {
                MessageBoxResult mbr = MessageBox.Show(BSky.GlobalResources.Properties.Resources.CantSaveAsExcel,
                                                       BSky.GlobalResources.Properties.Resources.SaveToOtherFormat, MessageBoxButton.OKCancel, MessageBoxImage.Asterisk);
                if (mbr == MessageBoxResult.OK)
                {
                    SaveFileDialog saveasFileDialog = new SaveFileDialog();
                    saveasFileDialog.Filter = FileNameFilter;
                    Window1 appwin = LifetimeService.Instance.Container.Resolve <Window1>();
                    bool?   output = saveasFileDialog.ShowDialog(appwin);//Application.Current.MainWindow);
                    if (output.HasValue && output.Value)
                    {
                        service.SaveAs(saveasFileDialog.FileName, controller.GetActiveDocument()); // #0
                        controller.GetActiveDocument().Changed = false;                            //21Mar2014 during close it should not prompt again for saving

                        if (System.IO.File.Exists(saveasFileDialog.FileName))
                        {
                            //Close current Dataset on which Save As was run
                            FileCloseCommand fcc = new FileCloseCommand();
                            fcc.CloseDataset(false);

                            //Open Dataset that was SaveAs-ed.
                            FileOpenCommand fo = new FileOpenCommand();
                            fo.FileOpen(saveasFileDialog.FileName);
                        }
                        else
                        {
                            BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
                            MessageBox.Show(BSky.GlobalResources.Properties.Resources.SaveAsFailed + saveasFileDialog.FileName, BSky.GlobalResources.Properties.Resources.InternalError, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                        }
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                service.SaveAs(filename, controller.GetActiveDocument()); // #0
                controller.GetActiveDocument().Changed = false;           //21Mar2014 during close it should not prompt again for saving
            }
            BSkyMouseBusyHandler.HideMouseBusy();                         //HideProgressbar_old();
        }
Beispiel #13
0
        ////Send executed command to output window. So, user will know what he executed
        //protected override void SendToOutputWindow(string command, string title)//13Dec2013
        //{
        //    #region Get Active output Window
        //    //////// Active output window ///////
        //    OutputWindowContainer owc = (LifetimeService.Instance.Container.Resolve<IOutputWindowContainer>()) as OutputWindowContainer;
        //    OutputWindow ow = owc.ActiveOutputWindow as OutputWindow; //get currently active window
        //    #endregion
        //    ow.AddMessage(command, title);
        //}

        public bool OpenDataframe(string dframename)
        {
            initGlobalObjects();
            if (!AreDefaultRPackagesLoaded())
            {
                return(false);
            }
            BSkyMouseBusyHandler.ShowMouseBusy();//ShowProgressbar_old();//ShowStatusProgressbar();//29Oct2014
            bool isSuccess = false;


            string filename = controller.GetActiveDocument().FileName;
            //For Excel
            string sheetname = controller.GetActiveDocument().SheetName;

            if (sheetname == null)
            {
                sheetname = string.Empty;
            }
            // if dataset was already loaded last time then this time we want to refresh it
            bool isDatasetNew = service.isDatasetNew(dframename + sheetname);

            try
            {
                DataSource ds       = service.OpenDataframe(dframename, sheetname);
                string     errormsg = string.Empty;
                if (ds != null && ds.Message != null && ds.Message.Length > 0) //message that is related to error
                {
                    errormsg = "\n" + ds.Message;
                    ds       = null; //making it null so that we do execute further
                }
                if (ds != null)      //03Dec2012
                {
                    logService.WriteToLogLevel("Start Loading Dataframe: " + ds.Name, LogLevelEnum.Info);
                    if (isDatasetNew)
                    {
                        controller.Load_Dataframe(ds);
                    }
                    else
                    {
                        controller.RefreshBothGrids(ds); //23Jul2015 .RefreshGrids(ds);//.RefreshDataSet(ds);
                    }
                    ds.Changed = true;                   // keep track of change made, so that it can prompt for saving while closing dataset tab.
                    logService.WriteToLogLevel("Finished Loading Dataframe: " + ds.Name, LogLevelEnum.Info);
                    //recentfiles.AddXMLItem(dframename);//adding to XML file for recent docs
                    isSuccess = true;
                }
                else
                {
                    BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
                    MessageBox.Show(appwindow, BSky.GlobalResources.Properties.Resources.cantopen + " '" + dframename + "'" +
                                    "\n" + BSky.GlobalResources.Properties.Resources.reasonsAre +
                                    "\n" + BSky.GlobalResources.Properties.Resources.NotDataframe2 +
                                    "\n" + BSky.GlobalResources.Properties.Resources.FormatNotSupported2 +
                                    "\n" + BSky.GlobalResources.Properties.Resources.NoRowsColsPresent +
                                    "\n" + BSky.GlobalResources.Properties.Resources.OldSessionRunning2 +
                                    "\n" + BSky.GlobalResources.Properties.Resources.RSideIssue2,
                                    BSky.GlobalResources.Properties.Resources.warning, MessageBoxButton.OK, MessageBoxImage.Warning);
                    SendToOutputWindow(BSky.GlobalResources.Properties.Resources.ErrOpeningDataset2, dframename + errormsg);
                }
            }
            catch (Exception ex)
            {
                logService.WriteToLogLevel("Error:" + ex.Message, LogLevelEnum.Error);
            }
            finally
            {
                //18OCt2013 move up for using in msg box   Window1 appwindow = LifetimeService.Instance.Container.Resolve<Window1>();//for refeshing recent files list
                //appwindow.RefreshRecent();
                BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();//HideStatusProgressbar();//29Oct2014
            }

            //if (isSuccess)
            //{
            //08Apr2015 bring main window in front after file open, instead of output window
            //Window1 window = LifetimeService.Instance.Container.Resolve<Window1>();
            //window.Activate();
            //}
            return(isSuccess);
        }
Beispiel #14
0
        //this is common. Called from FileOpen and OnExecute, only after checking default R packages
        private void OpenDataset(string filename)
        {
            // Start Some animation for loading dataset ///
            BSkyMouseBusyHandler.ShowMouseBusy();//ShowProgressbar_old();//ShowStatusProgressbar();//29Oct2014

            if (filename != null && filename.Length > 0)
            {
                if (System.IO.File.Exists(filename))
                {
                    string sheetname = null;
                    if (filename.EndsWith(".xls") || filename.EndsWith(".xlsx"))//27Jan2014
                    {
                        object tbls = service.GetOdbcTableList(filename);
                        if (tbls != null)
                        {
                            SelectTableWindow stw   = new SelectTableWindow();
                            string[]          tlist = null;

                            if (tbls.GetType().Name.Equals("String"))
                            {
                                tlist    = new string[1];
                                tlist[0] = tbls as string;
                            }
                            else if (tbls.GetType().Name.Equals("String[]"))
                            {
                                tlist = tbls as string[];
                            }

                            stw.FillList(tlist);
                            BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
                            stw.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            stw.ShowDialog();
                            BSkyMouseBusyHandler.ShowMouseBusy();     //ShowProgressbar_old();
                            if (stw.SelectedTableName == null)        //cancel clicked
                            {
                                BSkyMouseBusyHandler.HideMouseBusy(); //HideProgressbar_old();//HideStatusProgressbar();//29Oct2014
                                return;
                            }
                            else
                            {
                                sheetname = stw.SelectedTableName;
                            }
                        }
                    }
                    logService.WriteToLogLevel("Setting DataSource: ", LogLevelEnum.Info);
                    DataSource ds       = service.Open(filename, sheetname);
                    string     errormsg = string.Empty;
                    if (ds != null && ds.Message != null && ds.Message.Length > 0) //message that is related to error
                    {
                        errormsg = "\n" + ds.Message;
                        ds       = null;//making it null so that we stop executing further
                    }

                    if (ds != null)//03Dec2012
                    {
                        logService.WriteToLogLevel("Start Loading: " + ds.Name, LogLevelEnum.Info);
                        controller.LoadNewDataSet(ds);
                        logService.WriteToLogLevel("Finished Loading: " + ds.Name, LogLevelEnum.Info);
                        recentfiles.AddXMLItem(filename);//adding to XML file for recent docs
                    }
                    else
                    {
                        BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();

                        //Following block is not needed
                        //StringBuilder sb = new StringBuilder();
                        //List<string> defpacklist = defaultpackges.RecentFileList;
                        //foreach(string s in defpacklist)
                        //{
                        //    sb.Append(s+", ");

                        //}
                        //sb.Remove(sb.Length - 1, 1);//removing last comma
                        //string defpkgs = sb.ToString();


                        MessageBox.Show(errormsg, BSky.GlobalResources.Properties.Resources.ErrOpeningFile + "(" + filename + ")", MessageBoxButton.OK, MessageBoxImage.Warning);
                        SendToOutputWindow(BSky.GlobalResources.Properties.Resources.ErrOpeningDataset, filename + errormsg);
                    }
                }
                else
                {
                    BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
                    MessageBox.Show(filename + " " + BSky.GlobalResources.Properties.Resources.DoesNotExist,
                                    BSky.GlobalResources.Properties.Resources.FileNotFound, MessageBoxButton.OK, MessageBoxImage.Warning);
                    //If file does not exist. It should be removed from the recent files list.
                    recentfiles.RemoveXMLItem(filename);
                }
                //18OCt2013 move up for using in msg box   Window1 appwindow = LifetimeService.Instance.Container.Resolve<Window1>();//for refeshing recent files list
                appwindow.RefreshRecent();
            }
            BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();// HideStatusProgressbar();//29Oct2014

            //08Apr2015 bring main window in front after file open, instead of output window
            Window1 window = LifetimeService.Instance.Container.Resolve <Window1>();

            window.Activate();
        }
Beispiel #15
0
        protected override void OnExecute(object param)
        {
            BSkyMouseBusyHandler.ShowMouseBusy();//ShowProgressbar_old();
            IUnityContainer container  = LifetimeService.Instance.Container;
            IDataService    service    = container.Resolve <IDataService>();
            IUIController   controller = container.Resolve <IUIController>();

            if (controller.GetActiveDocument().isUnprocessed)
            {
                NewDatasetProcessor procDS = new NewDatasetProcessor();
                bool isProcessed           = procDS.ProcessNewDataset("", true);
                if (isProcessed)//true:empty rows cols removed successfully. False: whole dataset was empty and nothing was removed.
                {
                    controller.GetActiveDocument().isUnprocessed = false;
                }
                else
                {
                    BSkyMouseBusyHandler.HideMouseBusy();
                    MessageBox.Show("The dataset is empty. Please populate the dataset and save the file.", "Empty Dataset", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
            }

            //Get current filetype from loaded dataset. This is file extension and Filter
            DataSource actds = controller.GetActiveDocument();//06Nov2012

            if (actds == null)
            {
                return;
            }
            string datasetName = "" + actds.Name;//uadatasets$lst$
            //string datasetName = "uadatasets$lst$" + controller.GetActiveDocument().Name;
            //Also try to get the filename of currently loaded file. This is FileName.
            string extension = controller.GetActiveDocument().Extension;
            string filename  = controller.GetActiveDocument().FileName;


            SaveFileDialog saveasFileDialog = new SaveFileDialog();

            saveasFileDialog.Filter = FileNameFilter;
            //CheckBox cbox = new CheckBox();

            //saveasFileDialog.FileName = filename;//////
            Window1 appwin = LifetimeService.Instance.Container.Resolve <Window1>();
            bool?   output = saveasFileDialog.ShowDialog(appwin);//Application.Current.MainWindow);

            if (output.HasValue && output.Value)
            {
                service.SaveAs(saveasFileDialog.FileName, controller.GetActiveDocument()); // #0
                controller.GetActiveDocument().Changed = false;                            //21Mar2014 during close it should not prompt again for saving

                if (System.IO.File.Exists(saveasFileDialog.FileName))
                {
                    //Close current Dataset on whic Save As was run
                    FileCloseCommand fcc = new FileCloseCommand();
                    fcc.CloseDataset(false);

                    //Open Dataset that was SaveAs-ed.
                    FileOpenCommand fo = new FileOpenCommand();
                    fo.FileOpen(saveasFileDialog.FileName);
                }
                else
                {
                    BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
                    MessageBox.Show(BSky.GlobalResources.Properties.Resources.SaveAsFailed + saveasFileDialog.FileName, BSky.GlobalResources.Properties.Resources.InternalError, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
            }
            BSkyMouseBusyHandler.HideMouseBusy();//HideProgressbar_old();
        }