Exemplo n.º 1
0
        protected override NameValueCollection DataAsNameValueCollection()
        {
            NameValueCollection nvc = base.DataAsNameValueCollection();

            nvc["username"]       = UserName;
            nvc["itemsToDisplay"] = ItemsToDisplay.ToString();

            return(nvc);
        }
Exemplo n.º 2
0
        protected override NameValueCollection DataAsNameValueCollection()
        {
            NameValueCollection nvc = base.DataAsNameValueCollection();

            nvc["FeedUri"]        = FeedUri;
            nvc["itemsToDisplay"] = ItemsToDisplay.ToString();


            return(nvc);
        }
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            // If this is the first time we've finished rendering, then all the columns
            // have been added to the table so we'll go and get the data for the first time
            if (firstRender)
            {
                try
                {
                    if (AutoLoad)
                    {
                        await GetDataAsync().ConfigureAwait(true);

                        StateHasChanged();
                    }
                }
                catch (Exception ex)
                {
                    await HandleExceptionAsync(ex).ConfigureAwait(true);
                }
            }

            // focus first editor after edit mode begins
            if (BeginEditEvent.WaitOne(0) && Columns.Count > 0 && EditItem != null)
            {
                // find first editable column
                var key = string.Empty;
                foreach (var column in ActualColumnsToDisplay)
                {
                    var editable = column.Editable;
                    // override with dynamic config?
                    var config = ColumnsConfig?.Find(x => x.Id == column.Id);
                    if (config?.Editable ?? editable)
                    {
                        key = column.Id;
                        break;
                    }
                }
                var row = ItemsToDisplay.IndexOf(EditItem);
                if (key != string.Empty)
                {
                    await JSRuntime.InvokeVoidAsync("panoramicData.selectText", $"{IdEditPrefix}-{row}-{key}", _tableBeforeEditArgs !.SelectionStart, _tableBeforeEditArgs !.SelectionEnd).ConfigureAwait(true);

                    BeginEditEvent.Reset();
                }
            }
        }
        private void OnDragStart(DragEventArgs _)
        {
            _dragging = true;

            // need to set the data being dragged
            if (DragContext != null && KeyField != null)
            {
                // get all selected items
                var items = new List <TItem>();
                foreach (var key in Selection)
                {
                    var item = ItemsToDisplay.Find(x => KeyField(x).ToString() == key);
                    if (item != null)
                    {
                        items.Add(item);
                    }
                }
                DragContext.Payload = items;
            }
        }
Exemplo n.º 5
0
        private void ExecuteFtpList(string uri)
        {
            ItemsToDisplay.Clear();
            Uri serverUri = new Uri(uri, UriKind.Absolute);

            if (serverUri.Scheme != Uri.UriSchemeFtp)
            {
                Output = "wrong uri";
                return;
            }

            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);

            request.Method      = WebRequestMethods.Ftp.ListDirectoryDetails;
            request.Credentials = new NetworkCredential(Username, Password);
            WebResponse response;

            try
            {
                response = request.GetResponse();
            }
            catch (Exception e)
            {
                MoveFtpPathBack(2);
                ExecuteFtpList(BuildFtpPath());
                return;
            }
            var s = response.GetResponseStream();

            StreamReader sr     = new StreamReader(s, Encoding.UTF8);
            var          result = sr.ReadToEnd();
            var          items  = result.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            ItemsToDisplay.Add("..");
            foreach (var item in items)
            {
                var split = item.Split('/');
                ItemsToDisplay.Add(split.ElementAt(split.Length - 1));
            }
        }
        /// <summary>
        /// Begins editing of the given item.
        /// </summary>
        public async Task BeginEditAsync()
        {
            if (AllowEdit && !IsEditing && SelectionMode != TableSelectionMode.None && Selection.Count == 1 && KeyField != null)
            {
                // find item to edit
                var item = ItemsToDisplay.Find(x => KeyField(x).ToString() == Selection[0]);
                if (item != null)
                {
                    // notify and allow for cancel
                    EditItem             = item;
                    _tableBeforeEditArgs = new TableBeforeEditEventArgs <TItem>(EditItem);
                    await InvokeAsync(async() => await BeforeEdit.InvokeAsync(_tableBeforeEditArgs).ConfigureAwait(true)).ConfigureAwait(true);

                    if (!_tableBeforeEditArgs.Cancel)
                    {
                        _editValues.Clear();
                        IsEditing = true;
                        BeginEditEvent.Set();
                        await InvokeAsync(StateHasChanged).ConfigureAwait(true);
                    }
                }
            }
        }
        private async Task OnKeyDownAsync(KeyboardEventArgs args)
        {
            if (IsEditing)
            {
                switch (args.Code)
                {
                case "Escape":
                    CancelEdit();
                    break;

                case "Enter":
                case "Return":
                    await CommitEditAsync().ConfigureAwait(true);

                    break;
                }
            }
            else
            {
                switch (args.Code)
                {
                case "F2":
                    await BeginEditAsync().ConfigureAwait(true);

                    break;

                case "KeyA":
                    if (args.CtrlKey && SelectionMode == TableSelectionMode.Multiple)
                    {
                        await ClearSelectionAsync().ConfigureAwait(true);

                        Selection.AddRange(ItemsToDisplay.Select(x => KeyField !(x).ToString()));
                        await SelectionChanged.InvokeAsync(null).ConfigureAwait(true);
                    }
                    break;

                case "ArrowUp":
                case "ArrowDown":
                    if (Selection.Count == 1 && KeyField != null)
                    {
                        var items = ItemsToDisplay.ToList();
                        var item  = items.Find(x => KeyField(x).ToString() == Selection[0]);
                        if (item != null)
                        {
                            var idx = items.IndexOf(item);
                            if (args.Code == "ArrowUp" && idx > 0)
                            {
                                Selection.Clear();
                                Selection.Add(KeyField(items[idx - 1]).ToString());
                            }
                            else if (args.Code == "ArrowDown" && idx < items.Count - 1)
                            {
                                Selection.Clear();
                                Selection.Add(KeyField(items[idx + 1]).ToString());
                            }
                        }
                    }
                    break;
                }
            }

            await KeyDown.InvokeAsync(args).ConfigureAwait(true);
        }
        private async Task OnRowMouseDownAsync(MouseEventArgs args, TItem item)
        {
            if (SelectionMode != TableSelectionMode.None)
            {
                var key = KeyField !(item)?.ToString();
                if (key != null)
                {
                    var alreadySelected = Selection.Contains(key);

                    // begin edit mode?
                    if (AllowEdit && !IsEditing && Selection.Count == 1 && alreadySelected && !args.CtrlKey && args.Button == 0)
                    {
                        _editTimer?.Change(500, Timeout.Infinite);
                    }
                    else
                    {
                        if (SelectionMode == TableSelectionMode.Single)
                        {
                            if (!alreadySelected)
                            {
                                Selection.Clear();
                                Selection.Add(key);
                                await SelectionChanged.InvokeAsync(null).ConfigureAwait(true);
                            }
                        }
                        else if (SelectionMode == TableSelectionMode.Multiple)
                        {
                            if (args.ShiftKey && Selection.Count > 0)                             // range selection (from last selected to row clicked on)
                            {
                                Selection.RemoveRange(0, Selection.Count - 1);
                                var idxFrom = ItemsToDisplay.FindIndex(x => KeyField !(x)?.ToString() == Selection[0]);
                                var idxTo   = ItemsToDisplay.FindIndex(x => KeyField !(x)?.ToString() == key);
                                if (idxFrom > -1 && idxTo > -1)
                                {
                                    Selection.Clear();
                                    Selection.AddRange(ItemsToDisplay
                                                       .GetRange(Math.Min(idxFrom, idxTo), (Math.Max(idxFrom, idxTo) - Math.Min(idxFrom, idxTo)) + 1)
                                                       .Select(x => KeyField !(x).ToString()));
                                    await SelectionChanged.InvokeAsync(null).ConfigureAwait(true);
                                }
                            }
                            else if (args.CtrlKey)                             // toggle selection
                            {
                                if (alreadySelected)
                                {
                                    Selection.Remove(key);
                                }
                                else
                                {
                                    Selection.Add(key);
                                }
                                await SelectionChanged.InvokeAsync(null).ConfigureAwait(true);
                            }
                            else if (!alreadySelected)                             // single selection
                            {
                                Selection.Clear();
                                Selection.Add(key);
                                await SelectionChanged.InvokeAsync(null).ConfigureAwait(true);
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Returns an array of all currently selected items.
 /// </summary>
 public TItem[] GetSelectedItems()
 {
     return(KeyField == null ? new TItem[0] : ItemsToDisplay.Where(x => Selection.Contains(KeyField(x).ToString())).ToArray());
 }
Exemplo n.º 10
0
        private void ProcessInteractions()
        {
            var groupedItems = ItemsToDisplay.GroupBy(i => i.Position);

            foreach (var items in groupedItems)
            {
                if (items.Count() > 1)
                {
                    if (items.Any(i => i.Type == ItemType.Bullet))
                    {
                        var bullets = new List <Item>();
                        if (items.Any(i => i.Type == ItemType.Player))
                        {
                            var bulletArray = items.Where(i => i.Type == ItemType.Bullet).ToArray();
                            foreach (var item in bulletArray)
                            {
                                var bullet = (Bullet)item;
                                if (bullet.Holder == ItemType.Enemy)
                                {
                                    bullets.Add(item);
                                    IsActive = false;
                                    GameOver?.Invoke(this, null);
                                }
                            }
                        }
                        else if (items.Any(i => i.Type == ItemType.Enemy))
                        {
                            var bulletArray = items.Where(i => i.Type == ItemType.Bullet).ToArray();
                            foreach (var item in bulletArray)
                            {
                                var bullet = (Bullet)item;
                                if (bullet.Holder == ItemType.Player)
                                {
                                    Player.Score += 20;
                                    bullets.Add(item);
                                    var enemies = items.Where(i => i.Type == ItemType.Enemy).ToArray();
                                    KillEnemy(enemies);
                                }
                            }
                        }
                        else if (items.Any(i => i.Type == ItemType.DammageableWall))
                        {
                            var bulletArray = items.Where(i => i.Type == ItemType.Bullet).ToArray();
                            foreach (var item in bulletArray)
                            {
                                var bullet = (Bullet)item;
                                if (bullet.Holder == ItemType.Player)
                                {
                                    Player.Score += 5;
                                    bullets.Add(item);
                                    var itemWall = (DammageableBarrier)items.FirstOrDefault(i => i.Type == ItemType.DammageableWall);
                                    itemWall.Dammaged = true;
                                }
                            }
                        }
                        else if (items.Any(i => i.Type == ItemType.Wall))
                        {
                            var itemWall = (Barrier)items.FirstOrDefault(i => i.Type == ItemType.Wall);
                            itemWall.IsDirty = true;
                            var bulletArray = items.Where(i => i.Type == ItemType.Bullet).ToArray();
                            foreach (var item in bulletArray)
                            {
                                bullets.Add(item);
                            }
                        }
                        else if (items.Any(i => i.Type == ItemType.Water))
                        {
                            var itemWater = (Water)items.FirstOrDefault(i => i.Type == ItemType.Water);
                            itemWater.IsDirty = true;
                        }
                        KillBullet(bullets.ToArray());
                    }
                    else if (items.Any(i => i.Type == ItemType.Player))
                    {
                        if (items.Any(i => i.Type == ItemType.Enemy))
                        {
                            IsActive = false;
                            GameOver?.Invoke(this, null);
                        }
                        else if (items.Any(i => i.Type == ItemType.Bonus))
                        {
                            Player.Score += 50;
                            var bonuses = items.Where(i => i.Type == ItemType.Bonus).ToArray();
                            KillBonus(bonuses);
                        }
                    }
                }
            }
        }