예제 #1
0
        public void ComputeHashTest()
        {
            const string key     = "SteveRuben-SuperDuper-Key";
            var          keyHash = KeyUtility.GetKeyHash(key);

            Assert.IsTrue(keyHash.Length > 0);
        }
예제 #2
0
        private void OutputDescriptionPropertyKeyAndKey(string format, string property)
        {
            //// Attacks per Second: 1.50
            //[PropertyKey("Attacks per Second: {0}")]
            //AttacksPerSecond,

            Debug.WriteLine("// " + property);
            Debug.WriteLine(@"[PropertyKey(""" + format + @""")]");

            var percentage = format.Contains("%");

            format = format.Replace(":", string.Empty);
            format = format.Replace("%", string.Empty);
            format = format.Replace("-", string.Empty);
            format = format.Replace("(", string.Empty);
            format = format.Replace(")", string.Empty);

            for (var i = 0; i < 10; i++)
            {
                format = format.Replace("{" + i.ToString(CultureInfo.InvariantCulture) + "}", string.Empty);
            }

            var key = KeyUtility.FormatStringToKey(format);

            if (percentage)
            {
                key += "Percentage";
            }

            Debug.WriteLine(key + ",");
            Debug.WriteLine(string.Empty);
        }
        // *******************************************************************

        /// <inheritdoc />
        public override async Task <TModel> AddAsync(
            TModel model,
            CancellationToken cancellationToken = default
            )
        {
            // Validate the parameters before attempting to use them.
            Guard.Instance().ThrowIfNull(model, nameof(model));

            try
            {
                // Is the key missing?
                if (KeyUtility.IsKeyMissing(model.Key))
                {
                    // Create a new random key value.
                    model.Key = KeyUtility.CreateRandomKey <TKey>();
                }

                // Wrap the model up.
                var wrapper = new CosmoDbWrapper <TModel>()
                {
                    id    = $"{model.Key}",
                    model = model
                };

                // Defer to the CosmoDb container.
                var newModel = await Container.Value.CreateItemAsync(
                    item : wrapper,
                    cancellationToken : cancellationToken
                    ).ConfigureAwait(false);

                // Return the result.
                return(newModel.Resource.model);
            }
            catch (Exception ex)
            {
                // Add better context to the error.
                throw new RepositoryException(
                          message: string.Format(
                              Resources.CosmoDbCrudRepository_AddAsync,
                              GetType().Name,
                              typeof(TModel).Name,
                              JsonSerializer.Serialize(model)
                              ),
                          innerException: ex
                          );
            }
        }
        // *******************************************************************

        /// <inheritdoc />
        public override async Task <TModel> AddAsync(
            TModel model,
            CancellationToken cancellationToken = default
            )
        {
            // Validate the parameters before attempting to use them.
            Guard.Instance().ThrowIfNull(model, nameof(model));

            try
            {
                // Is the key missing?
                if (KeyUtility.IsKeyMissing(model.Key))
                {
                    // Create a new random key value.
                    model.Key = KeyUtility.CreateRandomKey <TKey>();
                }

                // Defer to the CosmoDb container.
                await Collection.InsertOneAsync(
                    model,
                    new InsertOneOptions()
                {
                    BypassDocumentValidation = true
                },
                    cancellationToken
                    ).ConfigureAwait(false);

                // Return the model.
                return(model);
            }
            catch (Exception ex)
            {
                // Add better context to the error.
                throw new RepositoryException(
                          message: string.Format(
                              Resources.MongoDbCrudRepository_AddAsync,
                              nameof(MongoDbCrudRepository <TOptions, TModel, TKey>),
                              typeof(TModel).Name,
                              JsonSerializer.Serialize(model)
                              ),
                          innerException: ex
                          );
            }
        }
예제 #5
0
        private void PopulateWithMappings()
        {
            Thickness buttonMargin = new Thickness();

            buttonMargin.Left = 15;

            List <VirtualKey> virtualKeys = KeyUtility.GetVirtualKeyValues();

            foreach (VirtualKey vk in virtualKeys)
            {
                StackPanel stackPanel = new StackPanel();
                stackPanel.Orientation = Orientation.Horizontal;
                stackPanel.Tag         = vk;

                TextBlock textblock = new TextBlock()
                {
                    FontWeight = FontWeights.Bold
                };
                textblock.Text  = vk.ToString();
                textblock.Width = 100;
                stackPanel.Children.Add(textblock);

                for (int i = 0; i < Settings.AdvancedMappingPage_MappingsToShow; i++)
                {
                    Button button = new Button();
                    button.Click += Handler_ButtonClicked;
                    button.Margin = buttonMargin;
                    button.Tag    = i;
                    button.Width  = 120;

                    stackPanel.Children.Add(button);
                }

                mappingHolder.Children.Add(stackPanel);
            }

            RefreshButtonContents();
        }
예제 #6
0
        public void KeyForPoeNinjaId()
        {
            var expected = Key.ExaltedOrb;

            Assert.True(KeyUtility.KeyForPoeNinjaId(2) == expected);
        }