예제 #1
0
        public Task <bool> SyncContractInfoAsync(bool forced = false)
        {
            var today = DateTime.Now.Date.ToShortDateString();
            var key   = string.Format("{0}:{1}", nameof(ContractInfo), GetType().Name);

            if (!forced && MFUtilities.GetSyncVersion(key) == today)
            {
                return(Task.FromResult(true));
            }

            var sst = new StringMap();

            sst.Header          = new DataHeader();
            sst.Header.SerialId = NextSerialId;
            var msgId = (uint)BusinessMessageID.MSG_ID_QUERY_INSTRUMENT;

            var tcs = new TaskCompletionSource <bool>();

            var serialId = NextSerialId;

            sst.Header = new DataHeader {
                SerialId = serialId
            };

            MessageWrapper.RegisterAction <PBContractInfoList, ExceptionMessage>
                (msgId,
                (resp) =>
            {
                if (resp.Header?.SerialId == serialId)
                {
                    OnSyncContractInfo(key, resp);

                    tcs.TrySetResult(true);
                }
            },
                (bizErr) =>
            {
                tcs.SetResult(false);
            }
                );

            MessageWrapper.SendMessage(msgId, sst);

            return(tcs.Task);
        }