示例#1
0
        protected internal virtual void StartAddin(string name)
        {
            AssemblyInformation asmInfo = assemblyDAO.GetAssemblyInformation(name, "A");

            assemblyManager.UpdateAppDataFolder(asmInfo, AppDomain.CurrentDomain.BaseDirectory);
            LoadAddin(asmInfo);
        }
示例#2
0
        protected internal virtual void StartAddin(string addinCode)
        {
            AssemblyInformation asmInfo = assemblyDAO.GetAssemblyInformation(addinCode);

            if (asmInfo != null)
            {
                LoadAddin(asmInfo);
            }
        }
示例#3
0
        internal void RemoveAddIn(string addinCode)
        {
            AssemblyInformation asm = asmDAO.GetAssemblyInformation(addinCode);

            if (asm != null)
            {
                List <AssemblyInformation> dependencies = asmDAO.GetDependencies(asm);
                foreach (var dep in dependencies)
                {
                    if (asmDAO.GetDependencyCount(dep) == 1)
                    {
                        asmDAO.RemoveAssembly(dep.Code);
                    }
                }
                asmDAO.RemoveAssembly(asm.Code);
                Logger.Info(string.Format(Messages.RemoveAddinSuccess, asm.Name));
            }
        }
示例#4
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);
        }
示例#5
0
        /// <summary>
        /// Register a valid addin. WARNING: this method does not check if the addin is valid, it just
        /// save it to the database with the correct data structure, such as version and MD5SUM. It's important
        /// to call AddInIsValid if you're not sure on what is being passed as path, otherwise there will
        /// be errors during addin startup.
        /// </summary>
        /// <param name="path">path for the file to be saved</param>
        /// <returns>Name of saved addin</returns>
        internal string SaveAddIn(string path)
        {
            if (path == null || path.Length < 4)
            {
                Logger.Error(string.Format(Messages.SaveAddInError, path.Return(x => x, String.Empty)));
                return(string.Empty);
            }
            else
            {
                try
                {
                    string directory;
                    string fileName  = Path.GetFileName(path);
                    string addInName = fileName.Substring(0, fileName.Length - 4);
                    bool   hasi18n   = false;
                    string type      = (addInName == "Framework") ? "C" : "A";
                    byte[] asmBytes;

                    AssemblyInformation existingAsm = asmDAO.GetAssemblyInformation(addInName, type);

                    if (fileName.EndsWith(".zip"))
                    {
                        directory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                        Directory.CreateDirectory(directory);
                        fileName = UnzipFile(path, directory);
                        hasi18n  = true;
                    }
                    else
                    {
                        directory = Path.GetDirectoryName(path);
                    }

                    AssemblyInformation newAsm   = GetNewAsm(directory, fileName, addInName, type, out asmBytes);
                    AssemblyInformation savedAsm = SaveIfNotExistsOrDifferent(existingAsm, newAsm, asmBytes);
                    if (hasi18n)
                    {
                        SaveAddinI18NResources(directory, addInName, savedAsm.Code);
                    }

                    licenseManager.BootLicense(); // reload licenses to include added license.
                    Logger.Info(string.Format(Messages.SaveAddInSuccess, path));
                    return(addInName);
                }
                catch (Exception e)
                {
                    Logger.Error(string.Format(Messages.SaveAddInError, path), e);
                    return(string.Empty);
                }
            }
        }