BlueSky.Commands.Tools.Package.PackageHelperMethods.InstallReqPackageFrmCRAN C# (CSharp) Method

InstallReqPackageFrmCRAN() public method

public InstallReqPackageFrmCRAN ( string pkgname ) : UAReturn
pkgname string
return BSky.Statistics.Common.UAReturn
        public UAReturn InstallReqPackageFrmCRAN(string pkgname)
        {
            //set CRAN
            //UAReturn setcran = service.setCRANMirror();
            //if (setcran != null)
            //{
            //}

            ShowMouseBusy();

            //string pkgname = null;
            if (pkgname == null || pkgname.Length < 1)
            {
                ShowMouseFree();
                return null;
            }
            UAReturn instpkg = service.installReqPackageCRAN(pkgname);

            //Now try to load the pacakge, just installed by CRAN
            string retmsg = string.Empty;
            string[] pkgs = pkgname.Split(',');
            UAReturn loadpkg;
            string loadComm = string.Empty;
            if (instpkg != null)
            {
                if (instpkg.Success)//CRAN install was success
                {
                    loadpkg = service.loadPackageFromList(pkgs);
                    retmsg = loadpkg.Error;
                    loadComm = loadpkg.CommandString;
                }
                else if (!instpkg.Success)//CRAN install prbably failed. May be package already present or some other issue.
                {
                    retmsg = "";
                    loadComm = "";
                }
            }
            else//CRAN install prbably failed
            {
                retmsg = "";
                loadComm = "";
            }

            instpkg.Error = instpkg.Error + "\n" + retmsg;
            instpkg.CommandString = instpkg.CommandString + "\n" + loadComm;
            ShowMouseFree();
            return instpkg;
        }

Usage Example

        protected override void OnExecute(object param)
        {
            Window1 appwindow = LifetimeService.Instance.Container.Resolve <Window1>();

            try
            {
                appwindow.setLMsgInStatusBar(BSky.GlobalResources.Properties.Resources.PlzWait + " " + BSky.GlobalResources.Properties.Resources.InstallReqRPkgFrmCRAN2);
                ShowMouseBusy();
                //Get list of required pacakges from RequiredPackages.xml
                List <string>        reqPkgList = GetReqRPackageList();
                PackageHelperMethods phm        = new PackageHelperMethods();
                UAReturn             r          = null;
                foreach (string pkgname in reqPkgList)
                {
                    r = phm.InstallReqPackageFrmCRAN(pkgname);
                    if (r != null)
                    {
                        // It is not error message. It could be success/failure msg. A status message basically.
                        SendToOutputWindow(BSky.GlobalResources.Properties.Resources.RPkgInstallStatus, r.Error);
                    }
                }
                ShowMouseFree();
            }
            catch (Exception ex)
            {
                ShowMouseFree();
                MessageBox.Show(BSky.GlobalResources.Properties.Resources.ErrInstallReqPkgFrmCRAN, BSky.GlobalResources.Properties.Resources.ErrorOccurred);
                logService.WriteToLogLevel("Error:", LogLevelEnum.Error, ex);
            }
            appwindow.setLMsgInStatusBar("");
        }