Exemplo n.º 1
0
        public static String ItemValue(String item, ItemKey key)
        {
            if (!ItemData.ContainsKey(item))
                throw new Exception(String.Format("No such item [{0}]", item));

            if (ItemData[item].ContainsKey(key))
                return ItemData[item][key];

            Log.Warn(MethodBase.GetCurrentMethod().DeclaringType, String.Format("No such key {0}", key));

            return String.Empty;
        }
Exemplo n.º 2
0
        public void ToString_DiffenretDbNamesGenerateDifferntKeyStrings()
        {
            //Arrange
            ItemKey testItemKey1 = new ItemKey(_guid1, _path1, _ver1, _mockLanguageWrapperEnglish, _masterDbName);
            ItemKey testItemKey2 = new ItemKey(_guid1, _path1, _ver1, _mockLanguageWrapperEnglish, _webDbName);

            //Act
            string testItemKey1KeyString = testItemKey1.ToString();
            string testItemKey2KeyString = testItemKey2.ToString();

            //Assert
            Assert.AreNotEqual(testItemKey1KeyString, testItemKey2KeyString);
        }
Exemplo n.º 3
0
        public void GetKeyString_DifferntVersionsGerneateDifferentKeyStrings()
        {
            //Arrange
            ItemKey testItemKey1 = new ItemKey(_guid1, _path1, _ver1, _mockLanguageWrapperEnglish, _masterDbName);
            ItemKey testItemKey2 = new ItemKey(_guid1, _path1, _ver2, _mockLanguageWrapperEnglish, _masterDbName);

            //Act
            string testItemKey1KeyString = testItemKey1.GetKeyString();
            string testItemKey2KeyString = testItemKey2.GetKeyString();

            //Assert
            Assert.AreNotEqual(testItemKey1KeyString, testItemKey2KeyString);
        }
Exemplo n.º 4
0
        public void GetKeyString_EquivalentKeyItemsGenerateSameKeyString()
        {
            //Arrange
            ItemKey testItemKey1 = new ItemKey(_guid1, _path1, _ver1, _mockLanguageWrapperEnglish, _masterDbName);
            ItemKey testItemKey2 = new ItemKey(_guid1Duplicate, _path1Duplicate, _ver1Duplicate, _mockLanguageWrapperEnglishDuplicate, _masterDbNameDuplicate);

            //Act
            string testItemKey1KeyString = testItemKey1.GetKeyString();
            string testItemKey2KeyString = testItemKey2.GetKeyString();

            //Assert
            Assert.AreEqual(testItemKey1KeyString, testItemKey2KeyString);
        }
Exemplo n.º 5
0
        public void CreateItemShouldProperlyInitializeProperties()
        {
            // Arrange
            ItemKey   key       = new ItemKey("#key");
            FilterKey filterKey = new FilterKey("key");

            // Act
            var item = new Item(key, filterKey);

            // Assert
            item.Key.Should().Be(key);
            item.FilterKey.Should().Be(filterKey);
        }
Exemplo n.º 6
0
        private void DrawTimeLine(Rect timeLineRect, ItemKey timeLineDirection)
        {
            direction     = timeLineDirection;
            itemCount     = 0;
            lastBackColor = false;

            DrawControlLine(new Rect(timeLineRect.x, timeLineRect.y, timeLineRect.width, controlLineHeight));
            DrawGrid(timeLineRect.width / GetPeriod() * timeLinePrecision, timeLineRect, 0.25f, Color.grey);
            DrawGrid(timeLineRect.width / GetPeriod(), timeLineRect, 0.5f, Color.grey);


            DrawItemOnTimeLine(item, new Vector2(timeLineRect.x + GetItemBeforeOffset(item), timeLineRect.y));
        }
Exemplo n.º 7
0
        private Font CreateFont(ItemKey key, string defaultFontName)
        {
            if (key.Unit == GraphicsUnit.Pixel || key.Unit == GraphicsUnit.Point)
            {
                Font font;
                if (!_fonts.TryGetValue(key, out font))
                    _fonts[key] = font = CreateNewFont(key, defaultFontName);

                return font;
            }

            return CreateNewFont(key, defaultFontName);
        }
Exemplo n.º 8
0
        private Font CreateNewFont(ItemKey key, string defaultFontName)
        {
            CleanupFonts();

            try
            {
                return(new Font(key.Name, key.Size, key.Style, key.Unit));
            }
            catch (Exception ex)
            {
                Platform.Log(LogLevel.Error, ex);
                return(new Font(defaultFontName, key.Size, FontStyle.Regular, key.Unit));
            }
        }
Exemplo n.º 9
0
        public void Constructor2_ValidArgsSetCorrectly()
        {
            //Arrange

            //Act
            ItemKey testItemKey = new ItemKey(_guid1, _path1, _ver1, _mockLanguageWrapperEnglish, _masterDbName);

            //Assert
            Assert.AreEqual(testItemKey.Guid, _guid1);
            Assert.AreEqual(testItemKey.Path, _path1);
            Assert.AreEqual(testItemKey.Version, _ver1);
            Assert.AreEqual(testItemKey.Language, _mockLanguageWrapperEnglish);
            Assert.AreEqual(testItemKey.DatabaseName, _masterDbName);
        }
Exemplo n.º 10
0
 public IAsyncOperation <IItemDataTyped> EnsureItemAvailableAndGetByKeyAsync(ItemKey key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     return(AsyncInfo.Run(async cancelToken =>
     {
         using (await CrossThreadLockScope.Enter(m_lock))
         {
             return await m_items.GetItemByKeyAsync(key, true, cancelToken);
         }
     }));
 }
        public ViewKey(ItemKey key, DateTime effectiveDate)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (effectiveDate == null)
            {
                throw new ArgumentNullException("effectiveDate");
            }

            Key           = key;
            EffectiveDate = effectiveDate;
        }
Exemplo n.º 12
0
        /// <inheritdoc/>
        public override string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
        {
            // Set the output key as the default blank string
            string key;

            // Now determine what the key should be based on the bucketedBy value
            switch (bucketedBy)
            {
            case ItemKey.CRC:
                key = CRC;
                break;

            case ItemKey.MD5:
                key = MD5;
                break;

            case ItemKey.SHA1:
                key = SHA1;
                break;

            case ItemKey.SHA256:
                key = SHA256;
                break;

            case ItemKey.SHA384:
                key = SHA384;
                break;

            case ItemKey.SHA512:
                key = SHA512;
                break;

            case ItemKey.SpamSum:
                key = SpamSum;
                break;

            // Let the base handle generic stuff
            default:
                return(base.GetKey(bucketedBy, lower, norename));
            }

            // Double and triple check the key for corner cases
            if (key == null)
            {
                key = string.Empty;
            }

            return(key);
        }
Exemplo n.º 13
0
        private Font CreateFont(ItemKey key, string defaultFontName)
        {
            if (key.Unit == GraphicsUnit.Pixel || key.Unit == GraphicsUnit.Point)
            {
                Font font;
                if (!_fonts.TryGetValue(key, out font))
                {
                    _fonts[key] = font = CreateNewFont(key, defaultFontName);
                }

                return(font);
            }

            return(CreateNewFont(key, defaultFontName));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Remove an item. To remove, you must first acquire a lock on the item, and prove that you own the lock.
        /// If you use the higher level SychronizedType object, you won't have to acquire the lock yourself
        /// </summary>
        public IAsyncAction RemoveItemAsync(string typeID, ItemKey itemKey, RecordItemLock itemLock)
        {
            itemKey.ValidateRequired("key");
            if (itemLock == null)
            {
                throw new ArgumentNullException("itemLock");
            }

            m_itemLocks.ValidateLock(itemKey.ID, itemLock.LockID);

            return(AsyncInfo.Run(async cancelToken => {
                await m_localStore.RemoveItemAsync(itemKey);
                await m_changeManager.TrackRemoveAsync(typeID, itemKey);
            }));
        }
        internal async Task <IItemDataTyped> GetItemByKeyAsync(ItemKey key, bool shouldAwaitRefresh, CancellationToken cancelToken)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            int index = m_data.Keys.IndexOfItemKey(key);

            if (index < 0)
            {
                return(null);
            }

            return(await this.GetItemAsync(index, shouldAwaitRefresh, cancelToken));
        }
Exemplo n.º 16
0
 /// <summary>
 /// All items that are equal to this parameter will be removed, irrespective of the priority.
 /// During commit, all remove calls are executed after all insert calls(if any) are processed.
 /// Attempting to remove an item that is not inserted results in a no-op.
 /// </summary>
 internal void Remove(T item)
 {
     if (this.sortedItems.Count > 0)
     {
         ItemKey oldKey = null;
         if (!indexes.TryGetValue(item, out oldKey))
         {
             Debug.Fail("Remove called but item is not in the list");
             return;
         }
         cachedList = null;
         indexes.Remove(item);
         this.sortedItems.Remove(oldKey);
     }
 }
        public IAsyncOperation <DateTimeOffset> UpdateDateForAsync(ItemKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            return(AsyncInfo.Run(async cancelToken =>
            {
                using (await CrossThreadLockScope.Enter(m_lock))
                {
                    return await m_objectStore.GetUpdateDateAsync(key.ID);
                }
            }));
        }
Exemplo n.º 18
0
        public void AddLocationlessItem(ItemKey item)
        {
            ItemScope     scope    = new ItemScope(ItemScope.ScopeType.SPECIAL, -1);
            LocationScope locScope = new LocationScope(ItemScope.ScopeType.SPECIAL, -1, new SortedSet <int>(), new SortedSet <int>(), false);

            if (!Data.ContainsKey(item))
            {
                Data[item]        = new ItemLocations();
                Data[item].Unique = true;
            }
            if (!Data[item].Locations.ContainsKey(scope))
            {
                Data[item].Locations[scope] = new ItemLocation(scope);
            }
            AddLocationScope(item, scope, locScope);
        }
Exemplo n.º 19
0
 private void UpdateData(int planeId)
 {
     for (ItemKey i = 0; i < ItemKey.grouth; i++)
     {
         var trans = transform.Find(ConvertName(i));
         if (trans != null)
         {
             var key = KeysUtil.GetPropertyKeys(_key + i);
             trans.GetComponent <Text>().text = DataMgr.Single.GetObject(key).ToString();
         }
         else
         {
             Debug.LogError("当前预制名称错误,正确名称:" + ConvertName(i));
         }
     }
 }
Exemplo n.º 20
0
        protected override GutterIconDescriptor GetIconDescriptor(Item item)
        {
            GutterIconDescriptor  gutterIcon = null;
            InstantPackageManager manager    = new InstantPackageManager(new PackageSourceDictionary());
            IItemKey itemKey = new ItemKey(item);

            if (manager.Contains(itemKey))
            {
                gutterIcon         = new GutterIconDescriptor();
                gutterIcon.Icon    = "Core2/32x32/attach.png";
                gutterIcon.Tooltip = "This item will be downloaded with the next InstantPackage.";

                //TODO: Add a click handler that opens the XAML for the Instant package
            }
            return(gutterIcon);
        }
Exemplo n.º 21
0
        public ItemToggle(IItemDataManager itemDataManager, ITooltipManager tooltipManager, ItemKey itemKey,
                          bool active)
        {
            ItemDataManager = itemDataManager;
            TooltipManager  = tooltipManager;

            ItemKey = itemKey;
            Active  = active;

            Width  = Game1.tileSize;
            Height = Game1.tileSize;

            var itemName = ItemDataManager.GetItem(ItemKey).Name;

            Tooltip = new ItemTooltip(itemName);
        }
Exemplo n.º 22
0
 public static void CaptureItemPath(TSSItem item, ItemKey key)
 {
     if (item.path != null && item.path.enabled)
     {
         if (item.path.loop)
         {
             item.path.SetPointPos(0, TSSPathBase.ToLocal(item.path, item.transform.position), true);
             item.path.SetPointPos(0, TSSPathBase.ToLocal(item.path, item.transform.position), true);
             item.values.positions[0] = item.transform.localPosition;
             item.values.positions[1] = item.transform.localPosition;
             return;
         }
         item.path.SetPointPos(key == 0 ? 0 : item.path.count - 1, TSSPathBase.ToLocal(item.path, item.transform.position));
         item.path.UpdateSpacedPoints();
     }
 }
Exemplo n.º 23
0
        public void TestAcquireItemFromKeysWithPartiallyBadNodes()
        {
            using (var pool = CreateReplicaSetPool(2))
            {
                var itemKey = new ItemKey("key1");
                pool.BadReplica(new ReplicaKey("replica2"));
                pool.BadReplica(new ReplicaKey("replica2"));
                pool.BadReplica(new ReplicaKey("replica2"));
                pool.BadReplica(new ReplicaKey("replica2"));
                pool.BadReplica(new ReplicaKey("replica2")); // Health: 0.168

                var acquiredItems = Enumerable
                                    .Range(0, 100)
                                    .SelectMany(n =>
                {
                    var item1 = pool.Acquire(itemKey);
                    var item2 = pool.Acquire(itemKey);
                    return(new[] { item1, item2 });
                })
                                    .ToList();

                var acquiredItemCount = acquiredItems
                                        .GroupBy(x => x.ReplicaKey)
                                        .ToDictionary(x => x.Key, x => x.Count(), EqualityComparer <ReplicaKey> .Default);

                Assert.That(acquiredItemCount[new ReplicaKey("replica1")], Is.InRange(160, 180));
                Assert.That(acquiredItemCount[new ReplicaKey("replica2")], Is.InRange(20, 40));

                acquiredItems.ForEach(pool.Release);

                var reacquiredItems = Enumerable
                                      .Range(0, 10000)
                                      .SelectMany(n =>
                {
                    var item1 = pool.Acquire(itemKey);
                    var item2 = pool.Acquire(itemKey);
                    pool.Release(item1);
                    pool.Release(item2);
                    return(new[] { item1, item2 });
                })
                                      .GroupBy(x => x.ReplicaKey)
                                      .ToDictionary(x => x.Key, x => x.Count(), EqualityComparer <ReplicaKey> .Default);

                Assert.That(reacquiredItems[new ReplicaKey("replica1")], Is.InRange(16500, 17500));
                Assert.That(reacquiredItems[new ReplicaKey("replica2")], Is.InRange(2500, 3500));
            }
        }
Exemplo n.º 24
0
        private Font GetFont(ItemKey key, string defaultFontName)
        {
            if (key.Unit != GraphicsUnit.Pixel && key.Unit != GraphicsUnit.Point)
            {
                throw new NotSupportedException("Only Pixel and Point GraphicsUnits are supported.");
            }

            try
            {
                return(_fonts.Create(key));
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e);
                return(_fonts.Create(new ItemKey(defaultFontName, key.Size, FontStyle.Regular, key.Unit)));
            }
        }
Exemplo n.º 25
0
        internal Type GetType(string tableName, Type interfaceType)
        {
            Type type;
            var  key = new ItemKey {
                TableName = tableName, InterfaceType = interfaceType
            };

            if (types.TryGetValue(key, out type))
            {
                return(type);
            }

            //TODO:加锁
            type       = CreateEntityType(tableName, interfaceType);
            types[key] = type;
            return(type);
        }
Exemplo n.º 26
0
 public override int AttachToItemAndDetermineCorrectIndex(T newItem)
 {
     newItem.PropertyChanged += OnItemChanged;
     try
     {
         var key   = _keyGetter(newItem);
         var pair  = new ItemKey(newItem, key);
         var index = DetermineIndex(key);
         _keys.Insert(index, pair);
         return(index);
     }
     catch (Exception)
     {
         newItem.PropertyChanged -= OnItemChanged;
         throw;
     }
 }
        public async Task <T> GetAsync <T>(ItemKey itemKey, CancellationToken cancellationToken = default(CancellationToken), bool enableTraces = true)
        {
            if (itemKey == null)
            {
                throw new ArgumentNullException(nameof(itemKey));
            }

            var data = await Fetch(itemKey, cancellationToken, enableTraces);

            if (data == null)
            {
                return(default(T));
            }
            var serializer = _serializerFactory.Create(typeof(T));

            return(await DeserializeWithDecompression <T>(data, serializer, cancellationToken, enableTraces));
        }
        public async Task AddAsync <T>(ItemKey itemKey, T value, CancellationToken cancellationToken = default(CancellationToken), bool enableTraces = true)
        {
            if (value == null)
            {
                return;
            }

            if (itemKey == null)
            {
                throw new ArgumentNullException(nameof(itemKey));
            }

            var serializer     = _serializerFactory.Create(typeof(T));
            var compressedData = await SerializeWithCompression <T>(value, serializer, cancellationToken, enableTraces);

            await Push(itemKey.Category, itemKey.Key, compressedData, cancellationToken, enableTraces);
        }
Exemplo n.º 29
0
 public static void CaptureItemRectTransform(TSSItem item, ItemKey key)
 {
     if (item.rect != null)
     {
         item.values.rects[(int)key] = new Vector4
                                       (
             item.rect.offsetMin.x, item.rect.offsetMin.y,
             item.rect.offsetMax.x, item.rect.offsetMax.y
                                       );
         item.values.anchors[(int)key] = new Vector4
                                         (
             item.rect.anchorMin.x, item.rect.anchorMin.y,
             item.rect.anchorMax.x, item.rect.anchorMax.y
                                         );
         item.values.anchorPositions[(int)key] = item.rect.anchoredPosition;
     }
 }
Exemplo n.º 30
0
        private void LoadObjects(IContentPack contentPack, IContentSource contentSource, ICoreTranslationHelper translationHelper, IEnumerable <ContentPackDataInfo> sources)
        {
            var objects = (from source in sources
                           from entry in source.Content.Objects
                           select new { Source = source, Name = entry.Key, Data = entry.Value }).ToArray();

            // Create exceptions for conflicting item names
            Exception[] exceptions = (from itemGroup in this.GetDuplicateGroups(objects, item => item.Name)
                                      select new Exception($"Object '{itemGroup.Key}' is being registered by multiple content files: {string.Join(", ", itemGroup.Select(item => $"'{item.Source.FullPath}'"))}")).ToArray();

            // Throw the exceptions
            if (exceptions.Any())
            {
                if (exceptions.Length > 1)
                {
                    throw new AggregateException(exceptions);
                }

                throw exceptions.First();
            }

            // Create each object
            foreach (var obj in objects)
            {
                ItemKey key = new ItemKey(contentPack.Manifest, obj.Name);

                // Create the sprite for the object
                ISprite sprite = this.CreateSprite(contentSource, obj.Source, obj.Name, obj.Data);
                if (obj.Data.Tint != Color.White)
                {
                    sprite = new TintedSprite(sprite, obj.Data.Tint);
                }

                // Create the object's manager
                Category   category = new Category(obj.Data.CategoryNumber, obj.Data.CategoryName);
                IModObject manager  = obj.Data.Buffs.HasValue.Match <bool, IModObject>()
                                      .When(true, () => new ModFood(translationHelper, sprite, key.LocalKey, obj.Data.Cost, obj.Data.Edibility, category, false, obj.Data.Buffs.Value))
                                      .When(false, () => new ModObject(translationHelper, sprite, key.LocalKey, obj.Data.Cost, category, obj.Data.Edibility))
                                      .ElseThrow();

                // Register the object
                this._api.Items.CommonRegistry.Objects.Register(key, manager);
                this._api.Owner.Monitor.Log($" - {key} registered (object)", LogLevel.Trace);
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Adds an item according in order of Priority
        /// </summary>
        /// <remarks>
        /// Duplicate items can be added.
        /// </remarks>
        internal void Add(T item, int priority)
        {
            if (addIndex == int.MaxValue - 1)
            {
                // we've done so many add/removes on this list that the addIndex is about to wrap around, so now we need to force a full re-index.
                var saved = sortedItems;
                sortedItems = new SortedDictionary <ItemKey, T>();
                Clear();
                foreach (var pair in sortedItems)
                {
                    ItemKey key   = pair.Key;
                    T       item2 = pair.Value;
                    InternalAdd(item, key.Priority);
                }
            }

            InternalAdd(item, priority);
        }
        public IList <ItemKey> SelectItemKeys(int startAt, int count)
        {
            ValidateIndex(startAt);

            lock (m_keys)
            {
                this.EnsureOrdered();

                count = CorrectCount(startAt, count);
                var keys = new ItemKey[count];
                for (int i = startAt, max = i + count; i < max; ++i)
                {
                    keys[i] = m_keys[i].Key;
                }

                return(keys);
            }
        }
Exemplo n.º 33
0
 public static int ItemValueAsInt(String item, ItemKey key)
 {
     var value = ItemValue(item, key);
     return value != String.Empty ? int.Parse(value) : 0;
 }
Exemplo n.º 34
0
 /// <summary>
 /// Gets/Creates a <see cref="Font"/> given the specified arguments.
 /// </summary>
 public Font CreateFont(CreateFontArgs args)
 {
     var key = new ItemKey(args.Name, args.Size, args.Style, args.Unit);
     var defaultFontName = !string.IsNullOrWhiteSpace(args.DefaultFontName) ? args.DefaultFontName : GenericSansSerif;
     return GetFont(key, defaultFontName);
 }
Exemplo n.º 35
0
		private Font GetFont(ItemKey key, string defaultFontName)
		{
		    if (key.Unit != GraphicsUnit.Pixel && key.Unit != GraphicsUnit.Point)
		        throw new NotSupportedException("Only Pixel and Point GraphicsUnits are supported.");
		    
            try
		    {
		        return _fonts.Create(key);
		    }
		    catch (Exception e)
		    {
		        Platform.Log(LogLevel.Error, e);
		        return _fonts.Create(new ItemKey(defaultFontName, key.Size, FontStyle.Regular, key.Unit));
		    }
		}
Exemplo n.º 36
0
 public Font CreateFont(string fontName, float fontSize, FontStyle fontStyle, GraphicsUnit graphicsUnit, string defaultFontName)
 {
     var key = new ItemKey(fontName, fontSize, fontStyle, graphicsUnit);
     return CreateFont(key, defaultFontName);
 }
Exemplo n.º 37
0
		/// <summary>
		/// Gets a <see cref="Font"/> object for the specified typeface, size, style and unit.
		/// </summary>
		/// <param name="fontName">The name of the typeface.</param>
		/// <param name="fontSize">The size of the font.</param>
		/// <param name="fontStyle">The style of the font.</param>
		/// <param name="graphicsUnit">The units in which <paramref name="fontSize"/> is expressed.</param>
		/// <param name="defaultFontName">The name of a default typeface, in case the font referred to by <paramref name="fontName"/> does not exist.</param>
		/// <returns></returns>
		public Font GetFont(string fontName, float fontSize, FontStyle fontStyle = FontStyle.Regular, GraphicsUnit graphicsUnit = GraphicsUnit.Point, string defaultFontName = null)
		{
			var key = new ItemKey(fontName, fontSize, fontStyle, graphicsUnit);
			return GetFont(key, !string.IsNullOrEmpty(defaultFontName) ? defaultFontName : GenericSansSerif);
		}
Exemplo n.º 38
0
		private Font CreateNewFont(ItemKey key, string defaultFontName)
		{
			CleanupFonts();

			try
			{
				return new Font(key.Name, key.Size, key.Style, key.Unit);
			}
			catch (Exception ex)
			{
				Platform.Log(LogLevel.Error, ex);
				return new Font(defaultFontName, key.Size, FontStyle.Regular, key.Unit);
			}
		}