Beispiel #1
0
        public bool Request_Count(int id, IList <string> seq, SynchronizationContext ctx)
        {
            SynchronizationContext.SetSynchronizationContext(ctx);

            var query = new Query <int>(e =>
            {
                if (e.Result >= seq.Count)
                {
                    e.Cancel = true;
                    e.Result = -1;
                }
                else if (seq[e.Result] == "success")
                {
                    e.Cancel = true;
                }
                else
                {
                    e.Result++;
                }
            });

            var args = QueryEventArgs.Create(id);

            Assert.That(args.Query, Is.EqualTo(id));
            Assert.That(args.Result, Is.EqualTo(0));
            Assert.That(args.Cancel, Is.False);

            while (!args.Cancel)
            {
                query.Request(args);
            }
            return(args.Result != -1);
        }
Beispiel #2
0
        public void Invoke(string obj)
        {
            var src  = new QueryValue <string>(obj);
            var dest = QueryEventArgs.Create("OnceQuery(T)");

            src.Request(dest);

            Assert.That(src.Value, Is.EqualTo(obj));
            Assert.That(dest.Result, Is.EqualTo(obj));
            Assert.That(dest.Cancel, Is.False);
        }
Beispiel #3
0
        public void Create_QueryEventArgsSame(string query)
        {
            var args = QueryEventArgs.Create(query);

            Assert.That(args.Query, Is.EqualTo(query));
            Assert.That(args.Result, Is.Null);
            Assert.That(args.Cancel, Is.False);

            args.Result = nameof(Create_QueryEventArgsSame);
            Assert.That(args.Result, Is.EqualTo(nameof(Create_QueryEventArgsSame)));
        }
Beispiel #4
0
        public void Request_Count_None()
        {
            var query = new Query <int>();
            var args  = QueryEventArgs.Create(100);

            Assert.That(args.Query, Is.EqualTo(100));
            Assert.That(args.Result, Is.EqualTo(0));
            Assert.That(args.Cancel, Is.False);

            query.Request(args);

            Assert.That(args.Cancel, Is.True);
            Assert.That(args.Result, Is.EqualTo(0));
        }
        /* ----------------------------------------------------------------- */
        ///
        /// CryptoGetTextPassword
        ///
        /// <summary>
        /// 圧縮ファイルのパスワードを取得します。
        /// </summary>
        ///
        /// <param name="password">パスワード</param>
        ///
        /// <returns>OperationResult</returns>
        ///
        /* ----------------------------------------------------------------- */
        public int CryptoGetTextPassword(out string password)
        {
            Debug.Assert(Password != null);

            var e = QueryEventArgs.Create(Source);

            Password.Request(e);

            var ok = !e.Cancel && e.Result.HasValue();

            Result = e.Cancel ? OperationResult.UserCancel :
                     ok       ? OperationResult.OK :
                     OperationResult.WrongPassword;
            password = ok ? e.Result : string.Empty;

            return((int)Result);
        }
        /* ----------------------------------------------------------------- */
        ///
        /// RequestPassword
        ///
        /// <summary>
        /// Requests the password for the specified PDF file.
        /// </summary>
        ///
        /// <param name="query">Query object.</param>
        /// <param name="src">Path of the PDF file.</param>
        ///
        /// <returns>Query result.</returns>
        ///
        /// <remarks>
        /// 問い合わせ失敗時の挙動を EncryptionException を送出する形に
        /// 統一します。また、実行後に Result が空文字だった場合も失敗と
        /// 見なします。
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        public static QueryEventArgs <string> RequestPassword(this IQuery <string> query, string src)
        {
            var dest = QueryEventArgs.Create(src);

            try
            {
                query.Request(dest);
                if (dest.Cancel || dest.Result.HasValue())
                {
                    return(dest);
                }
                else
                {
                    throw new ArgumentException("Password is empty.");
                }
            }
            catch (Exception err) { throw Convert(err); }
        }
        /* ----------------------------------------------------------------- */
        ///
        /// CryptoGetTextPassword2
        ///
        /// <summary>
        /// 圧縮ファイルに設定するパスワードを取得します。
        /// </summary>
        ///
        /// <param name="enabled">パスワードが有効かどうかを示す値</param>
        /// <param name="password">パスワード</param>
        ///
        /// <returns>OperationResult</returns>
        ///
        /* ----------------------------------------------------------------- */
        public int CryptoGetTextPassword2(ref int enabled, out string password)
        {
            if (Password != null)
            {
                var e = QueryEventArgs.Create(Destination);
                Password.Request(e);

                var ok = !e.Cancel && e.Result.HasValue();

                Result   = ok ? OperationResult.OK : OperationResult.UserCancel;
                enabled  = ok ? 1 : 0;
                password = ok ? e.Result : string.Empty;
            }
            else
            {
                Result   = OperationResult.OK;
                enabled  = 0;
                password = string.Empty;
            }

            return((int)Result);
        }