Beispiel #1
0
        public NonModalWokIt(object session, CommandLineParams o)
        {
            InitializeComponent();

            this.session = session;

            this.o = o;
            l      = new EpicorLauncher();
        }
        private static Session GetEpiSession(CommandLineParams o)
        {
            string  password = o.Password;
            Session ses      = null;

            //Create a copy of the config file so that we can set a temporary cache folder for our instance
            var newConfig = Path.GetTempFileName().Replace(".tmp", ".sysconfig");

            File.Copy(o.ConfigFile, newConfig, true);
            o.NewConfig = newConfig;

            //Create a temp directory to store our epicor cache
            DirectoryInfo di = Directory.CreateDirectory(Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString()));

            o.Temp = di.FullName;
            var x = XElement.Load(newConfig);

            //Set our new Temp Cache location in our new config
            x.Descendants("appSettings").Elements().Where(r => r.Name == "AlternateCacheFolder").FirstOrDefault().FirstAttribute.Value = di.FullName;
            x.Save(newConfig);

            try
            {
                password = NeedtoEncrypt(o);
                ses      = new Session(o.Username, password, Session.LicenseType.Default, newConfig);
            }
            catch (Exception ex)
            {
                ShowProgressBar(false);
                MessageBox.Show("Failed to Authenticate", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);


                LoginForm frm = new LoginForm(o.EpicorClientFolder);
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    ShowProgressBar();
                    o.Username   = Settings.Default.Username;
                    o.Password   = Settings.Default.Password;
                    o.ConfigFile = Settings.Default.Environment;
                    o.Encrypted  = "true";
                    password     = NeedtoEncrypt(o);

                    try
                    {
                        ses = new Session(o.Username, password, Session.LicenseType.Default, newConfig);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Failed to Authenticate", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        ses = null;
                    }
                    ShowProgressBar(true);
                }
            }

            if (ses != null)
            {
                SecRightsHandler.CacheBOSecSettings(ses);

                dynamic curMRUList = typeof(SecRightsHandler).GetField("_currMRUList", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

                Startup.SetupPlugins(ses);

                if (!string.IsNullOrEmpty(o.DLLLocation))
                {
                    String fineName = Path.GetFileName(o.DLLLocation);
                    string newPath  = Path.GetDirectoryName((string)curMRUList.GetType().GetProperty("SavePath", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public).GetValue(curMRUList)).Replace("BOSecMRUList", "CustomDLLs");
                    o.DLLLocation = Path.Combine(newPath, fineName);
                }

                epi.Ice.Lib.Configuration c = new epi.Ice.Lib.Configuration(newConfig);

                c.AlternateCacheFolder = di.FullName;
                Assembly assy  = Assembly.LoadFile(Path.Combine(o.EpicorClientFolder, "Epicor.exe"));
                TypeInfo ty    = assy.DefinedTypes.Where(r => r.Name == "ConfigureForAutoDeployment").FirstOrDefault();
                dynamic  thing = Activator.CreateInstance(ty);

                object[] args = { c };
                thing.GetType().GetMethod("SetUpAssemblyRetrieversAndPossiblyGetNewConfiguration", BindingFlags.Instance | BindingFlags.Public).Invoke(thing, args);
                WellKnownAssemblyRetrievers.AutoDeployAssemblyRetriever  = (IAssemblyRetriever)thing.GetType().GetProperty("AutoDeployAssemblyRetriever", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).GetValue(thing);
                WellKnownAssemblyRetrievers.SessionlessAssemblyRetriever = (IAssemblyRetriever)thing.GetType().GetProperty("SessionlessAssemblyRetriever", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).GetValue(thing);

                Startup.PreStart(ses, true);
                launcher = new EpicorLauncher();
            }
            return(ses);
        }