当前位置: 首页>>代码示例>>C#>>正文


C# Resolver.CreateRequest方法代码示例

本文整理汇总了C#中Resolver.CreateRequest方法的典型用法代码示例。如果您正苦于以下问题:C# Resolver.CreateRequest方法的具体用法?C# Resolver.CreateRequest怎么用?C# Resolver.CreateRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Resolver的用法示例。


在下文中一共展示了Resolver.CreateRequest方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResolveMultipleAction

        public async Task ResolveMultipleAction()
        {
            IResolver resolver = new Resolver(true);
            TaskCompletionSource<IList<ResolvedAction>> action = new TaskCompletionSource<IList<ResolvedAction>>();
            resolver.ActionsResolved += (sender, args) =>
            {
                action.SetResult(args.ResolvedActions);
            };
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0003", Id2 = 48869, Id3 = 21321},
                EventType = BeaconEventType.Unknown
            });

            IList<ResolvedAction> result = await action.Task;

            Assert.AreEqual(4, result.Count, "Not 4 action found");
        }
开发者ID:sensorberg-dev,项目名称:windows10-sdk,代码行数:18,代码来源:ResolverTest.cs

示例2: TestBeaconEventExitChange

        public async Task TestBeaconEventExitChange()
        {
            Resolver resolver = new Resolver(true);
            resolver.BeaconManager.ExitTimeout = 1000;
            TaskCompletionSource<IList<ResolvedAction>> enterAction = new TaskCompletionSource<IList<ResolvedAction>>();
            TaskCompletionSource<IList<ResolvedAction>> exitAction = new TaskCompletionSource<IList<ResolvedAction>>();
            EventHandler<ResolvedActionsEventArgs> resolverOnActionsResolved = (sender, args) =>
            {
                if (args.BeaconEventType == BeaconEventType.Enter)
                {
                    enterAction.SetResult(args.ResolvedActions);
                }
                if (args.BeaconEventType == BeaconEventType.Exit)
                {
                    exitAction.SetResult(args.ResolvedActions);
                }

            };
            resolver.ActionsResolved += resolverOnActionsResolved;
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = new Beacon() { Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929 },
                EventType = BeaconEventType.Unknown
            });
            await Task.Delay(1500);
            IList<ResolvedAction> result = await enterAction.Task;

            Assert.AreEqual(1, result.Count, "Not 1 action found");

            result = await exitAction.Task;

            Assert.AreEqual(1, result.Count, "Not 1 action found");
            resolver.ActionsResolved -= resolverOnActionsResolved;


            resolver.BeaconManager.ExitTimeout = 100;

            enterAction = new TaskCompletionSource<IList<ResolvedAction>>();
            exitAction = new TaskCompletionSource<IList<ResolvedAction>>();
            resolverOnActionsResolved = (sender, args) =>
            {
                if (args.BeaconEventType == BeaconEventType.Enter)
                {
                    enterAction.SetResult(args.ResolvedActions);
                }
                if (args.BeaconEventType == BeaconEventType.Exit)
                {
                    exitAction.SetResult(args.ResolvedActions);
                }

            };
            resolver.ActionsResolved += resolverOnActionsResolved;
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = new Beacon() { Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929 },
                EventType = BeaconEventType.Unknown
            });
            await Task.Delay(300);
             result = await enterAction.Task;

            Assert.AreEqual(1, result.Count, "Not 1 action found");

            result = await exitAction.Task;

            Assert.AreEqual(1, result.Count, "Not 1 action found");
        }
开发者ID:sensorberg-dev,项目名称:windows10-sdk,代码行数:66,代码来源:ResolverTest.cs

示例3: TestMultipleEnterExitEvent

        public async Task TestMultipleEnterExitEvent()
        {
            Resolver resolver = new Resolver(true);
            resolver.BeaconManager.ExitTimeout = 100;

            int enterCounter = 0;
            int exitCounter = 0;
            resolver.ActionsResolved += (sender, args) =>
            {
                if (args.BeaconEventType == BeaconEventType.Enter)
                {
                    enterCounter++;
                }
                if (args.BeaconEventType == BeaconEventType.Exit)
                {
                    exitCounter++;
                }

            };
            Beacon beacon = new Beacon() { Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929 };
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = beacon,
                EventType = BeaconEventType.Unknown
            });
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = beacon,
                EventType = BeaconEventType.Unknown
            });
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = beacon,
                EventType = BeaconEventType.Unknown
            });

            await Task.Delay(1000);

            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = beacon,
                EventType = BeaconEventType.Unknown
            });


            Assert.AreEqual(2, enterCounter, "Not 2 enter action found");


            Assert.AreEqual(1, exitCounter, "Not 1 exit action found");
        }
开发者ID:sensorberg-dev,项目名称:windows10-sdk,代码行数:50,代码来源:ResolverTest.cs

示例4: MultipleRequestBlocksQueueTest

        public async Task MultipleRequestBlocksQueueTest()
        {
            MockLayoutManager layoutManager = new MockLayoutManager();
            layoutManager.FindOneAction = true;
            IResolver resolver = new Resolver(false);
            ServiceManager.ReadOnlyForTests = false;
            ServiceManager.LayoutManager = layoutManager;
            ServiceManager.ReadOnlyForTests = true;


            TaskCompletionSource<List<ResolvedActionsEventArgs>> requestReady = new TaskCompletionSource<List<ResolvedActionsEventArgs>>();
            List<ResolvedActionsEventArgs> requestsList = new List<ResolvedActionsEventArgs>();
            EventHandler<ResolvedActionsEventArgs> resolverOnActionsResolved = (sender, args) =>
            {
                requestsList.Add(args);
            };
            resolver.ActionsResolved += resolverOnActionsResolved;
            ((Resolver) resolver).Finished += () =>
            {
                if (requestsList.Count == 10)
                {
                    requestReady.TrySetResult(requestsList);
                }
            };

            for (int i = 0; i < 10; i++)
            {
                await resolver.CreateRequest(new BeaconEventArgs()
                {
                    Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0004", Id2 = (ushort) (39178+i), Id3 = 30929},
                    EventType = BeaconEventType.Unknown
                });
            }

            if (await Task.WhenAny(requestReady.Task, Task.Delay(500000)) == requestReady.Task)
            {
                Assert.AreEqual(10, requestReady.Task.Result.Count, "Request not successfull");

                Assert.AreEqual(10, requestsList.Count, "Not 10 request results");
            }
            else
            {
                Assert.Fail("Timout");
            }
            resolver.ActionsResolved -= resolverOnActionsResolved;

            requestsList = new List<ResolvedActionsEventArgs>();
            TaskCompletionSource<List<ResolvedActionsEventArgs>> requestReady2 = new TaskCompletionSource<List<ResolvedActionsEventArgs>>();

            resolver.ActionsResolved += (sender, args) =>
            {
                requestsList.Add(args);
            };
            ((Resolver) resolver).Finished += () =>
            {
                if (requestsList.Count == 10)
                {
                    requestReady2.TrySetResult(requestsList);
                }
            };
            for (int i = 0; i < 10; i++)
            {
                await resolver.CreateRequest(new BeaconEventArgs()
                {
                    Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929},
                    EventType = BeaconEventType.Unknown
                });
            }

            if (await Task.WhenAny(requestReady2.Task, Task.Delay(500000)) == requestReady2.Task)
            {
                Assert.AreEqual(10, requestReady2.Task.Result.Count, "Request not successfull");

                Assert.AreEqual(10, requestsList.Count, "Not 10 request results");
            }
            else
            {
                Assert.Fail("Timout2");
            }
        }
开发者ID:sensorberg-dev,项目名称:windows10-sdk,代码行数:80,代码来源:ResolverTest.cs

示例5: MultipleRequestWithFailuresQueueTest

        public async Task MultipleRequestWithFailuresQueueTest()
        {
            MockLayoutManager layoutManager = new MockLayoutManager();
            layoutManager.FindOneAction = true;
            IResolver resolver = new Resolver(false);
            ServiceManager.ReadOnlyForTests = false;
            ServiceManager.LayoutManager = layoutManager;
            ServiceManager.ReadOnlyForTests = true;

            layoutManager.ShouldFail += (r, fail) =>
            {
                if (r.RequestId == 5 && r.TryCount == 1)
                {
                    fail.Fail = true;
                    return;
                }

                if (r.RequestId == 6)
                {
                    fail.Fail = true;
                    return;
                }
            };

            TaskCompletionSource<List<ResolvedActionsEventArgs>> requestReady = new TaskCompletionSource<List<ResolvedActionsEventArgs>>();
            List<ResolvedActionsEventArgs> requestsList = new List<ResolvedActionsEventArgs>();
            resolver.ActionsResolved += (sender, args) =>
            {
                requestsList.Add(args);
            };
            int i = 0;
            ((Resolver) resolver).Finished += () =>
            {
                if (i == 10)
                {
                    requestReady.TrySetResult(requestsList);
                }
            };

            for (; i < 10; i++)
            {
                await resolver.CreateRequest(new BeaconEventArgs()
                {
                    Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929},
                    EventType = BeaconEventType.Unknown
                });
            }

            if (await Task.WhenAny(requestReady.Task, Task.Delay(5000)) == requestReady.Task)
            {
                Assert.AreEqual(9, requestReady.Task.Result.Count, "Request successfull (last should fail)");

                Assert.AreEqual(9, requestsList.Count, "Not 9 request results");
            }
            else
            {
                Assert.Fail("Timout");
            }
        }
开发者ID:sensorberg-dev,项目名称:windows10-sdk,代码行数:59,代码来源:ResolverTest.cs

示例6: SimpleRequestQueueTest

        public async Task SimpleRequestQueueTest()
        {
            MockLayoutManager layoutManager = new MockLayoutManager();
            layoutManager.FindOneAction = true;
            IResolver resolver = new Resolver(false);
            ServiceManager.ReadOnlyForTests = false;
            ServiceManager.LayoutManager = layoutManager;
            ServiceManager.ReadOnlyForTests = true;

            TaskCompletionSource<ResolvedActionsEventArgs> requestReady = new TaskCompletionSource<ResolvedActionsEventArgs>();
            resolver.ActionsResolved += (sender, args) =>
            {
                requestReady.TrySetResult(args);
            };
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929},
                EventType = BeaconEventType.Unknown
            });

            ResolvedActionsEventArgs state = await requestReady.Task;
            Assert.AreEqual(1, state.ResolvedActions.Count, "Request not successfull");
        }
开发者ID:sensorberg-dev,项目名称:windows10-sdk,代码行数:23,代码来源:ResolverTest.cs


注:本文中的Resolver.CreateRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。