当前位置: 首页>>代码示例>>C#>>正文


C# Key.Clone方法代码示例

本文整理汇总了C#中Key.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Key.Clone方法的具体用法?C# Key.Clone怎么用?C# Key.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Key的用法示例。


在下文中一共展示了Key.Clone方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetCollectionCreateKeyLazy

        public void SetCollectionCreateKeyLazy(MutatorSpec mutatorSpec)
        {
            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell>();
            for (var n = 0; n < Count; ++n) {
                key.Row = (n % 3) == 0 ? Guid.NewGuid().ToString() : null;
                cells.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            foreach (var cell in cells) {
                Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
            }

            Assert.AreEqual(Count, this.GetCellCount());
        }
开发者ID:andysoftdev,项目名称:ht4n,代码行数:19,代码来源:TestTableMutator.cs

示例2: SetCollectionDifferentSizedValues

        public void SetCollectionDifferentSizedValues(MutatorSpec mutatorSpec)
        {
            var sb = new StringBuilder();
            for (var n = 0; n < 0x40; ++n) {
                sb.Append(Guid.NewGuid().ToString());
            }

            var largeValue = Encoding.GetBytes(sb.ToString());
            for (var n = 0; n < 0x4000; ++n) {
                sb.Append(Guid.NewGuid().ToString());
            }

            var hugeValue = Encoding.GetBytes(sb.ToString());
            var smallValue = Encoding.GetBytes(Guid.NewGuid().ToString());

            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell> {
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue)
                };

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells, true);
            }

            foreach (var cell in cells) {
                Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
            }
        }
开发者ID:andysoftdev,项目名称:ht4n,代码行数:38,代码来源:TestTableMutator.cs

示例3: SetCollectionThreaded

        public void SetCollectionThreaded(MutatorSpec mutatorSpec)
        {
            var key = new Key { ColumnFamily = "a" };
            var cells1 = new List<Cell>();
            for (var n = 0; n < 16; ++n) {
                cells1.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            var cells2 = new List<Cell>();
            for (var n = 0; n < 16; ++n) {
                cells2.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                var c1 = 0;
                var c2 = 0;

                var t1 = new Thread(
                    () =>
                        {
                            for (var n = 0; n < Count; ++n, ++c1) {
                                mutator.Set(cells1, true);
                                if (n == Count / 2) {
                                    mutator.Flush();
                                }
                            }
                        });

                var t2 = new Thread(
                    () =>
                        {
                            for (var n = 0; n < Count; ++n, ++c2) {
                                mutator.Set(cells2, true);
                                if (n == Count / 2) {
                                    mutator.Flush();
                                }
                            }
                        });

                t1.Start();
                t2.Start();
                t1.Join();
                t2.Join();
                Assert.IsTrue(c1 > 0);
                Assert.IsTrue(c2 > 0);
            }
        }
开发者ID:andysoftdev,项目名称:ht4n,代码行数:47,代码来源:TestTableMutator.cs

示例4: Delete

        public void Delete(MutatorSpec mutatorSpec)
        {
            var key = new Key { ColumnFamily = "a" };

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.Row = "Row does not exist";
                mutator.Set(key, Encoding.GetBytes(key.Row));
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            var rowKeys = new SortedSet<string>();
            using (var scanner = table.CreateScanner()) {
                var cell = new Cell();
                while( scanner.Move(cell) ) {
                    rowKeys.Add(cell.Key.Row);
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                foreach (var rowKey in rowKeys) {
                    mutator.Delete(rowKey);
                }
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key { ColumnFamily = "a" };
            using (var mutator = table.CreateMutator(mutatorSpec))
            {
                key.Row = "Row does not exist";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                for (var n = 0; n < Count; ++n)
                {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            using (var scanner = table.CreateScanner(new ScanSpec { KeysOnly = true }))
            using (var mutator = table.CreateMutator())
            {
                var cell = new Cell();
                while (scanner.Move(cell))
                {
                    mutator.Delete(cell.Key);
                }
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key { ColumnFamily = "a" };
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            rowKeys = new SortedSet<string>();
            using (var scanner = table.CreateScanner()) {
                var cell = new Cell();
                while( scanner.Move(cell) ) {
                    rowKeys.Add(cell.Key.Row);
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key = new Key();
                foreach (var rowKey in rowKeys) {
                    key.Row = rowKey;
                    mutator.Delete(key);
                }
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key { ColumnFamily = "a" };
            var keys = new List<Key>();
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                    keys.Add((Key)key.Clone());
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(keys);
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key { ColumnFamily = "a", ColumnQualifier = null };
            using (var mutator = table.CreateMutator(mutatorSpec)) {
//.........这里部分代码省略.........
开发者ID:andysoftdev,项目名称:ht4n,代码行数:101,代码来源:TestTableMutator.cs

示例5: SetCollectionHugeValues

        public void SetCollectionHugeValues(MutatorSpec mutatorSpec)
        {
            const int K = 1024;
            const int M = K * K;
            var hugeValue = new byte[M];
            new Random().NextBytes(hugeValue);

            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell> {
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue)
                };

            using (var mutator = table.CreateMutator()) {
                mutator.Set(cells, true);
            }

            foreach (var cell in cells) {
                Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
            }
        }
开发者ID:andysoftdev,项目名称:ht4n,代码行数:30,代码来源:TestTableMutator.cs

示例6: AsyncSetCollectionThreaded

        public void AsyncSetCollectionThreaded(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

            var key = new Key { ColumnFamily = "a" };
            var cells1 = new List<Cell>();
            for (var n = 0; n < 16; ++n) {
                cells1.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            var cells2 = new List<Cell>();
            for (var n = 0; n < 16; ++n) {
                cells2.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            using (var asyncResult = new AsyncResult()) {
                using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    var c1 = 0;
                    var c2 = 0;

                    var t1 = new Thread(
                        () =>
                            {
                                for (var n = 0; n < Count; ++n, ++c1) {
                                    mutator.Set(cells1, true);
                                    if (n == Count / 2) {
                                        mutator.Flush();
                                    }
                                }
                            });

                    var t2 = new Thread(
                        () =>
                            {
                                for (var n = 0; n < Count; ++n, ++c2) {
                                    mutator.Set(cells2, true);
                                    if (n == Count / 2) {
                                        mutator.Flush();
                                    }
                                }
                            });

                    t1.Start();
                    t2.Start();
                    t1.Join();
                    t2.Join();
                    Assert.IsTrue(c1 > 0);
                    Assert.IsTrue(c2 > 0);
                }

                asyncResult.Join();
                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
            }
        }
开发者ID:andysoftdev,项目名称:ht4n,代码行数:57,代码来源:TestAsyncTableMutator.cs

示例7: AsyncSetCollectionHugeValues

        public void AsyncSetCollectionHugeValues(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

            const int K = 1024;
            const int M = K * K;
            var hugeValue = new byte[M];
            new Random().NextBytes(hugeValue);

            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell> {
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue)
                };

            using (var asyncResult = new AsyncResult()) {
                using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    mutator.Set(cells, true);
                }

                asyncResult.Join();
                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
                foreach (var cell in cells) {
                    Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                }
            }
        }
开发者ID:andysoftdev,项目名称:ht4n,代码行数:39,代码来源:TestAsyncTableMutator.cs

示例8: AsyncSetCollectionDifferentSizedValues

        public void AsyncSetCollectionDifferentSizedValues(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

            var sb = new StringBuilder();
            for (var n = 0; n < 0x40; ++n) {
                sb.Append(Guid.NewGuid().ToString());
            }

            var largeValue = Encoding.GetBytes(sb.ToString());
            for (var n = 0; n < 0x4000; ++n) {
                sb.Append(Guid.NewGuid().ToString());
            }

            var hugeValue = Encoding.GetBytes(sb.ToString());
            var smallValue = Encoding.GetBytes(Guid.NewGuid().ToString());

            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell> {
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue)
                };

            using (var asyncResult = new AsyncResult()) {
                using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    mutator.Set(cells, true);
                }

                asyncResult.Join();
                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
                foreach (var cell in cells) {
                    Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                }
            }
        }
开发者ID:andysoftdev,项目名称:ht4n,代码行数:47,代码来源:TestAsyncTableMutator.cs

示例9: AsyncSetCollectionCreateKeyLazy

        public void AsyncSetCollectionCreateKeyLazy(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell>();
            for (var n = 0; n < Count; ++n) {
                key.Row = (n % 3) == 0 ? Guid.NewGuid().ToString() : null;
                cells.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            using (var asyncResult = new AsyncResult()) {
                using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    mutator.Set(cells);
                }

                asyncResult.Join();
                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
                foreach (var cell in cells) {
                    Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                }

                Assert.AreEqual(Count, this.GetCellCount());
            }
        }
开发者ID:andysoftdev,项目名称:ht4n,代码行数:28,代码来源:TestAsyncTableMutator.cs


注:本文中的Key.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。