Esempio n. 1
0
        public CompilationException Add(string content)
        {
            CompilationException exception = new CompilationException();

            var(tree, formartter, errors) = content;


            exception.Formatter = formartter;
            exception.Diagnostics.AddRange(errors);


            if (exception.Diagnostics.Count != 0)
            {
                exception.ErrorFlag = ComplieError.Syntax;
                exception.Message   = "语法错误,请仔细检查脚本代码!";
                NError log = new NError();
                log.Handler(exception.Diagnostics);
                log.Write();
                exception.Log = log.Buffer.ToString();
            }
            else
            {
                Trees.Add(tree);
            }
            SyntaxExceptions.Add(exception);
            return(exception);
        }
Esempio n. 2
0
 public void onLoadAchievementFailure(string result)
 {
     Debug.Log("GamePotEventListener::onLoadAchievementFailure()" + result);
     if (GamePotInterface != null)
     {
         NError error = JsonMapper.ToObject <NError>(result);
         GamePotInterface.onLoadAchievementFailure(error);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 获取编译后的程序集
        /// </summary>
        /// <returns></returns>
        public Assembly GetAssembly()
        {
            if (ComplierInfos.Trees.Count == 0)
            {
                return(null);
            }


            if (Name == default)
            {
                Name = Guid.NewGuid().ToString("N");
            }


            var      result   = StreamComplier(ComplierInfos);
            Assembly assembly = result.Assembly;

            if (result.Compilation != null)
            {
                if (assembly == default || assembly == null)
                {
                    Exception.Diagnostics.AddRange(result.Errors);
                    Exception.ErrorFlag = ComplieError.Assembly;
                    Exception.Message   = "发生错误,无法生成程序集!";


                    NError logError = new NError();
                    logError.Handler(result.Compilation, Exception.Diagnostics);


                    Exception.Log = logError.Buffer.ToString();
                    if (NError.Enabled)
                    {
                        logError.Write();
                    }
                }
                else
                {
                    NSucceed logSucceed = new NSucceed();
                    logSucceed.Handler(result.Compilation);
                    Exception.ErrorFlag = ComplieError.None;

                    Exception.Log = logSucceed.Buffer.ToString();
                    if (NSucceed.Enabled)
                    {
                        logSucceed.Write();
                    }
                }
            }
            return(assembly);
        }
Esempio n. 4
0
 public override IObject Construct(IEnvironment environment, IArgs args)
 {
     var message = args[0].ConvertToString();
     if (message.BaseValue == "undefined")
     {
         message = environment.CreateString("");
     }
     var error = new NError(environment);
     error.Class = "Error";
     error.Extensible = true;
     error.Prototype = environment.ErrorPrototype;
     error.Put("message", message, false);
     return error;
 }
Esempio n. 5
0
        public override IObject Construct(IEnvironment environment, IArgs args)
        {
            var message = args[0].ConvertToString();

            if (message.BaseValue == "undefined")
            {
                message = environment.CreateString("");
            }
            var error = new NError(environment);

            error.Class      = "Error";
            error.Extensible = true;
            error.Prototype  = environment.ErrorPrototype;
            error.Put("message", message, false);
            return(error);
        }
Esempio n. 6
0
    public void onCreateLinkingFailure(string result)
    {
        Debug.Log("GamePotEventListener::onCreateLinkFailure() - " + result);
        NError error = JsonMapper.ToObject <NError>(result);

        if (cbCreateLinking != null)
        {
            cbCreateLinking(NCommon.ResultLinking.FAILED, null, error);
            cbCreateLinking = null;
        }
        else
        {
            if (GamePotInterface != null)
            {
                GamePotInterface.onCreateLinkingFailure(error);
            }
        }
    }
Esempio n. 7
0
    public void onPushStatusFailure(string result)
    {
        Debug.Log("GamePotEventListener::onPushStatusFailure()" + result);
        NError error = JsonMapper.ToObject <NError>(result);

        if (cbPushStatusEnable != null)
        {
            cbPushStatusEnable(false, error);
            cbPushStatusEnable = null;
        }
        else
        {
            if (GamePotInterface != null)
            {
                GamePotInterface.onPushStatusFailure(error);
            }
        }
    }
Esempio n. 8
0
    public void onCouponFailure(string result)
    {
        Debug.Log("GamePotEventListener::onCouponFailure() : " + result);
        NError error = JsonMapper.ToObject <NError>(result);

        if (cbCoupon != null)
        {
            cbCoupon(false, error);
            cbCoupon = null;
        }
        else
        {
            if (GamePotInterface != null)
            {
                GamePotInterface.onCouponFailure(error);
            }
        }
    }
Esempio n. 9
0
    public void onPurchaseFailure(string result)
    {
        Debug.Log("GamePotEventListener::onPurchaseFailure() - " + result);
        NError error = JsonMapper.ToObject <NError>(result);

        if (cbPurchase != null)
        {
            cbPurchase(NCommon.ResultPurchase.FAILED, null, error);
            cbPurchase = null;
        }
        else
        {
            if (GamePotInterface != null)
            {
                GamePotInterface.onPurchaseFailure(error);
            }
        }
    }
Esempio n. 10
0
    public void onDeleteLinkingFailure(string result)
    {
        Debug.Log("GamePotEventListener::onDeleteLinkFailure() - " + result);
        NError error = JsonMapper.ToObject <NError>(result);

        if (cbDeleteLinking != null)
        {
            cbDeleteLinking(false, error);
            cbDeleteLinking = null;
        }
        else
        {
            if (GamePotInterface != null)
            {
                GamePotInterface.onDeleteLinkingFailure(error);
            }
        }
    }
Esempio n. 11
0
    public void onAgreeDialogFailure(string result)
    {
        Debug.Log("GamePotEventListener::onAgreeDialogFailure()" + result);
        NError error = JsonMapper.ToObject <NError>(result);

        if (cbShowAgree != null)
        {
            cbShowAgree(false, null, error);
            cbShowAgree = null;
        }
        else
        {
            if (GamePotInterface != null)
            {
                GamePotInterface.onAgreeDialogFailure(error);
            }
        }
    }
Esempio n. 12
0
 public void onPurchaseFailure(NError error)
 {
 }
Esempio n. 13
0
 public void onCouponFailure(NError error)
 {
 }
Esempio n. 14
0
 public void onLoadAchievementFailure(NError error)
 {
 }
Esempio n. 15
0
 public void onAgreeDialogFailure(NError error)
 {
 }
Esempio n. 16
0
 public void onPushNightFailure(NError error)
 {
 }
Esempio n. 17
0
 public void onLogoutFailure(NError error)
 {
     PopupManager.ShowCustomPopup(popupRoot, "GamePotSamplePopup_BtnOne", "로그아웃", error.message);
 }
Esempio n. 18
0
 public void onCreateLinkingFailure(NError error)
 {
 }
Esempio n. 19
0
 public void onDeleteMemberFailure(NError error)
 {
     PopupManager.ShowCustomPopup(popupRoot, "GamePotSamplePopup_BtnOne", "회원탈퇴", error.message);
 }
Esempio n. 20
0
 public void onLoginFailure(NError error)
 {
 }
Esempio n. 21
0
 public void onAgreeDialogFailure(NError error)
 {
     Debug.Log("onAgreeDialogFailure - " + error);
 }
Esempio n. 22
0
 public void onPushStatusFailure(NError error)
 {
 }
Esempio n. 23
0
 public void onPushAdFailure(NError error)
 {
 }
Esempio n. 24
0
 public void onLogoutFailure(NError error)
 {
 }
Esempio n. 25
0
 public void onPushStatusFailure(NError error)
 {
     PopupManager.ShowCustomPopup(popupRoot, "GamePotSamplePopup_BtnOne", "Push Status", error.message);
 }
Esempio n. 26
0
 public void onCouponFailure(NError error)
 {
     PopupManager.ShowCustomPopup(popupRoot, "GamePotSamplePopup_BtnOne", "쿠폰", error.message);
 }
Esempio n. 27
0
 public void onDeleteLinkingFailure(NError error)
 {
 }
Esempio n. 28
0
        /// <summary>
        /// 使用内存流进行脚本编译
        /// </summary>
        /// <param name="sourceContent">脚本内容</param>
        /// <param name="errorAction">发生错误执行委托</param>
        /// <returns></returns>
        public static Assembly StreamComplier(string sourceContent, AssemblyDomain domain, out string formatContent, ref List <Diagnostic> diagnostics)
        {
            lock (domain)
            {
                var(tree, typeNames, formatter, errors) = GetTreeInfo(sourceContent.Trim());
                formatContent = formatter;
                diagnostics.AddRange(errors);
                if (diagnostics.Count() != 0)
                {
                    return(null);
                }


                if (domain.ClassMapping.ContainsKey(typeNames[0]))
                {
                    return(domain.ClassMapping[typeNames[0]]);
                }


                //创建语言编译
                CSharpCompilation compilation = CSharpCompilation.Create(
                    typeNames[0],
                    options: new CSharpCompilationOptions(
                        outputKind: OutputKind.DynamicallyLinkedLibrary,
                        optimizationLevel: OptimizationLevel.Release,
                        allowUnsafe: true),
                    syntaxTrees: new[] { tree },
                    references: domain.References);


                //编译并生成程序集
                using (MemoryStream stream = new MemoryStream())
                {
                    var fileResult = compilation.Emit(stream);
                    if (fileResult.Success)
                    {
                        stream.Position = 0;
                        var result = domain.LoadFromStream(stream);
                        domain.CacheAssembly(result, stream);


                        if (NSucceed.Enabled)
                        {
                            NSucceed logSucceed = new NSucceed();
                            logSucceed.WrapperCode(formatter);
                            logSucceed.Handler(compilation, result);
                        }
                        return(result);
                    }
                    else
                    {
                        diagnostics.AddRange(fileResult.Diagnostics);
                        if (NError.Enabled)
                        {
                            NError logError = new NError();
                            logError.WrapperCode(formatter);
                            logError.Handler(compilation, fileResult.Diagnostics);
                            logError.Write();
                        }
                    }
                }
            }
            return(null);
        }
Esempio n. 29
0
 public void onPurchaseFailure(NError error)
 {
     PopupManager.ShowCustomPopup(popupRoot, "GamePotSamplePopup_BtnOne", "결제", error.message);
 }
Esempio n. 30
0
        /// <summary>
        /// 获取编译后的程序集
        /// </summary>
        /// <returns></returns>
        public Assembly GetAssembly()
        {
            if (SyntaxInfos.Trees.Count == 0)
            {
                return(null);
            }


            if (AssemblyName == default)
            {
                AssemblyName = Guid.NewGuid().ToString("N");
            }


            var      result   = StreamComplier();
            Assembly assembly = result.Assembly;

            if (result.Compilation != null)
            {
                if (assembly == default || assembly == null)
                {
                    bool         CS0104SHUT = false;
                    bool         CS0234SHUT = false;
                    bool         CSO246SHUT = false;
                    var          tempCache  = SyntaxInfos.TreeCodeMapping;
                    SyntaxOption option     = new SyntaxOption();


                    foreach (var item in result.Errors)
                    {
                        if (item.Id == "CS0104")
                        {
                            CS0104SHUT = true;
                            var tempTree = item.Location.SourceTree;
                            var tempCode = tempCache[tempTree];
                            var(str1, str2) = CS0104Helper.Handler(item.Descriptor.MessageFormat.ToString(), item.GetMessage());
                            var sets = SyntaxInfos.TreeUsingMapping[tempTree];
                            if (sets.Contains(str2))
                            {
                                tempCache[tempTree] = tempCode.Replace($"using {str1};", "");
                            }
                            else if (sets.Contains(str1))
                            {
                                tempCache[tempTree] = tempCode.Replace($"using {str2};", "");
                            }
                            else
                            {
                                tempCache[tempTree] = tempCode.Replace($"using {str1};", "");
                            }
                        }
                        else if (item.Id == "CS0234")
                        {
                            CS0234SHUT = true;
                            var tempResult = CS0234Helper.Handler(item.Descriptor.MessageFormat.ToString(), item.GetMessage());
                            UsingDefaultCache.Remove(tempResult);
                            var tempTree = item.Location.SourceTree;
                            var tempCode = tempCache[tempTree];
                            tempCache[tempTree] = tempCode.Replace($"using {tempResult};", "");
                        }
                        else if (item.Id == "CS0246")
                        {
                            CSO246SHUT = true;
                            var tempTree = item.Location.SourceTree;
                            var tempCode = tempCache[tempTree];
                            var formart  = item.Descriptor.MessageFormat.ToString();
                            CS0246Helper.Handler(item.Descriptor.MessageFormat.ToString(), item.GetMessage());
                            foreach (var @using in CS0246Helper.GetUsings(formart, tempCode))
                            {
                                UsingDefaultCache.Remove(@using);
                                tempCache[tempTree] = tempCode.Replace($"using {@using};", "");
                            }
                        }
                    }


                    if (CS0104SHUT || CS0234SHUT || CSO246SHUT)
                    {
                        ErrorRetryCount += 1;
                        if (ErrorRetryCount < 2)
                        {
                            foreach (var item in tempCache)
                            {
                                option.Add(tempCache[item.Key], SyntaxInfos.TreeUsingMapping[item.Key]);
                            }

                            SyntaxInfos = option;
                            return(GetAssembly());
                        }
                    }


                    ComplieException.Diagnostics.AddRange(result.Errors);
                    ComplieException.ErrorFlag = ComplieError.Complie;
                    ComplieException.Message   = "发生错误,无法生成程序集!";


                    NError logError = new NError();
                    logError.Handler(result.Compilation, ComplieException.Diagnostics);
                    ComplieException.Log = logError.Buffer.ToString();
                    if (NError.Enabled)
                    {
                        logError.Write();
                    }
                }
                else
                {
                    if (_domain != DomainManagment.Default)
                    {
                        DomainCache.Add(result.Assembly, _domain);
                    }

                    NSucceed logSucceed = new NSucceed();
                    logSucceed.Handler(result.Compilation);
                    ComplieException.ErrorFlag = ComplieError.None;
                    ComplieException.Log       = logSucceed.Buffer.ToString();
                    if (NSucceed.Enabled)
                    {
                        logSucceed.Write();
                    }
                }
            }
            return(assembly);
        }
Esempio n. 31
0
 public void onDeleteLinkingFailure(NError error)
 {
     PopupManager.ShowCustomPopup(popupRoot, "GamePotSamplePopup_BtnOne", "연동", error.message);
     linkingStatusUpdate();
 }