コード例 #1
0
ファイル: PluginView.axaml.cs プロジェクト: nilaoda/Toolbox
        public PluginViewModel(
            PluginView view)
        {
            _view = view;

            IPluginService pluginService = Locator.Current.GetService <IPluginService>();

            _operationService = Locator.Current.GetService <OperationService>();

            OperationsCount = pluginService.OperationCollection.Count;

            OperationsList = new(
                pluginService.OperationCollection
                .GroupBy(x => x.OperationAttribute.Category)
                .Select(x =>
            {
                // Create OperationModel
                ObservableCollectionEx <OperationModel> models = new(
                    x.Select(y => new OperationModel
                {
                    Id = y.OperationAttribute.Id,
                    Name = y.OperationAttribute.Name,
                    Description = y.OperationAttribute.Description,
                    Rate = y.OperationAttribute.Rate,
                    Category = y.OperationAttribute.Category,
                    Author = y.OperationMeta.Author,
                    Type = y.OperationType
                }));

                // Create SearchStorage
                SearchStorage <OperationModel> searchStorage = new()
                {
                    Mode = CharParseMode.EnablePinyinSearch
                };
                searchStorage.Add(models, y => y.Name);

                return(new OperationModel
                {
                    Name = x.Key,
                    Children = models,
                    SearchStorage = searchStorage
                });
            }));

            this
            .ObservableForProperty(x => x.OperationSearchText)
            .Throttle(TimeSpan.FromSeconds(1))
            .Subscribe(x => OperationsList
                       .ForEach(y => y.Children.Reset(
                                    y.SearchStorage.Search(x.Value))));

            this
            .ObservableForProperty(x => x.OperationSearchText)
            .Subscribe(_ => ExpendTree());

            _isOperationSelected = this
                                   .WhenAnyValue(x => x.SelectedOperation)
                                   .Select(x => x?.Type != null)
                                   .ToProperty(this, x => x.IsOperationSelected);
        }
コード例 #2
0
 public static void Cancel()
 {
     StopTask = Task.Factory.StartNew(() => OperationsList.ForEach(x => x?.Abort()));
 }