コード例 #1
0
        private void SaveSmartMatchString(string matchString, Series series, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(matchString) || matchString.Length < 3)
            {
                return;
            }

            var info = _organizationService.GetSmartMatchInfos().Items.FirstOrDefault(i => string.Equals(i.ItemName, series.Name, StringComparison.OrdinalIgnoreCase));

            if (info == null)
            {
                info = new SmartMatchResult
                {
                    ItemName      = series.Name,
                    OrganizerType = CurrentFileOrganizerType,
                    DisplayName   = series.Name
                };
            }

            if (!info.MatchStrings.Contains(matchString, StringComparer.OrdinalIgnoreCase))
            {
                info.MatchStrings.Add(matchString);
                _organizationService.SaveResult(info, cancellationToken);
            }
        }
        private SmartMatchResult GetResultSmartMatch(IReadOnlyList <ResultSetValue> reader)
        {
            var index = 0;

            var result = new SmartMatchResult
            {
                Id = reader[0].ReadGuidFromBlob()
            };

            index++;
            result.ItemName = reader[index].ToString();

            index++;
            result.DisplayName = reader[index].ToString();

            index++;
            result.OrganizerType = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader[index].ToString(), true);

            index++;
            if (reader[index].SQLiteType != SQLiteType.Null)
            {
                result.MatchStrings.AddRange(JsonSerializer.Deserialize <List <string> >(reader[index].ToString(), JsonDefaults.Options));
            }

            return(result);
        }
        /// <inheritdoc/>
        public void SaveResult(SmartMatchResult result, CancellationToken cancellationToken)
        {
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            cancellationToken.ThrowIfCancellationRequested();

            using (WriteLock.Write())
            {
                using (var connection = CreateConnection())
                {
                    connection.RunInTransaction(
                        db =>
                    {
                        var commandText = "replace into SmartMatch (Id, ItemName, DisplayName, OrganizerType, MatchStrings) values (@Id, @ItemName, @DisplayName, @OrganizerType, @MatchStrings)";

                        using (var statement = db.PrepareStatement(commandText))
                        {
                            statement.TryBind("@Id", result.Id.ToGuidBlob());

                            statement.TryBind("@ItemName", result.ItemName);
                            statement.TryBind("@DisplayName", result.DisplayName);
                            statement.TryBind("@OrganizerType", result.OrganizerType.ToString());
                            statement.TryBind("@MatchStrings", JsonSerializer.Serialize(result.MatchStrings, JsonDefaults.Options));

                            statement.MoveNext();
                        }
                    },
                        TransactionMode);
                }
            }
        }
コード例 #4
0
        private SmartMatchResult GetResultSmartMatch(IResultSet reader)
        {
            var index = 0;

            var result = new SmartMatchResult
            {
                Id = reader.GetGuid(0)
            };

            index++;
            result.ItemName = reader.GetString(index);

            index++;
            result.DisplayName = reader.GetString(index);

            index++;
            result.OrganizerType = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader.GetString(index), true);

            index++;
            if (!reader.IsDBNull(index))
            {
                result.MatchStrings = _json.DeserializeFromString <List <string> >(reader.GetString(index));
            }

            return(result);
        }
コード例 #5
0
        /// <summary>
        /// Perform a one-time migration of smart match info from the plugin configuration to the SQLite database.
        /// </summary>
        /// <param name="manager">The manager to use for migrating the configuration.</param>
        /// <param name="service">The file organization service to use to save the migrated <see cref="SmartMatchResult"/> records.</param>
        public static void ConvertSmartMatchInfo(this IConfigurationManager manager, IFileOrganizationService service)
        {
            var options = manager.GetConfiguration <AutoOrganizeOptions>(AutoOrganizeOptionsKey);

            if (!options.Converted)
            {
                options.Converted = true;

#pragma warning disable CS0618 // Type or member is obsolete
                foreach (SmartMatchInfo optionsSmartMatchInfo in options.SmartMatchInfos)
#pragma warning restore CS0618 // Type or member is obsolete
                {
                    var result = new SmartMatchResult
                    {
                        DisplayName   = optionsSmartMatchInfo.DisplayName,
                        ItemName      = optionsSmartMatchInfo.ItemName,
                        OrganizerType = optionsSmartMatchInfo.OrganizerType,
                    };
                    result.MatchStrings.AddRange(optionsSmartMatchInfo.MatchStrings);
                    service.SaveResult(result, CancellationToken.None);
                }

                manager.SaveAutoOrganizeOptions(options);
            }
        }
コード例 #6
0
        public Task SaveResult(SmartMatchResult result, CancellationToken cancellationToken)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            return(_repo.SaveResult(result, cancellationToken));
        }
コード例 #7
0
        /// <inheritdoc/>
        public void SaveResult(SmartMatchResult result, CancellationToken cancellationToken)
        {
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            _repo.SaveResult(result, cancellationToken);
        }