Пример #1
0
            protected override UpdatedItem DoUpdate(JObject target, ISourceMatch source)
            {
                var propertyName = this.GetPropertyName(source);

                if (!this.ShouldMap(target.ContainsKey(propertyName)))
                {
                    return(UpdatedItem.Notupdated);
                }

                if (this.IsArray)
                {
                    var targetProperty = target.Property(propertyName);
                    if (targetProperty == null || !(targetProperty.Value is JArray targetArray))
                    {
                        targetArray          = new JArray();
                        target[propertyName] = targetArray;
                    }

                    var targetElement = source.Element.DeepClone();
                    targetArray.Add(targetElement);
                    return(targetElement.AsUpdated());
                }

                return(Merging.MergeToProperty(target, propertyName, source.Element).AsUpdated());
            }
        public void MergeMatchRecords()
        {
            foreach (RecordedMatch record in Records)
            {
                Merging.AdjustTeamInfo(Event, record);
            }

            Match merged = Merging.Merge(Event,
                                         Records[0], Records[1], Records[2],
                                         Records[3], Records[4], Records[5]);

            int index = Event.Matches.FindIndex((m) => m.Number == merged.Number);

            if (index != -1)
            {
                Event.Matches[index] = merged;
            }
            else
            {
                Event.Matches.Add(merged);
            }

            ScoutingJson.SaveEvent(Event, SavePath + Event.EventName +
                                   ScoutingJson.EventExtension);

            ArchiveRecords(merged.Number);
            Records = new RecordedMatch[6];
            OnPropertyChanged("CanMerge");
        }
Пример #3
0
        public void IterativeMergingTest()
        {
            int[] xs = { 3, 2, 1, 6, 5, 9, 4 };
            var   ms = new Merging <int>();

            ms.IterativeSort(xs);
            Assert.True(Sorting <int> .IsSorted(xs));
        }
Пример #4
0
        async Task <int> FetchNewMessages(IChatMessageOptions options, CancellationToken token)
        {
            IEnumerable <IChatMessage> messages = null;
            int count = 0;

            if (!token.IsCancellationRequested)
            {
                await ssFetch.WaitAsync(token);

                try
                {
                    messages = await GitterApi.GetChatMessages(ChatRoom.Id, options);

                    if (messages is object)
                    {
                        count = messages.Count();
                        if (!string.IsNullOrWhiteSpace(options.BeforeId))
                        {
                            Messages.InsertRange(0, RemoveDuplicates(Messages, messages));
                        }
                        else
                        {
                            Messages.AddRange(RemoveDuplicates(Messages, messages));
                        }

                        await Invoke(StateHasChanged);

                        await Task.Delay(1);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"RoomMessages.FetchNewMessages: {e.GetBaseException().Message}");
                }
                finally
                {
                    ssFetch.Release();
                }
            }
            return(count);

            IEnumerable <IChatMessage> RemoveDuplicates(IEnumerable <IChatMessage> Existing, IEnumerable <IChatMessage> Merging)
            {
                IEnumerable <string> ExistingIds = Existing.Select(m => m.Id);

                return(Merging.Where(m => !ExistingIds.Contains(m.Id)));
            }
        }
Пример #5
0
            public async Task no_merge_options_should()
            {
                var protection = new Protection {
                    Loader = loader
                };
                IValidation merging = new Merging {
                    Loader = loader
                };

                var ex = await Assert.ThrowsAsync <Exception>(() => merging.Validate());

                Assert.Contains(
                    "foo has no configured options to merge!"
                    , ex.Message
                    );
            }