public UAReturn PackageInstall(string[] pkgfilenames, bool autoLoad = true, bool overwrite = false)//(string package, string filepath)
        {
            UAReturn r = null;

            r = _userSession.DefaultDispatcher.InstallLocalPackage(pkgfilenames, autoLoad, overwrite);//(package, filepath);
            return(r);
        }
        private List <string> GetFunctionNamesInRPackage(string RPkgName)
        {
            List <string> PkgDatsetNames   = new List <string>();
            List <string> PkgFunctionNames = null;

            try
            {
                PackageHelperMethods phm = new PackageHelperMethods();
                UAReturn             r   = phm.GetFunctionnamesFromRPkg(RPkgName);
                if (r != null && r.Success && r.SimpleTypeData != null)
                {
                    PkgFunctionNames = r.SimpleTypeData as List <string>;
                }
                else
                {
                    if (r.Error != null && r.Error.Length > 1)
                    {
                        MessageBox.Show(r.Error);
                    }
                    ////SendToOutputWindow(BSky.GlobalResources.Properties.Resources.ErrGettingInstalledPkgs, "", false);
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(BSky.GlobalResources.Properties.Resources.ErrGettingInstalledPkgs2, BSky.GlobalResources.Properties.Resources.ErrorOccurred);
                MessageBox.Show(ex.Message);
                logService.WriteToLogLevel("Error:", LogLevelEnum.Error, ex);
            }
            return(PkgFunctionNames);//PkgDatsetNames;
        }
        private UAReturn IsUserRlibValid(string userRlibConfig)
        {
            UAReturn result = new UAReturn()
            {
                Success = true
            };

            if (!Directory.Exists(userRlibConfig))
            {
                string msg1 = "'User R library path' does not exist:\n" + userRlibConfig;
                string msg2 = "\nGo to Tools -> Configuration Settings -> Path Settings -> and set a valid 'User R library path'";
                result.Success = false;
                result.Error   = msg1 + msg2;
                logService.WriteToLogLevel(msg1 + msg2, LogLevelEnum.Error);
                return(result);
            }

            bool canWrite = isWritableDirectory(userRlibConfig);

            if (!canWrite)
            {
                string msg1 = "You do not have write permission in the current 'User R library path':\n" + userRlibConfig;
                string msg2 = "\nGo to Tools -> Configuration Settings -> Path Settings -> and set a valid 'User R library path'";
                result.Success = false;
                result.Error   = msg1 + msg2;
                logService.WriteToLogLevel(msg1 + msg2, LogLevelEnum.Error);
                return(result);
            }
            return(result);
        }
        public UAReturn showUserRLibInstalledPackages()
        {
            UAReturn r = _analyticService.ShowUserRlibPackageInstalled();

            //SendToOutput(r);
            return(r);
        }
        public UAReturn getMissingDefaultRPackages()
        {
            UAReturn r = _analyticService.GetMissingDefPackages();

            //SendToOutput(r);
            return(r);
        }
        public UAReturn installReqPackageCRAN(string packagename)//27Aug2015
        {
            UAReturn r = _analyticService.CRANReqPackageInstall(packagename);

            //SendToOutput(r);
            return(r);
        }
        public UAReturn loadPackage(string package)
        {
            UAReturn r = _analyticService.PackageLoad(package);

            //SendToOutput(r);
            return(r);
        }
        public UAReturn ShowPackageLoaded()
        {
            UAReturn r = null;

            r = _userSession.DefaultDispatcher.ShowLoadedPackages();
            return(r);
        }
        public UAReturn GetMissingDefPackages()
        {
            UAReturn r = null;

            r = _userSession.DefaultDispatcher.GetMissingDefRPackages();
            return(r);
        }
        public UAReturn ListPackageLoad(string[] packagenames)
        {
            UAReturn r = null;

            r = _userSession.DefaultDispatcher.LoadPackageFromList(packagenames);
            return(r);
        }
        public UAReturn ShowUserRlibPackageInstalled()
        {
            UAReturn r = null;

            r = _userSession.DefaultDispatcher.ShowUserRLibInstalledPackages();
            return(r);
        }
        public UAReturn PackageLoad(string package)
        {
            UAReturn r = null;

            r = _userSession.DefaultDispatcher.LoadLocalPackage(package);
            return(r);
        }
        public UAReturn setCRANMirror()
        {
            UAReturn r = null;

            r = _userSession.DefaultDispatcher.setCRANMirror();
            return(r);
        }
        //27Aug2015
        public UAReturn CRANReqPackageInstall(string packagename)
        {
            UAReturn r = null;

            r = _userSession.DefaultDispatcher.InstallReqPackageFromCRAN(packagename);
            return(r);
        }
        // 06Dec2013
        #region Package Related
        public UAReturn installPackage(string[] pkgfilenames, bool autoLoad = true, bool overwrite = false) //(string package, string filepath)
        {
            UAReturn r = _analyticService.PackageInstall(pkgfilenames, autoLoad, overwrite);                //(package, filepath);

            //SendToOutput(r);
            return(r);
        }
        public UAReturn PackageUninstall(string[] packagenames)
        {
            UAReturn r = null;

            r = _userSession.DefaultDispatcher.UninstallPackages(packagenames);
            return(r);
        }
        public UAReturn installCRANPackage(string packagename)
        {
            UAReturn r = _analyticService.CRANPackageInstall(packagename);

            //SendToOutput(r);
            return(r);
        }
        public UAReturn GetPkgDatasetList(string packagename)//12Feb2019
        {
            UAReturn r = null;

            r = _userSession.DefaultDispatcher.FetchRpkgDatasetList(packagename);
            return(r);
        }
        public UAReturn setCRANMirror()
        {
            UAReturn r = _analyticService.setCRANMirror();

            //SendToOutput(r);
            return(r);
        }
        public UAReturn ImportTableListFromSQL(string sqlcommand)//24Nov2015
        {
            UAReturn uret = _analyticService.GetSQLTableList(sqlcommand);

            //return uret.SimpleTypeData;
            return(uret);
        }
        public UAReturn loadPackageFromList(string[] packagenames)
        {
            UAReturn r = _analyticService.ListPackageLoad(packagenames);

            //SendToOutput(r);
            return(r);
        }
        public object GetRDataDataframeObjList(string filename)//23May2018
        {
            string   datasetname = "Dataset" + SessionDatasetCounter;
            UAReturn tbls        = _analyticService.GetRDataDframeObjList(filename);

            return(tbls.SimpleTypeData);
        }
        public UAReturn showLoadedPackages()
        {
            UAReturn r = _analyticService.ShowPackageLoaded();

            //SendToOutput(r);
            return(r);
        }
        //27Oct2016
        #region R Object save / Load

        public UAReturn GetAllRObjects()
        {
            UAReturn r = _analyticService.GetAllRObjs();

            //SendToOutput(r);
            return(r);
        }
        public UAReturn uninstallPackage(string[] packagenames)
        {
            UAReturn r = _analyticService.PackageUninstall(packagenames);

            //SendToOutput(r);
            return(r);
        }
        public UAReturn SaveRObjects(string objname, string fullpathfilename)
        {
            UAReturn r = _analyticService.SaveRObjs(objname, fullpathfilename);

            //SendToOutput(r);
            return(r);
        }
        //Currently Installed Packages.  pk <- installed.packages()
        public string[] GetInstalledPackages(bool AllLibPaths = true)
        {
            //Get R User lib from config
            //R standard rule: If lib is missing in install.packages(), defaults to the first element of .libPaths().
            //so better pass lib parameter so that user can install his/her own R packages in user personal library.
            string   userRlibConfig = confService.GetConfigValueForKey("userRlib");
            UAReturn result         = IsUserRlibValid(userRlibConfig);

            if (!result.Success)
            {
                string[] error = new string[1];
                error[0] = result.Error;
                return(error);
            }

            string commandstring = string.Empty;

            if (AllLibPaths)
            {
                commandstring = "tmp <- installed.packages(lib.loc= NULL, noCache = TRUE)";
            }
            else //only user-R-lib
            {
                commandstring = "tmp <- installed.packages(lib.loc= '" + userRlibConfig + "', noCache = TRUE)";
            }
            _journal.WriteLine(commandstring);
            _dispatcher.EvaluateToObject(commandstring, false);

            object o = _dispatcher.EvaluateToObject("rownames(tmp)", true); // returns row-header which are packagenames.

            string[] pkgs = this.ObjectToStringArray(o);
            return(pkgs);
        }
        public UAReturn LoadRObjects(string fullpathfilename)
        {
            UAReturn r = _analyticService.LoadRObjs(fullpathfilename);

            //SendToOutput(r);
            return(r);
        }
        //Uninstall multiple packages.
        public UAReturn UninstallMultiPakckage(string[] packagenames)
        {
            UAReturn res = new UAReturn()
            {
                Success = false
            };
            UAReturn      tmp  = null;                  //11May2014 for temporary return value
            StringBuilder sb   = new StringBuilder("");
            StringBuilder comm = new StringBuilder(""); //11May2014 for storing multiple commands in single place

            foreach (string pkgname in packagenames)
            {
                tmp = UninstallPackage(pkgname.Trim());
                if (tmp != null)
                {
                    if (tmp.CommandString != null) //11May2014
                    {
                        if (comm.Length > 1)
                        {
                            comm.Append("\n");                  // if there is already something then only add new line
                        }
                        comm.Append(tmp.CommandString);
                    }
                    if (tmp.Error != null && tmp.Error.Length > 1) // if there is some error msg
                    {
                        sb.Append(tmp.Error);
                    }
                }
            }
            res.Success       = sb.Length > 0 ? false : true;
            res.Error         = sb.ToString();
            res.CommandString = comm.ToString();//11May2014
            return(res);
        }
        //06Dec2013
        #region Package Related

        public UAReturn GetDefaultUserRLib()
        {
            UAReturn r = null;

            r = _userSession.DefaultDispatcher.GenerateDefaultUserPersonalRLibPath();
            return(r);
        }