示例#1
0
            protected void ShouldGetDifferentKeys(IKeyGenerator <string> generator)
            {
                // Act
                string key1 = generator.GetKey();
                string key2 = generator.GetKey();

                // Assert
                Assert.NotEqual(key1, key2);
            }
示例#2
0
            protected void ShouldGetANonNullGuid(IKeyGenerator <string> generator)
            {
                // Act
                string key = generator.GetKey();

                // Assert
                Assert.NotEqual(System.Guid.Empty.ToString(), key);
            }
示例#3
0
        public static IEnumerable <SerializationInfo> GetSerializationMembers(Type type, IKeyGenerator keyGen)
        {
            EnsureMetaDataInitialized(type);

            var data = MetaData[type];

            return(data.ImplicitMembers
                   .Select(sm => new SerializationInfo(sm, new TomlKey(keyGen.GetKey(sm.MemberInfo))))
                   .Concat(data.ExplicitMembers));
        }
示例#4
0
        public async Task <IActionResult> Upload(PhotoUploadViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userName  = _httpContextAccessor.HttpContext.Session.GetString("User");
                var uniqueKey = _keyGenerator.GetKey(userName);

                var fileName = Path.GetFileName(model.File.FileName);
                await _photoMetaData.SavePhotoMetaData(userName, model.Description, fileName);

                await _fileStorage.StoreFile(model.File, uniqueKey);
            }
            return(RedirectToAction("Display"));
        }
示例#5
0
 private Person SetIdsForNewEntities(Person person)
 {
     // all this example code to justify this part..., using NHiLo to generate new ids
     if (person.Id <= 0)
     {
         person.Id = _personKeyGenerator.GetKey();
     }
     foreach (var contact in person.Contacts)
     {
         // here the id is a guid, so we call the guid generator
         if (string.IsNullOrEmpty(contact.Id))
         {
             contact.Id = _contactKeyGenerator.GetKey();
         }
     }
     return(person);
 }
示例#6
0
        public async Task <IActionResult> Shorten([FromBody] string url)
        {
            // TODO: Move validation somewhere else
            // Ensures URL is valid
            if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri) &&
                uri.IsWellFormedOriginalString() &&
                (uri.Scheme == Uri.UriSchemeHttps || uri.Scheme == Uri.UriSchemeHttp))
            {
                string key = _keyGenerator.GetKey(6);

                _shortenerContext.Add(new ShortenedUrl()
                {
                    Key = key, Url = url
                });
                await _shortenerContext.SaveChangesAsync();

                return(Ok(new { key }));
            }

            return(BadRequest(new { error = "Invalid URL" }));
        }
示例#7
0
文件: Form1.cs 项目: fabiogouw/NHiLo
 private void button1_Click(object sender, EventArgs e)
 {
     textBox1.Text = _generator.GetKey().ToString();
 }
示例#8
0
 /// <summary>
 /// Returns the unique value as a int value.
 /// </summary>
 /// <param name="generator">An object that produces new key values.</param>
 /// <returns>Unique int value.</returns>
 public static int GetKeyAsInt(this IKeyGenerator <long> generator)
 {
     return((int)generator.GetKey());
 }