public async Task <IViewComponentResult> InvokeAsync(XException xexception)
        {
            _XExceptionModel xmodel = new _XExceptionModel(xexception);

            xmodel.XMessage = xexception.XInnerException.XMessage;
            return(View(xmodel));
        }
Beispiel #2
0
 public async Task <IActionResult> OnPost()
 {
     XObject[] xparams = _XMethodInfoModel.XFromForm(x, XConstructor.XGetParameters(), xtypeConverter, Request.Form, XThis);
     try
     {
         XObject xobject = XConstructor.XInvoke(xparams);
         if (xobject != x.XNULL)
         {
             _XObjectModel.XToCache(XThis, xobject);
             string url = _XObjectModel.XToHref(xobject);
             return(LocalRedirect(url));
         }
     }
     catch (Exception ex)
     {
         XException = x.XCatch(ex);
     }
     return(Page());
 }
Beispiel #3
0
        public async Task <bool> Start()
        {
            #region config
            if (mInited)
            {
                return(true);
            }
            mConfig = XConfig.GetConfig <UIConfig>(UIConst.ConfigPath_Resources);
            if (mConfig == null)
            {
                mStartException = new XException("[TinaX.UIKit] Connot found config file.");;
                return(false);
            }
            if (!mConfig.EnableUIKit)
            {
                return(true);
            }

            if (mConfig.UINameMode == UINameMode.UIGroup)
            {
                mCurUIGroup = mConfig.DefaultUIGroup;
            }
            else
            {
                mUIRootDirLoadPath = mConfig.UIRootDirectoryLoadPath;
                if (!mUIRootDirLoadPath.IsNullOrEmpty())
                {
                    if (mUIRootDirLoadPath.EndsWith("/"))
                    {
                        mUIRootDirLoadPath = mUIRootDirLoadPath.Substring(0, mUIRootDirLoadPath.Length - 1);
                    }
                    mUIRootDirLoadPath_withSlash = mUIRootDirLoadPath + "/";
                }
            }
            mUINameMode = mConfig.UINameMode;

            #endregion


            //Init UIKit GameObjects
            #region UIKit GameObjects
            mUIKit_Root_Go = XCore.GetMainInstance().BaseGameObject
                             .FindOrCreateGameObject("UIKit")
                             .SetPosition(new Vector3(-9999, -9999, -9999));

            if (mConfig.UseUICamera)
            {
                var camera_config = mConfig.UICameraConfig;
                if (camera_config == null)
                {
                    camera_config = new UICameraConfig();
                }

                mScreenUICamera = mUIKit_Root_Go.FindOrCreateGameObject("UICamera")
                                  .AddComponent <Camera>();
                mScreenUICamera.clearFlags          = camera_config.clearFlags;
                mScreenUICamera.backgroundColor     = camera_config.backgroundColor;
                mScreenUICamera.cullingMask         = camera_config.cullingMask;
                mScreenUICamera.orthographic        = camera_config.orthographic;
                mScreenUICamera.orthographicSize    = camera_config.orthographicSize;
                mScreenUICamera.nearClipPlane       = camera_config.nearClipPlane;
                mScreenUICamera.farClipPlane        = camera_config.farClipPlane;
                mScreenUICamera.depth               = camera_config.depth;
                mScreenUICamera.renderingPath       = camera_config.renderingPath;
                mScreenUICamera.targetTexture       = camera_config.targetTexture;
                mScreenUICamera.useOcclusionCulling = camera_config.useOcclusionCulling;
                mScreenUICamera.allowHDR            = camera_config.allowHDR;
                mScreenUICamera.allowMSAA           = camera_config.allowMSAA;
            }

            //Default UIRoot
            refreshUIRoot(0);

            //EventSystem
#if ENABLE_LEGACY_INPUT_MANAGER
            if (mConfig.AutoCreateEventSystem)
            {
                var es_go        = GameObjectHelper.FindOrCreateGameObject("EventSystem");
                var event_system = es_go.GetComponentOrAdd <UnityEngine.EventSystems.EventSystem>();
                event_system.sendNavigationEvents = true;
                event_system.pixelDragThreshold   = 10;
                var input_module = es_go.GetComponentOrAdd <UnityEngine.EventSystems.StandaloneInputModule>();
            }
#endif

            #endregion

            await Task.Delay(0);

            return(true);
        }
Beispiel #4
0
        public async Task <bool> Start()
        {
            if (mInited)
            {
                return(true);
            }
            mConfig = XConfig.GetConfig <I18NConfig>(I18NConst.ConfigPath_Resources, AssetLoadType.Resources);
            if (mConfig == null)
            {
                mStartException = new XException("[TinaX.I18N]Load I18N config file failed. please cheak in ProjectSettings window.");
                return(false);
            }
            if (!mConfig.EnableI18N)
            {
                return(true);
            }
            if (mAssets == null)
            {
                mStartException = new XException("[TinaX.I18N]No service implements the built-in asset loading interface in Framework");
                return(false);
            }

            if (mConfig.Regions != null && mConfig.Regions.Count > 0)
            {
                bool    check_default       = !mConfig.DefaultRegion.IsNullOrEmpty();
                string  default_region_name = check_default ? mConfig.DefaultRegion.ToLower() : string.Empty;
                XRegion _default_region     = null;
                foreach (var item in mConfig.Regions)
                {
                    if (item.Name.IsNullOrEmpty())
                    {
                        continue;
                    }

                    bool _flag_1 = false;
                    if (check_default && _default_region == null)
                    {
                        if (item.Name.ToLower().Equals(default_region_name))
                        {
                            _default_region = item;
                            _flag_1         = true;
                        }
                    }

                    if (mConfig.AutomaticMatchingBySystemLanaguage)
                    {
                        bool flag_2 = false;
                        if (item.BindLanguage != null && item.BindLanguage.Count > 0)
                        {
                            foreach (var lang in item.BindLanguage)
                            {
                                if (lang == Application.systemLanguage)
                                {
                                    flag_2          = true;
                                    _default_region = item;
                                    break;
                                }
                            }
                        }
                        if (flag_2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (_flag_1)
                        {
                            break;
                        }
                    }
                }
                if (_default_region != null)
                {
                    try
                    {
                        await this.useRegion(_default_region);
                    }
                    catch (XException e)
                    {
                        mStartException = e;
                        return(false);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }

            //Debug code
            //foreach(var item in mDicts)
            //{
            //    item.Key.LogConsole();
            //    foreach(var kv in item.Value)
            //    {
            //        ("    " + kv.Key + "  |  " + kv.Value).LogConsole();
            //    }
            //}

            mInited = true;
            return(true);
        }
Beispiel #5
0
        public async Task <bool> Start()
        {
            if (mInited)
            {
                return(true);
            }
            mConfig = XConfig.GetConfig <LuaConfig>(LuaConst.ConfigPath_Resources);
            if (mConfig == null)
            {
                mStartException = new XException("[TinaX.ILRuntime] Connot found config file.");;
                return(false);
            }
            if (!mConfig.EnableLua)
            {
                return(true);
            }

            mInternal_Lua_Folder_Load_Path = mConfig.FrameworkInternalLuaFolderLoadPath;
            if (!mInternal_Lua_Folder_Load_Path.IsNullOrEmpty())
            {
                if (mInternal_Lua_Folder_Load_Path.EndsWith("/"))
                {
                    mInternal_Lua_Folder_Load_Path = mInternal_Lua_Folder_Load_Path.Substring(0, mInternal_Lua_Folder_Load_Path.Length - 1);
                }
                mInternal_Lua_Folder_Load_Path_withSlash = mInternal_Lua_Folder_Load_Path + "/";
            }
            mLuaExtension = mConfig.LuaFileExtensionName;
            if (!mLuaExtension.StartsWith("."))
            {
                mLuaExtension = "." + mLuaExtension;
            }

            if (!XCore.MainInstance.TryGetBuiltinService(out Assets))
            {
                mStartException = new XException("[TinaX.ILRuntime]" + (IsChinese? "没有任何服务实现了Framework中的内置的资产加载接口": "No service implements the built-in asset loading interface in Framework"));
                return(false);
            }

            mLoader = LoadLuaFiles;
            mLuaVM.AddLoader(mLoader);

            try
            {
                await InitInternalEntry();
            }
            catch (XException e)
            {
                mStartException = e;
                return(false);
            }

            //准备好入口文件
            if (!mConfig.EntryLuaFileLoadPath.IsNullOrEmpty())
            {
                try
                {
                    TextAsset entry_ta = await Assets.LoadAsync <TextAsset>(mConfig.EntryLuaFileLoadPath);

                    mEntryFunc = mLuaVM.LoadString <LuaFunction>(entry_ta.bytes, mConfig.EntryLuaFileLoadPath);
                    Assets.Release(entry_ta);
                }
                catch (XException e)
                {
                    mStartException = e;
                    return(false);
                }
            }

            if (mUpdateTicket != null)
            {
                mUpdateTicket.Unregister();
            }
            mUpdateTicket = TimeMachine.RegisterUpdate(OnUpdate);

            await Task.Yield();

            mInited = true;
            return(true);
        }
Beispiel #6
0
 public _XExceptionModel(XException ex)
 {
     xexception = ex;
 }
Beispiel #7
0
        ///// <summary>从流中读取消息</summary>
        ///// <param name="stream">数据流</param>
        ///// <returns></returns>
        //public static Message Read(Stream stream) { return Read(stream, false); }

        /// <summary>从流中读取消息</summary>
        /// <param name="stream">数据流</param>
        /// <param name="rwkind"></param>
        /// <param name="ignoreException">忽略异常。如果忽略异常,读取失败时将返回空,并还原数据流位置</param>
        /// <returns></returns>
        public static Message Read(Stream stream, RWKinds rwkind = RWKinds.Binary, Boolean ignoreException = false)
        {
            if (stream == null || stream.Length - stream.Position < 1)
            {
                return(null);
            }

            //var reader = new BinaryReaderX(stream);
            var reader = RWService.CreateReader(rwkind);

            reader.Stream = stream;
            Set(reader.Settings);

            if (Debug)
            {
                reader.Debug = true;
                reader.EnableTraceStream();
            }

            var start = stream.Position;
            // 消息类型,不同序列化方法的识别方式不同
            MessageKind   kind   = (MessageKind)0;
            Type          type   = null;
            MessageHeader header = null;

            if (rwkind == RWKinds.Binary)
            {
                // 检查第一个字节
                //var ch = reader.Reader.PeekChar();
                var ch = stream.ReadByte();
                if (ch < 0)
                {
                    return(null);
                }
                stream.Seek(-1, SeekOrigin.Current);

                var first = (Byte)ch;

                #region 消息头部扩展
                // 第一个字节的最高位决定是否扩展
                if (MessageHeader.IsValid(first))
                {
                    try
                    {
                        header = new MessageHeader();
                        header.Read(reader.Stream);
                    }
                    catch
                    {
                        stream.Position = start;
                        return(null);
                    }

                    // 如果使用了消息头,判断一下数据流长度是否满足
                    if (header.HasFlag(MessageHeader.Flags.Length) && header.Length > stream.Length - stream.Position)
                    {
                        stream.Position = start;
                        return(null);
                    }
                }
                #endregion

                // 读取了响应类型和消息类型后,动态创建消息对象
                kind = (MessageKind)(reader.ReadByte() & 0x7F);
            }
            else
            {
                // 前面的数字表示消息种类
                var  sb = new StringBuilder();
                Char c;
                while (true)
                {
                    c = (Char)stream.ReadByte();
                    if (c < '0' || c > '9')
                    {
                        break;
                    }
                    sb.Append(c);
                }
                // 多读了一个,退回去
                stream.Seek(-1, SeekOrigin.Current);
                kind = (MessageKind)Convert.ToByte(sb.ToString());

                //var s = stream.IndexOf(new Byte[] { (Byte)'<' });
                //if (s >= 0)
                //{
                //    var e = stream.IndexOf(new Byte[] { (Byte)'>' }, s + 1);
                //    if (e >= 0)
                //    {
                //        stream.Position = s;
                //        var msgName = Encoding.UTF8.GetString(stream.ReadBytes(e - s - 1));
                //        if (!String.IsNullOrEmpty(msgName) && !msgName.Contains(" ")) type = TypeX.GetType(msgName);
                //    }
                //}
                //var settings = new XmlReaderSettings();
                //settings.IgnoreWhitespace = true;
                //settings.IgnoreComments = true;
                //var xr = XmlReader.Create(stream, settings);
                //while (xr.NodeType != XmlNodeType.Element) { if (!xr.Read())break; }

                //stream.Position = start;
            }

            #region 识别消息类型
            if (type == null)
            {
                type = ObjectContainer.Current.ResolveType <Message>(kind);
            }
            if (type == null)
            {
                if (ignoreException)
                {
                    stream.Position = start;
                    return(null);
                }
                else
                {
                    throw new XException("无法识别的消息类型(Kind={0})!", kind);
                }
            }
            #endregion

            #region 读取消息
            Message msg;
            if (stream.Position == stream.Length)
            {
                msg = TypeX.CreateInstance(type, null) as Message;
            }
            else
            {
                try
                {
                    msg = reader.ReadObject(type) as Message;
                    if (msg == null)
                    {
                        throw new XException("数据格式不正确!");
                    }
                }
                catch (Exception ex)
                {
                    if (ignoreException)
                    {
                        stream.Position = start;
                        return(null);
                    }

                    var em = ex.Message;
                    if (DumpStreamWhenError)
                    {
                        stream.Position = start;
                        var bin = String.Format("{0:yyyy_MM_dd_HHmmss_fff}.msg", DateTime.Now);
                        bin = Path.Combine(XTrace.LogPath, bin);
                        if (!Path.IsPathRooted(bin))
                        {
                            bin = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, bin);
                        }
                        bin = Path.GetFullPath(bin);
                        var dir = Path.GetDirectoryName(bin);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }
                        File.WriteAllBytes(bin, stream.ReadBytes());
                        em = String.Format("已Dump数据流到{0}。{1}", bin, em);
                    }
                    var ex2 = new XException("无法从数据流中读取{0}(Kind={1})消息!{2}", type.Name, kind, em);
                    throw ex2;
                }
            }
            msg.Header = header;
            return(msg);

            #endregion
        }