示例#1
0
        private string GetThisAsmCode(Assembly thisAsm)
        {
            var types = (from type in thisAsm.GetTypes()
                         where type.IsClass
                         select type);

            foreach (var type in types)
            {
                var            addinAttributes = type.GetCustomAttributes(typeof(AddInAttribute), true);
                AddInAttribute addinAttribute;
                if (addinAttributes.Count() > 0)
                {
                    addinAttribute = (AddInAttribute)addinAttributes[0];
                    return(asmDAO.GetAssemblyCode(addinAttribute.Name, addinAttribute.Namespace, Model.AssemblyType.Addin));
                }
            }
            return(null);
        }
示例#2
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>
        /// <param name="addinName">Name of the addin</param>
        /// <param name="addinNamespace">Namespace of the addin</param>
        internal void SaveAddIn(string path, string addinName, string addinNamespace)
        {
            if (path == null || path.Length < 4)
            {
                Logger.Error(string.Format(Messages.SaveAddInError, path.Return(x => x, String.Empty)));
            }
            else
            {
                try
                {
                    string directory;
                    string fileName = Path.GetFileName(path);
                    if (!fileName.EndsWith(".dover"))
                    {
                        Logger.Error(Messages.InvalidAddInExtension);
                    }

                    AssemblyType type = (addinName == "Framework" && addinNamespace == "Dover") ? AssemblyType.Core : AssemblyType.Addin;

                    directory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                    Directory.CreateDirectory(directory);
                    fileName = UnzipFile(path, directory);

                    string addinCode = asmDAO.GetAssemblyCode(addinName, addinNamespace, AssemblyType.Addin);
                    AssemblyInformation existingAsm = null;
                    if (addinCode != null)
                    {
                        existingAsm = asmDAO.GetAssemblyInformation(addinCode);
                    }
                    AssemblyInformation newAsm   = GetCurrentAsm(directory, fileName, type);
                    AssemblyInformation savedAsm = SaveIfNotExistsOrDifferent(existingAsm, newAsm, directory);

                    Logger.Info(string.Format(Messages.SaveAddInSuccess, path));
                }
                catch (InvalidCastException e)
                {
                    Logger.Error(string.Format(Messages.UpdateFrameworkError));
                }
                catch (Exception e)
                {
                    Logger.Error(string.Format(Messages.SaveAddInError, path), e);
                }
            }
        }