Exemple #1
0
        protected async Task Update()
        {
            IsBusy = true;
            ResetCancellationToken();
            var token = updateTokenSource.Token;

            try
            {
                BeforeUpdate?.Invoke(this, EventArgs.Empty);
                await OnUpdate(token);

                AfterUpdate?.Invoke(this, EventArgs.Empty);
            }
            catch (OperationCanceledException)
            {
                // log that the operation was cancelled here. this will have to be handled in each
                // viewmodel differently but the main log should go here
                await OnUpdateCancelled();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemple #2
0
        /// <summary>
        /// Update the value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public async Task <ExecutionResult <T> > UpdateAsync(T value)
        {
            var connectMessage = Connect();

            if (connectMessage != "OK")
            {
                throw new ConnectionException(connectMessage);
            }

            BeforeUpdate?.Invoke(value);

            var stop = new Stopwatch();

            stop.Start();

            if (_diagnosticSource.IsEnabled($"{typeof(T).Name}_Update"))
            {
                _diagnosticSource.Write($"{typeof(T).Name}_Update", value);
            }

            _logger.LogTrace("Try to update item");
            T result = await TryUpdate(value);

            stop.Stop();
            _logger.LogTrace($"End Update in {stop.Elapsed}");

            AfterUpdate?.Invoke(value);

            return(new ExecutionResult <T>(result != null, result));
        }
 protected virtual async Task OnAfterUpdate(GridUpdateComponent <T> component)
 {
     if (AfterUpdate != null)
     {
         await AfterUpdate.Invoke(component, _item);
     }
 }
Exemple #4
0
        /// <summary>
        /// Performs update step for all entities and components
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime)
        {
            ProcessEntitiesForAdding();
            ProcessComponentForAdding();

            BeforeUpdate?.Invoke();

            foreach (Entity entity in _entities)
            {
                if (!entity.Processable)
                {
                    continue;
                }

                // ReSharper disable once ForCanBeConvertedToForeach
                for (var i = 0; i < entity.Components.Count; i++)
                {
                    var entityComponent = entity.Components[i];

                    if (entityComponent.Processable)
                    {
                        entityComponent.Update(gameTime);
                    }
                }
            }

            AfterUpdate?.Invoke();

            ProcessEntitiesForRemoving();
            ProcessComponentsForRemoving();
        }
Exemple #5
0
        public void OnLoop(FrameTime frameTime)
        {
            CurrentTimestamp = frameTime.TotalSeconds;

            BeforeAll?.Invoke(frameTime);

            BeforeUpdate?.Invoke(frameTime);
            Update?.Invoke(frameTime);
            AfterUpdate?.Invoke(frameTime);

            BeforeRender?.Invoke(frameTime);
            Render?.Invoke(frameTime);
            AfterRender?.Invoke(frameTime);

            AfterAll?.Invoke(frameTime);
        }
 protected virtual void OnAfterUpdate(T entity)
 {
     AfterUpdate?.Invoke(entity);
 }
Exemple #7
0
        /// <summary>
        /// Create the DropDown list.
        /// </summary>
        /// <param name="size">List size (refers to the whole size of the list + the header when dropdown list is opened).</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        /// <param name="skin">Panel skin to use for this DropDown list and header.</param>
        public DropDown(Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) :
            base(size, anchor, offset)
        {
            // default padding of self is 0
            Padding = Vector2.Zero;

            // to get collision right when list is opened
            UseActualSizeForCollision = true;

            // create the panel and paragraph used to show currently selected value (what's shown when drop-down is closed)
            _selectedTextPanel     = new Panel(new Vector2(0, SelectedPanelHeight), skin, Anchor.TopLeft);
            _selectedTextParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.CenterLeft);
            _selectedTextParagraph.UseActualSizeForCollision = false;
            _selectedTextParagraph.UpdateStyle(SelectList.DefaultParagraphStyle);
            _selectedTextParagraph.UpdateStyle(DefaultParagraphStyle);
            _selectedTextParagraph.UpdateStyle(DefaultSelectedParagraphStyle);
            _selectedTextPanel.AddChild(_selectedTextParagraph, true);

            // create the arrow down icon
            _arrowDownImage = new Image(Resources.ArrowDown, new Vector2(ArrowSize, ArrowSize), ImageDrawMode.Stretch, Anchor.CenterRight, new Vector2(-10, 0));
            _selectedTextPanel.AddChild(_arrowDownImage, true);

            // create the list component
            _selectList = new SelectList(size, Anchor.TopCenter, Vector2.Zero, skin);

            // update list offset and space before
            _selectList.SetOffset(new Vector2(0, SelectedPanelHeight));
            _selectList.SpaceBefore = Vector2.Zero;

            // add the header and select list as children
            AddChild(_selectedTextPanel);
            AddChild(_selectList);

            // add callback on list value change
            _selectList.OnValueChange = (Entity entity) =>
            {
                // hide list
                ListVisible = false;

                // set selected text
                _selectedTextParagraph.Text = (SelectedValue ?? DefaultText);
            };

            // hide the list by default
            _selectList.Visible = false;

            // setup the callback to show / hide the list when clicking the dropbox
            _selectedTextPanel.OnClick = (Entity self) =>
            {
                // change visibility
                ListVisible = !ListVisible;
            };

            // set starting text
            _selectedTextParagraph.Text = (SelectedValue ?? DefaultText);

            // update styles
            _selectList.UpdateStyle(DefaultStyle);

            // make the list events trigger the dropdown events
            _selectList.OnListChange       += (Entity entity) => { OnListChange?.Invoke(this); };
            _selectList.OnMouseDown        += (Entity entity) => { OnMouseDown?.Invoke(this); };
            _selectList.OnMouseReleased    += (Entity entity) => { OnMouseReleased?.Invoke(this); };
            _selectList.WhileMouseDown     += (Entity entity) => { WhileMouseDown?.Invoke(this); };
            _selectList.WhileMouseHover    += (Entity entity) => { WhileMouseHover?.Invoke(this); };
            _selectList.OnClick            += (Entity entity) => { OnClick?.Invoke(this); };
            _selectList.OnValueChange      += (Entity entity) => { OnValueChange?.Invoke(this); };
            _selectList.OnMouseEnter       += (Entity entity) => { OnMouseEnter?.Invoke(this); };
            _selectList.OnMouseLeave       += (Entity entity) => { OnMouseLeave?.Invoke(this); };
            _selectList.OnMouseWheelScroll += (Entity entity) => { OnMouseWheelScroll?.Invoke(this); };
            _selectList.OnStartDrag        += (Entity entity) => { OnStartDrag?.Invoke(this); };
            _selectList.OnStopDrag         += (Entity entity) => { OnStopDrag?.Invoke(this); };
            _selectList.WhileDragging      += (Entity entity) => { WhileDragging?.Invoke(this); };
            _selectList.BeforeDraw         += (Entity entity) => { BeforeDraw?.Invoke(this); };
            _selectList.AfterDraw          += (Entity entity) => { AfterDraw?.Invoke(this); };
            _selectList.BeforeUpdate       += (Entity entity) => { BeforeUpdate?.Invoke(this); };
            _selectList.AfterUpdate        += (Entity entity) => { AfterUpdate?.Invoke(this); };

            // make the selected value panel trigger the dropdown events
            _selectedTextPanel.OnMouseDown        += (Entity entity) => { OnMouseDown?.Invoke(this); };
            _selectedTextPanel.OnMouseReleased    += (Entity entity) => { OnMouseReleased?.Invoke(this); };
            _selectedTextPanel.WhileMouseDown     += (Entity entity) => { WhileMouseDown?.Invoke(this); };
            _selectedTextPanel.WhileMouseHover    += (Entity entity) => { WhileMouseHover?.Invoke(this); };
            _selectedTextPanel.OnClick            += (Entity entity) => { OnClick?.Invoke(this); };
            _selectedTextPanel.OnValueChange      += (Entity entity) => { OnValueChange?.Invoke(this); };
            _selectedTextPanel.OnMouseEnter       += (Entity entity) => { OnMouseEnter?.Invoke(this); };
            _selectedTextPanel.OnMouseLeave       += (Entity entity) => { OnMouseLeave?.Invoke(this); };
            _selectedTextPanel.OnMouseWheelScroll += (Entity entity) => { OnMouseWheelScroll?.Invoke(this); };
            _selectedTextPanel.OnStartDrag        += (Entity entity) => { OnStartDrag?.Invoke(this); };
            _selectedTextPanel.OnStopDrag         += (Entity entity) => { OnStopDrag?.Invoke(this); };
            _selectedTextPanel.WhileDragging      += (Entity entity) => { WhileDragging?.Invoke(this); };
            _selectedTextPanel.BeforeDraw         += (Entity entity) => { BeforeDraw?.Invoke(this); };
            _selectedTextPanel.AfterDraw          += (Entity entity) => { AfterDraw?.Invoke(this); };
            _selectedTextPanel.BeforeUpdate       += (Entity entity) => { BeforeUpdate?.Invoke(this); };
            _selectedTextPanel.AfterUpdate        += (Entity entity) => { AfterUpdate?.Invoke(this); };
        }
Exemple #8
0
 internal void _DoUpdate()
 {
     BeforeUpdate?.Invoke();
     UnityUpdate();
     AfterUpdate?.Invoke();
 }