Exemplo n.º 1
0
        /// <summary>
        /// 创建合约筹码
        /// </summary>
        public IContractChip CreateContractChip <T>(IContractChipData contractChipData) where T : IContractChip
        {
            IContractChip contractChip = Activator.CreateInstance <T>();

            contractChip.Id = Guid.NewGuid().ToString();
            contractChip.ContractChipData = contractChipData;
            return(contractChip);
        }
Exemplo n.º 2
0
        public IEnumerable <string> Get()
        {
            IContractEvent contractEvent = ContractEventFactory.Instance.CreateContractEvent <StandardContractEvent>(new ContractEventData()
            {
                Description = "早上7点前起床"
            });
            IContractChip contractChip = ContractChipFactory.Instance.CreateContractChip <StandardContractChip>(new ContractChipData()
            {
                Description = "得到1毛钱"
            });
            IContractData contractData = new ContractData()
            {
                InitiatorIds    = new string[] { "A" },
                ActorIds        = new string[] { "B" },
                ContractEventId = contractEvent.Id,
                ContractChipId  = contractChip.Id
            };
            IContract contract = ContractFactory.Instance.CreateContract <Contract>(contractData);

            //保存到数据库
            _context.ContractEvents.Add(
                new DbContractEvent()
            {
                Id       = Guid.Parse(contractEvent.Id),
                JsonData = ContractEventFactory.Instance.SerializeContractEventData(contractEvent)
            }
                );
            _context.ContractChips.Add(
                new DbContractChip()
            {
                Id       = Guid.Parse(contractChip.Id),
                JsonData = ContractChipFactory.Instance.SerializeContractChipData(contractChip)
            }
                );
            _context.Contracts.Add(
                new DbContract()
            {
                Id       = Guid.Parse(contract.Id),
                JsonData = ContractFactory.Instance.SerializeContractData(contract)
            }
                );

            _context.SaveChanges();

            //返回结果
            return(new string[]
            {
                ContractFactory.Instance.SerializeContractData(contract),
                ContractEventFactory.Instance.SerializeContractEventData(contractEvent),
                ContractChipFactory.Instance.SerializeContractChipData(contractChip)
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// 解析合约筹码
        /// </summary>
        public IContractChip ParseContractChip <T1, T2>(string id, string jsonData) where T1 : IContractChip where T2 : IContractChipData
        {
            IContractChipData contractChipData = JsonConvert.DeserializeObject <T2>(jsonData);
            IContractChip     contractChip     = null;

            if (contractChipData != null && !string.IsNullOrEmpty(id))
            {
                contractChip    = Activator.CreateInstance <T1>();
                contractChip.Id = id;
                contractChip.ContractChipData = contractChipData;
            }
            return(contractChip);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 序列化合约筹码数据
        /// </summary>
        /// <param name="contractChip"></param>
        /// <returns></returns>
        public string SerializeContractChipData(IContractChip contractChip)
        {
            string jsonData = JsonConvert.SerializeObject(contractChip.ContractChipData);

            return(jsonData);
        }