Пример #1
0
        public void OpenNewSequence(string dbFileName,
                                    out BTreeDatabase db, out Sequence seq)
        {
            // Open a database.
            BTreeDatabaseConfig btreeDBConfig =
                new BTreeDatabaseConfig();

            btreeDBConfig.Creation = CreatePolicy.IF_NEEDED;
            db = BTreeDatabase.Open(dbFileName, btreeDBConfig);

            // Configure and initialize sequence.
            SequenceConfig seqConfig = new SequenceConfig();

            seqConfig.BackingDatabase = db;
            seqConfig.CacheSize       = 1000;
            seqConfig.Creation        = CreatePolicy.ALWAYS;
            seqConfig.Decrement       = false;
            seqConfig.FreeThreaded    = true;
            seqConfig.Increment       = true;
            seqConfig.InitialValue    = 100;
            seqConfig.key             = new DatabaseEntry(
                ASCIIEncoding.ASCII.GetBytes("key"));
            seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
            seqConfig.Wrap = true;
            seq            = new Sequence(seqConfig);
        }
Пример #2
0
        public static void Config(XmlElement xmlElement,
                                  ref SequenceConfig seqConfig, bool compulsory)
        {
            uint uintValue = new uint();
            bool boolValue = new bool();
            long longValue = new long();

            if (Configuration.ConfigUint(xmlElement, "CacheSize",
                                         ref uintValue, compulsory))
            {
                seqConfig.CacheSize = uintValue;
            }
            Configuration.ConfigCreatePolicy(xmlElement, "Creation",
                                             ref seqConfig.Creation, compulsory);
            if (Configuration.ConfigBool(xmlElement, "Decrement",
                                         ref boolValue, compulsory))
            {
                seqConfig.Decrement = boolValue;
            }
            Configuration.ConfigBool(xmlElement, "FreeThreaded",
                                     ref seqConfig.FreeThreaded, compulsory);
            if (Configuration.ConfigBool(xmlElement, "Increment",
                                         ref boolValue, compulsory))
            {
                seqConfig.Increment = boolValue;
            }
            if (Configuration.ConfigLong(xmlElement, "InitialValue",
                                         ref longValue, compulsory))
            {
                seqConfig.InitialValue = longValue;
            }
            Configuration.ConfigBool(xmlElement, "Wrap",
                                     ref seqConfig.Wrap, compulsory);
        }
Пример #3
0
        /// <summary>
        /// 创建数据库
        /// </summary>
        /// <param name="config"></param>
        private void CreateDB(DatabaseConfig config)
        {
            string dbFile = Path.Combine(home, dbName + dbFileEx);

            db_File = dbFile = dbName + dbFileEx;
            dbFile  = Path.Combine(Environment.CurrentDirectory, db_File);
            switch (DBType)
            {
            case DBType.BTree:
            case DBType.Sequence:
            {
                BTreeDatabaseConfig dbcfg = config as BTreeDatabaseConfig;

                if (DBType == DBType.Sequence)
                {
                    dbcfg.Duplicates = DuplicatesPolicy.NONE;
                }
                db = BTreeDatabase.Open(db_File, dbName, dbcfg);
                if (dbcfg.Duplicates != DuplicatesPolicy.SORTED)
                {
                    /* Configure and initialize sequence. */
                    seqConfig = new SequenceConfig
                    {
                        BackingDatabase = db,
                        Creation        = CreatePolicy.IF_NEEDED,
                        Increment       = true,
                        InitialValue    = Int64.MaxValue,
                        key             = new DatabaseEntry()
                    };
                    seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
                    seqConfig.Wrap = true;
                    DbtFromString(seqConfig.key, "excs_sequence");
                    seq = new Sequence(seqConfig);
                }
            }
            break;

            case DBType.Hash:
                db = HashDatabase.Open(dbFile, config as HashDatabaseConfig);
                break;

            case DBType.Recno:
                db = RecnoDatabase.Open(dbFile, config as RecnoDatabaseConfig);
                break;

            case DBType.Queue:
                db = QueueDatabase.Open(dbFile, config as QueueDatabaseConfig);
                break;

            default:
                db = BTreeDatabase.Open(dbFile, config as BTreeDatabaseConfig);
                break;
            }
        }
Пример #4
0
        public void TestConfig()
        {
            testName = "TestConfig";
            SetUpTest(false);
            SequenceConfig seqConfig = new SequenceConfig();
            XmlElement     xmlElem   = Configuration.TestSetUp(
                testFixtureName, testName);

            Config(xmlElem, ref seqConfig, true);
            Confirm(xmlElem, seqConfig, true);
        }
Пример #5
0
        public void TestRemoveWithNoSync()
        {
            testName = "TestRemoveWithNoSync";
            testHome = testFixtureHome + "/" + testName;
            string dbFileName = testName + ".db";

            Configuration.ClearDir(testHome);

            // Open a database and an increase sequence.
            DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig();

            envConfig.Create     = true;
            envConfig.UseLogging = true;
            envConfig.UseMPool   = true;
            envConfig.UseTxns    = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(testHome, envConfig);

            /* Configure and open sequence's database. */
            BTreeDatabaseConfig btreeDBConfig = new BTreeDatabaseConfig();

            btreeDBConfig.AutoCommit = true;
            btreeDBConfig.Creation   = CreatePolicy.IF_NEEDED;
            btreeDBConfig.Env        = env;
            BTreeDatabase btreeDB = BTreeDatabase.Open(dbFileName, btreeDBConfig);

            /* Configure and initialize sequence. */
            SequenceConfig seqConfig = new SequenceConfig();

            seqConfig.BackingDatabase = btreeDB;
            seqConfig.Creation        = CreatePolicy.IF_NEEDED;
            seqConfig.Increment       = true;
            seqConfig.InitialValue    = Int64.MaxValue;
            seqConfig.key             = new DatabaseEntry();
            seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
            seqConfig.Wrap     = true;
            seqConfig.key      = new DatabaseEntry();
            seqConfig.key.Data = ASCIIEncoding.ASCII.GetBytes("ex_csharp_sequence");
            Sequence seq = new Sequence(seqConfig);

            /*
             * Remove the sequence. The sequence handle can not
             * be accessed again.
             */
            seq.Remove(true);
            btreeDB.Close();
            env.Close();
        }
Пример #6
0
 public static void Confirm(XmlElement xmlElement,
                            SequenceConfig seqConfig, bool compulsory)
 {
     Configuration.ConfirmUint(xmlElement, "CacheSize",
                               seqConfig.CacheSize, compulsory);
     Configuration.ConfirmCreatePolicy(xmlElement, "Creation",
                                       seqConfig.Creation, compulsory);
     Configuration.ConfirmBool(xmlElement, "Decrement",
                               seqConfig.Decrement, compulsory);
     Configuration.ConfirmBool(xmlElement, "FreeThreaded",
                               seqConfig.FreeThreaded, compulsory);
     Configuration.ConfirmBool(xmlElement, "Increment",
                               seqConfig.Increment, compulsory);
     Configuration.ConfirmLong(xmlElement, "InitialValue",
                               seqConfig.InitialValue, compulsory);
     Configuration.ConfirmBool(xmlElement, "Wrap",
                               seqConfig.Wrap, compulsory);
 }
Пример #7
0
        public CipherStrategy(
            ICipherSuitesProvider cipherSuitesProvider,

            Connection connection,

            EndConfig endConfig,
            SequenceConfig sequenceConfig,
            BlockCipherConfig blockCipherConfig,
            CipherSuiteConfig cipherSuiteConfig)
        {
            _cipherSuitesProvider = cipherSuitesProvider;

            _connection = connection;

            _endConfig         = endConfig;
            _sequenceConfig    = sequenceConfig;
            _blockCipherConfig = blockCipherConfig;
            _cipherSuiteConfig = cipherSuiteConfig;
        }
Пример #8
0
        public AEADCipherStrategy(
            IRandom random,
            ICipherSuitesProvider cipherSuitesProvider,

            Connection connection,

            CipherSuiteConfig cipherSuiteConfig,
            SequenceConfig sequenceConfig,
            EndConfig endConfig,
            AEADCipherConfig aeadConfig)
        {
            _random = random;
            _cipherSuitesProvider = cipherSuitesProvider;

            _connection = connection;

            _cipherSuiteConfig = cipherSuiteConfig;
            _sequenceConfig    = sequenceConfig;
            _endConfig         = endConfig;
            _aeadConfig        = aeadConfig;
        }
Пример #9
0
        public void TestConfig()
        {
            testName = "TestConfig";
            testHome = testFixtureHome + "/" + testName;
            string     dbFileName = testHome + "/" + testName + ".db";
            XmlElement xmlElem    = Configuration.TestSetUp(
                testFixtureName, testName);

            Configuration.ClearDir(testHome);

            // Open a database.
            BTreeDatabaseConfig btreeDBConfig =
                new BTreeDatabaseConfig();

            btreeDBConfig.Creation = CreatePolicy.IF_NEEDED;
            BTreeDatabase btreeDB = BTreeDatabase.Open(
                dbFileName, btreeDBConfig);

            // Configure and initialize sequence.
            SequenceConfig seqConfig = new SequenceConfig();

            seqConfig.BackingDatabase = btreeDB;
            seqConfig.Creation        = CreatePolicy.IF_NEEDED;
            seqConfig.key             = new DatabaseEntry(
                ASCIIEncoding.ASCII.GetBytes("key"));
            seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
            SequenceConfigTest.Config(xmlElem, ref seqConfig, true);
            Sequence seq = new Sequence(seqConfig);


            /*
             * Confirm that the squence is opened with the
             * configuration that we set.
             */
            Confirm(xmlElem, seq, true);

            /* Close sequence, database and environment. */
            seq.Close();
            btreeDB.Close();
        }
Пример #10
0
        public void OpenNewSequenceInEnv(string home, string dbname,
                                         out DatabaseEnvironment env, out BTreeDatabase db,
                                         out Sequence seq)
        {
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create     = true;
            envConfig.UseTxns    = true;
            envConfig.UseMPool   = true;
            envConfig.UseLogging = true;
            env = DatabaseEnvironment.Open(home, envConfig);

            Transaction         openTxn  = env.BeginTransaction();
            BTreeDatabaseConfig dbConfig =
                new BTreeDatabaseConfig();

            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env      = env;
            db = BTreeDatabase.Open(dbname + ".db", dbConfig,
                                    openTxn);
            openTxn.Commit();

            Transaction    seqTxn    = env.BeginTransaction();
            SequenceConfig seqConfig = new SequenceConfig();

            seqConfig.BackingDatabase = db;
            seqConfig.Creation        = CreatePolicy.ALWAYS;
            seqConfig.Decrement       = false;
            seqConfig.FreeThreaded    = true;
            seqConfig.Increment       = true;
            seqConfig.InitialValue    = 0;
            seqConfig.key             = new DatabaseEntry(
                ASCIIEncoding.ASCII.GetBytes("key"));
            seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
            seqConfig.Wrap = true;
            seq            = new Sequence(seqConfig);
            seqTxn.Commit();
        }
Пример #11
0
        public void TestConfigObj()
        {
            testName = "TestConfigObj";
            testHome = testFixtureHome + "/" + testName;
            string dbFileName = testHome + "/" + testName + ".db";

            Configuration.ClearDir(testHome);

            // Open a database.
            BTreeDatabaseConfig btreeDBConfig =
                new BTreeDatabaseConfig();

            btreeDBConfig.Creation = CreatePolicy.IF_NEEDED;
            BTreeDatabase btreeDB = BTreeDatabase.Open(
                dbFileName, btreeDBConfig);

            /* Configure and initialize sequence. */
            SequenceConfig seqConfig = new SequenceConfig();

            seqConfig.BackingDatabase = btreeDB;
            seqConfig.Creation        = CreatePolicy.IF_NEEDED;
            seqConfig.key             = new DatabaseEntry(
                ASCIIEncoding.ASCII.GetBytes("key"));
            seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
            Sequence seq = new Sequence(seqConfig);

            // Confirm the objects set in SequenceConfig.
            Assert.AreEqual(dbFileName,
                            seq.BackingDatabase.FileName);
            Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("key"),
                            seq.Key.Data);
            Assert.AreEqual(Int64.MinValue, seq.Min);
            Assert.AreEqual(Int64.MaxValue, seq.Max);

            /* Close sequence, database and environment. */
            seq.Close();
            btreeDB.Close();
        }
Пример #12
0
        static void Main(string[] args)
        {
            BTreeDatabase             btreeDB;
            BTreeDatabaseConfig       btreeDBConfig;
            DatabaseEnvironment       env;
            DatabaseEnvironmentConfig envConfig;
            Sequence       seq;
            SequenceConfig seqConfig;
            string         buff;
            string         dbFileName;
            string         home;
            string         progName;

            /*
             * excs_sequence is meant to be run from build_windows\AnyCPU, in
             * either the Debug or Release directory. The required core
             * libraries, however, are in either build_windows\Win32 or
             * build_windows\x64, depending upon the platform.  That location
             * needs to be added to the PATH environment variable for the
             * P/Invoke calls to work.
             */
            try {
                String pwd = Environment.CurrentDirectory;
                pwd = Path.Combine(pwd, "..");
                pwd = Path.Combine(pwd, "..");
                if (IntPtr.Size == 4)
                {
                    pwd = Path.Combine(pwd, "Win32");
                }
                else
                {
                    pwd = Path.Combine(pwd, "x64");
                }
#if DEBUG
                pwd = Path.Combine(pwd, "Debug");
#else
                pwd = Path.Combine(pwd, "Release");
#endif
                pwd += ";" + Environment.GetEnvironmentVariable("PATH");
                Environment.SetEnvironmentVariable("PATH", pwd);
            } catch (Exception e) {
                Console.WriteLine(
                    "Unable to set the PATH environment variable.");
                Console.WriteLine(e.Message);
                return;
            }

            progName = "excs_sequence";
            try {
                home       = args[0];
                dbFileName = args[1];
            } catch {
                Usage();
                return;
            };

            /* Optiionally remove the existing database file. */
            if (File.Exists(dbFileName))
            {
                while (true)
                {
                    Console.Write
                        ("File already exists, delete or not (y/n)?");
                    buff = Console.ReadLine();
                    if (buff == "y" || buff == "n")
                    {
                        break;
                    }
                }

                if (buff == "y")
                {
                    File.Delete(dbFileName);
                    Console.WriteLine("The existing {0} is deleted",
                                      dbFileName);
                }
            }

            /* Configure and open environment. */
            envConfig            = new DatabaseEnvironmentConfig();
            envConfig.Create     = true;
            envConfig.UseLogging = true;
            envConfig.UseMPool   = true;
            envConfig.UseTxns    = true;
            try {
                env = DatabaseEnvironment.Open(home, envConfig);
            } catch (Exception e) {
                Console.WriteLine("{0}:{1}\n{2}",
                                  e.Source, e.Message, e.StackTrace);
                return;
            }

            /* Configure and open sequence's database. */
            btreeDBConfig             = new BTreeDatabaseConfig();
            btreeDBConfig.AutoCommit  = true;
            btreeDBConfig.Creation    = CreatePolicy.IF_NEEDED;
            btreeDBConfig.ErrorPrefix = progName;
            btreeDBConfig.Env         = env;
            try {
                btreeDB = BTreeDatabase.Open(dbFileName,
                                             btreeDBConfig);
            } catch (Exception e) {
                Console.WriteLine("{0}:{1}\n{2}",
                                  e.Source, e.Message, e.StackTrace);
                return;
            }

            /* Configure and initialize sequence. */
            seqConfig = new SequenceConfig();
            seqConfig.BackingDatabase = btreeDB;
            seqConfig.Creation        = CreatePolicy.IF_NEEDED;
            seqConfig.Increment       = true;
            seqConfig.InitialValue    = Int64.MaxValue;
            seqConfig.key             = new DatabaseEntry();
            seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
            seqConfig.Wrap = true;
            DbtFromString(seqConfig.key, "excs_sequence");
            seq = new Sequence(seqConfig);

            /* Get from sequence. */
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("{0}", seq.Get(2));
                Console.ReadLine();
            }

            Console.WriteLine("Sequence Name: {0}",
                              seq.BackingDatabase.FileName);
            Console.WriteLine("Sequence Key: {0}",
                              StrFromDBT(seq.Key));
            Console.WriteLine("{0}->{1}", seq.Min, seq.Max);
            Console.WriteLine(seq.Wrap ? "wrap" : "not wrap");
            Console.WriteLine(seq.Increment ? "increase" :
                              "decrease");

            /* Close sequence, database and environment. */
            seq.Close();
            btreeDB.Close();
            env.Close();
        }
Пример #13
0
 private void OnSequenceUpdated(SequenceConfig sequenceConfig)
 {
     currentSequenceConfig = sequenceConfig;
 }
Пример #14
0
    void Awake()
    {
        //TODO: Find solution for JSON on Android

        sequencePath = Application.streamingAssetsPath + "/Sequence.json";
        menuPath     = Application.streamingAssetsPath + "/MainMenu.json";
        boardPath    = Application.streamingAssetsPath + "/TestLevel1.json";
        chamberPath  = Application.streamingAssetsPath + "/Chamber.json";
        cutScenePath = Application.streamingAssetsPath + "/CutScene.json";

        //F**k it. For now, not reading JSON from external JSON file, so config will go here for the time being.

        string jsonString  = "{ \"sequences\": [{\"seq1\":\"8484239823\",\"seq2\":\"Powai\",\"seq3\":\"Random Nick\"}]}";
        string jsonString2 = "{ \"sequences\": [\"fuu fuu\",\"fee fee\",3,4]}";


        SeqArray seqArray = JsonUtility.FromJson <SeqArray> (jsonString2);

        //Debug.Log (seqArray.sequences [0]);

        for (int i = 0; i < seqArray.sequences.Count; i++)
        {
            //Debug.Log(seqArray.sequences[i].faa_faa);
        }


        //MAKE THIS INTO A SINGLE FUNCTION ------------------------

        // Main Menu JSON
        if (Application.platform == RuntimePlatform.Android)           //Need to extract file from apk first
        {
            WWW menuReader = new WWW(menuPath);

            while (!menuReader.isDone)
            {
            }

            menuJSONString = menuReader.text;
        }
        else
        {
            menuJSONString = File.ReadAllText(menuPath);
        }

        //Board JSON
        if (Application.platform == RuntimePlatform.Android)           //Need to extract file from apk first
        {
            WWW boardReader = new WWW(boardPath);

            while (!boardReader.isDone)
            {
            }

            boardJSONString = boardReader.text;
        }
        else
        {
            boardJSONString = File.ReadAllText(boardPath);
        }

        //Chamber JSON
        if (Application.platform == RuntimePlatform.Android)           //Need to extract file from apk first
        {
            WWW chamberReader = new WWW(chamberPath);

            while (!chamberReader.isDone)
            {
            }

            chamberJSONString = chamberReader.text;
        }
        else
        {
            chamberJSONString = File.ReadAllText(chamberPath);
        }

        //Cut Scene JSON
        if (Application.platform == RuntimePlatform.Android)           //Need to extract file from apk first
        {
            WWW cutSceneReader = new WWW(cutScenePath);

            while (!cutSceneReader.isDone)
            {
            }

            cutSceneJSONString = cutSceneReader.text;
        }
        else
        {
            cutSceneJSONString = File.ReadAllText(cutScenePath);
        }
        //--------------------------------------

        sequenceConfig = JsonUtility.FromJson <SequenceConfig> (sequenceJSONString);
        menuConfig     = JsonUtility.FromJson <MenuConfig> (menuJSONString);
        boardConfig    = JsonUtility.FromJson <BoardConfig> (boardJSONString);
        chamberConfig  = JsonUtility.FromJson <ChamberConfig> (chamberJSONString);
        cutSceneConfig = JsonUtility.FromJson <CutSceneConfig> (cutSceneJSONString);
    }