public void AddAddress(URL url) { url.Id = URLList.Count; url.ShortAdress = hashids.Encode(new Random().Next()); URLList.Add(url); }
void it_encodes_a_single_number() { hashids.Encode(1).Should().Be("NV"); hashids.Encode(22).Should().Be("K4"); hashids.Encode(333).Should().Be("OqM"); hashids.Encode(9999).Should().Be("kQVg"); hashids.Encode(123000).Should().Be("58LzD"); hashids.Encode(456000000).Should().Be("5gn6mQP"); hashids.Encode(987654321).Should().Be("oyjYvry"); }
private void It_can_encode_with_a_custom_alphabet() { var h = new Hashids(SALT, 0, "ABCDEFGhijklmn34567890-:"); h.Encode(1, 2, 3, 4, 5).ShouldBe("6nhmFDikA0"); }
public static string HashId(long id) { var code = Convert.ToInt32(id); return(HashMachine.Encode(code)); }
public void AddLink(Link link) { link.ShortLink = hashids.Encode(TimeSinceMidnight()); _context.Links.Add(link); _context.SaveChanges(); }
void it_can_encode_with_a_custom_alphabet() { var h = new Hashids(salt, 0, "ABCDEFGhijklmn34567890-:"); h.Encode(1, 2, 3, 4, 5).Should().Be("6nhmFDikA0"); }
public string Encode(int id) { return(_hashids.Encode(id)); }
private string EncryptHashids(int stringToEncrypt) { return(_hashids.Encode(stringToEncrypt)); }
void it_can_encode_with_a_custom_alphabet() { var h = new Hashids(salt, 0, "ABCDEFGhijklmn34567890-:"); h.Encode(1, 2, 3, 4, 5).Should().Be("6nhmFDikA0"); }
void it_can_encodes_to_a_minimum_length() { var h = new Hashids(salt, 18); h.Encode(1).Should().Be("aJEDngB0NV05ev1WwP"); h.Encode(4140, 21147, 115975, 678570, 4213597, 27644437). Should().Be("pLMlCWnJSXr1BSpKgqUwbJ7oimr7l6"); }
private static string CreateChannel() { return(_hashids.Encode(_random.Next())); }
// Bijective functions // starbukcs.com --> 1001 // starbukcs.com --> 1424 // starbukcs.com --> 1001 ->afsasfba public static string Encode(int i) { return(hashids.Encode(i)); }
public static string GenerateIdForAccount(object userId) { var hash = new Hashids(userId.ToString()); return(userId + "_" + hash.Encode(DateTime.Now.Millisecond)); }
public static string ProduceCode(params int[] values) { return(hashIds.Encode(values)); }
public static string Obfuscate(int value) { return(String.Format(CultureInfo.InvariantCulture, "{0}{1}", HasherPrefix, hasher.Encode(value))); }
/// <summary> /// Encodes the provided numbers into a hashed string /// </summary> /// <param name="numbers">the numbers to encode</param> /// <returns>the hashed string</returns> public string Encode(params int[] numbers) { return(_hasher.Encode(numbers)); }
/// <summary> /// Sayıyı şifrelenmiş bir string olarak döner. /// </summary> public static string Encrypt(int number) => number < 0 ? null : Hashids.Encode(number);
public static string ToEncodedId(this int key) { return(Hashids.Encode(key)); }
/// <summary> /// 对ID进行编码 /// </summary> /// <param name="id">ID</param> /// <returns>哈希值</returns> public static string Encode(int id) => _hashids.Encode(id);
public string HashValue(Guid id) { return(_hashIds.Encode(id.ToByteArray().Select(Convert.ToInt32).ToArray())); }
private string GenerateHash(int id) { return(hashids.Encode(id)); }
void it_can_encode_with_a_custom_alphabet_and_few_seps() { var h = new Hashids(salt, 0, "ABCDEFGHIJKMNOPQRSTUVWXYZ23456789"); h.Encode(1, 2, 3, 4, 5).Should().Be("44HYIRU3TO"); }
/// <summary> /// Claim the rewards /// </summary> /// <param name="db"></param> /// <param name="rewardsId"></param> /// <param name="registrationId"></param> /// <returns></returns> public static AffiliateRewardsClaim ClaimReward(NancyBlackDatabase db, int rewardsId, int registrationId) { AffiliateReward rewards; var reg = db.GetById <AffiliateRegistration>(registrationId); rewards = db.GetById <AffiliateReward>(rewardsId); var canClaim = AffiliateReward.CanClaim(db, rewardsId, registrationId); if (canClaim == false && reg.NcbUserId != 1) { return(null); } if (rewards.MaxPerUser > 0) { lock (BaseModule.GetLockObject("RewardClaim-Reg-" + registrationId)) { var totalClaimedByUser = db.Query <AffiliateRewardsClaim>() .Where(c => c.AffiliateRewardsId == rewards.Id && c.AffiliateRegistrationId == registrationId).Count(); if (reg.NcbUserId == 1) // Super Admin { // not check } else { if (totalClaimedByUser >= rewards.MaxPerUser) { return(null); } } } } if (rewards.TotalQuota > 0) { lock (BaseModule.GetLockObject("RewardClaim-" + rewardsId)) { var totalClaimed = db.Query <AffiliateRewardsClaim>().Where(c => c.AffiliateRewardsId == rewards.Id).Count(); rewards.RemainingQuota = rewards.TotalQuota - totalClaimed; db.UpsertRecord(rewards); } } if (rewards.IsRewardsClaimable == false) { return(null); } if (rewards.IsCodeDiscount || rewards.IsFreeGiftInSaleOrder) { var until = DateTime.MaxValue.Ticks; if (rewards.CodeDicountExpiryInDays != null) { until = DateTime.Now.AddDays(rewards.CodeDicountExpiryInDays.Value).Ticks; } if (rewards.CodeDiscountExpiryDate != null) { until = rewards.CodeDiscountExpiryDate.Value.Ticks; } AffiliateRewardsClaim claim = null; db.Transaction(() => { // free gift also gets created as code Product p = new Product(); if (rewards.IsCodeDiscount) { p.Price = rewards.CodeDiscountAmount * -1; p.Attributes = new { rewardId = rewards.Id, description = rewards.Title + ", ราคาก่อนส่วนลดขั้นต่ำ: " + rewards.MinimumPurchaseAmount, min = rewards.MinimumPurchaseAmount, onetime = true, until = until, discount = rewards.CodeDiscountAmount, affiliateName = reg.AffiliateName, require = rewards.RequiredProductIds, }; } if (rewards.IsFreeGiftInSaleOrder) { p.DiscountPrice = 0; p.Price = rewards.CodeDiscountAmount; p.PromotionEndDate = new DateTime(until); p.MasterProductId = rewards.RewardsProductId; p.IsVariation = true; p.Attributes = new { rewardId = rewards.Id, description = rewards.Title + ", ราคาก่อนส่วนลดขั้นต่ำ: " + rewards.MinimumPurchaseAmount, min = rewards.MinimumPurchaseAmount, onetime = true, until = until, discount = rewards.CodeDiscountAmount, isfreeproduct = 1, affiliateName = reg.AffiliateName, require = rewards.RequiredProductIds, }; } db.UpsertRecord(p); var code = hashids.Encode(p.Id, reg.Id); p.Url = "/promotions/code/" + code; p.Title = "Affiliate Discount: " + code; if (rewards.IsFreeGiftInSaleOrder) { p.Title = "GIFT ITEM:" + rewards.Title; } db.UpsertRecord(p); claim = new AffiliateRewardsClaim(); claim.AffiliateRegistrationId = reg.Id; claim.NcbUserId = reg.NcbUserId; claim.AffiliateCode = reg.AffiliateCode; claim.DiscountCode = code; claim.RewardsName = rewards.Title; claim.AffiliateRewardsId = rewards.Id; claim.ProductId = p.Id; claim.CouponAttributes = p.Attributes; db.UpsertRecord(claim); }); return(claim); } { var claim = new AffiliateRewardsClaim(); claim.AffiliateRegistrationId = reg.Id; claim.NcbUserId = reg.NcbUserId; claim.AffiliateCode = reg.AffiliateCode; claim.RewardsName = rewards.Title; claim.AffiliateRewardsId = rewards.Id; claim.ProductId = rewards.RewardsProductId; db.UpsertRecord(claim); return(claim); } }