Пример #1
0
        public IExtension Load(string extensionPath)
        {
            var document = new XmlDocument();

            document.Load(extensionPath);

            var topNode = document.GetElementsByTagName("ExtensionDefinition");

            if (topNode.Count == 0)
            {
                Log("Malformed " + extensionPath + " file");
                return(null);
            }

            var definition = new ExtensionDefinition();

            foreach (XmlNode item in topNode[0].ChildNodes)
            {
                if (item.Name == "AssemblyPath")
                {
                    definition.AssemblyPath = item.InnerText;
                }
                else if (item.Name == "TypeName")
                {
                    definition.TypeName = item.InnerText;
                }
            }

            var extension = Load(definition);

            return(extension);
        }
Пример #2
0
        /// <summary>
        /// Loads <see cref="IExtension"/> from assembly.
        /// </summary>
        /// <param name="extensionPath">Assembly full path</param>
        /// <returns>Loaded <see cref="IExtension"/></returns>
        public IExtension Load(string extensionPath)
        {
            var document = new XmlDocument();
            document.Load(extensionPath);

            var topNode = document.GetElementsByTagName("ExtensionDefinition");

            if (topNode.Count == 0)
            {
                Log("Malformed " + extensionPath + " file");
                return null;
            }

            var definition = new ExtensionDefinition();
            var path = Path.GetDirectoryName(extensionPath);
            foreach (XmlNode item in topNode[0].ChildNodes)
            {
                if (item.Name == "AssemblyPath")
                {
                    path = Path.Combine(path, item.InnerText);
                    definition.AssemblyPath = path;
                }
                else if (item.Name == "TypeName")
                {
                    definition.TypeName = item.InnerText;
                }
            }

            var extension = Load(definition);
            return extension;
        }
Пример #3
0
        private IExtension Load(ExtensionDefinition extension)
        {
            try
            {
                if (extension.RequiresSignedEntryPoint)
                {
                    CertificateVerification.CheckAssemblyForValidCertificate(extension.AssemblyPath);
                }

                var assembly = Assembly.LoadFrom(extension.AssemblyPath);
                var result   = assembly.CreateInstance(extension.TypeName) as IExtension;
                ExtensionLoading?.Invoke(result);

                Logging.Analytics.TrackEvent(
                    Actions.Load,
                    Categories.ExtensionOperations, extension.TypeName);

                return(result);
            }
            catch (Exception ex)
            {
                var name = extension.TypeName == null ? "null" : extension.TypeName;
                Log("Could not create an instance of " + name);
                Log(ex.Message);
                Log(ex.StackTrace);
                return(null);
            }
        }
Пример #4
0
 private IExtension Load(ExtensionDefinition extension)
 {
     try
     {
         var assembly = Assembly.Load(extension.AssemblyPath);
         var result   = assembly.CreateInstance(extension.TypeName) as IExtension;
         return(result);
     }
     catch
     {
         var name = extension.TypeName == null ? "null" : extension.TypeName;
         Log("Could not create an instance of " + name);
         return(null);
     }
 }
Пример #5
0
 private IExtension Load(ExtensionDefinition extension)
 {
     try
     {
         var assembly = Assembly.LoadFrom(extension.AssemblyPath);
         var result = assembly.CreateInstance(extension.TypeName) as IExtension;
         return result;
     }
     catch
     {
         var name = extension.TypeName == null ? "null" : extension.TypeName;
         Log("Could not create an instance of " + name);
         return null;
     }
 }
Пример #6
0
 private IExtension Load(ExtensionDefinition extension)
 {
     try
     {
         var assembly = Assembly.LoadFrom(extension.AssemblyPath);
         var result   = assembly.CreateInstance(extension.TypeName) as IExtension;
         ExtensionLoading?.Invoke(result);
         return(result);
     }
     catch (Exception ex)
     {
         var name = extension.TypeName == null ? "null" : extension.TypeName;
         Log("Could not create an instance of " + name);
         Log(ex.Message);
         Log(ex.StackTrace);
         return(null);
     }
 }
Пример #7
0
        /// <summary>
        /// Loads <see cref="IExtension"/> from assembly.
        /// </summary>
        /// <param name="extensionPath">Assembly full path</param>
        /// <returns>Loaded <see cref="IExtension"/></returns>
        public IExtension Load(string extensionPath)
        {
            var document = new XmlDocument();

            document.Load(extensionPath);

            var topNode = document.GetElementsByTagName("ExtensionDefinition");

            if (topNode.Count == 0)
            {
                Log("Malformed " + extensionPath + " file");
                return(null);
            }

            var definition = new ExtensionDefinition();
            var path       = Path.GetDirectoryName(extensionPath);

            foreach (XmlNode item in topNode[0].ChildNodes)
            {
                if (item.Name == "AssemblyPath")
                {
                    path = Path.Combine(path, item.InnerText);
                    definition.AssemblyPath = path;
                }
                else if (item.Name == "TypeName")
                {
                    definition.TypeName = item.InnerText;
                }
            }

            //Check if the extension definition file was located in a directory which requires certificate validation.
            foreach (var pathToVerifyCert in DirectoriesToVerifyCertificates)
            {
                if (extensionPath.Contains(pathToVerifyCert))
                {
                    definition.RequiresSignedEntryPoint = true;
                }
            }

            var extension = Load(definition);

            return(extension);
        }