Exemplo n.º 1
0
        /// <summary>
        /// add assembly to list
        /// </summary>
        /// <param name="name"></param>
        /// <param name="itemAssembly"></param>
        /// <returns>list of dependend assemblies</returns>
        private static string[] AddAssembly(string name, Assembly itemAssembly)
        {
            List <string> dependAssemblies = new List <string>();

            object[] attributes = itemAssembly.GetCustomAttributes(true);
            foreach (object itemAttribute in attributes)
            {
                string fullnameAttribute = itemAttribute.GetType().FullName;
                DebugConsole.WriteLine("Attribute:{0}", fullnameAttribute);
                if (fullnameAttribute == "NetOffice.NetOfficeAssemblyAttribute")
                {
                    Type factoryInfoType = itemAssembly.GetType(name + ".Utils.ProjectInfo");
                    NetOffice.IFactoryInfo factoryInfo = Activator.CreateInstance(factoryInfoType) as NetOffice.IFactoryInfo;

                    bool exists = false;
                    foreach (IFactoryInfo itemFactory in _factoryList)
                    {
                        DebugConsole.WriteLine("IFactoryInfo:{0}:{1}", itemFactory.Assembly.FullName, factoryInfo.Assembly.FullName);

                        if (itemFactory.Assembly.FullName == factoryInfo.Assembly.FullName)
                        {
                            exists = true;
                            break;
                        }
                    }
                    if (!exists)
                    {
                        _factoryList.Add(factoryInfo);
                    }

                    foreach (string itemDependency in factoryInfo.Dependencies)
                    {
                        bool found = false;
                        foreach (string itemExistingDependency in dependAssemblies)
                        {
                            if (itemDependency == itemExistingDependency)
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            dependAssemblies.Add(itemDependency);
                        }
                    }
                }
            }

            return(dependAssemblies.ToArray());
        }
Exemplo n.º 2
0
 /// <summary>
 /// Assembly loader for multitargeting(host) scenarios
 /// </summary>
 /// <param name="fileName"></param>
 /// <returns></returns>
 private static Assembly TryLoadAssembly(string fileName)
 {
     try
     {
         string directoryName = _thisAssembly.CodeBase.Substring(0, _thisAssembly.CodeBase.LastIndexOf("/"));
         directoryName = directoryName.Replace("/", "\\").Substring(8);
         string fullFileName = System.IO.Path.Combine(directoryName, fileName);
         if (System.IO.File.Exists(fullFileName))
         {
             Assembly assembly                  = System.Reflection.Assembly.LoadFrom(fullFileName);
             Type     factoryInfoType           = assembly.GetType(fileName.Substring(0, fileName.Length - 4) + ".Utils.ProjectInfo", false, false);
             NetOffice.IFactoryInfo factoryInfo = Activator.CreateInstance(factoryInfoType) as NetOffice.IFactoryInfo;
             bool exists = false;
             foreach (IFactoryInfo itemFactory in _factoryList)
             {
                 if (itemFactory.Assembly.FullName == factoryInfo.Assembly.FullName)
                 {
                     exists = true;
                     break;
                 }
             }
             if (!exists)
             {
                 _factoryList.Add(factoryInfo);
                 DebugConsole.WriteLine("Recieve IFactoryInfo:{0}:{1}", factoryInfo.Assembly.FullName, factoryInfo.Assembly.FullName);
             }
             return(assembly);
         }
         else
         {
             DebugConsole.WriteLine(string.Format("Unable to resolve assembly {0}. The assembly doesnt exists in current codebase.", fileName));
             return(null);
         }
     }
     catch (Exception exception)
     {
         DebugConsole.WriteException(exception);
         return(null);
     }
 }