示例#1
0
                /// <summary>
                ///     Called to check whether or not this instance can close.
                /// </summary>
                /// <param name="callback">The implementor calls this action with the result of the close check.</param>
                public override void CanClose(Action <bool> callback)
                {
                    CloseStrategy.Execute(items.ToList(), (canClose, closable) => {
                        if (!canClose && closable.Any())
                        {
                            closable.OfType <IDeactivate>().Apply(x => x.Deactivate(true));
                            items.RemoveRange(closable);
                        }

                        callback(canClose);
                    });
                }
示例#2
0
        //public void ShowTemplateMonsters()
        //{
        //    WindowManager wm = new WindowManager();

        //    Dictionary<string, object> settings = new Dictionary<string, object>();
        //    settings.Add("Height", 600);
        //    settings.Add("Width", 1000);
        //    settings.Add("SizeToContent", System.Windows.SizeToContent.Manual);

        //    TemplateMonsterListViewModel tmlvm = new TemplateMonsterListViewModel(this);
        //    wm.ShowDialog(tmlvm, null, settings);
        //}

        public void Save()
        {
            TextWriter writer = new StreamWriter(System.IO.Path.Combine(_dataPath, "data.json"));

            Models.SystemModel sys = new Models.SystemModel();

            sys.Monsters  = _monsters.ToList();
            sys.Traits    = _traits.ToList();
            sys.Templates = _templates.ToList();

            writer.Write(JsonConvert.SerializeObject(sys));
            writer.Flush();
            writer.Close();
        }
示例#3
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            services = Context.Client;
            var result = services.GetAll <UserView>().Where(x => x.team_id == Context.User.team_id);

            Users = new BindableCollection <UserView>(result);

            //Govno
            var team_info = services.Get <TeamView>(Context.User.team_id);

            txtTeamName.Text = team_info.name;

            panelView.Back.Click      += BackButton;
            panelEmployees.ItemsSource = Users.ToList();
        }
示例#4
0
                /// <summary>
                /// Called to check whether or not this instance can close.
                /// </summary>
                /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                public override async Task <bool> CanCloseAsync(CancellationToken cancellationToken)
                {
                    ICloseResult <T> closeResult = await CloseStrategy.ExecuteAsync(_items.ToList(), cancellationToken);

                    if (!closeResult.CloseCanOccur && closeResult.Children.Any())
                    {
                        foreach (IDeactivate deactivate in closeResult.Children.OfType <IDeactivate>())
                        {
                            await deactivate.DeactivateAsync(true, cancellationToken);
                        }

                        _items.RemoveRange(closeResult.Children);
                    }

                    return(closeResult.CloseCanOccur);
                }
示例#5
0
        protected override Task Poll()
        {
            if (!api.IsLoggedIn)
            {
                return(base.Poll());
            }

            var tcs = new TaskCompletionSource <bool>();

            pollReq?.Cancel();
            pollReq = new GetRoomsRequest(currentFilter.PrimaryFilter);

            pollReq.Success += result =>
            {
                // Remove past matches
                foreach (var r in rooms.ToList())
                {
                    if (result.All(e => e.RoomID.Value != r.RoomID.Value))
                    {
                        rooms.Remove(r);
                    }
                }

                for (int i = 0; i < result.Count; i++)
                {
                    var r = result[i];
                    r.Position = i;

                    update(r, r);
                    addRoom(r);
                }

                RoomsUpdated?.Invoke();

                tcs.SetResult(true);
            };

            pollReq.Failure += _ => tcs.SetResult(false);

            api.Queue(pollReq);

            return(tcs.Task);
        }
示例#6
0
        public async Task GetProcessListAsync(BindableCollection <ProcComboboxItem> data)
        {
            await Task.Run(() =>
            {
                BindableCollection <ProcComboboxItem> tmpCollection = new BindableCollection <ProcComboboxItem>();

                foreach (Process proc in ProcessEnumerable())
                {
                    try
                    {
                        var item = new ProcComboboxItem()
                        {
                            proc  = proc,
                            Title = proc.MainWindowTitle,
                            Icon  = Utils.PEIcon2BitmapImage(proc.GetMainModuleFileName())
                        };
                        tmpCollection.Add(item);
                        if (data.Contain(item))
                        {
                            continue;
                        }
                        else
                        {
                            data.Add(item);
                        }
                    }
                    catch (Win32Exception ex)
                    {
                        // Casue by `GetMainModuleFileName()`
                        // Access Denied. 32bit -> 64bit module
                        log.Warn(ex.Message);
                    }
                }
                foreach (var i in data.ToList())
                {
                    if (!tmpCollection.Contain(i))
                    {
                        data.Remove(i);
                    }
                }
            }).ConfigureAwait(false);
        }
示例#7
0
                /// <summary>
                /// Initializes a new instance of the <see cref="Conductor&lt;T&gt;.Collection.AllActive"/> class.
                /// </summary>
                public AllActive()
                {
                    items.CollectionChanged += (s, e) =>
                    {
                        switch (e.Action)
                        {
                        case NotifyCollectionChangedAction.Add:
                            e.NewItems.OfType <IChild>().Apply(x => x.Parent = this);
                            break;

                        case NotifyCollectionChangedAction.Remove:
                            e.OldItems.OfType <IChild>().Apply(x => x.Parent = null);
                            break;

                        case NotifyCollectionChangedAction.Replace:
                            e.NewItems.OfType <IChild>().Apply(x => x.Parent = this);
                            e.OldItems.OfType <IChild>().Apply(x => x.Parent = null);
                            break;

                        case NotifyCollectionChangedAction.Reset:
                            items.OfType <IChild>().Apply(x => x.Parent = this);
                            break;
                        }
                    };

                    CloseGuard = () =>
                    {
                        var tcs = new TaskCompletionSource <bool>();
                        CloseStrategy.Execute(items.ToList(), (canClose, closable) =>
                        {
                            if (!canClose && closable.Any())
                            {
                                closable.OfType <IDeactivate>().Apply(x => x.Deactivate(true));
                                items.RemoveRange(closable);
                            }

                            tcs.SetResult(canClose);
                        });
                        return(tcs.Task);
                    };
                }
                /// <summary>
                /// Called to check whether or not this instance can close.
                /// </summary>
                /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                public override async Task <bool> CanCloseAsync(CancellationToken cancellationToken)
                {
                    var closeResult = await CloseStrategy.ExecuteAsync(_items.ToArray(), cancellationToken);

                    if (!closeResult.CloseCanOccur && closeResult.Children.Any())
                    {
                        var closable = closeResult.Children;

                        if (closable.Contains(ActiveItem))
                        {
                            var list = _items.ToList();
                            var next = ActiveItem;
                            do
                            {
                                var previous = next;
                                next = DetermineNextItemToActivate(list, list.IndexOf(previous));
                                list.Remove(previous);
                            } while (closable.Contains(next));

                            var previousActive = ActiveItem;
                            await ChangeActiveItemAsync(next, true, cancellationToken);

                            _items.Remove(previousActive);

                            var stillToClose = closable.ToList();
                            stillToClose.Remove(previousActive);
                            closable = stillToClose;
                        }

                        foreach (var deactivate in closable.OfType <IActivate>())
                        {
                            await deactivate.DeactivateAsync(true, cancellationToken);
                        }

                        _items.RemoveRange(closable);
                    }

                    return(closeResult.CloseCanOccur);
                }
        public void GetAllSelection(IList <NodeItem> selected)
        {
            List <NodeItem> removeList = new List <NodeItem>();

            foreach (var item in selected)
            {
                if (!_classes.Any(o => o.Name == item.ClassificationName))
                {
                    removeList.Add(item);
                }
            }
            foreach (var item in removeList)
            {
                selected.Remove(item);
            }
            SelectedClasses.Clear();
            if (selected.Count > 0)
            {
                BindableCollection <NodeItem> newNodes = new BindableCollection <NodeItem>(
                    NodeItem.RestructureFlatNodes(_classes.ToList(), selected));
                SelectedClasses = newNodes;
            }
            UpdatePropNotice(_selectedClasses);
        }
示例#10
0
                /// <summary>
                /// Initializes a new instance of the <see cref="Conductor&lt;T&gt;.Collection.OneActive"/> class.
                /// </summary>
                public OneActive()
                {
                    items.CollectionChanged += (s, e) =>
                    {
                        switch (e.Action)
                        {
                        case NotifyCollectionChangedAction.Add:
                            e.NewItems.OfType <IChild>().Apply(x => x.Parent = this);
                            break;

                        case NotifyCollectionChangedAction.Remove:
                            e.OldItems.OfType <IChild>().Apply(x => x.Parent = null);
                            break;

                        case NotifyCollectionChangedAction.Replace:
                            e.NewItems.OfType <IChild>().Apply(x => x.Parent = this);
                            e.OldItems.OfType <IChild>().Apply(x => x.Parent = null);
                            break;

                        case NotifyCollectionChangedAction.Reset:
                            items.OfType <IChild>().Apply(x => x.Parent = this);
                            break;
                        }
                    };

                    CloseGuard = () =>
                    {
                        var tcs = new TaskCompletionSource <bool>();
                        CloseStrategy.Execute(items.ToList(), (canClose, closable) =>
                        {
                            if (!canClose && closable.Any())
                            {
                                if (closable.Contains(ActiveItem))
                                {
                                    var list = items.ToList();
                                    var next = ActiveItem;
                                    do
                                    {
                                        var previous = next;
                                        next         = DetermineNextItemToActivate(list, list.IndexOf(previous));
                                        list.Remove(previous);
                                    } while (closable.Contains(next));

                                    var previousActive = ActiveItem;
                                    ChangeActiveItem(next, true);
                                    items.Remove(previousActive);

                                    var stillToClose = closable.ToList();
                                    stillToClose.Remove(previousActive);
                                    closable = stillToClose;
                                }

                                closable.OfType <IDeactivate>().Apply(x => x.Deactivate(true));
                                items.RemoveRange(closable);
                            }

                            tcs.SetResult(canClose);
                        });
                        return(tcs.Task);
                    };
                }
示例#11
0
        private void HoldCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            if (!IsActive)
            {
                return;
            }

            // stop the timer so that we don't try to re-fix this thing after moving to our
            // final destination.
            _dispatcherTimer.Stop();

            var dragIndex      = _currentIndex;
            var targetItem     = _pointIndex.Get(_currentIndex);
            var targetLocation = targetItem.Position.Top - _scrollViewer.VerticalOffset;
            var transform      = _dragImage.GetVerticalOffset().Transform;

            transform.Animate(null, targetLocation, CompositeTransform.TranslateYProperty, 200, 0, completed: () =>
            {
                // reshow the hidden item
                if (_cardView != null)
                {
                    _cardView.Opacity = 1.0;
                }

                // fade out the dragged image
                if (_dragImage != null)
                {
                    _dragImage.Animate(null, 0.0, UIElement.OpacityProperty, 700, 0,
                                       completed: () => { _dragImage.Visibility = Visibility.Collapsed; });
                }

                Complete();

                if (dragIndex == _initialIndex)
                {
                    return;
                }

                // move the dragged item
                if (_cardView == null)
                {
                    return;
                }

                var item = (CardViewModel)_cardView.DataContext;

                _cardsModel.Remove(item);
                _cardsModel.Insert(dragIndex, item);
                _cardsModel.Refresh();

                // fire off the event for subscribers
                _eventAggregator.Publish(CardPriorityChanged.Create(item.Id, dragIndex, _cardsModel.ToList()));
            });

            IsActive = false;
        }