Esempio n. 1
0
        private void Worker_DoWorkDelete(object sender, DoWorkEventArgs e)
        {
            int index          = 0;
            int countDeleted   = 0;
            int countUnDeleted = 0;

            try {
                foreach (var item in SelectedItems)
                {
                    if (_workerDeleteRecords.CancellationPending)
                    {
                        e.Cancel = true;
                        break;
                    }
                    index++;
                    T rec = item as T;
                    try {
                        _workerDeleteRecords.ReportProgress(0, $"{index} / {SelectedItems.Count} \n{rec.Name}");
                        int deleted = _db.Database.ExecuteSqlCommand("DELETE FROM " + TableName + " WHERE Id = " + rec.Id);
                        countDeleted++;
                    } catch (Exception eDel) {
                        _workerDeleteRecords.ReportProgress(0, $"{index} / {SelectedItems.Count} \n{rec.Name} \n{ErrorProcessing.GetExeptionContent(eDel.GetBaseException())}");
                        countUnDeleted++;
                    }
                }
            } catch (Exception eWorkerDelete) {
                _workerDeleteRecords.ReportProgress(-1, ErrorProcessing.GetExeptionContent(eWorkerDelete));
            } finally {
                _workerDeleteRecords.ReportProgress(0, $"Успешно удалено: {countDeleted}" +
                                                    $"\nНе удалено: {countUnDeleted}");
            }
        }
Esempio n. 2
0
 private void Worker_DoWorkSync(object sender, DoWorkEventArgs e)
 {
     try {
         Stack <DirectoryInfo> stackDir = new Stack <DirectoryInfo>();
         DirectoryInfo         dir      = new DirectoryInfo(_folder);
         int    idPath;
         string nameFile = string.Empty;
         if (dir.Exists)
         {
             // Фиксируем выбранную папку
             if (_originalOperation == DML.Insert)
             {
                 _workerSyncFolder.ReportProgress(0, _folder);
                 _insert.Invoke(_folder);
             }
             else if (_originalOperation == DML.Update)
             {
                 _update.Invoke(_folder);
                 _workerSyncFolder.ReportProgress(0, _folder);
             }
             stackDir.Push(dir);
             while (stackDir.Count > 0)
             {
                 if (_workerSyncFolder.CancellationPending)
                 {
                     e.Cancel = true;
                     return;
                 }
                 dir = stackDir.Pop();
                 _workerSyncFolder.ReportProgress(0, dir.FullName);
                 // Формируем список вложенных папок
                 foreach (var item in dir.EnumerateDirectories())
                 {
                     stackDir.Push(item);
                 }
                 idPath = ModelUtilities.Instance.GetId <RefPathway>(dir.FullName);
                 if (idPath == 0)
                 {
                     if (IsContainsFiles(dir))
                     {
                         _insert.Invoke(dir.FullName);
                         idPath = ModelUtilities.Instance.GetId <RefPathway>(dir.FullName);
                         if (idPath == 0)
                         {
                             throw new InvalidOperationException(dir.FullName);
                         }
                         _countAddFolders++;
                     }
                     else
                     {
                         _countEmptyFolders++;
                         continue;
                     }
                 }
                 // Синхронизация файлов
                 // Проверка наличия зарегистрированных файлов
                 CheckFolderRegisteredFiles(dir, idPath);
                 // Регистрация новых файлов
                 foreach (var pattern in ListSearchPatternContentFiles)
                 {
                     foreach (var fileInfo in dir.EnumerateFiles(pattern.Pattern))
                     {
                         if (pattern.Kind == KindFile.Image)
                         {
                             if (!ExistsUrlContentImage(Path.GetFileNameWithoutExtension(fileInfo.Name), idPath, pattern.Id))
                             {
                                 UrlContent content = new UrlContent()
                                 {
                                     Name      = Path.GetFileNameWithoutExtension(fileInfo.Name),
                                     Pathway   = idPath,
                                     ImageType = pattern.Id
                                 };
                                 Settings.Instance.ContentDB.UrlContents.Add(content);
                                 Settings.Instance.ContentDB.SaveChanges();
                                 _workerSyncFolder.ReportProgress(0, fileInfo.FullName);
                                 _countAddFiles++;
                             }
                         }
                         else if (pattern.Kind == KindFile.Video)
                         {
                             if (!ExistsUrlContentVideo(Path.GetFileNameWithoutExtension(fileInfo.Name), idPath, pattern.Id))
                             {
                                 UrlContent content = new UrlContent()
                                 {
                                     Name      = Path.GetFileNameWithoutExtension(fileInfo.Name),
                                     Pathway   = idPath,
                                     VideoType = pattern.Id
                                 };
                                 Settings.Instance.ContentDB.UrlContents.Add(content);
                                 Settings.Instance.ContentDB.SaveChanges();
                                 _workerSyncFolder.ReportProgress(0, fileInfo.FullName);
                                 _countAddFiles++;
                             }
                         }
                     }
                 }
                 if (_workerSyncFolder.CancellationPending)
                 {
                     e.Cancel = true;
                     return;
                 }
             }
             if (_originalOperation == DML.Insert || _originalOperation == DML.Update || _originalOperation == DML.Synchronization)
             {
                 _workerSyncFolder.ReportProgress(0, $"{Settings.Instance.LocalisationHelper["ContentFoldersRes.ReportSyncFoldersAddFolders"]}: {_countAddFolders}" +
                                                  $"\n{Settings.Instance.LocalisationHelper["ContentFoldersRes.ReportSyncFoldersEmptyFolders"]}: {_countEmptyFolders}" +
                                                  $"\n{Settings.Instance.LocalisationHelper["ContentFoldersRes.ReportSyncFoldersAddFiles"]}: {_countAddFiles}" +
                                                  $"\n{Settings.Instance.LocalisationHelper["ContentFoldersRes.ReportSyncFoldersCheckFiles"]}: {_countCheckFiles}" +
                                                  $"\n{Settings.Instance.LocalisationHelper["ContentFoldersRes.ReportSyncFoldersDelRegisteresFiles"]}: {_countDelRegisteresFiles}");
             }
         }
         else
         {
             _workerSyncFolder.ReportProgress(-1, Settings.Instance.LocalisationHelper["ContentFoldersRes.MsgDirectoryNotFound"]);
         }
     } catch (Exception eWorker) {
         _workerSyncFolder.ReportProgress(-1, ErrorProcessing.GetExeptionContent(eWorker));
     }
 }