コード例 #1
0
        private void HandleSynchronizationProgress(object progress)
        {
            try
            {
                switch (progress)
                {
                case ImportCreateIndexProgress createIndexProgress:
                    if (currentStep != Step.CREATING_INDEXES)
                    {
                        currentStep = Step.CREATING_INDEXES;
                        currentStepIndex++;
                        totalSteps++;
                        UpdateStatus(Localization.StatusCreatingIndexes);
                        Logs.AddLogItem(Localization.GetLogLineStep(currentStepIndex), Localization.LogLineCreatingIndexes);
                    }
                    CurrentLogItem.LogLines.Add(Localization.GetLogLineCreatingIndexForColumn(createIndexProgress.ColumnName));
                    break;

                case ImportLoadLibgenIdsProgress importLoadLibgenIdsProgress:
                    if (currentStep != Step.LOADING_EXISTING_IDS)
                    {
                        currentStep = Step.LOADING_EXISTING_IDS;
                        currentStepIndex++;
                        UpdateStatus(Localization.StatusLoadingIds);
                        Logs.AddLogItem(Localization.GetLogLineStep(currentStepIndex), Localization.LogLineLoadingIds);
                    }
                    CurrentLogItem.LogLines.Add(Localization.GetLogLineLoadingColumnValues("LibgenId"));
                    break;

                case SynchronizationObjectsProgress synchronizationObjectsProgress:
                    string secondLogLine = GetSynchronizedBookCountLogLine(synchronizationObjectsProgress.ObjectsDownloaded,
                                                                           synchronizationObjectsProgress.ObjectsAdded, synchronizationObjectsProgress.ObjectsUpdated);
                    if (currentStep != Step.SYNCHRONIZATION)
                    {
                        currentStep = Step.SYNCHRONIZATION;
                        currentStepIndex++;
                        Logs.AddLogItem(Localization.GetLogLineStep(currentStepIndex), Localization.LogLineSynchronizingBookList,
                                        Localization.LogLineDownloadingNewBooks);
                        CurrentLogItem.LogLines.Add(secondLogLine);
                        UpdateStatus(Localization.StatusSynchronizingData);
                    }
                    else
                    {
                        CurrentLogItem.LogLines[1] = secondLogLine;
                    }
                    break;

                case SynchronizationDiskSpaceProgress synchronizationDiskSpaceProgress:
                    string freeSpaceInBytesString = synchronizationDiskSpaceProgress.FreeSpaceInBytes.HasValue ?
                                                    languageFormatter.FileSizeToString(synchronizationDiskSpaceProgress.FreeSpaceInBytes.Value, false) : Localization.Unknown;
                    FreeSpace = Localization.GetFreeSpaceString(freeSpaceInBytesString);
                    break;
                }
            }
            catch (Exception exception)
            {
                cancellationTokenSource.Cancel();
                ShowErrorWindow(exception, CurrentWindowContext);
            }
        }
コード例 #2
0
        private void HandleImportProgress(object progress)
        {
            try
            {
                switch (progress)
                {
                case ImportSearchTableDefinitionProgress searchTableDefinitionProgress:
                    if (searchTableDefinitionProgress.TotalBytes != 0)
                    {
                        decimal scannedPercentage = Math.Round((decimal)searchTableDefinitionProgress.BytesParsed * 100 / searchTableDefinitionProgress.TotalBytes, 1);
                        if (scannedPercentage != lastScannedPercentage)
                        {
                            CurrentLogItem.LogLine = GetScannedPercentageStatusString(scannedPercentage);
                            lastScannedPercentage  = scannedPercentage;
                        }
                    }
                    break;

                case ImportTableDefinitionFoundProgress tableDefinitionFoundProgress:
                    tableType = tableDefinitionFoundProgress.TableFound;
                    switch (tableDefinitionFoundProgress.TableFound)
                    {
                    case TableType.NON_FICTION:
                        CurrentLogItem.LogLine = Localization.LogLineNonFictionTableFound;
                        break;

                    case TableType.FICTION:
                        CurrentLogItem.LogLine = Localization.LogLineFictionTableFound;
                        break;

                    case TableType.SCI_MAG:
                        CurrentLogItem.LogLine = Localization.LogLineSciMagTableFound;
                        break;
                    }
                    break;

                case ImportCreateIndexProgress createIndexProgress:
                    if (currentStep != Step.CREATING_INDEXES)
                    {
                        currentStep = Step.CREATING_INDEXES;
                        currentStepIndex++;
                        totalSteps++;
                        UpdateStatus(Localization.StatusCreatingIndexes);
                        Logs.AddLogItem(Localization.GetLogLineStep(currentStepIndex), Localization.LogLineCreatingIndexes);
                    }
                    CurrentLogItem.LogLines.Add(Localization.GetLogLineCreatingIndexForColumn(createIndexProgress.ColumnName));
                    break;

                case ImportLoadLibgenIdsProgress importLoadLibgenIdsProgress:
                    if (currentStep != Step.LOADING_EXISTING_IDS)
                    {
                        currentStep = Step.LOADING_EXISTING_IDS;
                        currentStepIndex++;
                        totalSteps++;
                        UpdateStatus(Localization.StatusLoadingIds);
                        Logs.AddLogItem(Localization.GetLogLineStep(currentStepIndex), Localization.LogLineLoadingIds);
                    }
                    CurrentLogItem.LogLines.Add(Localization.GetLogLineLoadingColumnValues("LibgenId"));
                    break;

                case ImportObjectsProgress importObjectsProgress:
                    if (currentStep != Step.IMPORTING_DATA)
                    {
                        currentStep = Step.IMPORTING_DATA;
                        currentStepIndex++;
                        UpdateStatus(Localization.StatusImportingData);
                        Logs.AddLogItem(Localization.GetLogLineStep(currentStepIndex), Localization.LogLineImportingData);
                    }
                    string logLine = GetImportedObjectCountLogLine(importObjectsProgress.ObjectsAdded, importObjectsProgress.ObjectsUpdated);
                    CurrentLogItem.LogLine = logLine;
                    break;

                case ImportDiskSpaceProgress importDiskSpaceProgress:
                    string freeSpaceInBytesString = importDiskSpaceProgress.FreeSpaceInBytes.HasValue ?
                                                    languageFormatter.FileSizeToString(importDiskSpaceProgress.FreeSpaceInBytes.Value, false) : Localization.Unknown;
                    FreeSpace = Localization.GetFreeSpaceString(freeSpaceInBytesString);
                    break;
                }
            }
            catch (Exception exception)
            {
                cancellationTokenSource.Cancel();
                ShowErrorWindow(exception, CurrentWindowContext);
            }
        }