Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchCommand"/> class.
        /// </summary>
        /// <exception cref="ArgumentNullException"><paramref name="condition"/> is not set.</exception>
        /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
        /// <param name="condition">The set of <see cref="MediaControlSearchCondition"/>.</param>
        /// <since_tizen> 5 </since_tizen>
        public SearchCommand(MediaControlSearchCondition condition)
        {
            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }

            NativeClient.CreateSearchHandle(out _searchHandle).ThrowIfError("Failed to create search handle.");

            try
            {
                if (condition.Bundle != null)
                {
                    NativeClient.SetSearchConditionBundle(_searchHandle, condition.ContentType, condition.Category,
                                                          condition.Keyword, condition.Bundle.SafeBundleHandle).
                    ThrowIfError("Failed to set search condition.");
                }
                else
                {
                    NativeClient.SetSearchCondition(_searchHandle, condition.ContentType, condition.Category,
                                                    condition.Keyword, IntPtr.Zero).
                    ThrowIfError("Failed to set search condition.");
                }
            }
            catch
            {
                if (_searchHandle != IntPtr.Zero)
                {
                    NativeClient.DestroySearchHandle(_searchHandle).ThrowIfError("Failed to destroy search handle");
                }
                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchCommand"/> class.
        /// </summary>
        /// <remarks>User can search maximum 20 items once.</remarks>
        /// <exception cref="ArgumentNullException"><paramref name="conditions"/> is not set.</exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="conditions.Count"/> is greater than maximum value(20).<br/>
        ///     -or-<br/>
        ///     <paramref name="conditions.Count"/> is less than 1.
        /// </exception>
        /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
        /// <param name="conditions">The set of <see cref="MediaControlSearchCondition"/>.</param>
        /// <since_tizen> 5 </since_tizen>
        public SearchCommand(List <MediaControlSearchCondition> conditions)
        {
            if (conditions == null)
            {
                throw new ArgumentNullException(nameof(conditions));
            }
            if (conditions.Count <= 0 || conditions.Count > 20)
            {
                var errMessage = $"Invalid number of search conditions. : {conditions.Count}. " +
                                 $"Valid range is 1 ~ 20.";
                throw new ArgumentException(errMessage);
            }

            NativeClient.CreateSearchHandle(out _searchHandle).ThrowIfError("Failed to create search handle.");

            try
            {
                foreach (var condition in conditions)
                {
                    if (condition.Bundle != null)
                    {
                        NativeClient.SetSearchConditionBundle(_searchHandle, condition.ContentType, condition.Category,
                                                              condition.Keyword, condition.Bundle.SafeBundleHandle).
                        ThrowIfError("Failed to set search condition.");
                    }
                    else
                    {
                        NativeClient.SetSearchCondition(_searchHandle, condition.ContentType, condition.Category,
                                                        condition.Keyword, IntPtr.Zero).
                        ThrowIfError("Failed to set search condition.");
                    }
                }
            }
            catch
            {
                if (_searchHandle != IntPtr.Zero)
                {
                    NativeClient.DestroySearchHandle(_searchHandle).ThrowIfError("Failed to destroy search handle");
                }
                throw;
            }
        }