Пример #1
0
 public static SyncModelWrapper Create(long?changeVersion, PersistOperationType operationType, SyncModel model)
 {
     return(new SyncModelWrapper
     {
         ChangeVersion = changeVersion,
         Model = model,
         OperationType = operationType
     });
 }
Пример #2
0
        private void Persist(ISyncModelAdapter adapter, PersistOperationType type, IList <SyncModel> entities)
        {
            if (entities.Count == 0)
            {
                return;
            }
            if (adapter == null)
            {
                Log.LogInfo($"No adapter for {entities[0].GetType().Name}");
                return;
            }
            var requestStartTime = DateTimeOffset.UtcNow;
            var requestTimer     = Stopwatch.StartNew();

            try
            {
                adapter.Persist(type, entities);
            }
            catch (Exception)
            {
                Log.LogError($"Error durring persisting {entities[0].GetType().Name}");
                int cnt = 0;
                foreach (var entity in entities)
                {
                    var s = JsonConvert.SerializeObject(entity);
                    Log.LogError(s);
                    cnt++;
                    if (cnt >= MAX_LOOGED_ENTITIES)
                    {
                        break;
                    }
                }
                if (cnt < entities.Count)
                {
                    Log.LogError($"only first {MAX_LOOGED_ENTITIES}  of {entities.Count} entities were logged");
                }
                throw;
            }

            string typeName    = type.ToString();
            var    adapterName = adapter.GetType().Name;

            Log.LogInfo($"persist {typeName} by {adapterName}");
            Telemetry.DispatchRequest(typeName, adapterName, requestStartTime, requestTimer.Elapsed, true, Verbosity.Info, districtId.ToString(), taskId.ToString());
        }
Пример #3
0
 public void Persist(PersistOperationType type, IList <SyncModel> entities)
 {
     persistActions[type](entities.Cast <TSyncModel>().ToList());
 }