Beispiel #1
0
        /// <summary>
        /// 给设计节点添加签出信息,如果已签出的模型节点则用本地存储替换原模型
        /// </summary>
        internal void BindCheckoutInfo(DesignNode node, bool isNewNode)
        {
            //if (node.NodeType == DesignNodeType.FolderNode || !node.AllowCheckout)
            //    throw new ArgumentException("不允许绑定签出信息: " + node.NodeType.ToString());

            //先判断是否新增的
            if (isNewNode)
            {
                node.CheckoutInfo = new CheckoutInfo(node.NodeType, node.CheckoutInfoTargetID, node.Version,
                                                     DesignHub.Session.Name, DesignHub.Session.LeafOrgUnitID);
                return;
            }

            //非新增的比对服务端的签出列表
            string key = CheckoutInfo.MakeKey(node.NodeType, node.CheckoutInfoTargetID);

            if (_checkouts.TryGetValue(key, out CheckoutInfo checkout))
            {
                node.CheckoutInfo = checkout;
                if (node.IsCheckoutByMe) //如果是被当前用户签出的模型
                {
                    if (node is ModelNode modelNode)
                    {
                        //从本地缓存加载
                        var stagedModel = Staged.FindModel(modelNode.Model.Id);
                        if (stagedModel != null)
                        {
                            modelNode.Model = stagedModel;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 用于DesignTree加载时
        /// </summary>
        internal static async Task <Dictionary <string, CheckoutInfo> > LoadAllAsync()
        {
            var list = new Dictionary <string, CheckoutInfo>();

#if FUTURE
            var q = new TableScan(Consts.SYS_CHECKOUT_MODEL_ID);
#else
            var q = new SqlQuery(Consts.SYS_CHECKOUT_MODEL_ID);
#endif
            var res = await q.ToListAsync();

            if (res != null)
            {
                for (int i = 0; i < res.Count; i++)
                {
                    var info = new CheckoutInfo((DesignNodeType)res[i].GetByte(Consts.CHECKOUT_NODETYPE_ID),
                                                res[i].GetString(Consts.CHECKOUT_TARGETID_ID),
                                                (uint)res[i].GetInt32(Consts.CHECKOUT_VERSION_ID),
                                                res[i].GetString(Consts.CHECKOUT_DEVELOPERNAME_ID),
                                                res[i].GetGuid(Consts.CHECKOUT_DEVELOPERID_ID));
                    list.Add(info.GetKey(), info);
                }
            }

            return(list);
        }
Beispiel #3
0
 /// <summary>
 /// 用于签出节点成功后添加签出信息列表
 /// </summary>
 internal void AddCheckoutInfos(List <CheckoutInfo> infos)
 {
     for (int i = 0; i < infos.Count; i++)
     {
         string key = CheckoutInfo.MakeKey(infos[i].NodeType, infos[i].TargetID);
         if (!_checkouts.ContainsKey(key))
         {
             _checkouts.Add(key, infos[i]);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// 目前仅支持签出ModelRootNode及ModelNode
        /// </summary>
        public virtual async Task <bool> Checkout() //TODO:考虑加入参数允许签出所有下属节点
        {
            //判断是否已签出或者能否签出
            if (!AllowCheckout)
            {
                return(false);
            }
            if (IsCheckoutByMe)
            {
                return(true);
            }

            //调用签出服务
            List <CheckoutInfo> infos = new List <CheckoutInfo>();
            CheckoutInfo        info  = new CheckoutInfo(NodeType, CheckoutInfoTargetID, Version,
                                                         DesignTree.DesignHub.Session.Name,
                                                         DesignTree.DesignHub.Session.LeafOrgUnitID);

            infos.Add(info);
            CheckoutResult result = await CheckoutService.CheckoutAsync(infos);

            if (result.Success)
            {
                //签出成功则将请求的签出信息添加至当前的已签出列表
                DesignTree.AddCheckoutInfos(infos);
                //如果签出的是单个模型,且具备更新的版本,则更新
                if (this is ModelNode modelNode && result.ModelWithNewVersion != null)
                {
                    modelNode.Model = result.ModelWithNewVersion;                              //替换旧模型
                    await DesignTree.DesignHub.TypeSystem.UpdateModelDocumentAsync(modelNode); //更新为新模型的RoslynDocument
                }
                //更新当前节点的签出信息
                CheckoutInfo = infos[0];
            }

            return(result.Success);
        }