Esempio n. 1
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);
                }
            }
        }