77using Intersect . Enums ;
88using Intersect . GameObjects ;
99using Intersect . Logging ;
10+ using Intersect . Reflection ;
1011using Intersect . Security ;
1112using Intersect . Server . Core ;
1213using Intersect . Server . Database . Logging . Entities ;
@@ -309,8 +310,16 @@ public async Task SaveAsync(
309310
310311 public void Save ( bool force = false , bool create = false ) => Save ( default , force , create ) ;
311312
312- public void Save ( PlayerContext ? playerContext , bool force = false , bool create = false )
313+ #if DIAGNOSTIC
314+ private int _saveCounter = 0 ;
315+ #endif
316+
317+ private void Save ( PlayerContext ? playerContext , bool force = false , bool create = false )
313318 {
319+ #if DIAGNOSTIC
320+ var currentExecutionId = _saveCounter ++ ;
321+ #endif
322+
314323 //No passing in custom contexts here.. they may already have this user in the change tracker and things just get weird.
315324 //The cost of making a new context is almost nil.
316325 var lockTaken = false ;
@@ -332,6 +341,10 @@ public void Save(PlayerContext? playerContext, bool force = false, bool create =
332341 return ;
333342 }
334343
344+ #if DIAGNOSTIC
345+ Log . Debug ( $ "DBOP-A Save({ playerContext } , { force } , { create } ) #{ currentExecutionId } { Name } ({ Id } )") ;
346+ #endif
347+
335348 if ( playerContext == null )
336349 {
337350 createdContext = DbInterface . CreatePlayerContext ( false ) ;
@@ -360,6 +373,10 @@ public void Save(PlayerContext? playerContext, bool force = false, bool create =
360373 }
361374
362375 playerContext . SaveChanges ( ) ;
376+
377+ #if DIAGNOSTIC
378+ Log . Debug ( $ "DBOP-B Save({ playerContext } , { force } , { create } ) #{ currentExecutionId } { Name } ({ Id } )") ;
379+ #endif
363380 }
364381 catch ( DbUpdateConcurrencyException ex )
365382 {
@@ -369,37 +386,46 @@ public void Save(PlayerContext? playerContext, bool force = false, bool create =
369386 var type = entry . GetType ( ) . FullName ;
370387 concurrencyErrors . AppendLine ( $ "Entry Type [{ type } / { entry . State } ]") ;
371388 concurrencyErrors . AppendLine ( "--------------------" ) ;
389+ concurrencyErrors . AppendLine ( $ "Type: { entry . Entity . GetFullishName ( ) } ") ;
372390
373391 var proposedValues = entry . CurrentValues ;
374392 var databaseValues = entry . GetDatabaseValues ( ) ;
375393
376- foreach ( var property in proposedValues . Properties )
377- {
378- concurrencyErrors . AppendLine (
379- $ "{ property . Name } (Token: { property . IsConcurrencyToken } ): Proposed: { proposedValues [ property ] } Original Value: { entry . OriginalValues [ property ] } Database Value: { ( databaseValues != null ? databaseValues [ property ] : "null" ) } "
380- ) ;
381- }
394+ var propertyNameColumnSize = proposedValues . Properties . Max ( property => property . Name . Length ) ;
382395
383- foreach ( var property in entry . Properties )
396+ foreach ( var property in proposedValues . Properties )
384397 {
385398 concurrencyErrors . AppendLine (
386- $ "{ property . Metadata . Name } { nameof ( property . IsModified ) } = { property . IsModified } { nameof ( property . IsTemporary ) } = { property . IsTemporary } "
399+ $ "\t { property . Name : propertyNameColumnSize } (Token: { property . IsConcurrencyToken } ): Proposed: { proposedValues [ property ] } Original Value: { entry . OriginalValues [ property ] } Database Value: { ( databaseValues != null ? databaseValues [ property ] : "null" ) } "
387400 ) ;
388401 }
389402
390403 concurrencyErrors . AppendLine ( "" ) ;
391404 concurrencyErrors . AppendLine ( "" ) ;
392405 }
393406
394- Log . Error ( ex , $ "Jackpot! Concurrency Bug For { Name } in { ( createdContext == default ? "Existing" : "Created" ) } Context") ;
407+ var suffix = string . Empty ;
408+ #if DIAGNOSTIC
409+ suffix = $ "#{ currentExecutionId } ";
410+ #endif
411+ Log . Error ( ex , $ "Jackpot! Concurrency Bug For { Name } in { ( createdContext == default ? "Existing" : "Created" ) } Context { suffix } ") ;
395412 Log . Error ( concurrencyErrors . ToString ( ) ) ;
413+
414+ #if DIAGNOSTIC
415+ Log . Debug ( $ "DBOP-C Save({ playerContext } , { force } , { create } ) #{ currentExecutionId } { Name } ({ Id } )") ;
416+ #endif
417+
396418 ServerContext . DispatchUnhandledException (
397419 new Exception ( "Failed to save user, shutting down to prevent rollbacks!" )
398420 ) ;
399421 }
400422 catch ( Exception ex )
401423 {
402424 Log . Error ( ex , "Failed to save user: " + Name ) ;
425+
426+ #if DIAGNOSTIC
427+ Log . Debug ( $ "DBOP-C Save({ playerContext } , { force } , { create } ) #{ currentExecutionId } { Name } ({ Id } )") ;
428+ #endif
403429 ServerContext . DispatchUnhandledException (
404430 new Exception ( "Failed to save user, shutting down to prevent rollbacks!" )
405431 ) ;
@@ -449,7 +475,8 @@ public static User TryLogin(string username, string ptPassword)
449475 var hashedPassword = SaltPasswordHash ( ptPassword , user . Salt ) ;
450476 if ( string . Equals ( user . Password , hashedPassword , StringComparison . Ordinal ) )
451477 {
452- return PostLoad ( user ) ;
478+ //return PostLoad(user);
479+ return user ;
453480 }
454481 }
455482 else
0 commit comments