Horizon – Diff between revs 12 and 20

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 12 Rev 20
Line 380... Line 380...
380 { 380 {
381 _databaseLock.Release(); 381 _databaseLock.Release();
382 } 382 }
383 } 383 }
Line 384... Line 384...
384   384  
385 public async Task SetCompleteSnapshotAsync(TransferSnapshot transferSnapshot, CancellationToken cancellationToken) 385 public async Task ApplyTransferSnapshotAsync(TransferSnapshot transferSnapshot, CancellationToken cancellationToken)
386 { 386 {
387 await _databaseLock.WaitAsync(cancellationToken); 387 await _databaseLock.WaitAsync(cancellationToken);
388 try 388 try
389 { 389 {
390 using (var sqliteConnection = 390 using (var sqliteConnection =
391 new SQLiteConnection(_sqliteConnectionStringBuilder.ConnectionString)) 391 new SQLiteConnection(_sqliteConnectionStringBuilder.ConnectionString))
392 { 392 {
Line -... Line 393...
-   393 await sqliteConnection.OpenAsync(cancellationToken);
393 await sqliteConnection.OpenAsync(cancellationToken); 394  
394   395 var color = Color.Empty;
395 using (var dbTransaction = sqliteConnection.BeginTransaction()) 396 using (var dbTransaction = sqliteConnection.BeginTransaction())
396 { 397 {
397 try 398 try
Line 443... Line 444...
443 var numeric = transferSnapshot.Color; 444 var numeric = transferSnapshot.Color;
444 switch (numeric) 445 switch (numeric)
445 { 446 {
446 case 0: 447 case 0:
447 sqliteCommand.Parameters.Add( 448 sqliteCommand.Parameters.Add(
448 new SQLiteParameter("@color", null)); 449 new SQLiteParameter("@color", DBNull.Value));
-   450 color = Color.Empty;
449 break; 451 break;
450 default: 452 default:
451 sqliteCommand.Parameters.Add( 453 sqliteCommand.Parameters.Add(
452 new SQLiteParameter("@color", numeric)); 454 new SQLiteParameter("@color", numeric));
-   455 color = Color.FromArgb(transferSnapshot.Color);
453 break; 456 break;
454 } 457 }
Line 455... Line 458...
455   458  
Line 500... Line 503...
500 } 503 }
Line 501... Line 504...
501   504  
Line 502... Line 505...
502 dbTransaction.Commit(); 505 dbTransaction.Commit();
503   506  
-   507 SnapshotCreate?.Invoke(this,
504 SnapshotCreate?.Invoke(this, 508 new SnapshotCreateSuccessEventArgs(
505 new SnapshotCreateSuccessEventArgs(transferSnapshot.Name, 509 transferSnapshot.Name,
-   510 transferSnapshot.Time,
506 transferSnapshot.Time, transferSnapshot.Path, 511 transferSnapshot.Path,
-   512 color,
507 Color.FromArgb(transferSnapshot.Color), 513 transferSnapshot.Hash)
508 transferSnapshot.Hash)); 514 );
509 } 515 }
510 } 516 }
511 } 517 }
Line 517... Line 523...
517 dbTransaction.Rollback(); 523 dbTransaction.Rollback();
Line 518... Line 524...
518   524  
519 if (exception.ResultCode != SQLiteErrorCode.Constraint) 525 if (exception.ResultCode != SQLiteErrorCode.Constraint)
520 { 526 {
521 SnapshotCreate?.Invoke(this, 527 SnapshotCreate?.Invoke(this,
-   528 new SnapshotCreateFailureEventArgs(
522 new SnapshotCreateFailureEventArgs(transferSnapshot.Name, transferSnapshot.Path, 529 transferSnapshot.Name,
-   530 transferSnapshot.Path,
-   531 color,
-   532 exception)
523 Color.FromArgb(transferSnapshot.Color), exception)); 533 );
Line 524... Line 534...
524 } 534 }
525   535  
526 throw; 536 throw;
527 } 537 }
528 catch (Exception exception) 538 catch (Exception exception)
Line 529... Line 539...
529 { 539 {
530 dbTransaction.Rollback(); 540 dbTransaction.Rollback();
531   541  
-   542 SnapshotCreate?.Invoke(this,
-   543 new SnapshotCreateFailureEventArgs(
-   544 transferSnapshot.Name,
-   545 transferSnapshot.Path,
Line 532... Line 546...
532 SnapshotCreate?.Invoke(this, 546 color,
533 new SnapshotCreateFailureEventArgs(transferSnapshot.Name, transferSnapshot.Path, 547 exception)
534 Color.FromArgb(transferSnapshot.Color), exception)); 548 );
535   549  
Line 543... Line 557...
543 _databaseLock.Release(); 557 _databaseLock.Release();
544 } 558 }
545 } 559 }
Line 546... Line 560...
546   560  
547   561  
548 public async Task<TransferSnapshot> GetCompleteSnapshot(string hash, CancellationToken cancellationToken) 562 public async Task<TransferSnapshot> GenerateTransferSnapshotAsync(string hash, CancellationToken cancellationToken)
549 { 563 {
550 await _databaseLock.WaitAsync(cancellationToken); 564 await _databaseLock.WaitAsync(cancellationToken);
551 try 565 try
Line 720... Line 734...
720 var numeric = color.ToArgb(); 734 var numeric = color.ToArgb();
721 switch (numeric) 735 switch (numeric)
722 { 736 {
723 case 0: 737 case 0:
724 sqliteCommand.Parameters.Add( 738 sqliteCommand.Parameters.Add(
725 new SQLiteParameter("@color", null)); 739 new SQLiteParameter("@color", DBNull.Value));
726 break; 740 break;
727 default: 741 default:
728 sqliteCommand.Parameters.Add( 742 sqliteCommand.Parameters.Add(
729 new SQLiteParameter("@color", numeric)); 743 new SQLiteParameter("@color", numeric));
730 break; 744 break;
Line 875... Line 889...
875 var numeric = color.ToArgb(); 889 var numeric = color.ToArgb();
876 switch (numeric) 890 switch (numeric)
877 { 891 {
878 case 0: 892 case 0:
879 sqliteCommand.Parameters.Add( 893 sqliteCommand.Parameters.Add(
880 new SQLiteParameter("@color", null)); 894 new SQLiteParameter("@color", DBNull.Value));
881 break; 895 break;
882 default: 896 default:
883 sqliteCommand.Parameters.Add( 897 sqliteCommand.Parameters.Add(
884 new SQLiteParameter("@color", numeric)); 898 new SQLiteParameter("@color", numeric));
885 break; 899 break;
Line 1265... Line 1279...
1265 using (var sqliteCommand = 1279 using (var sqliteCommand =
1266 new SQLiteCommand(UpdateColorFromHashSql, sqliteConnection, dbTransaction)) 1280 new SQLiteCommand(UpdateColorFromHashSql, sqliteConnection, dbTransaction))
1267 { 1281 {
1268 sqliteCommand.Parameters.AddRange(new[] 1282 sqliteCommand.Parameters.AddRange(new[]
1269 { 1283 {
1270 new SQLiteParameter("@hash", hash), 1284 new SQLiteParameter("@hash", hash)
1271 new SQLiteParameter("@color", color.ToArgb()) -  
1272 }); 1285 });
Line -... Line 1286...
-   1286  
-   1287 var numeric = color.ToArgb();
-   1288 switch (numeric)
-   1289 {
-   1290 case 0:
-   1291 sqliteCommand.Parameters.Add(
-   1292 new SQLiteParameter("@color", DBNull.Value));
-   1293 break;
-   1294 default:
-   1295 sqliteCommand.Parameters.Add(
-   1296 new SQLiteParameter("@color", numeric));
-   1297 break;
-   1298 }
1273   1299  
Line 1274... Line 1300...
1274 sqliteCommand.Prepare(); 1300 sqliteCommand.Prepare();
1275   1301  
1276 try 1302 try