////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);
        }
예제 #2
0
        //This is to finally execute a query that will return a data frame that will be loaded in a grid.
        private bool ExecuteQuery(string query, string dframename)
        {
            //Get table using custom query
            DataFrame alltablesDF = null;
            //Get list of Tables in a database.
            string command = null;// "GetDataframe(" + ConnectionString + ", databasename ='" + SelectedDatabase + "', '" + query + "','" + dframename + "')";

            if (ServerType.Equals("MS-ACCESS"))
            {
                command = "GetDataframe(" + ConnectionString + ", query= '" + query + "', datasetname='" + dframename + "')";
            }
            else
            {
                command = "GetDataframe(" + ConnectionString + ", databasename ='" + SelectedDatabase + "', query= '" + query + "', datasetname='" + dframename + "')";
            }
            //object alltables = service.ImportTableListFromSQL(command);


            UAReturn uaret = service.ImportTableListFromSQL(command);

            OutputHelper.AnalyticsData.Result = uaret;//putting DOM

            //A table is always returned with single bool value that shows whether Dataset
            //creation in R memory was success or not
            bool[] visibleRows;
            int    datanumber     = 1;                             // there is just one table that we are intrested in. Its first table in  /Root/UATableList
            bool   isDatasetReady = false;
            int    backup         = OutputHelper.FlexGridMaxCells; //backup current value

            OutputHelper.FlexGridMaxCells = 1000;                  //change to required value
            string[,] datasetReady        = OutputHelper.GetDataMatrix(datanumber, out visibleRows);
            OutputHelper.FlexGridMaxCells = backup;                //restore original value back again;
            if (datasetReady != null)
            {
                isDatasetReady = datasetReady[0, 0].ToLower().Equals("true") ? true : false;
            }
            //// Now fetching errors if any
            string[,] ew = OutputHelper.GetBSkyErrorsWarning(0, "normal");//0 for automatically finding the tablenumber
            if (ew != null)
            {
                StringBuilder errmsg = new StringBuilder();
                int           rcount = ew.GetLength(0);
                int           ccount = ew.GetLength(1);
                for (int r = 0; r < rcount; r++)
                {
                    for (int c = 0; c < ccount; c++)
                    {
                        errmsg.Append(ew[r, c] + "\n");
                    }
                }

                MessageBox.Show(errmsg.ToString(), "Errors/Warnings:", MessageBoxButton.OK, MessageBoxImage.Error);
                HideProgressbar();
            }

            if (!isDatasetReady) // if dataset was not created in R memory due to wrong query or other reasons.
            {
                return(false);
            }


            DataSource ds        = service.OpenDataframe(dframename, "");
            bool       isSuccess = false;
            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
            {
                bool isDatasetNew = true; // service.isDatasetNew(dframename + "");
                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
            {
                HideProgressbar();
                MessageBox.Show("Unable to open SQL dataframe'" + 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)." +
                                "\n6. Incorrect values provided while connecting to the SQL server.",
                                "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                //SendToOutputWindow("Error Opening Dataset.(probably not a data frame)", dframename + errormsg);
            }

            HideProgressbar();
            return(true);
        }
예제 #3
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);
        }
        ////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)
        {
            ShowProgressbar();//ShowStatusProgressbar();//29Oct2014
            bool            isSuccess  = false;
            IUnityContainer container  = LifetimeService.Instance.Container;
            IDataService    service    = container.Resolve <IDataService>();
            IUIController   controller = container.Resolve <IUIController>();
            Window1         appwindow  = LifetimeService.Instance.Container.Resolve <Window1>();//for refeshing recent files list

            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
                {
                    HideProgressbar();
                    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. R.Net server from the old session still running (use task manager to kill it)." +
                                    "\n4. 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);
                }
            }
            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();
                HideProgressbar();//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);
        }