Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. public int EditFile(File file, FileValidationParameters validationParameters = null)
  2. {
  3. var isContentRelocationRequired = false;
  4.  
  5. try
  6. {
  7. string errorMessage;
  8. if (!ValidateFile(file, out errorMessage))
  9. {
  10. throw new Exception(errorMessage);
  11. }
  12.  
  13. DocumentFile documentFile = null;
  14. int newRevisionNumber;
  15. // TODO [IP] : Вернуть или удалить в зависимости от результата исследования проблемы с боя
  16. //using (var redisLock = new StrictRedisLockCreator(RedisCacheHelper.GenerateFullKey(RedisCacheKeyName.FileAccessLockObjectForVirusScannerKeyName, file.Guid.ToString()), TimeSpan.FromSeconds(15))
  17. // .Create(RedisLockConstants.DefaultLockWaitTime, RedisLockConstants.DefaultLockRetryTime))
  18. //{
  19. //if (redisLock.IsAcquired)
  20. // {
  21. documentFile = DataAccessEf.SelectDocumentFile(file.Guid);
  22. //}
  23.  
  24. if (documentFile == null)
  25. {
  26. throw new Exception(String.Format("Файл (Guid = {0}) не найден.", file.Guid.ToString()));
  27. }
  28.  
  29. isContentRelocationRequired = IsContentRelocationRequired(file, documentFile);
  30.  
  31. if (isContentRelocationRequired)
  32. {
  33. _redisCacheClient.Set(RedisCacheRegionName.FileFileServiceModifing, documentFile.Guid,
  34. Public.RedisCache.Client.NullObject.Value, TimeSpan.MaxValue);
  35. }
  36.  
  37. newRevisionNumber = documentFile.RevisionNumber + 1;
  38.  
  39. // Если контент документа был экспортирован во внешнее хранилище,
  40. // то сбрасываем этот признак, чтобы отдавать новый контент (из БД) и экспорт прошёл ещё раз (во внешнее хранилище).
  41. if (documentFile.IsMovedToStorage)
  42. {
  43. DocumentFileStoragePropertyService.ResetDocumentFileStorageProperties(documentFile);
  44. }
  45.  
  46. UpdateDocumentFile(documentFile, file);
  47. documentFile.VirusState = (int) VirusCheckState.NotChecked;
  48. documentFile.RevisionNumber = newRevisionNumber;
  49.  
  50. IUserSecurityToken token = ContextContainer.CurrentContext.GetUserSecurityToken();
  51.  
  52. if (token != null)
  53. {
  54. documentFile.LastChangeUserId = token.UserInfo.UserId;
  55. }
  56.  
  57. documentFile.LastChangeDate = DateTime.UtcNow;
  58.  
  59. DataAccessEf.UpdateDocumentFile(documentFile);
  60.  
  61. if (isContentRelocationRequired)
  62. {
  63. _redisCacheClient.Set(RedisCacheRegionName.FileFileServiceModified, documentFile.Guid,
  64. Public.RedisCache.Client.NullObject.Value, TimeSpan.MaxValue);
  65. }
  66.  
  67. UpdateCertificateThumbprint(documentFile, file);
  68.  
  69. var dalFileSignatures = DataAccess.SelectDocumentFileSignatures(documentFile.ID);
  70. UpdateFileSignatures(documentFile.ID, file.Signatures, dalFileSignatures);
  71. //}
  72.  
  73. return newRevisionNumber;
  74. }
  75. catch (Exception e)
  76. {
  77. throw LogAndWrapException(e);
  78. }
  79. finally
  80. {
  81. if (isContentRelocationRequired)
  82. {
  83. _redisCacheClient.Remove(RedisCacheRegionName.FileFileServiceModifing, file.Guid.ToString());
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement