Example #1
0
        public void Send(ICommandAble cmmd)
        {
            var cmmdStr  = _ser.Ser(cmmd);
            var filePath = CommandFile.GetFilePath(cmmd);

            File.WriteAllText(filePath, cmmdStr);
        }
Example #2
0
 public void Save(ICommandAble entity)
 {
     using var dbContext = new NetCoreSqliteDB.SqliteDBContext(_filePath);
     if (entity.BasedOnUpdatedDateTime == default(DateTime))
     {
         dbContext.Table1.Add(entity as Entity1);
     }
     else
     {
         var preEntity = dbContext.Table1.SingleOrDefault(e => e.Id == entity.Id);
         if (preEntity.UpdatedDateTime > entity.BasedOnUpdatedDateTime)
         {
             throw new Exception();
         }
         else
         {
             _mapper.Map(entity, preEntity);
         }
     }
     dbContext.SaveChanges();
 }
Example #3
0
 public CommandExecutedEventArg(ICommandAble entity)
 {
     Entity       = entity ?? throw new ArgumentNullException(nameof(entity));
     IsSuccess    = true;
     ErrorMessage = string.Empty;
 }
        private static void CheckData(Command cmd, IEntityRepository entityRepository, ICommandAble lastUpdatedEntity)
        {
            if (lastUpdatedEntity.LastUpdateDateTime > cmd.UpdateEntity.Entity.LastUpdateDateTime)
            {
                throw new DataUpdateConflictException(cmd.UpdateEntity.Entity.GetType().Name,
                                                      cmd.UpdateEntity.Entity.Id,
                                                      cmd.UpdateEntity.Entity.LastUpdateDateTime,
                                                      lastUpdatedEntity.LastUpdateDateTime,
                                                      lastUpdatedEntity.LastUpdatedUser);
            }

            var newerReferences = entityRepository.NewerReferences;

            if (newerReferences.Any())
            {
                var newerReference = newerReferences.First();
                var reference      = cmd.UpdateEntity.References.Single(i => i.Id == newerReference.Id);
                throw new ReferenceObsoleteException(
                          newerReference.GetType().Name,
                          newerReference.Id,
                          reference.LastUpdateDateTime,
                          newerReference.LastUpdatedUser,
                          newerReference.LastUpdateDateTime);
            }
        }
Example #5
0
 internal static string GetFilePath(ICommandAble cmmd)
 {
     return(Path.Combine(SharedFolder, GetFileName(cmmd)));
 }
Example #6
0
 internal static string GetFileName(ICommandAble cmmd)
 {
     return($"{cmmd.Id} {cmmd.UpdatedDateTime.ToString("yyMMdd hhmmss")} {cmmd.UpdatedUserName}{FileExtension}");
 }
Example #7
0
 public void Save(ICommandAble entity, string currentUpdateUser, DateTime currentUpdateDateTime)
 {
     throw new NotImplementedException();
 }
Example #8
0
 public string Ser(ICommandAble cmmd)
 {
     return(JsonConvert.SerializeObject(cmmd, _setting));
 }