Beispiel #1
0
        public static IManagedDownloaderToken AsManaged(this IDownloader @this, string managerName = DefaultManagerName)
        {
            Guards.ThrowIfNull(@this);
            Guards.ThrowIfNullOrEmpty(managerName);

            if (@this.Context == null)
            {
                throw new InvalidOperationException();
            }

            var id = @this.Context.Id;

            if (!ManagedDownloaderTokens.ContainsKey(id))
            {
                ManagedDownloaderTokens[id] = new ManagedDownloaderTokenImpl(GetFileDownloaderManager(managerName), @this);
            }

            return(ManagedDownloaderTokens[id]);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var vanguard = new Vanguard("前锋");

            vanguard.Attack();

            var center = new Center("中锋");

            center.Attack();
            center.Defend();

            Guards guards = new Guards("后卫");

            guards.Defend();

            ChineseCenter chineseCenter = new ChineseCenter("适配器");

            chineseCenter.Attack();
        }
Beispiel #3
0
        /*============================================================================*/
        /* Private Functions                                                          */
        /*============================================================================*/

        private void RunProcess(object view, Type type, IViewProcessorMapping mapping)
        {
            if (Guards.Approve(_injector, mapping.Guards))
            {
                if (mapping.Processor == null)
                {
                    mapping.Processor = CreateProcessor(mapping.ProcessorClass);
                }
                Hooks.Apply(_injector, mapping.Hooks);

                MethodInfo processMethod = mapping.Processor.GetType().GetMethod(ProcessMethodName);
                if (processMethod != null && processMethod.GetParameters().Length == 3)
                {
                    processMethod.Invoke(mapping.Processor, new object[3] {
                        view, type, _injector
                    });
                }
            }
        }
Beispiel #4
0
        public static Func <TInput, Task <IEnumerable <T> > > ThenAsync <TInput, TOutput, T>(
            this Func <TInput, Task <IEnumerable <TOutput> > > @this,
            Func <TOutput, T> function,
            CancellationToken cancellationToken = default)
        {
            Guards.ThrowIfNull(function);

            return(async input =>
            {
                cancellationToken.ThrowIfCancellationRequested();
                var output = await @this(input);

                return output.Select(item =>
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    return function(item);
                });
            });
        }
        public void TestMethodAdapter_Example()
        {
            Player b = new Forwards("Leo");

            b.Attack();

            Player m = new Guards("ken");

            m.Attack();

            Player ym = new Center("小明");

            ym.Attack();
            ym.Defense();

            Player ym2 = new Translator("阿木");

            ym2.Attack();
            ym2.Defense();
        }
        /// <summary>
        ///     Spawns guard at a random guard spawn tile
        /// </summary>
        /// <param name="potentialSpawnTiles"></param>
        /// <param name="gameParams"></param>
        private void MoveGuardAgents(List <IEnvTile> potentialSpawnTiles, Dictionary <GameParam, int> gameParams)
        {
            if (trainingScenario == TrainingScenario.SpyEvade)
            {
                if (Guards.Any(guard => guard.CompareTag("alertguard")))
                {
                    SwapAgents();
                }
            }
            if (potentialSpawnTiles.Count < Guards.Count)
            {
                throw new MapCreationException("Number of guards has exceeded the number of spawn places");
            }
            var indexes =
                RandomHelper.GetUniqueRandomList(
                    MaxNumberOfGuards(gameParams[GameParam.GuardAgentCount], gameParams[GameParam.ExitCount]),
                    potentialSpawnTiles.Count);

            for (var i = 0; i < Guards.Count; i++)
            {
                if (trainingScenario != TrainingScenario.GuardAlert)
                {
                    Guards[i].transform.position = potentialSpawnTiles[indexes[i]].Position;
                    Guards[i].GetComponent <Rigidbody>().velocity = Vector3.zero;
                }
                else
                {
                    var freeTiles = TileDict[TileType.GuardTiles]
                                    .Concat(TileDict[TileType.FreeTiles])
                                    .Where(tile => tile.OnPath)
                                    .ToList();
                    var maxNumOfGuard = MaxNumberOfGuards(gameParams[GameParam.GuardAgentCount], gameParams[GameParam.ExitCount]);
                    var agentIndex    = RandomHelper.GetUniqueRandomList(maxNumOfGuard,
                                                                         freeTiles.Count);

                    Guards[i].transform.position = freeTiles[agentIndex[i]].Position;
                    Guards[i].GetComponent <Rigidbody>().velocity = Vector3.zero;
                }
            }
        }
Beispiel #7
0
        /*============================================================================*/
        /* Private Functions                                                          */
        /*============================================================================*/

        private object CreateMediator(object item, IMediatorMapping mapping)
        {
            object mediator = GetMediator(item, mapping);

            if (mediator != null)
            {
                return(mediator);
            }

            if (mapping.Guards.Count == 0 || Guards.Approve(_injector, mapping.Guards))
            {
                mediator = _injector.InstantiateUnmapped(mapping.MediatorType);
                if (mapping.Hooks.Count > 0)
                {
                    _injector.Map(mapping.MediatorType).ToValue(mediator);
                    Hooks.Apply(_injector, mapping.Hooks);
                    _injector.Unmap(mapping.MediatorType);
                }
                AddMediator(mediator, item, mapping);
            }
            return(mediator);
        }
Beispiel #8
0
        public static Func <TInput, Task <IEnumerable <T> > > ThenAsync <TInput, TOutput, T>(
            this Func <TInput, Task <IEnumerable <TOutput> > > @this,
            Func <TOutput, Task <T> > function,
            CancellationToken cancellationToken = default)
        {
            Guards.ThrowIfNull(function);

            return(async input =>
            {
                cancellationToken.ThrowIfCancellationRequested();
                var output = await @this(input);

                var result = new List <T>();
                foreach (var item in output)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    result.Add(await function(item));
                }

                return result;
            });
        }
Beispiel #9
0
 public void SetValues(IDictionary <string, IList <string> > queryParameters)
 {
     if (queryParameters.TryGetValue(BooksQueryKey, out var b))
     {
         Books.SetValues(b);
     }
     if (queryParameters.TryGetValue(PartsQueryKey, out var p))
     {
         Parts.SetValues(p);
     }
     if (queryParameters.TryGetValue(FootworkQueryKey, out var f))
     {
         Footwork.SetValues(f);
     }
     if (queryParameters.TryGetValue(TargetsQueryKey, out var t))
     {
         Targets.SetValues(t);
     }
     if (queryParameters.TryGetValue(MeasureQueryKey, out var m))
     {
         Measure.SetValues(m);
     }
     if (queryParameters.TryGetValue(TechniquesQueryKey, out var a))
     {
         Techniques.SetValues(a);
     }
     if (queryParameters.TryGetValue(WeaponsQueryKey, out var w))
     {
         Weapons.SetValues(w);
     }
     if (queryParameters.TryGetValue(GuardsQueryKey, out var g))
     {
         Guards.SetValues(g);
     }
     if (queryParameters.TryGetValue(StartingGuardsQueryKey, out var sg))
     {
         StartingGuards.SetValues(sg);
     }
 }
    public void HandleOrder(Order order)
    {
        var context = new PaymentGuardContext();

        var state = new State <Order, OrderState>(order, a => a.State)
                    .Define(b =>
        {
            b.From(OrderState.Initial).To(OrderState.Paid)
            .Changing(OnTransitioningStateFromInitialToPaidHandler)
            .Changed(OnTransitionedStateFromInitialToPaidHandler);

            b.From(OrderState.Paid).To(OrderState.Processed);
            b.From(OrderState.Processed).To(OrderState.Delivered);
            b.OnEnter(OrderState.Paid, Guards <OrderState> .From(context,
                                                                 ValidateRequest,
                                                                 PayToPaymentGateway,
                                                                 PersistOrderToRepository
                                                                 ));
            b.DisableSameStateTransitionFor(OrderState.Paid);
        });
        var hasChangedState = state.ChangeTo(OrderState.Paid);

        //Assert.Equal(OrderState.Paid, order.State);
    }
Beispiel #11
0
        public string ToQueryString()
        {
            var queryParts = new List <string>();

            AddIfNotNull(Books.ToQueryString(BooksQueryKey));
            AddIfNotNull(Parts.ToQueryString(PartsQueryKey));
            AddIfNotNull(Footwork.ToQueryString(FootworkQueryKey));
            AddIfNotNull(Targets.ToQueryString(TargetsQueryKey));
            AddIfNotNull(Measure.ToQueryString(MeasureQueryKey));
            AddIfNotNull(Techniques.ToQueryString(TechniquesQueryKey));
            AddIfNotNull(Weapons.ToQueryString(WeaponsQueryKey));
            AddIfNotNull(Guards.ToQueryString(GuardsQueryKey));
            AddIfNotNull(StartingGuards.ToQueryString(StartingGuardsQueryKey));

            return(string.Join("&", queryParts));

            void AddIfNotNull(string?value)
            {
                if (value != null)
                {
                    queryParts.Add(value);
                }
            }
        }
Beispiel #12
0
        public static long GetTotalSize(this IDownloader @this)
        {
            Guards.ThrowIfNull(@this);

            return(@this.Context?.TotalSize ?? 0);
        }
Beispiel #13
0
        public static long GetCompletedSize(this IDownloader @this)
        {
            Guards.ThrowIfNull(@this);

            return(@this.BlockContexts?.Values.Sum(item => item.CompletedSize) ?? 0);
        }
        public ViewModelResolver(Func<IContainerProvider> containerFactory)
        {
            Guards.ThrowIfNull(containerFactory);

            _containerFactory = containerFactory;
        }
        public static IViewModelResolver IfInheritsFrom<TViewModel>(this IViewModelResolver @this, Action<FrameworkElement, TViewModel, IContainerProvider> configuration)
        {
            Guards.ThrowIfNull(@this, configuration);

            return @this.IfInheritsFrom(configuration);
        }
            //.IfInheritsFrom<IAwareTabItemSelectionChanged>((view, viewModel) =>
            //{
            //    TabControlHelper.SetAwareSelectionChanged(view, true);
            //});

        public static IViewModelResolver IfInheritsFrom<TViewModel>(this IViewModelResolver @this, Action<FrameworkElement, TViewModel> configuration)
        {
            Guards.ThrowIfNull(@this, configuration);

            return @this.IfInheritsFrom<FrameworkElement, TViewModel>((view, viewModel, container) => configuration(view, viewModel));
        }
Beispiel #17
0
 public void Require_throws_when_null()
 {
     Assert.Throws <ArgumentException>(() => Guards.Require(null, "message"));
 }
Beispiel #18
0
        public bool IsTrumped(TableFinal by)
        {
            Guards.ArgumentNotNull(by, nameof(by));

            return(by.Contains(CardA) || by.Contains(CardB));
        }
Beispiel #19
0
 public Pocket(byte[] binary)
 {
     Guards.ArgumentHasExactSize(binary, 2, nameof(binary));
     CardA = new Card(binary[0]);
     CardB = new Card(binary[1]);
 }
Beispiel #20
0
        private void ClosePage(object obj)
        {
            Guards.ArgumentGuard(obj);

            NavigationEvents.RequestPage(Pages.Back);
        }
Beispiel #21
0
        public void Require_returns_invoker_to_allow_chaining_more_guards()
        {
            var result = Guards.Require(0, "message");

            Assert.IsType <GuardInvoker>(result);
        }
 public DataTransmissionPanelViewModel(IContainerExtension container, IHouseSiteService houseSiteService) : base(container)
 {
     Guards.ThrowIfNull(container, houseSiteService);
     this.houseSiteService = houseSiteService;
 }
Beispiel #23
0
 public void ThrowIf_throws_when_conditioon_true()
 {
     Assert.Throws <ArgumentException>(() => Guards.ThrowIf(1 < 2, "message"));
 }
Beispiel #24
0
        public void ThrowIf_returns_invoker_to_allow_chaining_more_guards()
        {
            var result = Guards.ThrowIf(6 == 9, "message");

            Assert.IsType <GuardInvoker>(result);
        }
        public UpgradeService(Func <Task <List <UpgradeInfo> > > upgradeInfosGetter)
        {
            Guards.ThrowIfNull(upgradeInfosGetter);

            _upgradeInfosGetter = upgradeInfosGetter;
        }
Beispiel #26
0
 public void addGuard(Guards _guard)
 {
     levelGuards.Add(_guard);
 }
Beispiel #27
0
        public bool IsTrumped(Pocket by)
        {
            Guards.ArgumentNotNull(by, nameof(by));

            return(CardA.Equals(by.CardA) || CardA.Equals(by.CardB) || CardB.Equals(by.CardA) || CardB.Equals(by.CardB));
        }
 public DateValueConverter(string inputFormat, string outputFormat = null)
 {
     Guards.NotNull(inputFormat, "format");
     this.InputFormat  = inputFormat;
     this.OutputFormat = outputFormat == null ? inputFormat : outputFormat;
 }
Beispiel #29
0
 public PropertyValidator(BasePropertyDefinition definition)
 {
     Guards.NotNull(definition, "definition cannot be null");
     this.definition = definition;
 }
Beispiel #30
0
 public void ThrowIf_does_not_throw_when_conditioon_false()
 {
     Guards.ThrowIf(1 > 2, "message");
 }