Пример #1
0
        public VAssembly LoadAssembly(string assemblyAbsFile, EngineNS.ECSType csType, bool fromBytes = false, bool useCashe = true, string keyName = "", bool useVPDB = true)
        {
            ScopeLoadAssm.Begin();
            var ret = LoadAssembly_Impl(assemblyAbsFile, csType, fromBytes, useCashe, keyName, useVPDB);

            ScopeLoadAssm.End();
            return(ret);
        }
Пример #2
0
        public TypeCastControl(CodeGenerateSystem.Base.ConstructionParams csParam)
            : base(csParam)
        {
            InitConstruction();

            mCSType  = (EngineNS.ECSType)System.Enum.Parse(typeof(EngineNS.ECSType), csParam.ConstructParam);
            NodeName = "强制类型转换";
            AddLinkPinInfo("CtrlClassLinkHandle_In", mCtrlClassLinkHandle_In, null);
            AddLinkPinInfo("CtrlClassLinkHandle_Out", mCtrlClassLinkHandle_Out, null);
        }
Пример #3
0
        protected void SetParameters(string[] paramInfos, EngineNS.ECSType csType)
        {
            foreach (var info in paramInfos)
            {
                var tempSplits = info.Split(':');
                if (tempSplits.Length > 2)
                {
                    switch (tempSplits[2])
                    {
                    case "Ref":
                    case "Out":
                        tempSplits[1] += "&";
                        break;
                    }
                }
                CodeGenerateSystem.Base.BaseNodeControl pc = null;
                var type = EngineNS.Rtti.RttiHelper.GetTypeFromSaveString(tempSplits[1]);
                if (type != null && type.IsSubclassOf(typeof(System.Delegate)))
                {
                    var csParam = new MethodInvoke_DelegateControl.MethodInvoke_DelegateControlConstructionParams()
                    {
                        CSType             = csType,
                        HostNodesContainer = this.HostNodesContainer,
                        ConstructParam     = info + ":" + this.NodeName,
                        ConstructType      = MethodInvokeNode.enParamConstructType.MethodOverride,
                    };
                    pc = new MethodInvoke_DelegateControl(csParam);
                }
                else
                {
                    var csParam = new MethodInvokeParameterControl.MethodInvokeParameterConstructionParams()
                    {
                        CSType             = csType,
                        HostNodesContainer = this.HostNodesContainer,
                        ConstructParam     = info,
                        ConstructType      = MethodInvokeNode.enParamConstructType.MethodOverride,
                    };
                    pc = new MethodInvokeParameterControl(csParam);
                }

                AddChildNode(pc, mParamsPanel);
            }
        }
Пример #4
0
        //protected async Task<System.CodeDom.Compiler.CompilerResults> CompileMacrossCollector(MacrossLinkControlBase ctrl, EngineNS.EPlatformType platform)
        //{
        //    string collectorDllName = "";
        //    List<string> refAssemblys = new List<string>();
        //    refAssemblys.Add("System.dll");
        //    string compileOption = "";
        //    switch (ctrl.CSType)
        //    {
        //        case EngineNS.ECSType.Client:
        //            switch (platform)
        //            {
        //                case EngineNS.EPlatformType.PLATFORM_WIN:
        //                    collectorDllName = EngineNS.CEngine.Instance.FileManager.Bin + EngineNS.Macross.MacrossDataManager.MacrossCollectorDllName;
        //                    refAssemblys.Add(EngineNS.CEngine.Instance.FileManager.Bin + "CoreClient.Windows.dll");
        //                    if (mCompileType == enCompileType.Debug)
        //                        compileOption = "/define:MacrossDebug";
        //                    break;
        //                case EngineNS.EPlatformType.PLATFORM_DROID:
        //                    collectorDllName = EngineNS.CEngine.Instance.FileManager.Bin + EngineNS.Macross.MacrossDataManager.MacrossCollectorDllName_Android;
        //                    refAssemblys.Add(EngineNS.CEngine.Instance.FileManager.Bin + "CoreClient.Android.dll");
        //                    break;
        //                default:
        //                    throw new InvalidOperationException();
        //            }
        //            //refAssemblys.Add(EngineNS.CEngine.Instance.FileManager.Bin + "MacrossScript.dll");
        //            break;
        //        case EngineNS.ECSType.Server:
        //            throw new InvalidOperationException();
        //    }
        //    return await mCodeGenerator.CompileMacrossCollector(ctrl.CSType, collectorDllName, refAssemblys.ToArray(), compileOption, mCompileType == enCompileType.Debug);

        //}

        protected async Task <bool> CompileCode(MacrossLinkControlBase ctrl, EngineNS.ECSType csType)
        {
            await mCodeGenerator.GenerateAndSaveMacrossCollector(csType);

            var codeStr = await mCodeGenerator.GenerateCode(CurrentResourceInfo, ctrl);

            if (!EngineNS.CEngine.Instance.FileManager.DirectoryExists(CurrentResourceInfo.ResourceName.Address))
            {
                EngineNS.CEngine.Instance.FileManager.CreateDirectory(CurrentResourceInfo.ResourceName.Address);
            }
            var codeFile = $"{CurrentResourceInfo.ResourceName.Address}/{CurrentResourceInfo.ResourceName.PureName()}_{ctrl.CSType.ToString()}.cs";

            using (var fs = new System.IO.FileStream(codeFile, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite))
            {
                fs.Write(System.Text.Encoding.Default.GetBytes(codeStr), 0, Encoding.Default.GetByteCount(codeStr));
            }

            var files = mCodeGenerator.CollectionMacrossProjectFiles(csType);

            mCodeGenerator.GenerateMacrossProject(files.ToArray(), csType);

            return(await EditorCommon.Program.BuildGameDllImmediately(true));
        }
Пример #5
0
 public static bool UnRegisterAnalyseAssembly(EngineNS.ECSType csType, string keyName)
 {
     if (string.IsNullOrEmpty(keyName))
     {
         return(false);
     }
     mTypeNameDic.Clear();
     if (csType == ECSType.All)
     {
         foreach (var dic in mAnalyseAssemblyDic.Values)
         {
             VAssembly assembly;
             if (dic.TryGetValue(keyName, out assembly))
             {
                 mAnalyseAssemblyFullNameDic.Remove(assembly.FullName);
                 RemoveAssemblyTypes(assembly);
                 dic.Remove(keyName);
             }
         }
     }
     else
     {
         Dictionary <string, VAssembly> dic;
         if (mAnalyseAssemblyDic.TryGetValue(csType, out dic))
         {
             VAssembly assembly;
             if (dic.TryGetValue(keyName, out assembly))
             {
                 mAnalyseAssemblyFullNameDic.Remove(assembly.FullName);
                 RemoveAssemblyTypes(assembly);
                 dic.Remove(keyName);
             }
         }
     }
     return(true);
 }
Пример #6
0
        public void BuildAssemblyRPC(System.Reflection.Assembly[] assems, string[] assemMacro, EngineNS.ECSType csType)
        {
            if (assems == null)
            {
                assems = AppDomain.CurrentDomain.GetAssemblies();
            }
            List <RPCTypeInfo> AllClass = new List <RPCTypeInfo>();

            for (var i = 0; i < assems.Length; i++)
            {
                try
                {
                    var assm = assems[i];

                    if (assemMacro != null && assemMacro.Length == assems.Length && string.IsNullOrEmpty(assemMacro[i]))
                    {
                        assemMacro[i] = GetAssmemblyRPCMacro(assm);
                    }
                    foreach (var j in assm.GetTypes())
                    {
                        if (j.IsSubclassOf(typeof(RPCProcessor)))
                        {
                            if (j.IsGenericType)
                            {
                                continue;
                            }
                            if (RPCProcessor.GetProcessor(j) == null)
                            {
                                RPCProcessor.InitProcessor(j);
                            }
                        }

                        if (IsRPCClass(j))
                        {
                            var tmp = new RPCTypeInfo();
                            tmp.Type = j;
                            if (assemMacro != null && assemMacro.Length == assems.Length)
                            {
                                tmp.Macro = assemMacro[i];
                            }
                            AllClass.Add(tmp);
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    EngineNS.Profiler.Log.WriteException(ex);
                }
            }
            //只有不会再被派生的类才能做RPC分析,否则就会出现一个RPCParameter被多个函数使用的情况
            var finalKlass = GetFinalKlass(AllClass);

            foreach (var i in finalKlass)
            {
                RegClass(i.Type, i.Macro, csType);
            }

            RefreshRPCMap(null);
        }
Пример #7
0
 public void Initialize(EngineNS.ECSType csType)
 {
     CSType = csType;
 }
Пример #8
0
        /// <summary>
        /// 获取类的继承类列表
        /// </summary>
        /// <param name="parentTypeString">父类类型全名称,不包含Assembly信息</param>
        /// <returns></returns>
        public static List <Type> GetInheritTypesFromType(string parentTypeString, EngineNS.ECSType csType)
        {
            if (string.IsNullOrEmpty(parentTypeString))
            {
                return(new List <Type>());
            }

            Dictionary <EngineNS.EPlatformType, Dictionary <string, List <Type> > > platFormDic;

            if (!mTypeInheritDic.TryGetValue(csType, out platFormDic))
            {
                platFormDic             = new Dictionary <EngineNS.EPlatformType, Dictionary <string, List <Type> > >();
                mTypeInheritDic[csType] = platFormDic;
            }

            Dictionary <string, List <Type> > typeDic;

            if (!platFormDic.TryGetValue(CIPlatform.Instance.PlatformType, out typeDic))
            {
                typeDic = new Dictionary <string, List <Type> >();
                platFormDic[CIPlatform.Instance.PlatformType] = typeDic;
            }

            if (typeDic.ContainsKey(parentTypeString))
            {
                return(typeDic[parentTypeString]);
            }

            var parentType = GetTypeFromTypeFullName(parentTypeString, csType);

            if (parentType == null)
            {
                return(new List <Type>());
            }

            List <Type> retValue = new List <Type>();

            if (csType == EngineNS.ECSType.All)
            {
                foreach (var assemDic in mAnalyseAssemblyDic.Values)
                {
                    foreach (var assembly in assemDic.Values)
                    {
                        if (parentType.IsInterface)
                        {
                            foreach (var type in assembly.GetTypes())
                            {
                                if (type.GetInterface(parentType.FullName) != null)
                                {
                                    retValue.Add(type);
                                }
                            }
                        }
                        else
                        {
                            foreach (var type in assembly.GetTypes())
                            {
                                if (type.IsSubclassOf(parentType))
                                {
                                    retValue.Add(type);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Dictionary <string, VAssembly> assemDic;
                if (mAnalyseAssemblyDic.TryGetValue(csType, out assemDic))
                {
                    foreach (var assembly in assemDic.Values)
                    {
                        if (parentType.IsInterface)
                        {
                            foreach (var type in assembly.GetTypes())
                            {
                                if (type.GetInterface(parentType.FullName) != null)
                                {
                                    retValue.Add(type);
                                }
                            }
                        }
                        else
                        {
                            foreach (var type in assembly.GetTypes())
                            {
                                if (type.IsSubclassOf(parentType))
                                {
                                    retValue.Add(type);
                                }
                            }
                        }
                    }
                }
            }

            typeDic[parentTypeString] = retValue;
            return(retValue);
        }
Пример #9
0
 public static string GetClassName(Macross.ResourceInfos.MacrossResourceInfo info, EngineNS.ECSType csType)
 {
     if (info.ResourceName == null)
     {
         return("");
     }
     return(GetClassName(info.ResourceName));
 }
Пример #10
0
 public static string GetClassNamespace(Macross.ResourceInfos.MacrossResourceInfo info, EngineNS.ECSType csType)
 {
     return(GetClassNamespace(info.ResourceName));
 }
Пример #11
0
 public Editor_MacrossClassAttribute(EngineNS.ECSType csType, enMacrossType macrossType)
 {
     MacrossType = macrossType;
     CSType      = csType;
 }
Пример #12
0
        public void BuildAssemblyRPC(System.Reflection.Assembly[] assems, string[] assemMacro, EngineNS.ECSType csType)
        {
            if (this.HashExec.Count > 0)
            {
                return;
            }
            if (assems == null)
            {
                assems = AppDomain.CurrentDomain.GetAssemblies();
            }
            List <RPCTypeInfo> AllClass = new List <RPCTypeInfo>();
            var mapRpcFuncs             = new List <System.Reflection.MethodInfo>();

            for (var i = 0; i < assems.Length; i++)
            {
                try
                {
                    var assm = assems[i];

                    var mapKlass = assm.GetType("EngineNS.Bricks.RemoteServices" + ".SystemMapRPC");
                    if (mapKlass != null)
                    {
                        var mapFun = mapKlass.GetMethod("DoRPCMap");
                        if (mapFun != null)
                        {
                            var args = mapFun.GetParameters();
                            if (args.Length != 1)
                            {
                                continue;
                            }
                            if (args[0].ParameterType != this.GetType())
                            {
                                continue;
                            }
                            if (mapFun.IsStatic == false)
                            {
                                continue;
                            }

                            mapRpcFuncs.Add(mapFun);
                            //mapFun.Invoke(null, new object[] { this });
                        }
                    }

                    if (assemMacro != null && assemMacro.Length == assems.Length && string.IsNullOrEmpty(assemMacro[i]))
                    {
                        assemMacro[i] = GetAssmemblyRPCMacro(assm);
                    }
                    foreach (var j in assm.GetTypes())
                    {
                        if (IsRPCClass(j))
                        {
                            var tmp = new RPCTypeInfo();
                            tmp.Type = j;
                            if (assemMacro != null && assemMacro.Length == assems.Length)
                            {
                                tmp.Macro = assemMacro[i];
                            }
                            AllClass.Add(tmp);
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    EngineNS.Profiler.Log.WriteException(ex);
                }
            }
            //只有不会再被派生的类才能做RPC分析,否则就会出现一个RPCParameter被多个函数使用的情况
            var finalKlass = GetFinalKlass(AllClass);

            foreach (var i in finalKlass)
            {
                RegClass(i.Type, i.Macro, csType);
            }

            RefreshRPCMap(mapRpcFuncs);
        }
Пример #13
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);
        }
Пример #14
0
        // 添加函数节点
        public static CodeGenerateSystem.Controls.NodeListAttributeClass AddMethodNode(CodeGenerateSystem.Controls.NodesContainerControl.ContextMenuFilterData filterData, System.Reflection.MethodInfo methodInfo, Type parentClassType, CodeGenerateSystem.Controls.NodeListControl hostNodesList, EngineNS.ECSType csType, string attributeName, CodeDomNode.MethodInfoAssist.enHostType hostType)
        {
            //"CSUtility.Event.Attribute.AllowMember"
            //

            CodeGenerateSystem.Controls.NodeListAttributeClass attribute = null;
            var att = EngineNS.Rtti.AttributeHelper.GetCustomAttribute(methodInfo, attributeName, true);

            if (att == null)
            {
                return(attribute);
            }

            var path = EngineNS.Rtti.AttributeHelper.GetCustomAttributePropertyValue(att, "Path")?.ToString();

            if (string.IsNullOrEmpty(path))
            {
                path = EngineNS.Rtti.RttiHelper.GetAppTypeString(methodInfo.ReflectedType) + "." + methodInfo.Name;
            }
            var description = EngineNS.Rtti.AttributeHelper.GetCustomAttributePropertyValue(att, "Description").ToString();

            //var refTypeStr = EngineNS.Rtti.RttiHelper.GetAppTypeString(methodInfo.ReflectedType);
            //var methodInfoString = GetParamFromMethodInfo(methodInfo, path);
            //methodInfoString += "," + csType.ToString() + "," + methodInfo.IsGenericMethodDefinition;
            //if (usefulMemberData != null)
            //{
            //    var usefulMemberStr = usefulMemberData.ToString().Replace(usefulMemberData.ClassTypeFullName, refTypeStr);
            //    methodInfoString += ";" + usefulMemberStr;
            //    if (!string.IsNullOrEmpty(usefulMemberData.MemberHostName))
            //    {
            //        path = usefulMemberData.MemberHostName + "." + path;
            //    }
            //    if (usefulMemberData.HostControl != null)
            //    {
            //        path = GetNodeName(usefulMemberData) + "." + path;
            //    }
            //}
            //path += "(" + refTypeStr + ")";
            var csParam = new CodeDomNode.MethodInvokeNode.MethodNodeConstructionParams()
            {
                CSType         = csType,
                ConstructParam = "",
                MethodInfo     = GetMethodInfoAssistFromMethodInfo(methodInfo, parentClassType, hostType, path),
            };

            var displayatt = methodInfo.GetCustomAttributes(typeof(EngineNS.Editor.DisplayParamNameAttribute), true);

            if (displayatt.Length > 0)
            {
                csParam.DisplayName = ((EngineNS.Editor.DisplayParamNameAttribute)displayatt[0]).DisplayName;
            }

            var attrs = methodInfo.GetCustomAttributes(typeof(EngineNS.Editor.MacrossPanelPathAttribute), true);

            if (attrs.Length == 0)
            {
                path = path.Replace('.', '/');
            }
            else
            {
                path = ((EngineNS.Editor.MacrossPanelPathAttribute)attrs[0]).Path;
            }

            attribute = hostNodesList.AddNodesFromType(filterData, typeof(CodeDomNode.MethodInvokeNode), path, csParam, description, "", hostNodesList.TryFindResource("Icon_Function") as ImageSource);
            return(attribute);
        }
Пример #15
0
        /// <summary>
        /// 从类型全名称获取类型(不包含Assembly内容)
        /// </summary>
        /// <param name="typeFullName">类型的全名称</param>
        /// <returns>根据名称取得的类型,没有找到则返回null</returns>
        public static Type GetTypeFromTypeFullName(string typeFullName, EngineNS.ECSType csType = EngineNS.ECSType.All)
        //public static Type GetTypeFromTypeFullName(string typeFullName, EngineNS.ECSType csType)
        {
            if (string.IsNullOrEmpty(typeFullName))
            {
                return(null);
            }
            Dictionary <EngineNS.EPlatformType, Dictionary <string, Type> > platFormDic;

            if (!mTypeNameDic.TryGetValue(csType, out platFormDic))
            {
                platFormDic          = new Dictionary <EngineNS.EPlatformType, Dictionary <string, Type> >();
                mTypeNameDic[csType] = platFormDic;
            }

            Dictionary <string, Type> typeDic;

            if (!platFormDic.TryGetValue(CIPlatform.Instance.PlatformType, out typeDic))
            {
                typeDic = new Dictionary <string, Type>();
                platFormDic[CIPlatform.Instance.PlatformType] = typeDic;
            }

            if (typeDic.ContainsKey(typeFullName))
            {
                return(typeDic[typeFullName]);
            }

            if (csType == EngineNS.ECSType.All)
            {
                foreach (var assemDic in mAnalyseAssemblyDic.Values)
                {
                    foreach (var assembly in assemDic.Values)
                    {
                        foreach (var type in assembly.GetTypes())
                        {
                            if (type.FullName.Equals(typeFullName))
                            {
                                typeDic[typeFullName] = type;
                                return(type);
                            }
                        }
                    }
                }
            }
            else
            {
                Dictionary <string, VAssembly> assemDic;
                if (mAnalyseAssemblyDic.TryGetValue(csType, out assemDic))
                {
                    foreach (var assembly in assemDic.Values)
                    {
                        foreach (var type in assembly.GetTypes())
                        {
                            if (type.FullName.Equals(typeFullName))
                            {
                                typeDic[typeFullName] = type;
                                return(type);
                            }
                        }
                    }
                }
            }

            var cmType = Type.GetType(typeFullName);

            if (cmType != null)
            {
                typeDic[typeFullName] = cmType;
                return(cmType);
            }

            return(null);
        }
Пример #16
0
        public static CodeGenerateSystem.Controls.NodeListAttributeClass AddFieldNode(CodeGenerateSystem.Controls.NodesContainerControl.ContextMenuFilterData filterData, FieldInfo fieldInfo, Type parentClassType, CodeGenerateSystem.Controls.NodeListControl hostNodesList, CodeDomNode.PropertyInfoAssist.enDirection direction, EngineNS.ECSType csType, string attributeName, CodeDomNode.MethodInfoAssist.enHostType hostType)
        {
            var att = EngineNS.Rtti.AttributeHelper.GetCustomAttribute(fieldInfo, attributeName, true);

            if (att == null)
            {
                return(null);
            }

            var path = EngineNS.Rtti.AttributeHelper.GetCustomAttributePropertyValue(att, "Path")?.ToString();

            if (string.IsNullOrEmpty(path))
            {
                path = EngineNS.Rtti.RttiHelper.GetAppTypeString(fieldInfo.ReflectedType) + "." + fieldInfo.Name;
            }
            var description = EngineNS.Rtti.AttributeHelper.GetCustomAttributePropertyValue(att, "Description").ToString();

            var csParam = new CodeDomNode.PropertyNode.PropertyNodeConstructionParams()
            {
                CSType         = csType,
                ConstructParam = "",
                PropertyInfo   = CodeDomNode.PropertyNode.GetAssistFromFieldInfo(fieldInfo, parentClassType, direction, path, hostType),
            };

            var mpattr = fieldInfo.GetCustomAttributes(typeof(EngineNS.Editor.MacrossPanelPathAttribute), false);

            if (mpattr.Length > 0)
            {
                path = ((EngineNS.Editor.MacrossPanelPathAttribute)mpattr[0]).Path;
            }
            else
            {
                path = path.Replace('.', '/');
            }

            var displayattr = fieldInfo.GetCustomAttributes(typeof(System.ComponentModel.DisplayNameAttribute), false);

            if (displayattr.Length > 0)
            {
                csParam.DisplayName = ((System.ComponentModel.DisplayNameAttribute)displayattr[0]).DisplayName;
            }
            return(hostNodesList.AddNodesFromType(filterData, typeof(CodeDomNode.PropertyNode), $"{path}({PropertyNode.GetParamPreInfo(direction)})", csParam, description));
        }
Пример #17
0
        public static System.CodeDom.Compiler.CompilerResults CompileCode(string codeStr, EngineNS.ECSType csType, Guid dllId, string absCodeFile = "", string dllOutputFile = "", bool debug = false)
        {
            System.CodeDom.Compiler.CodeDomProvider cdProvider = new CodeGenerateSystem.CSharpCodeProvider();

            System.CodeDom.Compiler.CompilerParameters compilerParam = new System.CodeDom.Compiler.CompilerParameters();
            compilerParam.GenerateExecutable = false;
            compilerParam.GenerateInMemory   = false;

            compilerParam.ReferencedAssemblies.Add("System.dll");

            switch (csType)
            {
            case EngineNS.ECSType.Client:
                compilerParam.ReferencedAssemblies.Add(EngineNS.CEngine.Instance.FileManager.Bin + "/ClientCommon.dll");
                compilerParam.ReferencedAssemblies.Add(EngineNS.CEngine.Instance.FileManager.Bin + "/Client.dll");
                break;

                //case EngineNS.ECSType.Server:
                //    compilerParam.ReferencedAssemblies.Add(EngineNS.CEngine.Instance.FileManager.Root + CSUtility.Support.IFileConfig.Server_Directory + "/ServerCommon.dll");
                //    compilerParam.ReferencedAssemblies.Add(EngineNS.CEngine.Instance.FileManager.Root + CSUtility.Support.IFileConfig.Server_Directory + "/Server.dll");
                //    break;
            }

            if (!string.IsNullOrEmpty(dllOutputFile))
            {
                compilerParam.OutputAssembly = dllOutputFile;
            }

            System.CodeDom.Compiler.CompilerResults compilerResult = null;

            if (debug == true)
            {
                compilerParam.IncludeDebugInformation = true;

                if (string.IsNullOrEmpty(absCodeFile))
                {
                    absCodeFile = $"{EngineNS.CEngine.Instance.FileManager.ProjectSourceRoot}CodeFiles\\{dllId}_{csType.ToString()}.cs";
                }
                var fileDir = EngineNS.CEngine.Instance.FileManager.GetPathFromFullName(absCodeFile);
                if (!System.IO.Directory.Exists(fileDir))
                {
                    System.IO.Directory.CreateDirectory(fileDir);
                }
                var fs = new System.IO.FileStream(absCodeFile, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
                fs.Write(System.Text.Encoding.Default.GetBytes(codeStr), 0, System.Text.Encoding.Default.GetByteCount(codeStr));
                fs.Close();

                absCodeFile    = absCodeFile.Replace("/", "\\");
                compilerResult = cdProvider.CompileAssemblyFromFile(compilerParam, new string[] { absCodeFile });

                var purefileName = dllOutputFile.Substring(0, dllOutputFile.Length - 4);
                var pdbFile      = purefileName + ".pdb";
                if (EngineNS.CEngine.Instance.FileManager.FileExists(pdbFile))
                {
                    EngineNS.CEngine.Instance.FileManager.CopyFile(pdbFile, purefileName + ".vpdb", true);
                    EngineNS.CEngine.Instance.FileManager.DeleteFile(pdbFile);
                }
            }
            else
            {
                compilerResult = cdProvider.CompileAssemblyFromSource(compilerParam, codeStr);
            }

            return(compilerResult);
        }