示例#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 Initialize()
 {
     isInProgress     = true;
     currentStep      = Step.SEARCHING_TABLE_DEFINITION;
     currentStepIndex = 1;
     totalSteps       = 2;
     UpdateStatus(Localization.StatusDataLookup);
     startDateTime   = DateTime.Now;
     lastElapsedTime = TimeSpan.Zero;
     elapsedTimer.Change(TimeSpan.Zero, TimeSpan.FromMilliseconds(100));
     elapsed               = GetElapsedString(lastElapsedTime);
     cancelButtonText      = Localization.Interrupt;
     isCancelButtonVisible = true;
     isCancelButtonEnabled = true;
     isCloseButtonVisible  = false;
     lastScannedPercentage = 0;
     Logs.AddLogItem(Localization.GetLogLineStep(currentStepIndex), Localization.LogLineDataLookup, Localization.LogLineScanning);
     Import();
 }
示例#3
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;
                }
            }
            catch (Exception exception)
            {
                cancellationTokenSource.Cancel();
                ShowErrorWindow(exception, CurrentWindowContext);
            }
        }
        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++;
                        Status = ImportStatus.CREATING_INDEXES;
                        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++;
                        Status = ImportStatus.LOADING_IDS;
                        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++;
                        Status = ImportStatus.IMPORTING_DATA;
                        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;

                case ImportWrongTableDefinitionProgress importWrongTableDefinitionProgress:
                    string expected;
                    switch (importWrongTableDefinitionProgress.ExpectedTableType)
                    {
                    case TableType.NON_FICTION:
                        expected = Localization.LogLineExpectedNonFictionTable;
                        break;

                    case TableType.FICTION:
                        expected = Localization.LogLineExpectedFictionTable;
                        break;

                    case TableType.SCI_MAG:
                        expected = Localization.LogLineExpectedSciMagTable;
                        break;

                    case TableType.UNKNOWN:
                    default:
                        throw new Exception($"Unexpected table type: {importWrongTableDefinitionProgress.ExpectedTableType}.");
                    }
                    string found;
                    switch (importWrongTableDefinitionProgress.ActualTableType)
                    {
                    case TableType.NON_FICTION:
                        found = Localization.LogLineFoundNonFictionTable;
                        break;

                    case TableType.FICTION:
                        found = Localization.LogLineFoundFictionTable;
                        break;

                    case TableType.SCI_MAG:
                        found = Localization.LogLineFoundSciMagTable;
                        break;

                    case TableType.UNKNOWN:
                    default:
                        throw new Exception($"Unexpected table type: {importWrongTableDefinitionProgress.ActualTableType}.");
                    }
                    CurrentLogItem.LogLine = Localization.GetLogLineWrongTableFound(expected, found);
                    break;
                }
            }
            catch (Exception exception)
            {
                cancellationTokenSource.Cancel();
                ShowErrorWindow(exception, CurrentWindowContext);
            }
        }