Пример #1
0
        /// <summary>
        /// Puts the given DataEntity into its corresponding Mongo collection
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entityToStore"></param>
        public void Put <T>(T entityToStore) where T : DataEntityBase
        {
            IMongoCollection <T> collection = GetCollection <T>();

            if (collection.FindOneAndReplace(o => Equals(o.Id, entityToStore.Id), entityToStore) == null)
            {
                collection.InsertOne(entityToStore);


                if (!string.IsNullOrEmpty(_amazonKinesisStreamName))
                {
                    _amazonFirehoseProducer.PutRecord(_amazonKinesisStreamName,
                                                      FormatEntity(entityToStore, OperationType.Insert));
                }

                if (!string.IsNullOrEmpty(_dataPumpLambdaName))
                {
                    Task.Run(() => _lambdaDataPump.InvokeLambdaAsync(FormatEntity(entityToStore, OperationType.Insert)))
                    .ConfigureAwait(false);
                }

                Logger.Trace($"{nameof(MongoStore)}.{nameof(Put)}",
                             new LogItem("Event", "Insert entity"),
                             new LogItem("Type", typeof(T).ToString),
                             new LogItem("Entity", entityToStore.ToString));
            }
        }
        public void Put <T>(T entityToStore) where T : DataEntity
        {
            var table = GetCachedTable <T>();

            table.InsertOnSubmit(entityToStore);
            Stopwatch timer = Stopwatch.StartNew();

            try
            {
                _context.SubmitChanges();
                Logger.Trace($"{nameof(DynamoStore)}.{nameof(Put)}",
                             new LogItem("Event", "Insert entity"),
                             new LogItem("Type", typeof(T).ToString),
                             new LogItem("Entity", entityToStore.ToString),
                             new LogItem("DurationMilliseconds", timer.Elapsed.TotalMilliseconds));

                try
                {
                    _amazonFirehoseProducer.PutRecord(_amazonKinesisStreamName,
                                                      FormatEntity(entityToStore, Helpers.OperationType.Insert));
                }
                catch (Exception ex)
                {
                    Logger.Error($"{nameof(DynamoStore)}.{nameof(Put)}",
                                 new LogItem("Event", "Failed to send update to data lake"),
                                 new LogItem("Type", typeof(T).ToString),
                                 new LogItem("Entity", entityToStore.ToString),
                                 new LogItem("Exception Message", ex.Message),
                                 new LogItem("Stack Trace", ex.StackTrace),
                                 new LogItem("DurationMilliseconds", timer.Elapsed.TotalMilliseconds));
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"{nameof(DynamoStore)}.{nameof(Put)}",
                             new LogItem("Event", "Failed to insert entity"),
                             new LogItem("Type", typeof(T).ToString),
                             new LogItem("Entity", entityToStore.ToString),
                             new LogItem("Exception Message", ex.Message),
                             new LogItem("Stack Trace", ex.StackTrace),
                             new LogItem("DurationMilliseconds", timer.Elapsed.TotalMilliseconds));
                throw;
            }
        }
Пример #3
0
        /// <summary>
        /// Puts the given DataEntity into its corresponding Dynamo table
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entityToStore"></param>
        public void Put <T>(T entityToStore) where T : DataEntity
        {
            var table = GetCachedTable <T>();

            table.InsertOnSubmit(entityToStore);
            Stopwatch timer = Stopwatch.StartNew();

            try
            {
                _context.SubmitChanges();

                if (!string.IsNullOrEmpty(_amazonKinesisStreamName))
                {
                    _amazonFirehoseProducer.PutRecord(_amazonKinesisStreamName,
                                                      FormatEntity(entityToStore, Helpers.OperationType.Insert));
                }

                if (!string.IsNullOrEmpty(_dataPumpLambdaName))
                {
                    Task.Run(() =>
                             _lambdaDataPump.InvokeLambdaAsync(FormatEntity(entityToStore,
                                                                            Helpers.OperationType.Insert)))
                    .ConfigureAwait(false);
                }

                Logger.Trace($"{nameof(DynamoStore)}.{nameof(Put)}",
                             new LogItem("Event", "Insert entity"),
                             new LogItem("Type", typeof(T).ToString),
                             new LogItem("Entity", entityToStore.ToString),
                             new LogItem("DurationMilliseconds", timer.Elapsed.TotalMilliseconds));
            }
            catch (Exception ex)
            {
                Logger.Error($"{nameof(DynamoStore)}.{nameof(Put)}",
                             new LogItem("Event", "Failed to insert entity"),
                             new LogItem("Type", typeof(T).ToString),
                             new LogItem("Entity", entityToStore.ToString),
                             new LogItem("Exception Message", ex.Message),
                             new LogItem("Stack Trace", ex.StackTrace),
                             new LogItem("DurationMilliseconds", timer.Elapsed.TotalMilliseconds));
                throw;
            }
        }