Ejemplo n.º 1
0
Archivo: Log.cs Proyecto: 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);
        }
Ejemplo n.º 2
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);
        }