示例#1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (_query != null)
                    {
                        _query.OnTerminate   -= OnTerminate;
                        _query.OnOtherAck    -= OnOtherAck;
                        _query.OnAdviseData  -= OnAdviseData;
                        _query.OnExecute     -= OnExecute;
                        _query.OnExecuteAck  -= OnExecuteAck;
                        _query.OnRequestData -= OnRequestData;
                        _query.Dispose();
                        _query = null;
                    }

                    if (_app != null)
                    {
                        _app.Dispose();
                        _app = null;
                    }
                }

                disposedValue = true;
            }
        }
        protected override void Given()
        {
            instance = MockRepository.GenerateStub<TestInterface>();

            instance.Expect(
                x => x.BeginMethod(
                        Arg<string>.Is.Anything,
                        Arg<AsyncCallback>.Is.Anything,
                        Arg<object>.Is.Anything))
                    .Return(null)
                    .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(null));

            instance.Expect(x => x.EndMethod(null))
                    .Throw(exception);

            instance.Expect(
                x => x.BeginFunction(
                        Arg<string>.Is.Anything,
                        Arg<AsyncCallback>.Is.Anything,
                        Arg<object>.Is.Anything))
                    .Return(null)
                    .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(null));

            instance.Expect(x => x.EndFunction(null))
                    .Throw(exception);

            command = new AsyncCommand(() => instance.Method(null), true);
            query = new AsyncQuery<string>(() => instance.Function(null), true);
        }
        protected override void Given()
        {
            instance = MockRepository.GenerateStrictMock<TestInterface>();
            ar = MockRepository.GenerateStub<IAsyncResult>();

            instance.Expect(
                x => x.BeginMethod(
                        Arg<string>.Is.Equal(parameter),
                        Arg<AsyncCallback>.Is.NotNull,
                        Arg<object>.Is.Null))
                    .Return(null)
                    .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(ar));

            instance.Expect(x => x.EndMethod(ar));

            instance.Expect(
                x => x.BeginFunction(
                        Arg<string>.Is.Equal(parameter),
                        Arg<AsyncCallback>.Is.NotNull,
                        Arg<object>.Is.Null))
                    .Return(null)
                    .WhenCalled(x => ((AsyncCallback)x.Arguments[1])(ar));

            instance.Expect(x => x.EndFunction(ar)).Return(result);

            command = new AsyncCommand(() => instance.Method(parameter), true);
            query = new AsyncQuery<string>(() => instance.Function(parameter), true);
        }
示例#4
0
        public Task <MediaFile> SaveThumbnailAsync(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            string lookupColumn = (IsAggregate)
                                                                        ? ContactsContract.ContactsColumns.LookupKey
                                                                        : ContactsContract.RawContactsColumns.ContactId;

            AsyncQuery <byte[]> query = new AsyncQuery <byte[]> (this.content, c => c.GetBlob(c.GetColumnIndex(ContactsContract.CommonDataKinds.Photo.PhotoColumnId)));

            query.StartQuery(0, null, ContactsContract.Data.ContentUri, new[] { ContactsContract.CommonDataKinds.Photo.PhotoColumnId, ContactsContract.DataColumns.Mimetype },
                             lookupColumn + "=? AND " + ContactsContract.DataColumns.Mimetype + "=?", new[] { Id, ContactsContract.CommonDataKinds.Photo.ContentItemType }, null);

            return(query.Task.ContinueWith(t =>
            {
                if (t.Result == null)
                {
                    return null;
                }

                File.WriteAllBytes(path, t.Result);
                return new MediaFile(path, deletePathOnDispose: false);
            }, TaskScheduler.Default));
        }
示例#5
0
        public async Task <TResult> DispatchAsync <TResult>(AsyncQuery <TResult> query)
        {
            var handlerType = typeof(IAsyncQueryHandler <,>).MakeGenericType(query.GetType(), typeof(TResult));

            var handler = (IAsyncQueryHandler <TResult>)_serviceProvider.GetService(handlerType);

            return(await handler.HandleAsync(query));
        }
        public async Task AsyncQueryTest()
        {
            var stub = new StubForFodyCanCacheMySelf();
            await AsyncQuery.Query(stub);

            var task = AsyncQuery.Query(stub);

            Assert.True(task.IsCompleted);
        }
        protected override void Given()
        {
            instance = MockRepository.GenerateStub<TestInterface>();

            instance.Expect(x => x.Method(null)).Throw(exception);
            instance.Expect(x => x.Function(null)).Throw(exception);

            command = new AsyncCommand(()=> instance.Method(null));
            query = new AsyncQuery<string>(()=> instance.Function(null));
        }
        void qry_AfterExecutionCompleted(ExecutionCompletedEventArgs args)
        {
            if (args.Cancelled | args.Error != null)
            {
                return;
            }

            RenderDataSet(args.Result);
            asyncQry = null;
        }
        public void ExecuteAsync(ConnectionParams cp, string commandText)
        {
            if (IsExecutingAsync)
            {
                throw new Exception("Query is already executing!");
            }

            ClearAll();
            asyncQry = new AsyncQuery(cp.ConnectionString, commandText);
            asyncQry.AfterExecutionCompleted += new ExecutionCompletedDelegate(qry_AfterExecutionCompleted);
            asyncQry.Execute();
        }
示例#10
0
        IEnumerable<IAction> UpdateNews()
        {
            while (true)
            {
                var query = new AsyncQuery<string>(() => news.Download(5));
                yield return query;

                if (!query.Failed)
                    ticker.ScrollText = query.Result;

                yield return Sleep.Timeout(TimeSpan.FromSeconds(40));
            }
        }
        protected override void Given()
        {
            instance = MockRepository.GenerateStrictMock<TestInterface>();

            instance.Expect(x => x.Method(parameter))
                    .WhenCalled(x => callThreadId = CurrentThreadId());

            instance.Expect(x => x.Function(parameter)).Return(result)
                    .WhenCalled(x => callThreadId = CurrentThreadId()); ;

            command = new AsyncCommand(()=> instance.Method(parameter));
            query = new AsyncQuery<string>(()=> instance.Function(parameter));
        }
        public async ValueTask <DynamicObject> ExecuteAsync(Expression expression, CancellationToken cancellation)
        {
            var request = new AsyncQuery <Expression> {
                Request = expression
            };

            using var tcpClient = await InitiateQueryAsync(request, cancellation).ConfigureAwait(false);

            using var stream = tcpClient.GetStream();
            var result = await stream.ReadAsync <DynamicObject>(cancellation).ConfigureAwait(false);

            return(result);
        }
示例#13
0
        IEnumerable <IAction> UpdateNews()
        {
            while (true)
            {
                var query = new AsyncQuery <string>(() => news.Download(5));
                yield return(query);

                if (!query.Failed)
                {
                    ticker.ScrollText = query.Result;
                }

                yield return(Sleep.Timeout(TimeSpan.FromSeconds(40)));
            }
        }
示例#14
0
        public EmsAdapter(EmsSettings settings)
        {
            if (settings != null)
            {
                Settings = settings;
            }
            if (_app == null)
            {
                _app = new TalipcToolkitApp();
            }

            Stats = new Dictionary <string, OrderStats>();

            Service = "ACCOUNT_GATEWAY";
            Topic   = "ORDER";

            // THESE ARE SETTINGS
            GatewayMachine = settings.Gateway;
            Bank           = settings.Bank;
            Branch         = settings.Branch;
            Customer       = settings.Customer;
            Deposit        = settings.Deposit;

            _query                = _app.GetAsyncQuery(GatewayMachine, Service, Topic);
            _query.OnTerminate   += OnTerminate;
            _query.OnOtherAck    += OnOtherAck;
            _query.OnAdviseData  += OnAdviseData;
            _query.OnExecute     += OnExecute;
            _query.OnExecuteAck  += OnExecuteAck;
            _query.OnRequestData += OnRequestData;

            if (!_query.Connect())
            {
                Console.WriteLine("No dice on connection");
            }
            else
            {
                _query.Advise("ORDERS;*;", "TAL4");
                _query.Request("ORDERS;*;", "TAL4");
            }
        }
示例#15
0
 /// <summary>
 /// 异步查询
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public static void QueryAsync(object obj)
 {
     string str = obj.ToString();
     AsyncQuery asyncQuery = new AsyncQuery(WordBLL.Query);
     IAsyncResult ar = asyncQuery.BeginInvoke(str, null, null);
     //在指定时间内不能重数据库或网页中提取出单词信息,则认为查询失败
     //int timeLimit = 5000;
     //if (ar.AsyncWaitHandle.WaitOne(timeLimit,false) == false)
     //{
     //    QueryResult.IsFinish = true;
     //    QueryResult.Result = new Word();
     //    QueryResult.Result.WordContent = QueryResult.FailInfo;
     //    return;
     //}
     QueryResult.Result = asyncQuery.EndInvoke(ar);
     if (ar.IsCompleted)
     {
         QueryResult.IsFinish = true;
         if (string.IsNullOrEmpty(QueryResult.Result.WordContent))
         {
             QueryResult.Result.WordContent = QueryResult.FailInfo;
         }
     }
 }
示例#16
0
 public WriteHandler(AsyncQuery parent, AsyncClient client, Arguments args, string binName, int max)
 {
     this.parent = parent;
     this.client = client;
     this.args = args;
     this.binName = binName;
     this.max = max;
 }
示例#17
0
 public RecordSequenceHandler(AsyncQuery parent, string binName)
 {
     this.parent = parent;
     this.binName = binName;
 }
示例#18
0
 IDbAsyncEnumerator IDbAsyncEnumerable.GetAsyncEnumerator()
 => AsyncQuery.GetAsyncEnumerator();
示例#19
0
 public Repository(ShowsContext context, DbSet <T> dbSet)
 {
     _context = context;
     _dbSet   = dbSet;
     _query   = new AsyncQuery <T>(_dbSet.AsQueryable());
 }
示例#20
0
		public Task<MediaFile> SaveThumbnailAsync (string path)
		{
			if (path == null)
				throw new ArgumentNullException ("path");

			string lookupColumn = (IsAggregate)
									? ContactsContract.ContactsColumns.LookupKey
									: ContactsContract.RawContactsColumns.ContactId;

			AsyncQuery<byte[]> query = new AsyncQuery<byte[]> (this.content, c => c.GetBlob (c.GetColumnIndex (ContactsContract.CommonDataKinds.Photo.PhotoColumnId)));
			query.StartQuery (0, null, ContactsContract.Data.ContentUri, new[] { ContactsContract.CommonDataKinds.Photo.PhotoColumnId, ContactsContract.DataColumns.Mimetype },
					lookupColumn + "=? AND " + ContactsContract.DataColumns.Mimetype + "=?", new[] { Id, ContactsContract.CommonDataKinds.Photo.ContentItemType }, null);

			return query.Task.ContinueWith (t =>
			{
				if (t.Result == null)
					return null;

				File.WriteAllBytes (path, t.Result);
				return new MediaFile (path, deletePathOnDispose: false);
			}, TaskScheduler.Default);
		}
示例#21
0
 public IDbAsyncEnumerator <T> GetAsyncEnumerator()
 => AsyncQuery.GetAsyncEnumerator();