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


C# DB.Get方法代码示例

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


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

示例1: TestDeleteEntryFromDatabase

 public void TestDeleteEntryFromDatabase()
 {
     using (var db = new DB(new Options { CreateIfMissing = true }, "test1.db"))
     {
         db.Put(new WriteOptions(), Slice.FromString("Foo"), Slice.FromString("Bar"));
         Assert.IsNotNull(db.Get(new ReadOptions(), Slice.FromString("Foo")));
         Assert.IsTrue(db.Delete(new WriteOptions(), Slice.FromString("Foo")));
         Assert.IsNull(db.Get(new ReadOptions(), Slice.FromString("Foo")));
     }
 }
开发者ID:maxpert,项目名称:LevelDBWinRT,代码行数:10,代码来源:BasicTests.cs

示例2: Main

 public static void Main(string[] args)
 {
     using (var database = new DB("mytestdb", new Options() { CreateIfMissing = true, BloomFilter = new BloomFilterPolicy(10) }))
     {
         database.Put("key1", "value1");
         Assert.AreEqual("value1", database.Get("key1"));
         Assert.IsTrue(database.Get("key1") != null);
         database.Delete("key1");
         Assert.IsFalse(database.Get("key1") != null);
         Assert.IsNull(database.Get("key1"));
     }
 }
开发者ID:ren85,项目名称:leveldb.net,代码行数:12,代码来源:DatabaseTest.cs

示例3: Main3

        static void Main3()
        {
            var path = CleanTestDB();

            using (var db = new DB(new Options {CreateIfMissing = true}, path))
            {
                db.Put(1, new[] {2, 3}, new WriteOptions());
                db.Put(2, new[] {1, 2, 4});
                db.Put(3, new[] {1, 3});
                db.Put(4, new[] {2, 5, 7});
                db.Put(5, new[] {4, 6, 7, 8});
                db.Put(6, new[] {5});
                db.Put(7, new[] {4, 5, 8});
                db.Put(8, new[] {5, 7});

                var a = db.Get(1);
                var b = db.Get(2);
                var c = db.Get(3);
                var d = db.Get(4);
                var e = db.Get(5);
                var f = db.Get(6);
                var g = db.Get(7);
                var h = db.Get(8);

            }
        }
开发者ID:huyi,项目名称:LevelDB,代码行数:26,代码来源:Program.cs

示例4: LevelDBBlockchain

 public LevelDBBlockchain()
 {
     Slice value;
     db = DB.Open(Settings.Default.DataDirectoryPath);
     if (db.TryGet(ReadOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Initialized), out value) && value.ToBoolean())
     {
         value = db.Get(ReadOptions.Default, SliceBuilder.Begin(DataEntryPrefix.SYS_CurrentBlock));
         this.current_block = new UInt256(value.ToArray().Take(32).ToArray());
         this.current_height = BitConverter.ToUInt32(value.ToArray(), 32);
     }
     else
     {
         WriteBatch batch = new WriteBatch();
         ReadOptions options = new ReadOptions { FillCache = false };
         using (Iterator it = db.NewIterator(options))
         {
             for (it.SeekToFirst(); it.Valid(); it.Next())
             {
                 batch.Delete(it.Key());
             }
         }
         batch.Put(SliceBuilder.Begin(DataEntryPrefix.CFG_Version), 0);
         db.Write(WriteOptions.Default, batch);
         AddBlockToChain(GenesisBlock);
         db.Put(WriteOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Initialized), true);
     }
     thread_persistence = new Thread(PersistBlocks);
     thread_persistence.Name = "LevelDBBlockchain.PersistBlocks";
     thread_persistence.Start();
     AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
 }
开发者ID:4T-Shirt,项目名称:AntShares,代码行数:31,代码来源:LevelDBBlockchain.cs

示例5: TestCRUD

        public void TestCRUD()
        {
            var path = CleanTestDB();

            using (var db = new DB(path, new Options { CreateIfMissing = true }))
            {
                db.Put("Tampa", "green");
                db.Put("London", "red");
                db.Put("New York", "blue");

                Assert.AreEqual(db.Get("Tampa"), "green");
                Assert.AreEqual(db.Get("London"), "red");
                Assert.AreEqual(db.Get("New York"), "blue");

                db.Delete("New York");

                Assert.IsNull(db.Get("New York"));

                db.Delete("New York");
            }
        }
开发者ID:ren85,项目名称:leveldb.net,代码行数:21,代码来源:ReactiveTests.cs

示例6: TestReadFromSnapshotOfDatabase

 public void TestReadFromSnapshotOfDatabase()
 {
     using (var db = new DB(new Options { CreateIfMissing = true }, "test1.db"))
     {
         db.Put(new WriteOptions(), Slice.FromString("Foo"), Slice.FromString("Bar"));
         using (var snapshot = db.GetSnapshot())
         {
             var opts = new ReadOptions{ Snapshot = snapshot };
             Assert.IsNotNull(db.Get(opts, Slice.FromString("Foo")));
             Assert.IsTrue(db.Delete(new WriteOptions(), Slice.FromString("Foo")));
             Assert.IsNotNull(db.Get(opts, Slice.FromString("Foo")));
         }
     }
 }
开发者ID:maxpert,项目名称:LevelDBWinRT,代码行数:14,代码来源:BasicTests.cs

示例7: Main

        static void Main()
        {
            var l = new Logger(s => Console.WriteLine(s));
            var x = new Options 
                    { 
                        CreateIfMissing = true, 
                        RestartInterval = 13, 
                        MaxOpenFiles = 100,
                        InfoLog = l
                    };

            var db = new DB(x, @"C:\Temp\A");
            db.Put("hello", "world");
            var world = db.Get("hello");
            Console.WriteLine(world);

            for (var j = 0; j < 5; j++)
            {
                var r = new Random(0);
                var data = "";

                for (int i = 0; i < 1024; i++)
                {
                    data += 'a' + r.Next(26);
                }
                for (int i = 0; i < 5*1024; i++)
                {
                    db.Put(string.Format("row{0}", i), data);
                }
                Thread.Sleep(100);
            }
            Console.WriteLine();

            //using(var logger = new Logger(Console.WriteLine))
            //{
            //    Console.WriteLine("hello");
            //}

            db.Dispose();
            GC.KeepAlive(l);
        }
开发者ID:huyi,项目名称:LevelDB,代码行数:41,代码来源:Program.cs

示例8: LevelDBBlockchain

 public LevelDBBlockchain(string path)
 {
     header_index.Add(GenesisBlock.Hash);
     Version version;
     Slice value;
     db = DB.Open(path, new Options { CreateIfMissing = true });
     if (db.TryGet(ReadOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Version), out value) && Version.TryParse(value.ToString(), out version) && version >= Version.Parse("0.4"))
     {
         ReadOptions options = new ReadOptions { FillCache = false };
         value = db.Get(options, SliceBuilder.Begin(DataEntryPrefix.SYS_CurrentBlock));
         this.current_block_hash = new UInt256(value.ToArray().Take(32).ToArray());
         this.current_block_height = BitConverter.ToUInt32(value.ToArray(), 32);
         foreach (Block header in db.Find(options, SliceBuilder.Begin(DataEntryPrefix.DATA_HeaderList), (k, v) =>
         {
             using (MemoryStream ms = new MemoryStream(v.ToArray(), false))
             using (BinaryReader r = new BinaryReader(ms))
             {
                 return new
                 {
                     Index = BitConverter.ToUInt32(k.ToArray(), 1),
                     Headers = r.ReadSerializableArray<Block>()
                 };
             }
         }).OrderBy(p => p.Index).SelectMany(p => p.Headers).ToArray())
         {
             if (header.Hash != GenesisBlock.Hash)
             {
                 header_chain.Add(header.Hash, header, header.PrevBlock);
                 header_index.Add(header.Hash);
             }
             stored_header_count++;
         }
         if (stored_header_count == 0)
         {
             Dictionary<UInt256, Block> table = db.Find(options, SliceBuilder.Begin(DataEntryPrefix.DATA_Block), (k, v) => Block.FromTrimmedData(v.ToArray(), 0)).ToDictionary(p => p.PrevBlock);
             for (UInt256 hash = GenesisBlock.Hash; hash != current_block_hash;)
             {
                 Block header = table[hash];
                 header_chain.Add(header.Hash, header, header.PrevBlock);
                 header_index.Add(header.Hash);
                 hash = header.Hash;
             }
         }
         else if (current_block_height >= stored_header_count)
         {
             List<Block> list = new List<Block>();
             for (UInt256 hash = current_block_hash; hash != header_index[(int)stored_header_count - 1];)
             {
                 Block header = Block.FromTrimmedData(db.Get(options, SliceBuilder.Begin(DataEntryPrefix.DATA_Block).Add(hash)).ToArray(), 0);
                 list.Add(header);
                 header_index.Insert((int)stored_header_count, hash);
                 hash = header.PrevBlock;
             }
             for (int i = list.Count - 1; i >= 0; i--)
             {
                 header_chain.Add(list[i].Hash, list[i], list[i].PrevBlock);
             }
         }
         this.current_header_hash = header_index[header_index.Count - 1];
     }
     else
     {
         WriteBatch batch = new WriteBatch();
         ReadOptions options = new ReadOptions { FillCache = false };
         using (Iterator it = db.NewIterator(options))
         {
             for (it.SeekToFirst(); it.Valid(); it.Next())
             {
                 batch.Delete(it.Key());
             }
         }
         db.Write(WriteOptions.Default, batch);
         Persist(GenesisBlock);
         db.Put(WriteOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Version), Assembly.GetExecutingAssembly().GetName().Version.ToString());
     }
     thread_persistence = new Thread(PersistBlocks);
     thread_persistence.Name = "LevelDBBlockchain.PersistBlocks";
     thread_persistence.Start();
     AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
 }
开发者ID:butine,项目名称:research,代码行数:80,代码来源:LevelDBBlockchain.cs

示例9: Error

 public void Error()
 {
     var options = new Options () {
         CreateIfMissing = false
     };
     var db = new DB (options, "non-existent");
     Assert.Fail ();
     db.Get ("key1");
 }
开发者ID:vebin,项目名称:BD2,代码行数:9,代码来源:DBTests.cs

示例10: TestReadMissingEntryDatabase

 public void TestReadMissingEntryDatabase()
 {
     using (var db = new DB(new Options { CreateIfMissing = true }, "test1.db"))
     {
         Assert.IsNull(db.Get(new ReadOptions(), Slice.FromString("boo")));
     }
 }
开发者ID:maxpert,项目名称:LevelDBWinRT,代码行数:7,代码来源:BasicTests.cs

示例11: IngestAnalysisMethodSpecificsFromDB

        /// <summary>
        /// Get specific parameter sets for the given detector, material type pair.
        /// Returns default values if database entry not found
        /// </summary>
        /// <param name="detname"></param>
        /// <param name="mat"></param>
        /// <param name="db"></param>
        public void IngestAnalysisMethodSpecificsFromDB(INCCSelector sel, AnalysisMethods ams, DB.AnalysisMethodSpecifiers db)
        {
            foreach (AnalysisMethod am in System.Enum.GetValues(typeof(AnalysisMethod)))
            {
                if (!ams.choices[(int)am])
                    continue;
                if (!(am > AnalysisMethod.None && am <= AnalysisMethod.TruncatedMultiplicity && (am != AnalysisMethod.INCCNone)))
                {
                    if (!am.IsNone())
                        NC.App.Pest.logger.TraceEvent(LogLevels.Warning, 34061, "Skipping DB ingest of {0} {1} calib params", sel, am);
                    continue;
                }
                string current = String.Format("{0} {1} parameters", sel, am.FullName());
                int logid = 34170 + (int)am;
                LogLevels lvl = LogLevels.Verbose;
                DataRow dr;
                switch (am)
                {
                    case AnalysisMethod.KnownA:
                        INCCAnalysisParams.known_alpha_rec ks = new INCCAnalysisParams.known_alpha_rec();
                        dr = db.Get(sel.detectorid, sel.material, "known_alpha_rec");
                        if (dr != null)
                        {
                            ks.rho_zero = DB.Utils.DBDouble(dr["rho_zero"]);
                            ks.alpha_wt = DB.Utils.DBDouble(dr["alpha_wt"]);
                            ks.k = DB.Utils.DBDouble(dr["k"]);
                            ks.cev.a = DB.Utils.DBDouble(dr["a"]);
                            ks.cev.b = DB.Utils.DBDouble(dr["b"]);
                            ks.cev.var_a = DB.Utils.DBDouble(dr["var_a"]);
                            ks.cev.var_b = DB.Utils.DBDouble(dr["var_b"]);
                            ks.cev.setcovar(Coeff.a, Coeff.b, DB.Utils.DBDouble(dr["covar_ab"]));
                            ks.cev.sigma_x = DB.Utils.DBDouble(dr["sigma_x"]);
                            ks.known_alpha_type = (INCCAnalysisParams.KnownAlphaVariant)(DB.Utils.DBInt32(dr["known_alpha_type"]));
                            ks.ring_ratio.cal_curve_equation = (INCCAnalysisParams.CurveEquation)(DB.Utils.DBInt32(dr["ring_ratio_equation"]));
                            ks.ring_ratio.a = DB.Utils.DBDouble(dr["ring_ratio_a"]);
                            ks.ring_ratio.b = DB.Utils.DBDouble(dr["ring_ratio_b"]);
                            ks.ring_ratio.c = DB.Utils.DBDouble(dr["ring_ratio_c"]);
                            ks.ring_ratio.d = DB.Utils.DBDouble(dr["ring_ratio_d"]);
                            ks.dcl_mass = DB.Utils.ReifyDoubles((string)dr["dcl_mass"]);
                            ks.doubles = DB.Utils.ReifyDoubles((string)dr["doubles"]);
                            ks.heavy_metal_reference = DB.Utils.DBDouble(dr["heavy_metal_reference"]);
                            ks.heavy_metal_corr_factor = DB.Utils.DBDouble(dr["heavy_metal_corr_factor"]);
                            ks.cev.upper_mass_limit = DB.Utils.DBDouble(dr["upper_mass_limit"]);
                            ks.cev.lower_mass_limit = DB.Utils.DBDouble(dr["lower_mass_limit"]);
                        }
                        else
                            lvl = LogLevels.Info;
                        ams.AddMethod(am, ks);
                        break;
                    case AnalysisMethod.CalibrationCurve:
                        INCCAnalysisParams.cal_curve_rec cs = new INCCAnalysisParams.cal_curve_rec();
                        dr = db.Get(sel.detectorid, sel.material, "cal_curve_rec");
                        if (dr != null)
                        {
                            CalCurveDBSnock(cs.cev, dr);
                            cs.CalCurveType = (INCCAnalysisParams.CalCurveType)DB.Utils.DBInt32(dr["cal_curve_type"]);
                            cs.dcl_mass = DB.Utils.ReifyDoubles((string)dr["dcl_mass"]);
                            cs.doubles = DB.Utils.ReifyDoubles((string)dr["doubles"]);
                            cs.percent_u235 = DB.Utils.DBDouble(dr["percent_u235"]);
                            cs.heavy_metal_reference = DB.Utils.DBDouble(dr["heavy_metal_reference"]);
                            cs.heavy_metal_corr_factor = DB.Utils.DBDouble(dr["heavy_metal_corr_factor"]);
                        }
                        else
                            lvl = LogLevels.Info;
                        ams.AddMethod(am, cs);
                        break;
                    case AnalysisMethod.KnownM:
                        INCCAnalysisParams.known_m_rec ms = new INCCAnalysisParams.known_m_rec();
                        dr = db.Get(sel.detectorid, sel.material, "known_m_rec");
                        if (dr != null)
                        {
                            ms.sf_rate = DB.Utils.DBDouble(dr["sf_rate"]);
                            ms.vs1 = DB.Utils.DBDouble(dr["vs1"]);
                            ms.vs2 = DB.Utils.DBDouble(dr["vs2"]);
                            ms.vi1 = DB.Utils.DBDouble(dr["vi1"]);
                            ms.vi2 = DB.Utils.DBDouble(dr["vi2"]);
                            ms.b = DB.Utils.DBDouble(dr["b"]);
                            ms.c = DB.Utils.DBDouble(dr["c"]);
                            ms.sigma_x = DB.Utils.DBDouble(dr["sigma_x"]);
                            ms.lower_mass_limit = DB.Utils.DBDouble(dr["lower_mass_limit"]);
                            ms.upper_mass_limit = DB.Utils.DBDouble(dr["upper_mass_limit"]);
                        }
                        else
                            lvl = LogLevels.Info;
                        ams.AddMethod(am, ms);
                        break;
                    case AnalysisMethod.Multiplicity:
                        INCCAnalysisParams.multiplicity_rec mu = new INCCAnalysisParams.multiplicity_rec();
                        dr = db.Get(sel.detectorid, sel.material, "multiplicity_rec");
                        if (dr != null)
                        {
                            mu.solve_efficiency = (INCCAnalysisParams.MultChoice)DB.Utils.DBInt32(dr["solve_efficiency"]);
                            mu.sf_rate = DB.Utils.DBDouble(dr["sf_rate"]);
//.........这里部分代码省略.........
开发者ID:hnordquist,项目名称:INCC6,代码行数:101,代码来源:INCCCalibCollections.cs

示例12: TestSnapshot

        public void TestSnapshot()
        {
            var path = CleanTestDB();

            using (var db = new DB(path, new Options { CreateIfMissing = true }))
            {
                db.Put("Tampa", "green");
                db.Put("London", "red");
                db.Delete("New York");

                using (var snapShot = db.CreateSnapshot())
                {
                    var readOptions = new ReadOptions { Snapshot = snapShot };

                    db.Put("New York", "blue");

                    Assert.AreEqual(db.Get("Tampa", readOptions), "green");
                    Assert.AreEqual(db.Get("London", readOptions), "red");

                    // Snapshot taken before key was updates
                    Assert.IsNull(db.Get("New York", readOptions));
                }

                // can see the change now
                Assert.AreEqual(db.Get("New York"), "blue");

            }
        }
开发者ID:ren85,项目名称:leveldb.net,代码行数:28,代码来源:ReactiveTests.cs

示例13: Execute

        public Dictionary<string, string> Execute(DB db)
        {
            // TODO: This needs to handle getting more than one result row.
            var results = new Dictionary<string, string>();
            var columns = new List<string>(this.ColumnNames);

            if (columns.Contains("*"))
            {
                this.selectAll = true;
            }

            string key = string.Format(
                SEEK_ROW_BY_INDEX,
                this.TableName,
                this.WhereClauses.Keys.ToArray()[0],
                this.WhereClauses.Values.ToArray()[0]);

            var val = db.Get(key);
            if (val == null)
            {
                return results;
            }
            var enumerator = db.GetEnumerator(val);

            // TODO: Remove try. For some reason we are getting a pinvoke memory access violation.
            try
            {
                while (enumerator.MoveNext())
                {
                    var paths = enumerator.Current.Key.Split('/', ':');
                    if (enumerator.Current.Value != "row" && enumerator.Current.Value != "index" && paths[2] != "index")
                    {
                        var column = paths[paths.Length - 1];
                        if (selectAll || columns.Contains(column))
                        {
                            results.Add(column, enumerator.Current.Value);
                            columns.Remove(column);

                            if (columns.Count == 0)
                            {
                                // Exit since we have read all the columns from the query.
                                break;
                            }
                        }
                    }

                    if (enumerator.Current.Key != val && enumerator.Current.Value == "row")
                    {
                        // We've encountered a new row, exit.
                        break;
                    }
                }
            }
            catch (AccessViolationException e)
            {
                // TODO: I should do something here.
            }

            return results;
        }
开发者ID:pedroreys,项目名称:Dazzle,代码行数:60,代码来源:LevelDbSelectOperation.cs


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