예제 #1
0
        public static bool RegisterAnalyseAssembly(string keyName, VAssembly assembly)
        {
            if (assembly == null)
            {
                return(false);
            }
            assembly.KeyName = keyName;
            Dictionary <string, VAssembly> dic;

            if (!mAnalyseAssemblyDic.TryGetValue(assembly.CSType, out dic))
            {
                dic = new Dictionary <string, VAssembly>();
                mAnalyseAssemblyDic.Add(assembly.CSType, dic);
            }
            dic.Add(keyName, assembly);
            mAnalyseAssemblyFullNameDic[assembly.FullName] = assembly;

            return(true);
        }
예제 #2
0
        public VAssembly GetAssembly(System.Reflection.Assembly assembly, ECSType csType, string keyName = "")
        {
            if (assembly == null)
            {
                return(null);
            }

            var vAssem = EngineNS.Rtti.RttiHelper.GetAnalyseAssemblyByFullName(assembly.FullName);

            if (vAssem != null)
            {
                mAssembly_FullNameDic[vAssem.FullName] = vAssem;
                if (!assembly.IsDynamic)
                {
                    mAssembly_AbsFileDic[assembly.Location.Replace("\\", "/")] = vAssem;
                }
                return(vAssem);
            }
            if (mAssembly_FullNameDic.TryGetValue(assembly.FullName, out vAssem))
            {
                return(vAssem);
            }
            vAssem = new VAssembly(assembly, csType);
            if (string.IsNullOrEmpty(keyName))
            {
                vAssem.KeyName = assembly.GetName().Name;// + ".dll";
            }
            else
            {
                vAssem.KeyName = keyName;
            }
            mAssembly_FullNameDic[assembly.FullName] = vAssem;
            if (!assembly.IsDynamic)
            {
                mAssembly_AbsFileDic[assembly.Location.Replace("\\", "/")] = vAssem;
            }
            return(vAssem);
        }
예제 #3
0
        static void RemoveAssemblyTypes(VAssembly assembly)
        {
            if (assembly == null)
            {
                return;
            }
            Dictionary <EngineNS.EPlatformType, Dictionary <string, Type> > platFormDic;

            if (!mTypeNameDic.TryGetValue(assembly.CSType, out platFormDic))
            {
                return;
            }
            Dictionary <string, Type> typeDic;

            if (!platFormDic.TryGetValue(CIPlatform.Instance.PlatformType, out typeDic))
            {
                return;
            }
            foreach (var type in assembly.GetTypes())
            {
                typeDic.Remove(type.FullName);
            }
        }
예제 #4
0
        public VAssembly GetAssemblyFromType(Type sourceType)
        {
            if (sourceType == null)
            {
                return(null);
            }
            VAssembly outAssembly;

            if (mAssembly_TypeDic.TryGetValue(sourceType, out outAssembly))
            {
                return(outAssembly);
            }

            if (mAssembly_FullNameDic.TryGetValue(sourceType.Assembly.FullName, out outAssembly))
            {
                mAssembly_TypeDic[sourceType] = outAssembly;
                return(outAssembly);
            }

            outAssembly = EngineNS.Rtti.RttiHelper.GetAnalyseAssemblyByFullName(sourceType.Assembly.FullName);
            if (outAssembly != null)
            {
                mAssembly_TypeDic[sourceType] = outAssembly;
                return(outAssembly);
            }

            outAssembly                   = new VAssembly(sourceType.Assembly, ECSType.Common);
            outAssembly.KeyName           = sourceType.Assembly.GetName().Name;// + ".dll";
            mAssembly_TypeDic[sourceType] = outAssembly;
            mAssembly_FullNameDic[outAssembly.FullName] = outAssembly;
            if (!outAssembly.Assembly.IsDynamic)
            {
                mAssembly_AbsFileDic[outAssembly.Assembly.Location.Replace("\\", "/")] = outAssembly;
            }
            return(outAssembly);
            //var assemblys = AppDomain.CurrentDomain.GetAssemblies();
            //for(int i=0; i<assemblys.Length; i++)
            //{
            //    try
            //    {
            //        var types = assemblys[i].GetTypes();
            //        for (int typeIdx = 0; typeIdx < types.Length; typeIdx++)
            //        {
            //            ////////////////////////////////////////////////////////
            //            if(types[typeIdx].Name.Contains("ObservableCollection"))
            //            {

            //            }
            //            ////////////////////////////////////////////////////////
            //            if (types[typeIdx].Equals(sourceType))
            //            {
            //                outAssembly = new VAssembly(assemblys[i], ECSType.Common);
            //                outAssembly.KeyName = assemblys[i].GetName().Name + ".dll";
            //                mAssembly_TypeDic[sourceType] = outAssembly;
            //                mAssembly_FullNameDic[outAssembly.FullName] = outAssembly;
            //                return outAssembly;
            //            }
            //        }
            //    }
            //    catch (System.Exception ex)
            //    {
            //        System.Diagnostics.Trace.WriteLine(ex.ToString());
            //    }
            //}

            //return null;
        }
예제 #5
0
        public VAssembly LoadAssembly_Impl(string assemblyAbsFile, EngineNS.ECSType csType, bool fromBytes = false, bool useCashe = true, string keyName = "", bool useVPDB = true)
        {
            if (CEngine.Instance != null && !CEngine.Instance.FileManager.FileExists(assemblyAbsFile))
            {
                return(null);
            }

            assemblyAbsFile = assemblyAbsFile.Replace("\\", "/");

            if (useCashe)
            {
                VAssembly retValue;
                if (mAssembly_AbsFileDic.TryGetValue(assemblyAbsFile, out retValue))
                {
                    return(retValue);
                }

                var assemblys = System.AppDomain.CurrentDomain.GetAssemblies();
                for (int i = 0; i < assemblys.Length; i++)
                {
                    if (assemblys[i].IsDynamic)
                    {
                        continue;
                    }

                    var path = assemblys[i].Location.Replace("\\", "/");
                    if (string.Equals(path, assemblyAbsFile))
                    {
                        var retAs = GetAssembly(assemblys[i], csType, keyName);
                        if (!string.IsNullOrEmpty(keyName))
                        {
                            retAs.KeyName = keyName;
                        }
                        return(retAs);
                    }
                }
            }

            {
                try
                {
                    var assemblyBytes = IO.FileManager.ReadFile(assemblyAbsFile);
                    if (assemblyBytes == null)
                    {
                        return(null);
                    }

                    System.Reflection.Assembly assembly = null;
                    if (fromBytes)
                    {
                        string pdbExt = ".pdb";
                        if (useVPDB)
                        {
                            pdbExt = ".vpdb";
                        }
                        var    pdbFile  = assemblyAbsFile.Substring(0, assemblyAbsFile.Length - 4) + pdbExt;
                        byte[] pdbBytes = null;
                        if (CEngine.Instance.FileManager.FileExists(pdbFile))
                        {
                            pdbBytes = IO.FileManager.ReadFile(pdbFile);
                        }

                        assembly = System.Reflection.Assembly.Load(assemblyBytes, pdbBytes);
                    }
                    else
                    {
                        assembly = System.Reflection.Assembly.LoadFrom(assemblyAbsFile);
                    }
                    var vAssem = new VAssembly(assembly, csType);
                    mAssembly_FullNameDic[assembly.FullName] = vAssem;
                    mAssembly_AbsFileDic[assemblyAbsFile]    = vAssem;
                    if (string.IsNullOrEmpty(keyName))
                    {
                        vAssem.KeyName = assembly.GetName().Name;
                    }
                    else
                    {
                        vAssem.KeyName = keyName;
                    }
                    return(vAssem);
                }
                catch (Exception e)
                {
                    EngineNS.Profiler.Log.WriteException(e);
                    //System.Diagnostics.Trace.WriteLine("VAssemblyManager.LoadAssembly\r\n" + e.ToString());
                }
            }

            return(null);
        }