コード例 #1
0
ファイル: PipeLineBuffer.cs プロジェクト: xztaityozx/ptolemy
        public override void Invoke(CancellationToken token)
        {
            OnBegin?.Invoke();
            var box = new List <List <TItem> > {
                new List <TItem>()
            };
            var idx = 0;

            foreach (var item in Sources.GetConsumingEnumerable())
            {
                token.ThrowIfCancellationRequested();
                OnInterval?.Invoke(item);

                box[idx].Add(item);
                if (box[idx].Count != Size)
                {
                    continue;
                }

                Results.Add(box[idx].ToArray(), token);
                idx++;
                box.Add(new List <TItem>());
            }

            if (box[idx].Any())
            {
                Results.Add(box[idx].ToArray(), token);
            }
            Results.CompleteAdding();
            OnFinish?.Invoke();
        }
コード例 #2
0
        public override void Invoke(CancellationToken token)
        {
            OnBegin?.Invoke();

            var tasks = new List <Task>();

            for (var i = 0; i < Workers; i++)
            {
                tasks.Add(Task.Factory.StartNew(() => {
                    foreach (var source in Sources.GetConsumingEnumerable())
                    {
                        token.ThrowIfCancellationRequested();

                        foreach (var result in filter(source))
                        {
                            Results.Add(result, token);
                            OnInnerInterval?.Invoke(result);
                        }

                        OnInterval?.Invoke(source);
                    }
                }, token));
            }

            Task.WaitAll(tasks.ToArray());

            Results.CompleteAdding();
            OnFinish?.Invoke();
        }
コード例 #3
0
 public void Start(bool reverse)
 {
     IsReversed = _hasBegunReversed = reverse;
     TimeLeft   = Duration;
     Value      = Percent = IsReversed ? 1f : 0f;
     IsActive   = true;
     OnBegin?.Invoke(this);
 }
コード例 #4
0
        public void Begin()
        {
            if (IsActive)
            {
                return;
            }

            IsActive = true;
            OnBegin?.Invoke(this, EventArgs.Empty);
            BeginImpl();
        }
コード例 #5
0
        private void Initialize(Scene scene)
        {
            if (Initialized)
            {
                return;
            }
            Initialized = true;

            WrappedScene.Begin();
            scene.RendererList.Add(Renderer);
            Renderer.Alloc();
            OnBegin?.Invoke(WrappedScene);
        }
コード例 #6
0
ファイル: Menu.cs プロジェクト: skthomasjr/ConsoleObjects
        public void AwaitKeyPress()
        {
            OnBegin?.Invoke();
            if (!string.IsNullOrWhiteSpace(Title))
            {
                Console.Title = Title;
            }
            Console.BackgroundColor = Background;
            Console.Clear();

            foreach (var group in Groups)
            {
                if (!string.IsNullOrWhiteSpace(group.Caption))
                {
                    Console.WriteLine();
                    Console.WriteLine(new string(' ', Indent) + group.Caption);
                }

                Console.WriteLine();
                foreach (var item in group.Items)
                {
                    if (!string.IsNullOrWhiteSpace(item.Caption))
                    {
                        Console.WriteLine(new string(' ', Indent) + item.Caption.Replace("{key}", item.Key.ToString()));
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine(" " + new string('┈', Console.BufferWidth - 2) + " ");

            EndingCursorTop = Console.CursorTop;

            while (!exit)
            {
                var key      = Console.ReadKey(true).Key;
                var menuItem = Groups.SelectMany(g => g.Items).SingleOrDefault(i => i.Key == key);
                if (menuItem != null)
                {
                    if (menuItem.OnSelection == null)
                    {
                        exit = true;
                    }
                    else
                    {
                        menuItem.OnSelection.Invoke();
                    }
                }
            }
            OnEnd?.Invoke();
        }
コード例 #7
0
ファイル: Game.cs プロジェクト: lucas-miranda/Raccoon
        protected virtual void Initialize()
        {
            // systems initialization
            Debug.Console.Start();

            OnBegin?.Invoke();
            OnBegin = null;

            SwitchScene(StartSceneName);
            UpdateCurrentScene();

            // late systems initialization
            Util.Tween.Tweener.Instance.Start();
        }
        public void Subscribe(EventHandler <TResponse> value)
        {
            OnData += value;
            Task.Run(async() => {
                using NamedPipeClientStream stream = new NamedPipeClientStream(pipeName);
                using StreamReader reader          = new StreamReader(stream);
                using StreamWriter writer          = new StreamWriter(stream);

                await stream.ConnectAsync(5000, _externCancellationToken).ConfigureAwait(false);

                await writer.WriteLineAsync(request.ToJson()).ConfigureAwait(false);
                await writer.FlushAsync().ConfigureAwait(false);
                stream.WaitForPipeDrain();

                while (!_externCancellationToken.IsCancellationRequested && !unsubscribeToken.IsCancellationRequested)
                {
                    string responsJson             = await reader.ReadLineAsync().ConfigureAwait(false);
                    StreamlabsOBSResponse response = JsonConvert.DeserializeObject <StreamlabsOBSResponse>(responsJson);
                    response.JsonResponse          = responsJson;

                    if (response.Results.Value <string>("_type").Equals("SUBSCRIPTION"))
                    {
                        OnBegin?.Invoke(this, response);
                    }
                    else
                    if (response.Results.Value <string>("_type").Equals("EVENT"))
                    {
                        StreamlabsOBSEvent eventData = response.GetResultFirstOrDefault <StreamlabsOBSEvent>();

                        OnEvent?.Invoke(this, eventData);
                        if (typeof(TResponse).IsAssignableFrom(typeof(StreamlabsOBSEvent)))
                        {
                            OnData?.Invoke(this, eventData as TResponse);
                        }
                        else
                        {
                            OnData?.Invoke(this, eventData.GetDataFirstOrDefault <TResponse>());
                        }
                    }
                    else
                    {
                        OnUnsupported?.Invoke(this, responsJson);
                    }
                }
            },
                     _externCancellationToken);
        }
コード例 #9
0
        /// <summary>
        /// Starts the game or round. Initializes the GameFlowHandler to begin the round.
        /// </summary>
        public virtual void Begin()
        {
            if (Game.RoundNumber == 0)
            {
                LastTurn = new GameBeginningTurn(PlayerOnTurn);
            }
            else
            {
                LastTurn = new GameTurn(PlayerOnTurn);
            }

            RedrawToPlayersPerspective();

            OnBegin?.Invoke();

            var factory = new GameBotFactory();
            var bot     = factory.CreateFromGame(Game, PlayerOnTurn, GameBotType.MonteCarloTreeSearchBot);

            //bot.FindBestMove();
        }
コード例 #10
0
        public Exception Run(CancellationToken token, string logFile)
        {
            OnBegin?.Invoke();

            // init logger
            Logger = new Logger.Logger();
            if (!string.IsNullOrEmpty(logFile))
            {
                Logger.AddHook(new FileHook(logFile));
            }

            // Bind
            Vtn = new Transistor(Bind(VtnString, (VtnThreshold, VtnSigma, VtnNumberOfSigma), Sigma));
            Vtp = new Transistor(Bind(VtpString, (VtpThreshold, VtpSigma, VtpNumberOfSigma), Sigma));

            var rt = Do(token);

            OnFinish?.Invoke();
            return(rt);
        }
コード例 #11
0
ファイル: GameManager.cs プロジェクト: jxz12/StopTouching
    public void Begin()
    {
        lives = 3;
        foreach (Image im in hearts)
        {
            im.color = heartCol;
        }
        skinnedMesh.materials[1].mainTexture = idle;
        skinnedMesh.materials[0].color       = skinCol;

        score = 0;
        DisplayScore();
        // if (mode == Difficulty.Easy) {
        //     StartCoroutine(SpawnConstantly(()=>minSpeed + Mathf.Log(1+.01f*Time.time),
        //                                    ()=>minDelay + (maxDelay-minDelay)/(1+.01f*Time.time)));
        // } else if (mode == Difficulty.Hard) {
        StartCoroutine(SpawnConstantly(() => minSpeed + (float)Math.Log(1 + Math.Sqrt(.01 * score)),
                                       () => minDelay + (maxDelay - minDelay) / (1 + (float)Math.Sqrt(.01f * score))));
        // }
        OnBegin.Invoke();
    }
コード例 #12
0
 //Public Methods:
 public void FireBegin()
 {
     Active = true;
     OnBegin?.Invoke();
 }
コード例 #13
0
 private void BeginRound(object sender, EventArgs e)
 {
     OnBegin?.Invoke();
 }
コード例 #14
0
ファイル: LevelStage.cs プロジェクト: moe4b-work/Zombie-Party
 public virtual void Begin()
 {
     OnBegin?.Invoke();
 }
コード例 #15
0
 public void Begin()
 {
     OnBegin?.Invoke();
 }