예제 #1
0
        /// <summary>
        /// Saves the specified egm metrics.
        /// </summary>
        /// <param name="egmMetrics">The egm metrics.</param>
        public void Save(ICollection <EgmMetric> egmMetrics)
        {
            using (var context = new HmsDbContext())
            {
                //context.Database.Log = Console.Write;

                foreach (var egmMetric in egmMetrics)
                {
                    if (!context.EgmMetrics.Any(metric => metric.Id == egmMetric.Id))
                    {
                        // no matching PK for this EgmMetric in database,
                        // thus we create new entity and add it to db
                        DaoUtilities.SaveCreatedEntity(context, context.EgmMetrics, egmMetric,
                                                       SetNewEntityState, false);
                    }
                    else
                    {
                        // matching PK found, thus we update state of existing EgmMetric entity
                        DaoUtilities.SaveUpdatedEntity(context, context.EgmMetrics, egmMetric,
                                                       UpdateExistingEntityState, false);
                    }
                }

                DaoUtilities.SaveToDbWithRetry(context, DaoUtilities.SaveType.UpdateExistingEntity,
                                               ResolveEntityUpdateConflict);
            }
        }
        /// <summary>
        /// Saves the specified composite egm meter datas.
        /// </summary>
        /// <param name="compositeEgmMeterDatas">The composite egm meter datas.</param>
        public void Save(ICollection <CompositeEgmMeterData> compositeEgmMeterDatas)
        {
            using (var context = new HmsDbContext())
            {
                //context.Database.Log = Console.Write;

                foreach (var compositeEgmMeterData in compositeEgmMeterDatas)
                {
                    if (!context.CompositeEgmMeterDatas.Any(cemd => cemd.Id == compositeEgmMeterData.Id))
                    {
                        // no matching PK for this CompositeEgmMeterData in database,
                        // thus we create new entity and add it to db
                        DaoUtilities.SaveCreatedEntity(context, context.CompositeEgmMeterDatas, compositeEgmMeterData,
                                                       SetNewEntityState, false);
                    }
                    else
                    {
                        // matching PK found, thus we update state of existing CompositeEgmMeterData entity
                        DaoUtilities.SaveUpdatedEntity(context, context.CompositeEgmMeterDatas, compositeEgmMeterData,
                                                       UpdateExistingEntityState, false);
                    }
                }

                DaoUtilities.SaveToDbWithRetry(context, DaoUtilities.SaveType.UpdateExistingEntity,
                                               ResolveEntityUpdateConflict);
            }
        }
예제 #3
0
 /// <summary>
 /// Cleans EgmMetric Entities older than specified date-time.
 /// </summary>
 /// <param name="oldDateTime">The old date time.</param>
 public void CleanOlderThan(DateTime oldDateTime)
 {
     using (var context = new HmsDbContext())
     {
         context.EgmMetrics.RemoveRange(
             context.EgmMetrics.Where(
                 mr => mr.ReportedAt != DaoUtilities.UnsentData && mr.ReportedAt < oldDateTime));
         DaoUtilities.SaveToDbWithRetry(context, DaoUtilities.SaveType.DeleteExistingEntity,
                                        ResolveEntityUpdateConflict);
     }
 }