示例#1
0
 public bool IsPointToSameFile(SourceDataFileDescriptor other)
 {
     if (other == null)
         return false;
     return
         string.CompareOrdinal(Path.GetFileName(FilePath), Path.GetFileName(other.FilePath)) == 0 &&
         FileSize == other.FileSize;
 }
示例#2
0
 public bool IsPointToSameFile(SourceDataFileDescriptor other)
 {
     if (other == null)
     {
         return(false);
     }
     return
         (string.CompareOrdinal(Path.GetFileName(FilePath), Path.GetFileName(other.FilePath)) == 0 &&
          FileSize == other.FileSize);
 }
示例#3
0
 private void SetSourceDataInternal( 
     SourceData newSd,  
     SourceDataFileDescriptor newSdFileDescriptor, 
     SourceDataChangesCache newSdChangesCache, 
     bool newIsSdCorrect)
 {
     var newSdFileDescriptorDiffer = SetSourceDataFileDescriptor(newSdFileDescriptor);
     var newSdChangesCacheDiffer = SetSourceDataChangesCache(newSdChangesCache);
     var newSdDiffer = true;
     if (newSd == null)
     {
         if (newSdFileDescriptor == null)
         {
             if (SourceData == null)
                 newSdDiffer = false;
         }
         else if (newSdFileDescriptorDiffer)
         {
             LoadSourceDataFromFile(_sourceDataFileDescriptor, false, out newSd);
         }
         else
         {
             newSdDiffer = false;
         }
     }
     if (newSdDiffer || newSdChangesCacheDiffer)
     {
         if (SourceData != null)
         {
             UnsubscribeFromSourceDataChanges();
         }
         if (newSdDiffer)
             SourceData = newSd;
         if (SourceData != null)
         {
             _sourceDataChangesCache.ApplyChanges(SourceData);
             SubscribeToSourceDataChanges();
         }
     }
     _isSourceDataCorrect = newIsSdCorrect;
 }
示例#4
0
 private bool SetSourceDataFileDescriptor(SourceDataFileDescriptor newSdFileDescriptor)
 {
     var oldIsNull = (_sourceDataFileDescriptor == null);
     if (newSdFileDescriptor == null)
     {
         if (oldIsNull)
             return false;
         _sourceDataFileDescriptor = null;
         return true;
     }
     var stateFilePath = Path.Combine(
         _fileSystemManager.GetDataDirectoryPath(FileType.State),
         Path.GetFileName(newSdFileDescriptor.FilePath));
     _sourceDataFileDescriptor = new SourceDataFileDescriptor(
         stateFilePath,
         newSdFileDescriptor.FileSize,
         newSdFileDescriptor.Uik,
         _syncManager.LocalScannerSerialNumber);
     var stateFile = new FileInfo(stateFilePath);
     if (!stateFile.Exists)
     {
         CopySourceDataFile(newSdFileDescriptor, stateFilePath);
         return true;
     }
     if (_sourceDataFileDescriptor.IsPointToFile(stateFilePath, stateFile.Length))
         return oldIsNull;
     CopySourceDataFile(newSdFileDescriptor, stateFilePath);
     return true;
 }
示例#5
0
 private void CopySourceDataFile(SourceDataFileDescriptor sdFileDescriptor, string targetFilePath)
 {
     if (string.CompareOrdinal(
         sdFileDescriptor.ScannerSerialNumner,
         _syncManager.LocalScannerSerialNumber) == 0)
     {
         File.Copy(sdFileDescriptor.FilePath, targetFilePath, true);
         SystemHelper.SyncFileSystem();
         return;
     }
     var content = _syncManager.RemoteScanner.GetFileContent(sdFileDescriptor.FilePath);
     File.WriteAllBytes(targetFilePath, content);
     SystemHelper.SyncFileSystem();
 }
示例#6
0
 public bool SetSourceData(SourceData sourceData, SourceDataFileDescriptor sourceDataFileDescriptor)
 {
     CodeContract.Requires(sourceData != null);
     CodeContract.Requires(sourceDataFileDescriptor != null);
     try
     {
         SetSourceDataInternal(
             sourceData,
             sourceDataFileDescriptor,
             null,
             false);
     }
     catch (Exception ex)
     {
         Logger.LogError(Message.Election_SetSourceDataFailed, ex);
         return false;
     }
     RaiseStateChanged();
     Logger.LogInfo(
         Message.Election_SetSourceDataSucceeded,
         SourceData.Uik,
         SourceData.ElectionDate.ToString("dd.MM.yyyy"),
         SourceData.GetVotingModeStartTime(VotingMode.Main),
         SourceData.GetVotingModeStartTime(VotingMode.Portable));
     return true;
 }
示例#7
0
 public bool LoadSourceDataFromFile( 
     SourceDataFileDescriptor sdFileDescriptor, bool needVerify, out SourceData sd)
 {
     needVerify = !QuietMode && needVerify;
     try
     {
         using (var stream = new FileStream(sdFileDescriptor.FilePath, FileMode.Open, FileAccess.Read))
         {
             var uncompressedStream = ZipCompressor.Uncompress(stream);
             sd = DeserializeSourceData(uncompressedStream);
             uncompressedStream.Close();
             if (sd.Id == Guid.Empty)
             {
                 if (_votingResultManager.PackResultsEnabled)
                     throw new SourceDataVerifierException(
                         "Исходные данные не содержат уникального идентификатора");
                 sd.Id = GenerateSourceDataId(sd);
             }
         }
         sd.Init(sdFileDescriptor.Uik);
         var verifier = new SourceDataVerifier(sd, _config.DefaultVotingModeTimes);
         Logger.LogVerbose(Message.Election_SourceDataRepairing);
         verifier.Repair();
         if (needVerify)
         {
             Logger.LogVerbose(Message.Election_SourceDataVerifying);
             verifier.Verify();
         }
     }
     catch (SourceDataVerifierException ex)
     {
         sd = null;
         Logger.LogWarning(Message.Election_SourceDataIncorrect, sdFileDescriptor.FilePath, ex.Message);
         return false;
     }
     catch (Exception ex)
     {
         sd = null;
         Logger.LogWarning(Message.Election_SourceDataLoadFromFileFailed, ex, sdFileDescriptor.FilePath);
         return false;
     }
     if (needVerify)
     {
         try
         {
             Logger.LogVerbose(Message.Election_CheckCreateModel);
             _recognitionManager.CheckCreateModel(sd);
         }
         catch (Exception ex)
         {
             sd = null;
             Logger.LogWarning(Message.Election_SourceDataIncorrect, sdFileDescriptor.FilePath, ex.Message);
             return false;
         }
     }
     Logger.LogVerbose(Message.Election_SourceDataSuccessfullyLoadedFromFile, sdFileDescriptor.FilePath);
     return true;
 }
示例#8
0
 public bool FindSourceDataFile( 
     WaitHandle stopSearchingEvent, out SourceDataFileDescriptor sdFileDescriptor)
 {
     const string SOURCE_DATA_FILE_NAME_MASK = "*-?*.bin";
     const string UIK_GROUP_SD_FILE_NAME_PATTERN = "uik";
     sdFileDescriptor = null;
     var sourceDataDirName = _config.DataDirectories.SourceDataDirName;
     var sourceDataDirNameUpper = sourceDataDirName.ToUpper();
     var sourceDataDirNames = new[]
     {
         sourceDataDirName,                                          // как в конфиге
         sourceDataDirNameUpper,                                     // БОЛЬШИМИ буквами
         sourceDataDirNameUpper[0] + sourceDataDirName.Substring(1)  // первая заглавная, остальные как в конфиге
     };
     var tryCount = 0;   // счетчик попыток
     while (true)
     {
         tryCount++;
         foreach (var sdName in sourceDataDirNames)
         {
             foreach (PathConfig item in _config.DataDirectories.RootPaths)
             {
                 try
                 {
                     foreach (var rootDataDirPath in GetDirectoriesByWildcard(item))
                     {
                         var sourceDataDirPath = Path.Combine(rootDataDirPath, sdName);
                         try
                         {
                             var sourceDataDirInfo = new DirectoryInfo(sourceDataDirPath);
                             if (!sourceDataDirInfo.Exists)
                                 continue;
                             Logger.LogInfo(Message.Election_SearchSourceDataInDir, sourceDataDirPath);
                             var files = sourceDataDirInfo.GetFiles(SOURCE_DATA_FILE_NAME_MASK);
                             foreach (var file in files)
                             {
                                 Logger.LogVerbose(Message.Election_CheckSourceDataFile, file);
                                 var regex = new SourceDataFileNameRegex();
                                 var match = regex.Match(file.Name);
                                 if (!match.Success)
                                     continue;
                                 sdFileDescriptor = new SourceDataFileDescriptor(
                                     file.FullName,
                                     file.Length,
                                     int.Parse(match.Groups[UIK_GROUP_SD_FILE_NAME_PATTERN].Value),
                                     _syncManager.LocalScannerSerialNumber);
                                 _rootDataDirPath = rootDataDirPath;
                                 return true;
                             }
                         }
                         catch (Exception ex)
                         {
                             Logger.LogWarning(
                                 Message.Election_FindSourceDataError, sourceDataDirPath, ex.Message, tryCount);
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     Logger.LogWarning(
                         Message.Election_FindSourceDataError,
                         Path.Combine(item.RootPath, item.Wildcard),
                         ex.Message,
                         tryCount);
                 }
             }
         }
         if (tryCount >= _config.SourceDataFileSearch.MaxTryCount)
             return false;
         if (stopSearchingEvent == null)
         {
             Thread.Sleep(_config.SourceDataFileSearch.Delay);
         }
         else if (stopSearchingEvent.WaitOne(_config.SourceDataFileSearch.Delay))
         {
             return false;
         }
     }
 }