Esempio n. 1
0
        /// <summary>
        /// 获取参数值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="p_paramID"></param>
        /// <returns></returns>
        public static async Task <T> GetParam <T>(string p_paramID)
        {
            await InitParams();

            var row = AtState.First($"select val from UserParams where id='{p_paramID}'");

            Throw.IfNull(row, $"无参数【{p_paramID}】");

            string val = row.Str(0);

            if (string.IsNullOrEmpty(val))
            {
                return(default);
Esempio n. 2
0
        /// <summary>
        /// 系统初始化
        /// </summary>
        /// <param name="p_stub">系统存根</param>
        /// <param name="p_callback"></param>
        internal static void Startup(IStub p_stub, ICallback p_callback)
        {
            Stub     = p_stub;
            Callback = p_callback;
            if (Stub.SerializeTypes != null)
            {
                SerializeTypeAlias.Merge(Stub.SerializeTypes);
            }

            var app = Application.Current;

            app.Suspending += OnSuspending;
            app.Resuming   += OnResuming;

            // 异常处理
#if UWP
            app.UnhandledException += OnUwpUnhandledException;
#elif ANDROID
            Android.Runtime.AndroidEnvironment.UnhandledExceptionRaiser += OnAndroidUnhandledException;
#elif IOS
            // 在iOS项目的Main函数处理
#elif WASM
            //TaskScheduler.UnobservedTaskException += (s, e) => OnUnhandledException(e.Exception);
            AppDomain.CurrentDomain.UnhandledException += (s, e) => OnUnhandledException(e.ExceptionObject as Exception);
#endif

            // 创建本地文件存放目录
            if (!Directory.Exists(CachePath))
            {
                Directory.CreateDirectory(CachePath);
            }
            if (!Directory.Exists(DataPath))
            {
                Directory.CreateDirectory(DataPath);
            }

#if WASM
            // .net5.0 只能引用 SQLite3Provider_sqlite3,DllImport("sqlite3")
            // 默认为 SQLite3Provider_e_sqlite3 引用时出错!
            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());
#else
            // 初始化不同平台的包绑定!V2支持类型和属性的绑定
            // 内部调用 SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3());
            SQLitePCL.Batteries_V2.Init();
#endif

            // 打开状态库
            AtState.OpenDb();
        }
Esempio n. 3
0
File: Log.cs Progetto: Daoting/dt
        /// <summary>
        /// 输出并保存客户端日志
        /// </summary>
        /// <param name="p_level"></param>
        /// <param name="p_msg"></param>
        /// <param name="p_ex"></param>
        static void OutputAndSave(LogEventLevel p_level, string p_msg, Exception p_ex)
        {
            string msg = p_msg == null ? "" : p_msg + "\r\n";

            if (p_ex != null)
            {
                msg += p_ex.Message;
            }

#if UWP
            System.Diagnostics.Debug.WriteLine(msg);
#else
            Console.Error.WriteLine(msg);
#endif

            ClientLog log = new ClientLog(
                Level: p_level,
                Content: msg,
                Ctime: DateTime.Now);
            _ = AtState.Save(log, false);
        }
Esempio n. 4
0
 static void UpdateDataVersion(string p_ver)
 {
     if (!string.IsNullOrEmpty(p_ver))
     {
         var ls  = p_ver.Split(',');
         var tbl = AtState.Query("select id,ver from DataVersion");
         if (tbl != null && tbl.Count > 0)
         {
             foreach (var row in tbl)
             {
                 if (!ls.Contains($"{row[0]}+{row[1]}"))
                 {
                     // 删除版本号,未实际删除缓存数据,待下次用到时获取新数据!
                     AtState.Exec($"delete from DataVersion where id='{row.Str(0)}'");
                 }
             }
         }
     }
     else
     {
         // 所有缓存数据失效
         AtState.Exec("delete from DataVersion");
     }
 }
Esempio n. 5
0
        /// <summary>
        /// 判断当前登录用户是否具有指定权限
        /// </summary>
        /// <param name="p_id">权限ID</param>
        /// <returns>true 表示有权限</returns>
        public static async Task <bool> HasPrv(string p_id)
        {
            int cnt = AtState.GetScalar <int>("select count(*) from DataVersion where id='privilege'");

            if (cnt == 0)
            {
                // 查询服务端
                Dict dt = await new UnaryRpc(
                    "cm",
                    "UserRelated.GetPrivileges",
                    UserID
                    ).Call <Dict>();

                // 记录版本号
                var ver = new DataVersion(ID: "privilege", Ver: dt.Str("ver"));
                await AtState.Save(ver, false);

                // 清空旧数据
                AtState.Exec("delete from UserPrivilege");
                // 插入新数据
                var ls = (List <string>)dt["result"];
                if (ls != null && ls.Count > 0)
                {
                    List <Dict> dts = new List <Dict>();
                    foreach (var prv in ls)
                    {
                        dts.Add(new Dict {
                            { "prv", prv }
                        });
                    }
                    AtState.BatchExec("insert into UserPrivilege (prv) values (:prv)", dts);
                }
            }

            return(AtState.GetScalar <int>($"select count(*) from UserPrivilege where Prv='{p_id}'") > 0);
        }