示例#1
0
        public FieldCollection <T> Update(long fieldId, Func <T, T> updater)
        {
            Guard.NotNull(updater, nameof(updater));

            if (!ById.TryGetValue(fieldId, out var field))
            {
                return(this);
            }

            var newField = updater(field);

            if (ReferenceEquals(newField, field))
            {
                return(this);
            }

            if (!(newField is T typedField))
            {
                throw new InvalidOperationException($"Field must be of type {typeof(T)}");
            }

            return(Clone(clone =>
            {
                clone.fieldsOrdered = clone.fieldsOrdered.Replace(field, typedField);
            }));
        }
示例#2
0
                public static ById Create(int id)
                {
                    var inst = new ById();

                    inst.Id = id;
                    return(inst);
                }
        public void ById_Should_Map(ById byId, Beer beer)
        {
            _storage.Setup(m => m.SearchById(It.IsAny <string>())).ReturnsAsync(beer);


            var results = _sut.SearchById(byId).Result;

            results.BeerName.ShouldBe(beer.BeerName);
        }
示例#4
0
 void OnEnable()
 {
     if (Application.isPlaying)
     {
         entries = entries.Concat(betweenSceneReferences.Where(g => g.gameObject != null)).Where(g => g.gameObject != null).ToList();
         FixEntries();
         ById.Clear();
         ByObject.Clear();
         betweenSceneReferences = entries.Where(g => g.gameObject != null).ToList();
     }
 }
示例#5
0
        public FieldCollection <T> Remove(long fieldId)
        {
            if (!ById.TryGetValue(fieldId, out var field))
            {
                return(this);
            }

            return(Clone(clone =>
            {
                clone.fieldsOrdered = fieldsOrdered.Remove(field);
            }));
        }
示例#6
0
        public FieldCollection <T> Remove(long fieldId)
        {
            if (!ById.TryGetValue(fieldId, out _))
            {
                return(this);
            }

            return(Clone(clone =>
            {
                clone.fieldsOrdered = fieldsOrdered.Where(x => x.Id != fieldId).ToArray();
            }));
        }
示例#7
0
        public FieldCollection <T> Add(T field)
        {
            Guard.NotNull(field, nameof(field));

            if (ByName.ContainsKey(field.Name) || ById.ContainsKey(field.Id))
            {
                throw new ArgumentException($"A field with name '{field.Name}' and id {field.Id} already exists.", nameof(field));
            }

            return(Clone(clone =>
            {
                clone.fieldsOrdered = clone.fieldsOrdered.Add(field);
            }));
        }
示例#8
0
        public FieldCollection <T> Reorder(List <long> ids)
        {
            Guard.NotNull(ids, nameof(ids));

            if (ids.Count != fieldsOrdered.Length || ids.Any(x => !ById.ContainsKey(x)))
            {
                throw new ArgumentException("Ids must cover all fields.", nameof(ids));
            }

            return(Clone(clone =>
            {
                clone.fieldsOrdered = fieldsOrdered.OrderBy(f => ids.IndexOf(f.Id)).ToImmutableArray();
            }));
        }
示例#9
0
        private bool RemoveSubscriptionLocked(string From, string Id, bool RemoveFromThings)
        {
            if (!this.subscriptionsByJID.TryGetValue(From, out Dictionary <string, Subscription> ById))
            {
                return(false);
            }

            if (!ById.TryGetValue(Id, out Subscription Subscription))
            {
                return(false);
            }

            ById.Remove(Id);
            if (ById.Count == 0)
            {
                this.subscriptionsByJID.Remove(From);
            }

            if (!RemoveFromThings)
            {
                return(true);
            }

            Subscription.Active = false;

            foreach (ThingReference Ref in Subscription.Nodes)
            {
                if (!this.subscriptionsByThing.TryGetValue(Ref, out LinkedList <Subscription> Subscriptions))
                {
                    continue;
                }

                if (!Subscriptions.Remove(Subscription))
                {
                    continue;
                }

                if (Subscriptions.First == null)
                {
                    this.subscriptionsByThing.Remove(Ref);
                }
            }

            return(true);
        }
示例#10
0
        public FieldCollection <T> Add(T field)
        {
            Guard.NotNull(field, nameof(field));

            if (ByName.ContainsKey(field.Name))
            {
                throw new ArgumentException($"A field with name '{field.Name}' already exists.", nameof(field));
            }

            if (ById.ContainsKey(field.Id))
            {
                throw new ArgumentException($"A field with id {field.Id} already exists.", nameof(field));
            }

            return(Clone(clone =>
            {
                clone.fieldsOrdered = clone.fieldsOrdered.Union(Enumerable.Repeat(field, 1)).ToArray();
            }));
        }
示例#11
0
        /// <summary>
        /// 通过Id获取视频Url
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public async Task <CommonResult <VideoDto> > GetOnPalyUrl(ById value)
        {
            var result = new CommonResult <VideoDto>();

            try
            {
                var video = await _context.Videos.Where(x => x.Id == value.Id).FirstAsync();

                if (string.IsNullOrEmpty(video.Url))
                {
                    result.scode  = "200";
                    result.remark = "查询数据成功";
                    result.result = null;

                    return(result);
                }

                var analysisUrls = await _context.AnalysisUrls.ToArrayAsync();

                var analysisUrl = analysisUrls.OrderBy(x => Guid.NewGuid()).First();

                analysisUrl.PlayCount += 1;
                video.PlayCount       += 1;

                _context.SaveChanges();

                VideoDto videoUrl = new VideoDto
                {
                    Url = analysisUrl.Url + video.Url
                };

                result.scode  = "200";
                result.remark = "查询数据成功";
                result.result = videoUrl;
            }
            catch (Exception ex)
            {
                result.scode  = "500";
                result.remark = "服务器端错误:" + ex.Message;
            }

            return(result);
        }
示例#12
0
 public void Clear()
 {
     ById.Clear();
     ByObject.Clear();
     entries.Clear();
 }
示例#13
0
 public void RegisterSerializersForIdType(Type type)
 {
     ById.RegisterSerializerAndDeserializer(type);
 }
示例#14
0
        public async Task <CommonResult <VideoDto> > GetOnPalyUrl([FromBody] ById value)
        {
            var video = await _videoService.GetOnPalyUrl(value);

            return(video);
        }
        public void ById_Should_Call_Method(ById byid)
        {
            _sut.SearchById(byid);

            _storage.Verify(x => x.SearchById(It.IsAny <string>()), Times.Once);
        }
示例#16
0
            public override SkillRaceClassInfo ConvertTo(byte[] rawData, ref int id)
            {
                id = GetInt32(rawData, 0);

                int currentIndex = 0;

                var info = new SkillRaceClassInfo();

                info.Id = GetUInt32(rawData, currentIndex++);

                var skillId = (SkillId)GetUInt32(rawData, currentIndex++);

                info.RaceMask     = (RaceMask)GetUInt32(rawData, currentIndex++);
                info.ClassMask    = (ClassMask)GetUInt32(rawData, currentIndex++);
                info.Flags        = (SkillRaceClassFlags)GetUInt32(rawData, currentIndex++);
                info.MinimumLevel = GetUInt32(rawData, currentIndex++);

                int skillTierId = GetInt32(rawData, currentIndex++);

                if (skillTierId > 0)
                {
                    TierReader.Entries.TryGetValue(skillTierId, out info.Tiers);
                }

                info.SkillCostIndex = GetUInt32(rawData, currentIndex);

                // there are outdated skills referenced by this DBC (which do not exist anymore)
                info.SkillLine = ById.Get((uint)skillId);
                if (info.SkillLine != null)
                {
                    foreach (var classId in WCellConstants.AllClassIds)
                    {
                        if (classId >= ClassId.End)
                        {
                            continue;
                        }
                        var classMask = classId.ToMask();
                        foreach (var raceMask in WCellConstants.RaceTypesByMask.Keys)
                        {
                            RaceId raceId = WCellConstants.GetRaceType(raceMask);
                            if (info.RaceMask.HasAnyFlag(raceMask) && info.ClassMask.HasAnyFlag(classMask))
                            {
                                Dictionary <SkillId, SkillRaceClassInfo>[] byClass = RaceClassInfos[(int)raceId];
                                if (byClass == null)
                                {
                                    RaceClassInfos[(int)raceId] = byClass = new Dictionary <SkillId, SkillRaceClassInfo> [WCellConstants.ClassTypeLength];
                                }

                                Dictionary <SkillId, SkillRaceClassInfo> infos = byClass[(int)classId];
                                if (infos == null)
                                {
                                    byClass[(int)classId] = infos = new Dictionary <SkillId, SkillRaceClassInfo>();
                                }

                                SkillRaceClassInfo oldInf;
                                if (infos.TryGetValue(skillId, out oldInf))
                                {
                                    // double skill entry: Update races and classes, everything else is the same
                                    info.RaceMask  |= oldInf.RaceMask;
                                    info.ClassMask |= oldInf.ClassMask;
                                }
                                else
                                {
                                    // we can do this here because SkillTiers are the same for all races/classes
                                    if (info.SkillLine.Tiers.Id == 0 && info.Tiers.Id != 0)
                                    {
                                        info.SkillLine.Tiers = info.Tiers;
                                    }
                                }

                                infos[skillId] = info;
                            }
                        }
                    }
                }

                return(info);
            }
示例#17
0
            public override SkillRaceClassInfo ConvertTo(byte[] rawData, ref int id)
            {
                id = GetInt32(rawData, 0);
                int num1 = 0;
                SkillRaceClassInfo skillRaceClassInfo1 = new SkillRaceClassInfo();
                SkillRaceClassInfo skillRaceClassInfo2 = skillRaceClassInfo1;

                byte[] data1    = rawData;
                int    field1   = num1;
                int    num2     = field1 + 1;
                int    uint32_1 = (int)GetUInt32(data1, field1);

                skillRaceClassInfo2.Id = (uint)uint32_1;
                byte[]             data2               = rawData;
                int                field2              = num2;
                int                num3                = field2 + 1;
                SkillId            uint32_2            = (SkillId)GetUInt32(data2, field2);
                SkillRaceClassInfo skillRaceClassInfo3 = skillRaceClassInfo1;

                byte[] data3    = rawData;
                int    field3   = num3;
                int    num4     = field3 + 1;
                int    uint32_3 = (int)GetUInt32(data3, field3);

                skillRaceClassInfo3.RaceMask = (RaceMask)uint32_3;
                SkillRaceClassInfo skillRaceClassInfo4 = skillRaceClassInfo1;

                byte[] data4    = rawData;
                int    field4   = num4;
                int    num5     = field4 + 1;
                int    uint32_4 = (int)GetUInt32(data4, field4);

                skillRaceClassInfo4.ClassMask = (ClassMask)uint32_4;
                SkillRaceClassInfo skillRaceClassInfo5 = skillRaceClassInfo1;

                byte[] data5    = rawData;
                int    field5   = num5;
                int    num6     = field5 + 1;
                int    uint32_5 = (int)GetUInt32(data5, field5);

                skillRaceClassInfo5.Flags = (SkillRaceClassFlags)uint32_5;
                SkillRaceClassInfo skillRaceClassInfo6 = skillRaceClassInfo1;

                byte[] data6    = rawData;
                int    field6   = num6;
                int    num7     = field6 + 1;
                int    uint32_6 = (int)GetUInt32(data6, field6);

                skillRaceClassInfo6.MinimumLevel = (uint)uint32_6;
                byte[] data7  = rawData;
                int    field7 = num7;
                int    field8 = field7 + 1;
                int    int32  = GetInt32(data7, field7);

                if (int32 > 0)
                {
                    TierReader.Entries.TryGetValue(int32, out skillRaceClassInfo1.Tiers);
                }
                skillRaceClassInfo1.SkillCostIndex = GetUInt32(rawData, field8);
                skillRaceClassInfo1.SkillLine      = ById.Get((uint)uint32_2);
                if (skillRaceClassInfo1.SkillLine != null)
                {
                    foreach (ClassId allClassId in WCellConstants.AllClassIds)
                    {
                        if (allClassId < ClassId.End)
                        {
                            ClassMask mask = allClassId.ToMask();
                            foreach (RaceMask key in WCellConstants.RaceTypesByMask.Keys)
                            {
                                RaceId raceType = WCellConstants.GetRaceType(key);
                                if (skillRaceClassInfo1.RaceMask.HasAnyFlag(key) &&
                                    skillRaceClassInfo1.ClassMask.HasAnyFlag(mask))
                                {
                                    Dictionary <SkillId, SkillRaceClassInfo>[] dictionaryArray =
                                        RaceClassInfos[(int)raceType];
                                    if (dictionaryArray == null)
                                    {
                                        RaceClassInfos[(int)raceType] = dictionaryArray =
                                            new Dictionary <SkillId, SkillRaceClassInfo> [WCellConstants.ClassTypeLength];
                                    }
                                    Dictionary <SkillId, SkillRaceClassInfo> dictionary =
                                        dictionaryArray[(int)allClassId];
                                    if (dictionary == null)
                                    {
                                        dictionaryArray[(int)allClassId] =
                                            dictionary = new Dictionary <SkillId, SkillRaceClassInfo>();
                                    }
                                    SkillRaceClassInfo skillRaceClassInfo7;
                                    if (dictionary.TryGetValue(uint32_2, out skillRaceClassInfo7))
                                    {
                                        skillRaceClassInfo1.RaceMask  |= skillRaceClassInfo7.RaceMask;
                                        skillRaceClassInfo1.ClassMask |= skillRaceClassInfo7.ClassMask;
                                    }
                                    else if (skillRaceClassInfo1.SkillLine.Tiers.Id == 0U &&
                                             skillRaceClassInfo1.Tiers.Id != 0U)
                                    {
                                        skillRaceClassInfo1.SkillLine.Tiers = skillRaceClassInfo1.Tiers;
                                    }

                                    dictionary[uint32_2] = skillRaceClassInfo1;
                                }
                            }
                        }
                    }
                }

                return(skillRaceClassInfo1);
            }
示例#18
0
        public async Task <SearchViewModel> SearchById(ById byId)
        {
            var results = await _repository.SearchById(byId.Id);

            return(SearchViewModel.FromBeerModel(results));
        }