<commit_before>﻿/* ------------------------------------------------------------------------- */
//
// Copyright (c) 2010 CubeSoft, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
/* ------------------------------------------------------------------------- */
using System;
using System.Threading;

namespace Cube
{
    #region Query(T)

    /* --------------------------------------------------------------------- */
    ///
    /// IQuery(T)
    ///
    /// <summary>
    /// 問い合わせ用プロバイダーを定義します。
    /// </summary>
    ///
    /* --------------------------------------------------------------------- */
    public interface IQuery<T>
    {
        /* ----------------------------------------------------------------- */
        ///
        /// Request
        ///
        /// <summary>
        /// 問い合わせを実行します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        void Request(QueryEventArgs<T> value);
    }

    /* --------------------------------------------------------------------- */
    ///
    /// Query(T)
    ///
    /// <summary>
    /// IQuery(T) を実装したクラスです。
    /// </summary>
    ///
    /* --------------------------------------------------------------------- */
    public class Query<T> : IQuery<T>
    {
        #region Constructors

        /* ----------------------------------------------------------------- */
        ///
        /// Query
        ///
        /// <summary>
        /// オブジェクトを初期化します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public Query()
        {
            _context = SynchronizationContext.Current;
        }

        /* ----------------------------------------------------------------- */
        ///
        /// Query
        ///
        /// <summary>
        /// オブジェクトを初期化します。
        /// </summary>
        ///
        /// <param name="callback">コールバック関数</param>
        ///
        /* ----------------------------------------------------------------- */
        public Query(Action<QueryEventArgs<T>> callback) : this()
        {
            Requested += (s, e) => callback(e);
        }

        #endregion

        #region Events

        /* ----------------------------------------------------------------- */
        ///
        /// Requested
        ///
        /// <summary>
        /// 問い合わせ時に発生するイベントです。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public event QueryEventHandler<T> Requested;

        /* ----------------------------------------------------------------- */
        ///
        /// OnRequested
        ///
        /// <summary>
        /// Requested イベントを発生させます。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public virtual void OnRequested(QueryEventArgs<T> e)
        {
            if (Requested != null)
            {
                if (_context != null) _context.Send(_ => Requested(this, e), null);
                else Requested(this, e);
            }
            else e.Cancel = true;
        }

        #endregion

        #region Methods

        /* ----------------------------------------------------------------- */
        ///
        /// Request
        ///
        /// <summary>
        /// 問い合わせを実行します。
        /// </summary>
        ///
        /// <remarks>
        /// 問い合わせの結果が無効な場合、Cancel プロパティが true に
        /// 設定されます。
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        public void Request(QueryEventArgs<T> value) => OnRequested(value);

        #endregion

        #region Fields
        private readonly SynchronizationContext _context;
        #endregion
    }

    #endregion

    #region Query(T, U)

    /* --------------------------------------------------------------------- */
    ///
    /// IQuery(T, U)
    ///
    /// <summary>
    /// 問い合わせ用プロバイダーを定義します。
    /// </summary>
    ///
    /// <remarks>
    /// Query と Result の型が同じ場合 IQuery(T, U) の代わりに IQuery(T) を
    /// 実装する事を検討下さい。
    /// </remarks>
    ///
    /* --------------------------------------------------------------------- */
    public interface IQuery<T, U>
    {
        /* ----------------------------------------------------------------- */
        ///
        /// Request
        ///
        /// <summary>
        /// 問い合わせを実行します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        void Request(QueryEventArgs<T, U> value);
    }

    /* --------------------------------------------------------------------- */
    ///
    /// Query(T, U)
    ///
    /// <summary>
    /// IQuery(T, U) を実装したクラスです。
    /// </summary>
    ///
    /* --------------------------------------------------------------------- */
    public class Query<T, U> : IQuery<T, U>
    {
        #region Constructors

        /* ----------------------------------------------------------------- */
        ///
        /// Query
        ///
        /// <summary>
        /// オブジェクトを初期化します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public Query()
        {
            _context = SynchronizationContext.Current;
        }

        /* ----------------------------------------------------------------- */
        ///
        /// Query
        ///
        /// <summary>
        /// オブジェクトを初期化します。
        /// </summary>
        ///
        /// <param name="callback">コールバック関数</param>
        ///
        /* ----------------------------------------------------------------- */
        public Query(Action<QueryEventArgs<T, U>> callback) : this()
        {
            Requested += (s, e) => callback(e);
        }

        #endregion

        #region Events

        /* ----------------------------------------------------------------- */
        ///
        /// Requested
        ///
        /// <summary>
        /// 問い合わせ時に発生するイベントです。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public event QueryEventHandler<T, U> Requested;

        /* ----------------------------------------------------------------- */
        ///
        /// OnRequested
        ///
        /// <summary>
        /// Requested イベントを発生させます。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public virtual void OnRequested(QueryEventArgs<T, U> e)
        {
            if (Requested != null)
            {
                if (_context != null) _context.Send(_ => Requested(this, e), null);
                else Requested(this, e);
            }
            else e.Cancel = true;
        }

        #endregion

        #region Methods

        /* ----------------------------------------------------------------- */
        ///
        /// Request
        ///
        /// <summary>
        /// 問い合わせを実行します。<commit_msg>Fix comments.<commit_after>﻿/* ------------------------------------------------------------------------- */
//
// Copyright (c) 2010 CubeSoft, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
/* ------------------------------------------------------------------------- */
using System;
using System.Threading;

namespace Cube
{
    #region Query(T)

    /* --------------------------------------------------------------------- */
    ///
    /// IQuery(T)
    ///
    /// <summary>
    /// Represents the query provider.
    /// </summary>
    ///
    /* --------------------------------------------------------------------- */
    public interface IQuery<T>
    {
        /* ----------------------------------------------------------------- */
        ///
        /// Request
        ///
        /// <summary>
        /// Invokes the request with the specified arguments.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        void Request(QueryEventArgs<T> value);
    }

    /* --------------------------------------------------------------------- */
    ///
    /// Query(T)
    ///
    /// <summary>
    /// Represents the IQuery(T) implementation.
    /// </summary>
    ///
    /* --------------------------------------------------------------------- */
    public class Query<T> : IQuery<T>
    {
        #region Constructors

        /* ----------------------------------------------------------------- */
        ///
        /// Query
        ///
        /// <summary>
        /// Initializes a new instance of the Query class.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public Query()
        {
            _context = SynchronizationContext.Current;
        }

        /* ----------------------------------------------------------------- */
        ///
        /// Query
        ///
        /// <summary>
        /// Initializes a new instance of the Query class with the
        /// specified callback.
        /// </summary>
        ///
        /// <param name="callback">Callback function.</param>
        ///
        /* ----------------------------------------------------------------- */
        public Query(Action<QueryEventArgs<T>> callback) : this()
        {
            Requested += (s, e) => callback(e);
        }

        #endregion

        #region Events

        /* ----------------------------------------------------------------- */
        ///
        /// Requested
        ///
        /// <summary>
        /// Occurs when the user request is received.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public event QueryEventHandler<T> Requested;

        /* ----------------------------------------------------------------- */
        ///
        /// OnRequested
        ///
        /// <summary>
        /// Raises the Requested event.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public virtual void OnRequested(QueryEventArgs<T> e)
        {
            if (Requested != null)
            {
                if (_context != null) _context.Send(_ => Requested(this, e), null);
                else Requested(this, e);
            }
            else e.Cancel = true;
        }

        #endregion

        #region Methods

        /* ----------------------------------------------------------------- */
        ///
        /// Request
        ///
        /// <summary>
        /// Invokes the request with the specified arguments.
        /// </summary>
        ///
        /// <remarks>
        /// 問い合わせの結果が無効な場合、Cancel プロパティが true に
        /// 設定されます。
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        public void Request(QueryEventArgs<T> value) => OnRequested(value);

        #endregion

        #region Fields
        private readonly SynchronizationContext _context;
        #endregion
    }

    #endregion

    #region Query(T, U)

    /* --------------------------------------------------------------------- */
    ///
    /// IQuery(T, U)
    ///
    /// <summary>
    /// Represents the query provider.
    /// </summary>
    ///
    /// <remarks>
    /// Query と Result の型が同じ場合 IQuery(T, U) の代わりに IQuery(T) を
    /// 実装する事を検討して下さい。
    /// </remarks>
    ///
    /* --------------------------------------------------------------------- */
    public interface IQuery<T, U>
    {
        /* ----------------------------------------------------------------- */
        ///
        /// Request
        ///
        /// <summary>
        /// Invokes the request with the specified arguments.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        void Request(QueryEventArgs<T, U> value);
    }

    /* --------------------------------------------------------------------- */
    ///
    /// Query(T, U)
    ///
    /// <summary>
    /// Represents the IQuery(T, U) implementation.
    /// </summary>
    ///
    /* --------------------------------------------------------------------- */
    public class Query<T, U> : IQuery<T, U>
    {
        #region Constructors

        /* ----------------------------------------------------------------- */
        ///
        /// Query
        ///
        /// <summary>
        /// Initializes a new instance of the Query class.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public Query()
        {
            _context = SynchronizationContext.Current;
        }

        /* ----------------------------------------------------------------- */
        ///
        /// Query
        ///
        /// <summary>
        /// Initializes a new instance of the Query class with the
        /// specified callback.
        /// </summary>
        ///
        /// <param name="callback">Callback function.</param>
        ///
        /* ----------------------------------------------------------------- */
        public Query(Action<QueryEventArgs<T, U>> callback) : this()
        {
            Requested += (s, e) => callback(e);
        }

        #endregion

        #region Events

        /* ----------------------------------------------------------------- */
        ///
        /// Requested
        ///
        /// <summary>
        /// Occurs when the user request is received.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public event QueryEventHandler<T, U> Requested;

        /* ----------------------------------------------------------------- */
        ///
        /// OnRequested
        ///
        /// <summary>
        /// Raises the Requested event.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public virtual void OnRequested(QueryEventArgs<T, U> e)
        {
            if (Requested != null)
            {
                if (_context != null) _context.Send(_ => Requested(this, e), null);
                else Requested(this, e);
            }
            else e.Cancel = true;
        }

        #endregion

        #region Methods

        /* ----------------------------------------------------------------- */
        ///
        /// Request
        ///
        /// <summary>
        /// Invokes the request with the specified arguments.
{'fraction_non_alphanumeric': 0.39377614399797184, 'fraction_numerical': 0.0010140702243630372, 'mean_word_length': 0.5689569454111564, 'pattern_counts': {'":': 0, '<': 115, '<?xml version=': 0, '>': 125, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1277902', 'n_tokens_mistral': 3464, 'n_tokens_neox': 3390, 'n_words': 726}