Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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;
         }
     }
 }