コード例 #1
0
        public static void InitializeOrUpdateDatabase(string databasePath,
                                                      InitializationStep steps,
                                                      CancellationToken cancellationToken,
                                                      IDbInitProgressHandler progressHandler)
        {
            using (var conn = new SQLiteConnection($"Data Source={databasePath}"))
            {
                conn.Open();

                int totalSteps = 0;

                foreach (InitializationStep step in Enum.GetValues(typeof(InitializationStep)))
                {
                    if (step != InitializationStep.All && steps.HasFlag(step))
                    {
                        totalSteps++;
                    }
                }

                progressHandler?.OnInitImportTask(totalSteps);

                if (steps.HasFlag(InitializationStep.LddPartsAndElements))
                {
                    var lddImporter = new LddDataImporter(conn, LDDEnvironment.Current, cancellationToken);
                    lddImporter.ProgressHandler = progressHandler;
                    lddImporter.ImportAllData();
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                if (steps.HasFlag(InitializationStep.RebrickableBaseData) ||
                    steps.HasFlag(InitializationStep.RebrickablePartsAndRelationships) ||
                    steps.HasFlag(InitializationStep.RebrickableSets) ||
                    steps.HasFlag(InitializationStep.RebrickableSetParts))
                {
                    var rbImporter = new RebrickableDataImporter(conn, LDDEnvironment.Current, cancellationToken);
                    rbImporter.ProgressHandler       = progressHandler;
                    rbImporter.InventoriesCsvFile    = @"C:\Users\JWTurner\Downloads\inventories.csv";
                    rbImporter.InventoryPartsCsvFile = @"C:\Users\JWTurner\Downloads\inventory_parts.csv";

                    if (steps.HasFlag(InitializationStep.RebrickableBaseData))
                    {
                        rbImporter.ImportBaseData();
                    }

                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (steps.HasFlag(InitializationStep.RebrickablePartsAndRelationships))
                    {
                        rbImporter.ImportPartsAndRelationships();
                    }

                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (steps.HasFlag(InitializationStep.RebrickableSets))
                    {
                        rbImporter.ImportSets();
                    }

                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (steps.HasFlag(InitializationStep.RebrickableSetParts))
                    {
                        rbImporter.ImportSetParts();
                    }
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                if (steps.HasFlag(InitializationStep.RebrickableLddMappings))
                {
                    InitializeDefaultMappings(databasePath, progressHandler);
                }
            }
        }
コード例 #2
0
        public static void InitializeOrUpdateDatabase(string databasePath,
                                                      InitializationStep steps,
                                                      CancellationToken cancellationToken,
                                                      IDbInitProgressHandler progressHandler)
        {
            using (var conn = new SQLiteConnection($"Data Source={databasePath}"))
            {
                conn.Open();

                int totalSteps = 0;

                foreach (InitializationStep step in Enum.GetValues(typeof(InitializationStep)))
                {
                    if (step == InitializationStep.All ||
                        step == InitializationStep.RebrickableData ||
                        step == InitializationStep.RebrickablePartsAndRelationships)
                    {
                        continue;
                    }

                    if (steps.HasFlag(step))
                    {
                        totalSteps++;
                    }
                }

                progressHandler?.OnInitImportTask(totalSteps);

                if (steps.HasFlag(InitializationStep.LddPartsAndElements))
                {
                    var lddImporter = new LddDataImporter(conn, LDDEnvironment.Current, cancellationToken);
                    lddImporter.ProgressHandler = progressHandler;
                    lddImporter.ImportAllData();
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                if (steps.HasFlag(InitializationStep.RebrickableBaseData) ||
                    steps.HasFlag(InitializationStep.RebrickableParts) ||
                    steps.HasFlag(InitializationStep.RebrickablePartsAndRelationships) ||
                    steps.HasFlag(InitializationStep.RebrickableSets) ||
                    steps.HasFlag(InitializationStep.RebrickableSetParts))
                {
                    var rbImporter = new RebrickableDataImporter(conn, LDDEnvironment.Current, cancellationToken);
                    rbImporter.ProgressHandler   = progressHandler;
                    rbImporter.DownloadDirectory = Path.Combine(Settings.SettingsManager.AppDataFolder, "Downloads");

                    if (steps.HasFlag(InitializationStep.RebrickableBaseData))
                    {
                        rbImporter.ImportBaseData();
                    }

                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (steps.HasFlag(InitializationStep.RebrickableParts))
                    {
                        rbImporter.ImportRebrickableParts();
                    }

                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (steps.HasFlag(InitializationStep.RebrickablePartRelationships))
                    {
                        rbImporter.ImportRebrickableRelationships();
                    }

                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (steps.HasFlag(InitializationStep.RebrickableSets))
                    {
                        rbImporter.ImportSets();
                    }

                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (steps.HasFlag(InitializationStep.RebrickableSetParts))
                    {
                        rbImporter.ImportSetParts();
                    }
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                if (steps.HasFlag(InitializationStep.RebrickableLddMappings))
                {
                    InitializeDefaultMappings(databasePath, progressHandler);
                }
            }
        }