Exemple #1
0
        private BulkObservableCollection <BaseItem> CreateDiagnosticAndGeneratorItems(ProjectId projectId, string language, CompilationOptions options, AnalyzerConfigOptionsResult?analyzerConfigOptions)
        {
            // Within an analyzer assembly, an individual analyzer may report multiple different diagnostics
            // with the same ID. Or, multiple analyzers may report diagnostics with the same ID. Or a
            // combination of the two may occur.
            // We only want to show one node in Solution Explorer for a given ID. So we pick one, but we need
            // to be consistent in which one we pick. Diagnostics with the same ID may have different
            // descriptions or messages, and it would be strange if the node's name changed from one run of
            // VS to another. So we group the diagnostics by ID, sort them within a group, and take the first
            // one.

            Contract.ThrowIfFalse(HasItems);

            var collection = new BulkObservableCollection <BaseItem>();

            collection.AddRange(
                AnalyzerReference.GetAnalyzers(language)
                .SelectMany(a => _diagnosticAnalyzerService.AnalyzerInfoCache.GetDiagnosticDescriptors(a))
                .GroupBy(d => d.Id)
                .OrderBy(g => g.Key, StringComparer.CurrentCulture)
                .Select(g =>
            {
                var selectedDiagnostic = g.OrderBy(d => d, s_comparer).First();
                var effectiveSeverity  = selectedDiagnostic.GetEffectiveSeverity(options, analyzerConfigOptions);
                return(new DiagnosticItem(projectId, AnalyzerReference, selectedDiagnostic, effectiveSeverity, language, CommandHandler));
            }));

            collection.AddRange(
                AnalyzerReference.GetGenerators(language)
                .Select(g => new SourceGeneratorItem(projectId, g, AnalyzerReference)));

            return(collection);
        }
Exemple #2
0
        public void AddRangeTest()
        {
            CollectionChangedEventArgs args = null;

            var collection = new BulkObservableCollection <int>();

            collection.CollectionChanged += (sender, e) => args = e;

            collection.Add(1);
            Assert.IsNotNull(args);
            Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
            Assert.AreEqual(1, args.NewItems.Count);
            Assert.AreEqual(1, args.NewItems[0]);

            args = null;
            collection.AddRange(new[] { 2, 3, 4, 5 });
            Assert.IsNotNull(args);
            Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
            Assert.AreEqual(4, args.NewItems.Count);
            Assert.AreEqual(2, args.NewItems[0]);
            Assert.AreEqual(5, args.NewItems[3]);
            Assert.AreEqual(5, collection.Count);

            args = null;
            collection.AddRange(new[] { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
            Assert.IsNotNull(args);
            Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
            Assert.AreEqual(10, args.NewItems.Count);
            Assert.AreEqual(6, args.NewItems[0]);
            Assert.AreEqual(15, args.NewItems[9]);
            Assert.AreEqual(15, collection.Count);
        }
Exemple #3
0
        public void OperationCollapseTest()
        {
            var argsList   = new List <CollectionChangedEventArgs>();
            var collection = new BulkObservableCollection <int>();

            collection.CollectionChanged += (sender, e) => argsList.Add(e);

            collection.BeginBatch();
            collection.Add(1);                      //  \
            collection.Add(2);                      //   > collapse into 1 add
            collection.Add(3);                      //  /
            collection.Remove(1);                   //  \
            collection.Remove(2);                   //   > collapse into 1 remove
            collection.Remove(3);                   //  /
            collection.AddRange(new[] { 1, 2, 3 }); //  \
            collection.Add(4);                      //   > collapse into 1 add
            collection.AddRange(new[] { 5, 6, 7 }); //  /
            collection.Remove(7);                   //  \
            collection.Remove(6);                   //   > collapse into 1 clear
            collection.Clear();                     //  /
            collection.Add(1);                      //  \
            collection.Add(2);                      //   > collapse into 1 add
            collection.Add(3);                      //  /
            collection[0] = 1337;                   // no collapse
            collection.Remove(1337);                // no collapse
            collection.Move(0, 1);                  // no collapse
            collection.Clear();                     // no collapse
            Assert.AreEqual(0, argsList.Count);
            collection.EndBatch();

            Assert.AreEqual(9, argsList.Count);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[0].Action);
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, argsList[0].NewItems);

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, argsList[1].Action);
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, argsList[1].OldItems);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[2].Action);
            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5, 6, 7 }, argsList[2].NewItems);

            Assert.AreEqual(NotifyCollectionChangedAction.Reset, argsList[3].Action);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[4].Action);
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, argsList[4].NewItems);

            Assert.AreEqual(NotifyCollectionChangedAction.Replace, argsList[5].Action);

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, argsList[6].Action);

            Assert.AreEqual(NotifyCollectionChangedAction.Move, argsList[7].Action);

            Assert.AreEqual(NotifyCollectionChangedAction.Reset, argsList[8].Action);
        }
        public ChatUserListStatsMessage(IEnumerable <EmployeeSearchResult> employees)
        {
            _employees.AddRange(employees);
            EmployeesView = CollectionViewSource.GetDefaultView(_employees);

            EmployeesView.SortDescriptions.Add(new SortDescription(nameof(EmployeeSearchResult.DisplayName), ListSortDirection.Ascending));
        }
        /// <summary>
        /// Initializes a new instance with the specified properties.
        /// </summary>
        /// <param name="moniker">The unique, non-localized identifier for the
        /// completion set.</param>
        /// <param name="displayName">The localized name of the completion set.
        /// </param>
        /// <param name="applicableTo">The tracking span to which the
        /// completions apply.</param>
        /// <param name="completions">The list of completions.</param>
        /// <param name="options">The options to use for filtering and
        /// selecting items.</param>
        /// <param name="comparer">The comparer to use to order the provided
        /// completions.</param>
        public FuzzyCompletionSet(string moniker, string displayName, ITrackingSpan applicableTo,
                                  IEnumerable <DynamicallyVisibleCompletion> completions,
                                  CompletionOptions options, IComparer <Completion> comparer,
                                  Func <string, IEnumerable <DynamicallyVisibleCompletion> > deferredLoadCallback) :
            base(moniker, displayName, applicableTo, null, null)
        {
            _options         = options;
            _initialComparer = comparer;
            _completions     = new BulkObservableCollection <Completion>();
            _loadedDeferredCompletionSubsets = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            _deferredLoadCallback            = deferredLoadCallback;
            _completions.AddRange(completions
                                  .Where(c => c != null && !string.IsNullOrWhiteSpace(c.DisplayText))
                                  .OrderBy(c => c, comparer)
                                  );
            _comparer = new FuzzyStringMatcher(options.SearchMode);

            _shouldFilter       = options.FilterCompletions;
            _shouldHideAdvanced = options.HideAdvancedMembers && !_completions.All(IsAdvanced);

            if (_shouldFilter | _shouldHideAdvanced)
            {
                _filteredCompletions = new WritableFilteredObservableCollection <Completion>(_completions);

                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    c.Visible = !_shouldHideAdvanced || !IsAdvanced(c);
                }
                _filteredCompletions.Filter(IsVisible);
            }
        }
Exemple #6
0
        public void BeginEndBulkOperationTest()
        {
            CollectionChangedEventArgs args = null;

            var collection = new BulkObservableCollection <int>();

            collection.CollectionChanged += (sender, e) => args = e;

            collection.BeginBatch();
            collection.Add(1);
            Assert.IsNull(args);
            collection.Add(2);
            Assert.IsNull(args);
            collection.EndBatch();
            Assert.IsNotNull(args);

            args = null;
            collection.BeginBatch();
            collection.AddRange(new[] { 1, 2, 3 });
            Assert.IsNull(args);
            collection.Add(4);
            Assert.IsNull(args);
            collection.Remove(4);
            Assert.IsNull(args);
            collection.Insert(0, 5);
            Assert.IsNull(args);
            collection.Move(0, 1);
            Assert.IsNull(args);
            collection.RemoveAt(0);
            Assert.IsNull(args);
            collection.Clear();
            Assert.IsNull(args);
            collection.EndBatch();
            Assert.IsNotNull(args);
        }
Exemple #7
0
        /// <summary>
        /// Discover logs and process them.
        /// </summary>
        private void FindLogs(CancellationToken cancellationToken)
        {
            LogDataProcessor.UnscheduleAll();

            // TODO: Fix the counters being off if a log is currently being processed
            LogDataProcessor.ResetTotalCounters();
            try
            {
                var newLogs = new List <LogData>();

                //foreach (var log in LogFinder.GetTesting())
                foreach (var log in Settings.LogRootPaths.SelectMany(x => LogFinder.GetFromDirectory(x, LogCache)))
                {
                    newLogs.Add(log);

                    if (log.ParsingStatus == ParsingStatus.Parsed)
                    {
                        ApiProcessor.RegisterLog(log);
                    }
                    else
                    {
                        LogDataProcessor.Schedule(log);
                    }

                    cancellationToken.ThrowIfCancellationRequested();
                }

                Application.Instance.Invoke(() => { logs.AddRange(newLogs); });
            }
            catch (Exception e) when(!(e is OperationCanceledException))
            {
                Application.Instance.Invoke(() =>
                {
                    MessageBox.Show(this, $"Logs could not be found.\nReason: {e.Message}", "Log Discovery Error",
                                    MessageBoxType.Error);
                });
            }

            if (LogCache.ChangedSinceLastSave)
            {
                LogCache.SaveToFile();
            }
        }
Exemple #8
0
        public void LoadFile(String filename)
        {
            Filename = Path.GetFileName(filename);
            FullPath = filename;

            if (_watch != null)
            {
                _watch.Changed -= watch_Changed;
            }

            _watch = new FileSystemWatcher();

            _watch.Path                = Path.GetDirectoryName(filename);
            _watch.Filter              = Filename;
            _watch.NotifyFilter        = NotifyFilters.LastWrite;
            _watch.Changed            += watch_Changed;
            _watch.EnableRaisingEvents = true;

            FileInfo info = new FileInfo(filename);

            Created     = info.CreationTime;
            LastUpdated = info.LastWriteTime;
            FileSize    = info.Length;

            var tempLines = FileHelper.ReadLines(filename);
            BulkObservableCollection <LogLineData> temp = new BulkObservableCollection <LogLineData>();

            temp.AddRange(tempLines, (line) => CreateLineData(line));

            Lines = temp;

            //create and start timer if null
            if (_timer != null)
            {
                return;
            }

            _timer           = new Timer(50);
            _timer.Elapsed  += _timer_Elapsed;
            _timer.AutoReset = false;
        }
        /// <summary>
        /// Initializes a new instance with the specified properties.
        /// </summary>
        /// <param name="moniker">The unique, non-localized identifier for the
        /// completion set.</param>
        /// <param name="displayName">The localized name of the completion set.
        /// </param>
        /// <param name="applicableTo">The tracking span to which the
        /// completions apply.</param>
        /// <param name="completions">The list of completions.</param>
        /// <param name="options">The options to use for filtering and
        /// selecting items.</param>
        /// <param name="comparer">The comparer to use to order the provided
        /// completions.</param>
        /// <param name="matchInsertionText">If true, matches user input against
        /// the insertion text; otherwise, uses the display text.</param>
        public FuzzyCompletionSet(
            string moniker,
            string displayName,
            ITrackingSpan applicableTo,
            IEnumerable <DynamicallyVisibleCompletion> completions,
            CompletionOptions options,
            IComparer <Completion> comparer,
            bool matchInsertionText = false
            ) :
            base(moniker, displayName, applicableTo, null, null)
        {
            _matchInsertionText = matchInsertionText;
            _completions        = new BulkObservableCollection <Completion>();
            _completions.AddRange(completions
                                  .Where(c => c != null && !string.IsNullOrWhiteSpace(c.DisplayText))
                                  .OrderBy(c => c, comparer)
                                  );
            _comparer = new FuzzyStringMatcher(options.SearchMode);

            _shouldFilter       = options.FilterCompletions;
            _shouldHideAdvanced = options.HideAdvancedMembers && !_completions.All(IsAdvanced);

            if (!_completions.Any())
            {
                _completions = null;
            }

            if (_completions != null && _shouldFilter | _shouldHideAdvanced)
            {
                _filteredCompletions = new FilteredObservableCollection <Completion>(_completions);

                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    c.Visible = !_shouldHideAdvanced || !IsAdvanced(c);
                }
                _filteredCompletions.Filter(IsVisible);
            }

            CommitByDefault = DefaultCommitByDefault;
        }
        /// <summary>
        /// Initializes a new instance with the specified properties.
        /// </summary>
        /// <param name="moniker">The unique, non-localized identifier for the completion set.</param>
        /// <param name="displayName">The localized name of the completion set.</param>
        /// <param name="applicableTo">The tracking span to which the completions apply.</param>
        /// <param name="completions">The list of completions.</param>
        /// <param name="options">The options to use for filtering and selecting items.</param>
        /// <param name="comparer">The comparer to use to order the provided completions.</param>
        /// <param name="matchInsertionText">If true, matches user input against
        /// the insertion text; otherwise, uses the display text.</param>
        public FuzzyCompletionSet(
            string moniker,
            string displayName,
            ITrackingSpan applicableTo,
            IEnumerable<DynamicallyVisibleCompletion> completions,
            IComparer<Completion> comparer,
            bool matchInsertionText = false
        ) :
            base(moniker, displayName, applicableTo, null, null) {
            _matchInsertionText = matchInsertionText;
            _completions = new BulkObservableCollection<Completion>();
            _completions.AddRange(completions
                .Where(c => c != null && !string.IsNullOrWhiteSpace(c.DisplayText))
                .OrderBy(c => c, comparer)
            );
            _comparer = new FuzzyStringMatcher(FuzzyMatchMode.Default);

#if FALSE
            _shouldFilter = options.FilterCompletions;
            _shouldHideAdvanced = options.HideAdvancedMembers && !_completions.All(IsAdvanced);
#endif
            _shouldFilter = true;
            _shouldHideAdvanced = false;

            if (_shouldFilter | _shouldHideAdvanced) {
                _filteredCompletions = new FilteredObservableCollection<Completion>(_completions);

                foreach (var c in _completions.Cast<DynamicallyVisibleCompletion>()) {
                    c.Visible = !_shouldHideAdvanced || !IsAdvanced(c);
                }
                _filteredCompletions.Filter(IsVisible);
            }
        }
Exemple #11
0
 public FilteredCompletionSet(string moniker, ITrackingSpan applicableTo, IEnumerable <Completion> completions, IEnumerable <Completion> completionBuilders, IReadOnlyList <IIntellisenseFilter> filters)
     : base(moniker, "All", applicableTo, completions, completionBuilders, filters)
 {
     _completions.AddRange(completions);
     currentCompletions = new FilteredObservableCollection <Completion>(_completions);
 }
Exemple #12
0
        public void GanttGridTests()
        {
            KProcess.Ksmed.Business.Tests.SampleData.ClearDatabaseThenImportDefaultProject();

            // On récupère les données
            var service = new AnalyzeService();

            var mre = new ManualResetEvent(false);

            var collection     = new BulkObservableCollection <DataTreeGridItem>();
            var actionsManager = new GridActionsManager(collection, null, null);

            actionsManager.ChangeView(Core.GanttGridView.WBS, null);

            var categories = new BulkObservableCollection <ActionCategory>();

            Video[]    videos    = null;
            Scenario[] scenarios = null;
            Scenario   scenario  = null;

            Exception ex = null;

            service.GetAcquireData(SampleData.GetProjectId(),
                                   data =>
            {
                categories.AddRange(data.Categories);
                videos = data.Videos;

                scenarios = data.Scenarios;

                scenario = scenarios.First();

                foreach (var action in scenario.Actions)
                {
                    action.StartTracking();
                }

                mre.Set();
            },
                                   e =>
            {
                ex = e;
                mre.Set();
            });

            mre.WaitOne();

            AssertExt.IsExceptionNull(ex);

            actionsManager.RegisterInitialActions(scenario.Actions);

            Assert.IsTrue(scenario.Actions.Count > 1);
            Assert.IsTrue(collection.Count > 1);
            Assert.IsTrue(videos.Length > 0);
            Assert.IsTrue(scenario.Actions[1].Video != null);

            // Capturons l'état de toutes les éléments
            var originalValues = GetCurrentValues(scenario.Actions, categories, videos);

            Modify(actionsManager, collection, scenario);

            var modifiedValues = GetCurrentValues(scenario.Actions, categories, videos);

            Assert.IsFalse(AreDumpsEqual(originalValues, modifiedValues));

            // On annule les changements
            actionsManager.UnregisterAllItems();
            ObjectWithChangeTrackerExtensions.CancelChanges(scenario.Actions, categories, videos);

            var revertedValues = GetCurrentValues(scenario.Actions, categories, videos);

            Assert.IsTrue(AreDumpsEqual(originalValues, revertedValues));



            // On recommence
            actionsManager.RegisterInitialActions(scenario.Actions);
            Modify(actionsManager, collection, scenario);

            modifiedValues = GetCurrentValues(scenario.Actions, categories, videos);

            Assert.IsFalse(AreDumpsEqual(originalValues, modifiedValues));

            // On annule les changements
            actionsManager.UnregisterAllItems();
            ObjectWithChangeTrackerExtensions.CancelChanges(scenario.Actions, categories, videos);

            revertedValues = GetCurrentValues(scenario.Actions, categories, videos);

            Assert.IsTrue(AreDumpsEqual(originalValues, revertedValues));
        }
        public override void Recalculate()
        {
            if (_isDismissed)
            {
                throw (new InvalidOperationException("Cannot recalculate.  The session is dismissed."));
            }

            // Clear out the active set of signatures.
            _activeSignatures.Clear();

            // In order to find the signatures to be displayed in this session, we'll need to go through each of the signature help
            // providers and ask them for signatures at the trigger point.

            List <ISignature> signatures = new List <ISignature>();

            foreach (ISignatureHelpSource provider in _componentContext.GetSignatureHelpSources(this))
            {
                provider.AugmentSignatureHelpSession(this, signatures);

                // The source could have done anything to the session.  Let's verify that we're still alive and well.
                if (this.IsDismissed)
                {
                    return;
                }
            }

            if (signatures != null)
            {
                _activeSignatures.AddRange(signatures);
            }

            // If we ended-up with zero signatures, that's it.  We need to dismiss and get out of here.
            if (_activeSignatures.Count == 0)
            {
                this.Dismiss();
                return;
            }

            // Let's determine which signature should be "selected" before we find a presenter.
            if (!_activeSignatures.Contains(_selectedSignature))
            {
                // The old selection is no longer valid (or we never had one).  Let's select the first signature.
                this.SelectedSignature = _activeSignatures[0];
            }

            // If we don't already have a presenter for this session, find one.
            if (base.presenter == null)
            {
                base.presenter = FindPresenter(this, _componentContext.OrderedIntellisensePresenterProviderExports, _componentContext.GuardedOperations);
                if (base.presenter != null)
                {
                    this.RaisePresenterChanged();
                }
                else
                {
                    this.Dismiss();
                    return;
                }
            }

            base.RaiseRecalculated();
        }
Exemple #14
0
        /// <summary>
        /// Initializes a new instance with the specified properties.
        /// </summary>
        /// <param name="moniker">The unique, non-localized identifier for the
        /// completion set.</param>
        /// <param name="displayName">The localized name of the completion set.
        /// </param>
        /// <param name="applicableTo">The tracking span to which the
        /// completions apply.</param>
        /// <param name="completions">The list of completions.</param>
        /// <param name="options">The options to use for filtering and
        /// selecting items.</param>
        /// <param name="comparer">The comparer to use to order the provided
        /// completions.</param>
        public FuzzyCompletionSet(string moniker, string displayName, ITrackingSpan applicableTo, IEnumerable<DynamicallyVisibleCompletion> completions, CompletionOptions options, IComparer<Completion> comparer)
            : base(moniker, displayName, applicableTo, null, null)
        {
            _completions = new BulkObservableCollection<Completion>();
            _completions.AddRange(completions.OrderBy(c => c, comparer));
            _comparer = new FuzzyStringMatcher(options.SearchMode);

            _shouldFilter = options.FilterCompletions;
            _shouldHideAdvanced = options.HideAdvancedMembers;

            if (_shouldFilter | _shouldHideAdvanced) {
                _filteredCompletions = new FilteredObservableCollection<Completion>(_completions);

                foreach (var c in _completions.Cast<DynamicallyVisibleCompletion>()) {
                    c.Visible = !_shouldHideAdvanced || !IsAdvanced(c);
                }
                _filteredCompletions.Filter(IsVisible);
            }
        }