예제 #1
0
        public override void Run()
        {
            var data = new AtModel()
            {
                Id = Guid.NewGuid(),
                At = DateTime.UtcNow.AddSeconds(10),
            };

            Trace.TraceInformation("Dequeue At: '{0}' (ID: {1})", data.At, data.Id);
            this.queue.SendBuffered(data, data.At).Wait();

            id++;
        }
예제 #2
0
 /// <summary>
 /// 读取模板内容,重写可自定义读取模板过程
 /// </summary>
 /// <returns></returns>
 public virtual Task <string> ReadTemplate()
 {
     return(Task.Run(() =>
     {
         string define = AtModel.GetScalar <string>("select define from OmReport where name=:name", new Dict {
             { "name", Name }
         });
         if (string.IsNullOrEmpty(define))
         {
             Kit.Warn($"未找到报表模板【{Name}】!");
         }
         return define;
     }));
 }
예제 #3
0
파일: MenuKit.cs 프로젝트: Daoting/dt
        /// <summary>
        /// 打开菜单项窗口,可以由点击菜单项或直接代码构造Menu的方式调用
        /// </summary>
        /// <param name="p_menu">OmMenu实例</param>
        /// <returns>返回打开的窗口或视图,null表示打开失败</returns>
        public static object OpenMenu(OmMenu p_menu)
        {
            if (p_menu == null)
            {
                Kit.Msg("打开菜单项不可为空!");
                return(null);
            }

            Type tp = Kit.GetViewType(p_menu.ViewName);

            if (tp == null)
            {
                Kit.Msg(string.Format("打开菜单时未找到视图【{0}】!", p_menu.ViewName));
                return(null);
            }

            Icons icon;

            Enum.TryParse(p_menu.Icon, out icon);
            object win = Kit.OpenWin(tp, p_menu.Name, icon, string.IsNullOrEmpty(p_menu.Params) ? null : p_menu.Params);

            // 保存点击次数,用于确定哪些是收藏菜单
            if (win != null)
            {
                Task.Run(() =>
                {
                    if (AtModel.GetScalar <int>($"select count(id) from ommenu where id=\"{p_menu.ID}\"") > 0)
                    {
                        // 点击次数保存在客户端
                        Dict dt      = new Dict();
                        dt["userid"] = Kit.UserID;
                        dt["menuid"] = p_menu.ID;
                        int cnt      = AtState.Exec("update menufav set clicks=clicks+1 where userid=:userid and menuid=:menuid", dt);
                        if (cnt == 0)
                        {
                            AtState.Exec("insert into menufav (userid, menuid, clicks) values (:userid, :menuid, 1)", dt);
                        }
                    }
                    // 收集使用频率
                    //await AtAuth.ClickMenu(p_menu.ID);
                });
            }
            return(win);
        }
예제 #4
0
파일: Startup.cs 프로젝트: Daoting/dt
        /// <summary>
        /// 更新打开模型文件
        /// 1. 与本地不同时下载新模型文件;
        /// 2. 打开模型库;
        /// </summary>
        /// <returns></returns>
        public static async Task <bool> OpenModelDb()
        {
            // 获取全局参数
            Dict cfg;

            try
            {
                cfg = await new UnaryRpc(_svcName, "ModelMgr.GetConfig").Call <Dict>();
                Kit.SyncTime(cfg.Date("now"));
            }
            catch
            {
                ShowTip("服务器连接失败!");
                return(false);
            }

            // 更新模型文件
            string modelVer = Path.Combine(Kit.DataPath, $"model-{cfg.Str("ver")}.ver");

            if (!File.Exists(modelVer))
            {
                string modelFile = Path.Combine(Kit.DataPath, "model.db");

                // 删除旧版的模型文件和版本号文件
                try { File.Delete(modelFile); } catch { }
                foreach (var file in new DirectoryInfo(Kit.DataPath).GetFiles($"model-*.ver"))
                {
                    try { file.Delete(); } catch { }
                }

                try
                {
                    // 下载模型文件,下载地址如 https://localhost/app/cm/.model
                    using (var response = await BaseRpc.Client.GetAsync($"{Kit.Stub.ServerUrl}/{_svcName}/.model"))
                        using (var stream = await response.Content.ReadAsStreamAsync())
                            using (var gzipStream = new GZipStream(stream, CompressionMode.Decompress))
                                using (var fs = File.Create(modelFile, 262140, FileOptions.WriteThrough))
                                {
                                    gzipStream.CopyTo(fs);
                                    fs.Flush();
                                }

                    // 版本号文件
                    File.Create(modelVer);
                }
                catch (Exception ex)
                {
                    try
                    {
                        File.Delete(modelFile);
                    }
                    catch { }
                    ShowTip("下载模型文件失败!" + ex.Message);
                    return(false);
                }
            }

            // 打开模型库
            try
            {
                AtModel.OpenDb();
            }
            catch (Exception ex)
            {
                ShowTip("打开模型库失败!" + ex.Message);
                return(false);
            }
            return(true);
        }
예제 #5
0
        public async void ShowDlg()
        {
            Lv lv = _owner.Lv;

            if (lv.Data != null && !_owner.RefreshData)
            {
                // 已设置数据源
            }
            else if (await _owner.OnLoadData())
            {
                // 外部自定义数据源
            }
            else if (!string.IsNullOrEmpty(_owner.Option))
            {
                // 基础选项
                lv.Data = AtModel.Query($"select name from OmOption where Category=\"{_owner.Option}\"");
            }
            else if (!string.IsNullOrEmpty(_owner.Sql))
            {
                // Sql查询数据
                lv.Data = await GetDataBySql(_owner.Sql);
            }
            else if (!string.IsNullOrEmpty(_owner.SqlKey))
            {
                // Sql键值查询
                lv.Data = await GetDataByKey(_owner.SqlKey, _owner.SqlKeyFilter);
            }
            else if (!string.IsNullOrEmpty(_owner.Enum))
            {
                // 枚举数据
                Type type = Type.GetType(_owner.Enum, true, true);
                lv.Data = CreateEnumData(type);
            }
            else if (((Type)_owner.ValBinding.ConverterParameter).IsEnum)
            {
                // 枚举类型
                lv.Data = CreateEnumData((Type)_owner.ValBinding.ConverterParameter);
            }
            else if (_owner.Items.Count > 0)
            {
                // xaml中定义的对象列表
                lv.Data = _owner.Items;
            }

            if (lv.View == null)
            {
                lv.ShowItemBorder = false;
                lv.View           = (lv.Data is Table) ? Application.Current.Resources["CListRowView"] : Application.Current.Resources["CListObjView"];
            }

            // 不向下层对话框传递Press事件
            AllowRelayPress = false;

            // phone模式先最大化
            if (Kit.IsPhoneUI)
            {
                ClearValue(HideTitleBarProperty);
                ClearValue(PhonePlacementProperty);
                ClearValue(HeightProperty);
            }
            Show();

            // phone模式选项内容不足半屏时在下部显示
            if (Kit.IsPhoneUI && DesiredSize.Height * 2 < SysVisual.ViewHeight)
            {
                //HideTitleBar = true;
                Top = SysVisual.ViewHeight - DesiredSize.Height;
                // uno中不可设置为固定高度!
                Height = double.NaN;
            }
        }
예제 #6
0
파일: MenuKit.cs 프로젝트: Daoting/dt
        /// <summary>
        /// 加载当前登录用户的菜单,性能已调优
        /// </summary>
        public static async Task LoadMenus()
        {
            // 所有可访问项
            List <long> idsAll = await GetAllUserMenus();

            // 常用组菜单项:固定项 + 点击次数最多的前n项,总项数 <= 8
            _favMenus.Clear();
            var fixedMenus = Kit.Stub.FixedMenus;

            if (fixedMenus != null)
            {
                // 固定项
                foreach (var om in fixedMenus)
                {
                    _favMenus.Add(om);
                }
            }

            // 点击次数最多的前n项
            int maxFav = 8;

            if (_favMenus.Count < maxFav)
            {
                var favMenu = AtState.Each <MenuFav>($"select menuid from menufav where userid={Kit.UserID} order by clicks desc LIMIT {maxFav}");
                foreach (var fav in favMenu)
                {
                    // 过滤无权限的项
                    if (idsAll.Contains(fav.MenuID))
                    {
                        var om = AtModel.First <OmMenu>($"select * from OmMenu where id={fav.MenuID}");
                        _favMenus.Add(om);
                        idsAll.Remove(fav.MenuID);
                        if (_favMenus.Count >= maxFav)
                        {
                            break;
                        }
                    }
                }
            }

            // 根页面菜单
            _rootPageMenus = new Nl <GroupData <OmMenu> >();
            // 除根页面的剩余项
            _leaveMenus = new List <OmMenu>();
            // 所有一级项
            var roots = new List <OmMenu>();

            // 整理菜单项
            foreach (var item in AtModel.Each <OmMenu>("select * from OmMenu"))
            {
                // 过滤无权限的项,保留所有分组
                if (!item.IsGroup && !idsAll.Contains(item.ID))
                {
                    continue;
                }

                // 一级项和其他分开
                if (!item.ParentID.HasValue)
                {
                    roots.Add(item);
                }
                else
                {
                    _leaveMenus.Add(item);
                }
            }
            // 根页面常用组
            if (_favMenus.Count > 0)
            {
                _rootPageMenus.Add(_favMenus);
            }

            // 移除无用的分组
            int index = 0;

            while (index < _leaveMenus.Count)
            {
                var om = _leaveMenus[index];
                if (!om.IsGroup || IsExistChild(om))
                {
                    index++;
                }
                else
                {
                    _leaveMenus.RemoveAt(index);
                }
            }

            // 整理一级菜单
            GroupData <OmMenu> grpLast = null;

            foreach (var om in roots)
            {
                // 一级的实体菜单项
                if (!om.IsGroup)
                {
                    if (grpLast == null)
                    {
                        grpLast = new GroupData <OmMenu>()
                        {
                            Title = "其它"
                        }
                    }
                    ;
                    grpLast.Add(om);
                    continue;
                }

                // 一级为分组,处理二级
                GroupData <OmMenu> grpCur = new GroupData <OmMenu>()
                {
                    Title = om.Name
                };
                index = 0;
                while (index < _leaveMenus.Count)
                {
                    var ch = _leaveMenus[index];
                    if (ch.ParentID == om.ID)
                    {
                        // 二级菜单
                        grpCur.Add(ch);
                        _leaveMenus.RemoveAt(index);
                    }
                    else
                    {
                        index++;
                    }
                }
                if (grpCur.Count > 0)
                {
                    _rootPageMenus.Add(grpCur);
                }
            }

            // 一级实体项放在最后
            if (grpLast != null)
            {
                _rootPageMenus.Add(grpLast);
            }
        }