コード例 #1
0
        public void ReturnToRelative()
        {
            var root = @"C:\fake\dir\";
            var file = @"another\file.js";
            var expected = @"another/file.js";

            var builder = new KeyBuilder(root, "");
            Assert.AreEqual(expected, builder.GetKeyFor(root + file));
        }
コード例 #2
0
        public void ReturnToRelative_Only_Replaces_First_Occurrence_Of_Root()
        {
            var root = @"test/";
            var file = @"another/andthen/test/again.js";
            var expected = @"another/andthen/test/again.js";

            var builder = new KeyBuilder(root, "");
            Assert.AreEqual(expected, builder.GetKeyFor(root + file));
        }
コード例 #3
0
        public void ReturnToRelative_Injects_Virtual_Directory()
        {
            var root = @"C:\fake\dir\";
            var file = @"another\file.js";
            var vdir = "/this";
            var expected = @"this/another/file.js";

            var builder = new KeyBuilder(root, vdir);
            Assert.AreEqual(expected, builder.GetKeyFor(root + file));
        }
コード例 #4
0
        public static StorageKey CreateStorageKey(this NativeContract contract, byte prefix, ISerializable key = null)
        {
            var k = new KeyBuilder(contract.Id, prefix);

            if (key != null)
            {
                k = k.Add(key);
            }
            return(k);
        }
コード例 #5
0
ファイル: ItemData.cs プロジェクト: AbnerSquared/Orikivo
        /// <summary>
        /// Initializes a unique <see cref="ItemData"/> stack.
        /// </summary>
        /// <param name="id">The ID of the <see cref="Item"/> to store.</param>
        /// <param name="data">The unique data of the <see cref="Item"/> to store.</param>
        public ItemData(string id, UniqueItemData data)
        {
            if (!ItemHelper.IsUnique(id))
            {
                throw new Exception("Incorrect item data initializer used.");
            }

            Id     = id;
            TempId = KeyBuilder.Generate(5);
            Data   = data;
        }
コード例 #6
0
        internal static byte[] GetStrongKey()
        {
            int size = DESTransform.BLOCK_BYTE_SIZE * 3;

            byte[] key = KeyBuilder.Key(size);
            while (TripleDES.IsWeakKey(key))
            {
                key = KeyBuilder.Key(size);
            }
            return(key);
        }
コード例 #7
0
        private int j;                 // Key indexer

        public RC2Transform(RC2 rc2Algo, bool encryption, byte[] key, byte[] iv)
            : base(rc2Algo, encryption, iv)
        {
            int t1 = rc2Algo.EffectiveKeySize;

            if (key == null)
            {
                key = KeyBuilder.Key(rc2Algo.KeySize >> 3);
            }
            else
            {
                key = (byte[])key.Clone();
                t1  = Math.Min(t1, key.Length << 3);
            }

            int t = key.Length;

            if (!KeySizes.IsLegalKeySize(rc2Algo.LegalKeySizes, (t << 3)))
            {
                string msg = Locale.GetText("Key is too small ({0} bytes), it should be between {1} and {2} bytes long.", t, 5, 16);
                throw new CryptographicException(msg);
            }

            // Expand key into a byte array, then convert to word
            // array since we always access the key in 16bit chunks.
            byte[] L = new byte[128];

            int t8 = ((t1 + 7) >> 3);             // divide by 8
            int tm = 255 % (2 << (8 + t1 - (t8 << 3) - 1));

            for (int i = 0; i < t; i++)
            {
                L[i] = key[i];
            }
            for (int i = t; i < 128; i++)
            {
                L[i] = (byte)(pitable[(L[i - 1] + L[i - t]) & 0xff]);
            }

            L[128 - t8] = pitable[L[128 - t8] & tm];

            for (int i = 127 - t8; i >= 0; i--)
            {
                L[i] = pitable[L[i + 1] ^ L[i + t8]];
            }

            K = new UInt16[64];
            int pos = 0;

            for (int i = 0; i < 64; i++)
            {
                K[i] = (UInt16)(L[pos++] + (L[pos++] << 8));
            }
        }
コード例 #8
0
ファイル: ItemData.cs プロジェクト: AbnerSquared/Orikivo
        /// <summary>
        /// Initializes a non-unique <see cref="ItemData"/> stack.
        /// </summary>
        /// <param name="id">The ID of the <see cref="Item"/> to store.</param>
        /// <param name="stackCount">The stack count of the <see cref="Item"/> to store.</param>
        internal ItemData(string id, int stackCount)
        {
            if (ItemHelper.IsUnique(id))
            {
                throw new Exception("Incorrect item data initializer used.");
            }

            Id         = id;
            TempId     = KeyBuilder.Generate(5);
            StackCount = stackCount;
        }
コード例 #9
0
        public void ReturnToRelative_Injects_Virtual_Directory()
        {
            var root     = @"C:\fake\dir\";
            var file     = @"another\file.js";
            var vdir     = "/this";
            var expected = @"this/another/file.js";

            var builder = new KeyBuilder(root, vdir);

            Assert.AreEqual(expected, builder.GetKeyFor(root + file));
        }
コード例 #10
0
        public static KeyBuilder ForNpgsql(
            [NotNull] this KeyBuilder keyBuilder,
            [NotNull] Action <NpgsqlKeyBuilder> builderAction)
        {
            Check.NotNull(keyBuilder, nameof(keyBuilder));
            Check.NotNull(builderAction, nameof(builderAction));

            builderAction(ForNpgsql(keyBuilder));

            return(keyBuilder);
        }
コード例 #11
0
        public static KeyBuilder ForSqlServer(
            [NotNull] this KeyBuilder keyBuilder,
            [NotNull] Action <SqlServerKeyBuilder> builderAction)
        {
            Check.NotNull(keyBuilder, nameof(keyBuilder));
            Check.NotNull(builderAction, nameof(builderAction));

            builderAction(ForSqlServer(keyBuilder));

            return(keyBuilder);
        }
コード例 #12
0
ファイル: KeyValueBuilder.cs プロジェクト: olivr70/Eto.Parse
        public override void Visit(VisitArgs args)
        {
            TRef value = default(TRef);
            TKey key   = default(TKey);

            var old = args.Match;

            var matches    = args.Match.Matches;
            var matchCount = matches.Count;

            for (int i = 0; i < matchCount; i++)
            {
                var match = args.Match = matches[i];
                args.ResetChild();
                if (namedKey && match.Name == keyName)
                {
                    KeyBuilder.Visit(args);
                    key = (TKey)args.Child;
                    continue;
                }

                if (namedValue && match.Name == valueName)
                {
                    ValueBuilder.Visit(args);
                    value = (TRef)args.Child;
                    continue;
                }
                if (!namedKey)
                {
                    KeyBuilder.Visit(args);
                    if (args.ChildSet)
                    {
                        key = (TKey)args.Child;
                        continue;
                    }
                }
                if (!namedValue)
                {
                    ValueBuilder.Visit(args);
                    if (args.ChildSet)
                    {
                        value = (TRef)args.Child;
                        continue;
                    }
                }
            }

            Add((T)args.Instance, key, value);
            args.Match = old;
        }
コード例 #13
0
        public bool Contains(Object key)
#endif
        {
            if (index != null)
            {
                Key k = KeyBuilder.getKeyFromObject(key);
                return(index.GetDictionaryEnumerator(k, k, IterationOrder.AscentOrder).MoveNext());
            }
            else
            {
                int i = binarySearch(key);
                return(i >= 0);
            }
        }
コード例 #14
0
        public RequestFile Map(CreatePhotoRequest source)
        {
            if (source == null)
            {
                return(null);
            }

            return(new RequestFile
            {
                Key = KeyBuilder.Build(),
                ContentType = source.ContentType,
                Data = source.Data
            });
        }
コード例 #15
0
        public Coin Map(CreateCoinRequest source)
        {
            if (source == null)
            {
                return(null);
            }

            return(new Coin
            {
                Key = KeyBuilder.Build(),
                Country = source.Country,
                Name = source.Name,
                Reference = source.Reference
            });
        }
コード例 #16
0
        /// <summary>
        /// Initializes a new <see cref="ActionQueue"/> with a generated ID.
        /// </summary>
        /// <param name="duration">The delay at which this <see cref="ActionQueue"/> will be called in.</param>
        /// <param name="actionId">The ID of the <see cref="GameAction"/> to invoke.</param>
        /// <param name="session">The <see cref="GameSession"/> to bind this <see cref="ActionQueue"/> for.</param>
        public ActionQueue(TimeSpan duration, string actionId, GameSession session)
        {
            if (session.Actions.All(x => x.Id != actionId))
            {
                throw new ValueNotFoundException("Failed to find the specified action in the current game session", actionId);
            }

            _session  = session;
            CreatedAt = StartedAt = DateTime.UtcNow;
            Id        = KeyBuilder.Generate(6);
            ActionId  = actionId;
            Delay     = duration;
            Timer     = new Timer(OnElapse, null, duration, TimeSpan.FromMilliseconds(-1));
            Logger.Debug($"[{Id}] Queued '{actionId}' (at {Format.FullTime(StartedAt)}) to invoke in {Format.Countdown(duration)}.");
        }
コード例 #17
0
        public Rfc2898DeriveBytes(string password, int saltSize, int iterations)
        {
            if (password == null)
            {
                throw new ArgumentNullException("password");
            }
            if (saltSize < 0)
            {
                throw new ArgumentOutOfRangeException("invalid salt length");
            }

            Salt           = KeyBuilder.Key(saltSize);
            IterationCount = iterations;
            _hmac          = new HMACSHA1(Encoding.UTF8.GetBytes(password));
        }
コード例 #18
0
        public async Task CreatePersonAsyncTest()
        {
            var person = Builder <Domain.Entities.Person>
                         .CreateNew()
                         .With(p => p.Key = KeyBuilder.Build())
                         .Build();

            await _repository.CreatePersonAsync(person);

            var persistedPerson = await _repository.GetPersonByKeyAsync(person.Key);

            Assert.Equal(person.Key, persistedPerson.Key);
            Assert.Equal(person.Name, persistedPerson.Name);
            Assert.Equal(person.Age, persistedPerson.Age);
        }
コード例 #19
0
        public Price Map(CreatePriceRequest source)
        {
            if (source == null)
            {
                return(null);
            }

            var coin = _coinMapper.Map(source.Coin);

            return(new Price
            {
                Key = KeyBuilder.Build(),
                Coin = coin,
                Value = source.Value
            });
        }
コード例 #20
0
        public KeyValueNode BuildNode()
        {
            var toReturn = new KeyValueNode();

            toReturn.Key = KeyBuilder.ToString();
            if (ValueBuilder.Length > 0)
            {
                toReturn.Value = ValueBuilder.ToString();
            }
            else
            {
                toReturn.Children = new Dictionary <string, List <KeyValueNode> >();
            }

            return(toReturn);
        }
コード例 #21
0
        public string GetKey(MethodInfo method, params object[] args)
        {
            var sb      = new StringBuilder();
            var builder = new KeyBuilder(sb);

            BuildKey(builder);

            builder.Append(method.DeclaringType.FullName);
            builder.Append(method.Name);

            foreach (var a in args)
            {
                builder.Append(a);
            }

            return(builder.ToString());
        }
コード例 #22
0
        public void Test_InitKeyBuilderWithGenericType_Ok()
        {
            // Arrange
            var expectedPrefix = string.Join(
                "-",
                UsingType.FullName,
                Constants.USING_KEY_PREFIX
                );

            // Act
            var actual = new KeyBuilder <UnitTestKeyBuilder>(
                Constants.USING_KEY_PREFIX
                );

            // Assert
            Assert.AreEqual(expectedPrefix, actual.KeyPrefix);
        }
コード例 #23
0
        private void btnPush_Click(object sender, EventArgs e)
        {
            try
            {
                string host     = txtHost.Text.Trim();
                string database = txtDatabase.Text.Trim();
                string appKey   = txtAppKey.Text.Trim();
                string username = txtUsername.Text.Trim();
                string password = txtPassword.Text.Trim();

                string key = KeyBuilder.Build(host, database, appKey);
                SecurityClient.Add(key, string.Format("{0},{1}", username, password));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #24
0
        public async Task WorkflowEngine_TriggerAsyncWithEntityWorkflowInstanceAndSameWorkflowVariable_ReturnsTriggerResult()
        {
            // Arrange
            var instance = new LightSwitcher();

            this.Context.Switchers.Add(instance);

            var workflow = Workflow.Create(instance.Id, instance.Type, instance.State, "tester");
            var variable = new LightSwitcherWorkflowVariable {
                CanSwitch = true
            };

            workflow.AddVariable(variable);

            this.Context.Workflows.Add(workflow);
            await this.Context.SaveChangesAsync();

            variable.CanSwitch = false;
            var param = new TriggerParam("SwitchOn", instance)
                        .AddVariableWithKey <LightSwitcherWorkflowVariable>(variable);;

            // Act
            var triggerResult = await this.WorkflowEngine.TriggerAsync(param);

            // Assert
            Assert.IsNotNull(triggerResult);
            Assert.IsFalse(triggerResult.HasErrors);
            Assert.AreEqual(instance.State, triggerResult.CurrentState);
            Assert.AreEqual("On", triggerResult.CurrentState);

            Assert.IsTrue(param.HasVariables);

            Assert.AreEqual(1, workflow.WorkflowHistories.Count());

            var workflowVariable       = workflow.WorkflowVariables.First();
            var type                   = KeyBuilder.FromKey(workflowVariable.Type);
            var myDeserializedVariable = JsonConvert.DeserializeObject(workflowVariable.Content, type);

            Assert.IsInstanceOfType(myDeserializedVariable, typeof(LightSwitcherWorkflowVariable));

            var variableInstance = myDeserializedVariable as LightSwitcherWorkflowVariable;

            Assert.IsFalse(variableInstance.CanSwitch);
        }
コード例 #25
0
        public Launch Map(CreateLaunchRequest source)
        {
            if (source == null)
            {
                return(null);
            }

            var coin = _coinMapper.Map(source.Coin);

            return(new Launch
            {
                Key = KeyBuilder.Build(),
                Type = source.Type,
                Value = source.Value,
                ValueType = source.ValueType,
                IsAvailable = true,
                Coin = coin
            });
        }
コード例 #26
0
        public static KeyBuilder PrimaryKey <T>(this EntityTypeBuilder <T> builder, params string[] properties)
            where T : class
        {
            Common.CheckForNull(builder);
            Common.CheckStrings(properties);

            string tableName      = NamingServices.TableNaming.GetTableName(typeof(T));
            string primaryKeyName = NamingServices.PrimaryKeyNaming.GetConstraintName(tableName, properties);

            KeyBuilder keyBuilder = builder.HasKey(properties)
                                    .HasName(primaryKeyName);

            for (int i = 1; i < properties.Length; i++)
            {
                builder.Index(properties[i]);
            }

            return(keyBuilder);
        }
コード例 #27
0
        private static string CreateQuery()
        {
            Persons.ForEach(p => p.Key = KeyBuilder.Build());

            var values = Persons
                         .Select(p => $"('{KeyBuilder.Build()}', '{p.Name}', {p.Age})");

            var query = $@"

            INSERT INTO Person.Persons

            (Persons.Key, Persons.Name, Persons.Age)

            VALUES
            
            {string.Join(',', values)}
            ";

            return(query);
        }
コード例 #28
0
 private GameServer(GameManager manager, IUser host, ServerProperties properties = null)
 {
     properties ??= ServerProperties.GetDefault(host.Username);
     _manager       = manager;
     HostId         = host.Id;
     Id             = KeyBuilder.Generate(8);
     Name           = properties.Name;
     GameId         = properties.GameId;
     Privacy        = properties.Privacy;
     Broadcasts     = DisplayBroadcast.GetReservedBroadcasts();
     Connections    = new List <ServerConnection>();
     Invites        = new List <ServerInvite>();
     AllowedActions = properties.AllowedActions;
     _players       = new List <Player>
     {
         new Player(this, host)
     };
     Destroyed   = false;
     LastUpdated = DateTime.UtcNow;
     LoadGameConfig();
 }
コード例 #29
0
        public void Test_InitKeyBuilder_WithConfig_Ok()
        {
            // Arrange
            var expectedPrefix = string.Join(
                "-",
                UsingType.FullName,
                Constants.USING_KEY_PREFIX
                );

            // Act
            var actual = new KeyBuilder(
                UsingType,
                new KeyBuilderConfiguration()
            {
                KeyPrefix = Constants.USING_KEY_PREFIX
            }
                );

            // Assert
            Assert.AreEqual(expectedPrefix, actual.KeyPrefix);
        }
コード例 #30
0
        public ProductEntity Map(CreateProductRequest source)
        {
            if (source == null)
            {
                return(null);
            }

            var properties = source?.Properties?.Select(p => _propertyMapper.Map(p)).ToList();
            var launches   = source?.Launches?.Select(l => _launchMapper.Map(l)).ToList();
            var price      = _priceMapper.Map(source.Price);

            return(new ProductEntity
            {
                Key = KeyBuilder.Build(),
                Code = source.Code,
                Name = source.Name,
                Properties = properties,
                Launches = launches,
                Price = price,
                IsEnabled = true
            });
        }
コード例 #31
0
ファイル: UT_Blockchain.cs プロジェクト: neo-project/neo
        public void TestValidTransaction()
        {
            var snapshot = TestBlockchain.TheNeoSystem.GetSnapshot();
            var walletA  = TestUtils.GenerateTestWallet("123");
            var acc      = walletA.CreateAccount();

            // Fake balance

            var key   = new KeyBuilder(NativeContract.GAS.Id, 20).Add(acc.ScriptHash);
            var entry = snapshot.GetAndChange(key, () => new StorageItem(new AccountState()));

            entry.GetInteroperable <AccountState>().Balance = 100_000_000 * NativeContract.GAS.Factor;
            snapshot.Commit();

            // Make transaction

            var tx = CreateValidTx(snapshot, walletA, acc.ScriptHash, 0);

            senderProbe.Send(system.Blockchain, tx);
            senderProbe.ExpectMsg <Blockchain.RelayResult>(p => p.Result == VerifyResult.Succeed);

            senderProbe.Send(system.Blockchain, tx);
            senderProbe.ExpectMsg <Blockchain.RelayResult>(p => p.Result == VerifyResult.AlreadyExists);
        }
コード例 #32
0
 protected override void SetKeyDictionary(KeyBuilder keyBuilder, DatabaseTable table)
 {
 }
コード例 #33
0
 public override void GenerateKey()
 {
     KeyValue = KeyBuilder.Key(KeySizeValue >> 3);
 }