Пример #1
0
        public async Task InsertAsync(T data)
        {
            var mState = new MongoState <K>();

            mState.StateId = data.StateId;
            mState.Id      = ObjectId.GenerateNewId().ToString();
            using (var ms = new PooledMemoryStream())
            {
                Serializer.Serialize <T>(ms, data);
                mState.Data = ms.ToArray();
            }
            if (mState.Data != null && mState.Data.Count() > 0)
            {
                await mongoStorage.GetCollection <MongoState <K> >(database, collection).InsertOneAsync(mState, null, new CancellationTokenSource(3000).Token);
            }
        }
Пример #2
0
        public async Task InsertAsync(T data)
        {
            var mState = new MongoState <K>
            {
                StateId = data.StateId,
                Id      = ObjectId.GenerateNewId().ToString(),
                Version = data.Version
            };

            using (var ms = new PooledMemoryStream())
            {
                Serializer.Serialize <T>(ms, data);
                mState.Data = ms.ToArray();
            }
            if (mState.Data != null && mState.Data.Count() > 0)
            {
                await grainConfig.Storage.GetCollection <MongoState <K> >(grainConfig.DataBase, grainConfig.SnapshotCollection).InsertOneAsync(mState, null, new CancellationTokenSource(3000).Token);
            }
        }