Exemple #1
0
        private void UpdateAddinDueDateByNamespace(string licenseNamespace)
        {
            List <string> addinsCode = licenseDAO.getAddinsByNamespace(licenseNamespace);

            licenseDAO.UpdateNamespaceDueDate(licenseNamespace, DateTime.MinValue);

            var setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.ConfigureDomain";
            setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
            AppDomain configureDomain = AppDomain.CreateDomain("ConfigureDomain", null, setup);

            try
            {
                configureDomain.SetData("assemblyName", "tempDomain");
                IApplication app = (IApplication)configureDomain.CreateInstanceAndUnwrap("Framework",
                                                                                         "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(configureDomain);
                LicenseManager licenseManager = app.Resolve <LicenseManager>();
                foreach (var addinCode in addinsCode)
                {
                    DateTime dueDate;
                    if (licenseManager.AddinIsValid(addinCode, out dueDate))
                    {
                        licenseDAO.UpdateAddinDueDate(addinCode, dueDate);
                    }
                }
            }
            finally
            {
                AppDomain.Unload(configureDomain);
            }
        }
Exemple #2
0
        internal bool AddinIsValid(string asmCode, out DateTime dueDate)
        {
            dueDate = DateTime.MinValue;
            if (asmCode == null)
            {
                return(false);
            }

            var setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.ConfigureDomain";
            string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(tempDirectory);
            setup.ApplicationBase = tempDirectory;
            AppDomain configureDomain = AppDomain.CreateDomain("ConfigureDomain", null, setup);

            try
            {
                AssemblyInformation asm = asmDAO.GetAssemblyInformation(asmCode);
                fileUpdate.UpdateAppDataFolder(asm, tempDirectory);

                configureDomain.SetData("assemblyName", "tempDomain");
                IApplication app = (IApplication)configureDomain.CreateInstanceAndUnwrap("Framework",
                                                                                         "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(configureDomain);
                LicenseVerifyAddin licenseManager = app.Resolve <LicenseVerifyAddin>();

                if (asm != null)
                {
                    return(licenseManager.AddinIsValid(asm.Name, out dueDate));
                }
            }
            catch (Exception e)
            {
                Logger.Error("Unhandled error", e);
            }
            finally
            {
                AppDomain.Unload(configureDomain);
                try
                {
                    Directory.Delete(tempDirectory, true);
                }
                catch (Exception e)
                {
                    Logger.Debug(string.Format("Directory {0} not cleaned", tempDirectory), e);
                }
            }
            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Return true if the addin is valid.
        /// </summary>
        /// <param name="path">Path name for the intended addin</param>
        /// <param name="comments">DataTable serialized, to be displayed to the user with db change information.</param>
        /// <returns>true if addin is valid</returns>
        internal bool AddInIsValid(string path, out string datatable)
        {
            string    extension  = Path.GetExtension(path);
            AppDomain testDomain = null;
            string    mainDll    = string.Empty;
            bool      ret;
            string    tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(tempDirectory);

            // check if it's a DLL or ZIP.
            if (extension != null && extension == ".zip")
            {
                mainDll = UnzipFile(path, tempDirectory);
            }
            else if (extension != null && (extension == ".dll" || extension == ".exe"))
            {
                string destination = Path.Combine(tempDirectory, Path.GetFileName(path));
                File.Copy(path, destination);
                mainDll = Path.GetFileName(path);
            }
            else
            {
                throw new ArgumentException(Messages.InvalidAddInExtension);
            }
            if (mainDll == null)
            {
                datatable = string.Empty;
                return(false);
            }

            mainDll = mainDll.Substring(0, mainDll.Length - 4);

            testDomain = CreateTestDomain(mainDll, tempDirectory);
            try
            {
                testDomain.SetData("assemblyName", mainDll); // Used to get current AssemblyName for logging and reflection
                Application testApp = (Application)testDomain.CreateInstanceAndUnwrap("Framework", "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(testDomain);
                var addinManager = testApp.Resolve <AddinManager>();
                ret = addinManager.CheckAddinConfiguration(mainDll, out datatable);
                testApp.ShutDownApp();
            }
            finally
            {
                AppDomain.Unload(testDomain);
                Directory.Delete(tempDirectory, true);
            }
            return(ret);
        }
Exemple #4
0
        /// <summary>
        /// Return true if the addin is valid.
        /// </summary>
        /// <param name="path">Path name for the intended addin</param>
        /// <param name="datatable">DataTable serialized, to be displayed to the user with db change information.</param>
        /// <param name="addinName">Name of the addin, defined using an AddinAttribute</param>
        /// <param name="addinName">Namespace of the addin, defined using an AddinAttribute</param>
        /// <returns>true if addin is valid</returns>
        internal bool AddInIsValid(string path, out string datatable, out string addinName, out string addinNamespace)
        {
            string    extension  = Path.GetExtension(path);
            AppDomain testDomain = null;
            string    mainDll    = string.Empty;
            bool      ret;
            string    tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(tempDirectory);

            // check if it's a DLL or ZIP.
            if (extension != null && extension == ".dover")
            {
                mainDll = UnzipFile(path, tempDirectory);
            }
            else
            {
                throw new ArgumentException(Messages.InvalidAddInExtension);
            }
            if (mainDll == null)
            {
                datatable      = string.Empty;
                addinName      = string.Empty;
                addinNamespace = string.Empty;
                return(false);
            }

            mainDll    = Path.GetFileNameWithoutExtension(mainDll);
            testDomain = CreateTestDomain(mainDll, tempDirectory);
            try
            {
                testDomain.SetData("assemblyName", mainDll); // Used to get current AssemblyName for logging and reflection
                IApplication testApp = (IApplication)testDomain.CreateInstanceAndUnwrap("Framework", "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(testDomain);
                var addinManager = testApp.Resolve <IAddinManager>();
                ret = addinManager.CheckAddinConfiguration(mainDll, out datatable, out addinName, out addinNamespace);
            }
            finally
            {
                AppDomain.Unload(testDomain);
                try
                {
                    Directory.Delete(tempDirectory, true);
                } catch (Exception e)
                {
                    Logger.Debug(string.Format("Directory {0} not cleaned", tempDirectory), e);
                }
            }
            return(ret);
        }
Exemple #5
0
        private void GetAssemblyInfoFromBin(string directory, byte[] asmBytes, AssemblyInformation asmInfo)
        {
            AppDomain tempDomain;
            var       setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.GetAssemblyInformation";
            setup.ApplicationBase = directory;
            tempDomain            = AppDomain.CreateDomain("Dover.GetAssemblyInformation", null, setup);
            List <AssemblyInformation> dependencyInformation;

            try
            {
                IApplication app = (IApplication)tempDomain.CreateInstanceAndUnwrap("Framework",
                                                                                    "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(tempDomain);
                ITempAssemblyLoader asmLoader = app.Resolve <ITempAssemblyLoader>();
                dependencyInformation = asmLoader.GetAssemblyInfoFromBin(asmBytes, asmInfo);
                asmInfo.Dependencies  = new List <AssemblyInformation>();

                // The appDomain will die, clone return.
                foreach (var dep in dependencyInformation)
                {
                    AssemblyInformation newInfo = new AssemblyInformation();
                    newInfo.Build       = dep.Build;
                    newInfo.Code        = dep.Code;
                    newInfo.Date        = dep.Date;
                    newInfo.FileName    = string.Copy(dep.FileName);
                    newInfo.Major       = dep.Major;
                    newInfo.MD5         = string.Copy(dep.MD5);
                    newInfo.Minor       = dep.Minor;
                    newInfo.Name        = string.Copy(dep.Name);
                    newInfo.Namespace   = string.Empty;
                    newInfo.Description = string.Copy(dep.Description);
                    newInfo.Revision    = dep.Revision;
                    newInfo.Size        = dep.Size;
                    newInfo.Type        = dep.Type;
                    asmInfo.Dependencies.Add(newInfo);
                }
            }
            finally
            {
                AppDomain.Unload(tempDomain);
            }
        }
Exemple #6
0
 private void PrivateBoot()
 {
     try
     {
         Application app = (Application)Inception.CreateInstanceAndUnwrap("Framework", "Dover.Framework.Application");
         SAPServiceFactory.PrepareForInception(Inception); // need to be after Application creation because of assembly resolving from embedded resources.
         Inception.SetData("assemblyName", "Framework");   // Used to get current AssemblyName for logging and reflection
         InceptionAddinManager = app.Resolve <AddinManager>();
         Sponsor <Application>  appSponsor          = new Sponsor <Application>(app);
         Sponsor <AddinManager> addInManagerSponsor = new Sponsor <AddinManager>(InceptionAddinManager);
         app.RunInception();
         AppDomain.Unload(Inception); // release AppDomain on shutdown.
     }
     catch (Exception e)
     {
         System.Windows.Forms.MessageBox.Show(string.Format("{0}\n{1}", e.Message, e.StackTrace));
         throw e;
     }
 }
Exemple #7
0
        private void GetAssemblyInfoFromBin(byte[] asmBytes, AssemblyInformation asmInfo)
        {
            AppDomain tempDomain;
            var       setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.GetAssemblyInformation";
            setup.ApplicationBase = Environment.CurrentDirectory;
            tempDomain            = AppDomain.CreateDomain("Dover.GetAssemblyInformation", null, setup);

            try
            {
                Application app = (Application)tempDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName,
                                                                                  "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(tempDomain);
                TempAssemblyLoader asmLoader = app.Resolve <TempAssemblyLoader>();
                asmLoader.GetAssemblyInfoFromBin(asmBytes, asmInfo);
            }
            finally
            {
                AppDomain.Unload(tempDomain);
            }
        }
Exemple #8
0
        private void ConfigureAddin(AssemblyInformation addin)
        {
            Logger.Info(String.Format(Messages.ConfiguringAddin, addin));
            var setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.ConfigureDomain";
            setup.ApplicationBase = Environment.CurrentDirectory;
            AppDomain configureDomain = AppDomain.CreateDomain("ConfigureDomain", null, setup);

            try
            {
                Application app = (Application)configureDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName,
                                                                                       "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(configureDomain);
                ConfigAddin addinConfig = app.Resolve <ConfigAddin>();
                addinConfig.ConfigureAddin(addin);
            }
            finally
            {
                AppDomain.Unload(configureDomain);
            }
        }
Exemple #9
0
        internal void Run()
        {
            var setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.Inception";
            setup.ApplicationBase = Environment.CurrentDirectory;
            var domain = AppDomain.CreateDomain("Dover.AddIn", null, setup);

            domain.SetData("shutdownEvent", shutdownEvent); // Thread synchronization
            domain.SetData("assemblyName", asm.Name);       // Used to get current AssemblyName for logging and reflection
            domain.SetData("frameworkManager", frameworkAddinManager);
            Application app = (Application)domain.CreateInstanceAndUnwrap("Framework", "Dover.Framework.Application");

            SAPServiceFactory.PrepareForInception(domain);
            addinB1SResourceManager = app.Resolve <B1SResourceManager>();
            addinFormEventHandler   = app.Resolve <FormEventHandler>();
            addinLoader             = app.Resolve <AddinLoader>();
            eventDispatcher         = app.Resolve <EventDispatcher>();
            Sponsor <Application>        appSponsor       = new Sponsor <Application>(app);
            Sponsor <B1SResourceManager> b1sSponsor       = new Sponsor <B1SResourceManager>(addinB1SResourceManager);
            Sponsor <FormEventHandler>   formEventSponsor = new Sponsor <FormEventHandler>(addinFormEventHandler);
            Sponsor <AddinLoader>        loaderSponsor    = new Sponsor <AddinLoader>(addinLoader);
            Sponsor <EventDispatcher>    eventSponsor     = new Sponsor <EventDispatcher>(eventDispatcher);

            try
            {
                app.RunAddin();
                AppDomain.Unload(domain);
            }
            catch (AppDomainUnloadedException e)
            {
                // ignore and continue shutdown.
            }
            finally
            {
                runningAddins.Remove(this);
                runningAddinsHash.Remove(asm.Name);
            }
        }
Exemple #10
0
        private void ConfigureAddin(AssemblyInformation addin, string baseDirectory)
        {
            Logger.Info(String.Format(Messages.ConfiguringAddin, addin));
            var setup = new AppDomainSetup();

            setup.ApplicationName = "Dover.ConfigureDomain";
            setup.ApplicationBase = baseDirectory;
            AppDomain configureDomain = AppDomain.CreateDomain("ConfigureDomain", null, setup);

            try
            {
                IApplication app = (IApplication)configureDomain.CreateInstanceAndUnwrap("Framework",
                                                                                         "Dover.Framework.Application");
                SAPServiceFactory.PrepareForInception(configureDomain);
                IConfigAddin addinConfig = app.Resolve <IConfigAddin>();
                addinConfig.ConfigureAddin(addin.Name);
            }
            finally
            {
                AppDomain.Unload(configureDomain);
            }
        }