Пример #1
0
        /// <summary>
        ///     Saves the <paramref name="scanOptions"/> for the given <paramref name="scanner"/>.
        /// </summary>
        public void SavePersistentScanOptionsForScanner(DiscoveredScanner scanner, PersistentScanOptions scanOptions)
        {
            try
            {
                string id;
                if (scanner.Debug)
                {
                    id = "DEBUG";
                }
                else
                {
                    id = scanner.Id;
                }

                // prepare command
                Connection.Open();
                SqliteCommand upsertCommand = new SqliteCommand
                                                  ($"INSERT INTO {TableName.ToUpper()} VALUES" +
                                                  $"(\"{id}\", {scanOptions.FlatbedBrightness != null}, {scanOptions.FlatbedBrightness ?? 0}, {scanOptions.FlatbedContrast != null}, " +
                                                  $"{scanOptions.FlatbedContrast ?? 0}, {scanOptions.FeederBrightness != null}, {scanOptions.FeederBrightness ?? 0}, " +
                                                  $"{scanOptions.FeederContrast != null}, {scanOptions.FeederContrast ?? 0}) " +
                                                  $"ON CONFLICT(id) DO UPDATE SET flatbed_brightness_set={scanOptions.FlatbedBrightness != null}, " +
                                                  $"flatbed_brightness={scanOptions.FlatbedBrightness ?? 0}, " +
                                                  $"flatbed_contrast_set={scanOptions.FlatbedContrast != null}, " +
                                                  $"flatbed_contrast={scanOptions.FlatbedContrast ?? 0}, " +
                                                  $"feeder_brightness_set={scanOptions.FeederBrightness != null}, " +
                                                  $"feeder_brightness={scanOptions.FeederBrightness ?? 0}, " +
                                                  $"feeder_contrast_set={scanOptions.FeederContrast != null}, " +
                                                  $"feeder_contrast={scanOptions.FeederContrast ?? 0}", Connection);

                // execute
                upsertCommand.ExecuteReader();

                Connection.Close();

                LogService?.Log.Information("SaveScanOptionsForScanner: Saved scan options");
            }
            catch (Exception exc)
            {
                AppCenterService?.TrackError(exc);
                LogService.Log.Error(exc, "Saving persistent scan options for scanner failed.");
            }
        }
Пример #2
0
        /// <summary>
        ///     Gets <see cref="PersistentScanOptions"/> for the given <paramref name="scanner"/>.
        /// </summary>
        public PersistentScanOptions GetPersistentScanOptionsForScanner(DiscoveredScanner scanner)
        {
            try
            {
                string id;
                if (scanner.Debug)
                {
                    id = "DEBUG";
                }
                else
                {
                    id = scanner.Id;
                }

                Connection.Open();
                SqliteCommand selectCommand = new SqliteCommand
                                                  ($"SELECT * FROM {TableName.ToUpper()} WHERE ID = \"{id}\"", Connection);
                SqliteDataReader query = selectCommand.ExecuteReader();

                // check if data for this scanner even exists
                if (!query.HasRows)
                {
                    return(null);
                }

                // load data
                PersistentScanOptions result = new PersistentScanOptions();
                while (query.Read())
                {
                    if (Convert.ToBoolean(int.Parse(query.GetString(1))))
                    {
                        result.FlatbedBrightness = int.Parse(query.GetString(2));
                    }

                    if (Convert.ToBoolean(int.Parse(query.GetString(3))))
                    {
                        result.FlatbedContrast = int.Parse(query.GetString(4));
                    }

                    if (Convert.ToBoolean(int.Parse(query.GetString(5))))
                    {
                        result.FeederBrightness = int.Parse(query.GetString(6));
                    }

                    if (Convert.ToBoolean(int.Parse(query.GetString(7))))
                    {
                        result.FeederContrast = int.Parse(query.GetString(8));
                    }
                }

                Connection.Close();

                LogService?.Log.Information($"GetPersistentScanOptionsForScanner: Returning scan options for {scanner.Name}");
                return(result);
            }
            catch (Exception exc)
            {
                AppCenterService?.TrackError(exc);
                LogService.Log.Error(exc, $"Getting persistent scan options for {scanner.Name} failed.");
                return(null);
            }
        }