Example #1
0
        /// <summary>
        /// Get licenses from resources embedded in the specified assembly. If assembly is null, licenses are loaded from the assembly containing the LicenseProvider implementation.
        /// </summary>
        /// <returns></returns>
        public List <ICreditInfo> GetCredits(Assembly assembly = null)
        {
            assembly = GetAssembly(assembly);
            List <Assembly> assemblies = new List <Assembly>();

            assemblies.Add(assembly);
            AssemblyName[] referencedAssemblies = assembly.GetReferencedAssemblies();
            foreach (var assemblyName in referencedAssemblies)
            {
                Assembly referencedAssembly = Assembly.Load(assemblyName);
                assemblies.Add(referencedAssembly);
            }
            List <ICreditInfo> credits = new List <ICreditInfo>();

            foreach (Assembly a in assemblies)
            {
                string[]          resourceNames    = a.GetManifestResourceNames();
                IEmbeddedResource embeddedResource = new EmbeddedResource();
                List <string>     resourceNameList = new List <string>(resourceNames.Length);
                resourceNameList.AddRange(resourceNames);
                resourceNameList.Sort();
                foreach (string resourceName in resourceNameList)
                {
                    if (resourceName.ToLower().EndsWith("credit.xml"))
                    {
                        using (Stream resourceStream = embeddedResource.ExtractToStream(resourceName, a))
                        {
                            try
                            {
                                var creditInfo = SerializerHelper <CreditInfo> .DeSerialize(resourceStream);

                                credits.Add(creditInfo);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Failed to deserialize embedded resource '{0}' in '{1}'. {2}",
                                                  resourceName, a.FullName, ex.Message);
                            }
                        }
                    }
                }
            }
            return(credits);
        }