/// <summary>
        /// 签出指定节点
        /// </summary>
        internal static async Task <CheckoutResult> CheckoutAsync(List <CheckoutInfo> checkoutInfos)
        {
            if (checkoutInfos == null || checkoutInfos.Count == 0)
            {
                return(null);
            }

            //尝试向存储插入签出信息
            var model = await RuntimeContext.Current.GetModelAsync <EntityModel>(Consts.SYS_CHECKOUT_MODEL_ID);

#if FUTURE
            var txn = await Transaction.BeginAsync();
#else
            using var conn = await SqlStore.Default.OpenConnectionAsync();

            using var txn = conn.BeginTransaction();
#endif
            try
            {
                for (int i = 0; i < checkoutInfos.Count; i++)
                {
                    var info = checkoutInfos[i];
                    var obj  = new Entity(model);
                    obj.SetByte(Consts.CHECKOUT_NODETYPE_ID, (byte)info.NodeType);
                    obj.SetString(Consts.CHECKOUT_TARGETID_ID, info.TargetID);
                    obj.SetGuid(Consts.CHECKOUT_DEVELOPERID_ID, info.DeveloperOuid);
                    obj.SetString(Consts.CHECKOUT_DEVELOPERNAME_ID, info.DeveloperName);
                    obj.SetInt32(Consts.CHECKOUT_VERSION_ID, (int)info.Version);

#if FUTURE
                    await EntityStore.InsertEntityAsync(obj, txn);

                    await txn.CommitAsync();
#else
                    await SqlStore.Default.InsertAsync(obj, txn);

                    txn.Commit();
#endif
                }
            }
            catch (Exception)
            {
                txn.Rollback();
                return(new CheckoutResult(false));
            }

            //检查签出单个模型时,存储有无新版本
            CheckoutResult result = new CheckoutResult(true);
            if (checkoutInfos[0].IsSingleModel)
            {
                var storedModel = await ModelStore.LoadModelAsync(ulong.Parse(checkoutInfos[0].TargetID));

                if (storedModel.Version != checkoutInfos[0].Version)
                {
                    result.ModelWithNewVersion = storedModel;
                }
            }
            return(result);
        }
Exemple #2
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);
        }