Exemple #1
0
        public void Init()
        {
            var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudBlobClient();

            _store = new AzureStore(client, false, null); // Do not snapshot and do tracing!
            _store.CreateContainerIfNotExists("testindexer");

            var store = new SecureStore(_store);

            _indexer = new LuceneIndex(store, "testindexer", "basePath", null);
        }
    UserDataTest loadedData = null; // stores the user data, this is just an example

    // Use this for initialization
    void Start()
    {
        // Set the file location to the Application.persistentDataPath, so we should write here:
        fileToEncrypt = Application.persistentDataPath + fileToEncrypt;
        encryptedFile = Application.persistentDataPath + encryptedFile;
        decryptedFile = Application.persistentDataPath + decryptedFile;

        //Create the secure store object:
        // dont forget the set the password insede the SecureStore.cs
        SecureStore store = new SecureStore();

        //or alternativly use the other constructor
        //SecureStore store = new SecureStore( "YourSecretPassword" );

        // Testing the string encrypter:
        Debug.Log("plainText string: " + plainTextString);
        encryptedTextString = store.encryptString(plainTextString);
        Debug.Log("encrypted string: " + encryptedTextString);
        decryptedTextString = store.decryptString(encryptedTextString);
        Debug.Log("decrypted string: " + decryptedTextString);

        // Testing the file encrypter:
        // Create a file to write to.
        using (StreamWriter sw = File.CreateText(fileToEncrypt))
        {
            sw.WriteLine("Hello!");
            sw.WriteLine("This is a plain text file.");
            sw.WriteLine("Encrypt me!");
        }
        Debug.Log("Text file can be found here: " + fileToEncrypt);

        // Now encrypt it:
        store.encryptFile(fileToEncrypt, encryptedFile);
        Debug.Log("Encryped file can be found here: " + encryptedFile);

        // And also decrypt it:
        store.decryptFile(encryptedFile, decryptedFile);
        Debug.Log("Decryped file can be found here: " + decryptedFile);


        // Testing the stream encrypter by serializing an Object:
        UserDataTest data = new UserDataTest("test-user-7854", "this is test user", 100);

        // Test the saving:
        saveUserData(store, data);

        // Test the loading:
        loadedData = loadUserData(store);
        Debug.Log("Userdata.userGuid: " + loadedData.userGuid);
        Debug.Log("Userdata.userDescription: " + loadedData.userDescription);
        Debug.Log("Userdata.userPoints: " + loadedData.userPoints);
    }
        public void CannotWriteTwoLuceneIndexesOnSameStore()
        {
            _indexer.DeleteAll().Wait();

            var store = new SecureStore(_store);
            using (var indexer2 = new LuceneIndex(store, "testindexer", "basePath", null))
            {
                Assert.Throws<LockObtainFailedException>(() =>
                {
                    indexer2.DeleteAll().Wait();
                });
            }
        }
        public void Init()
        {
            var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudBlobClient();
            _store = new AzureStore(client, false, null); // Do not snapshot and do tracing!
            _store.CreateContainerIfNotExists("testindexer");

            // Use a file based cache for tests (more common use case)
            _tempDir = IO.Path.Combine(IO.Path.GetTempPath(), IO.Path.GetFileNameWithoutExtension(IO.Path.GetRandomFileName()));
            IO.Directory.CreateDirectory(_tempDir);

            var store = new SecureStore(_store);
            _indexer = new LuceneIndex(store, "testindexer", "basePath", null, _tempDir);
        }
Exemple #5
0
        public void WaitsForNewGenerationOnReader()
        {
            var store = new SecureStore(_store);

            using (var readIndexer = new LuceneIndex(store, "testindexer", "basePath", null))
            {
                // Hit the reader initially
                readIndexer.SearchDocuments(s => s.Search(new MatchAllDocsQuery(), int.MaxValue)).Count();

                _indexer.WriteToIndex(CreateIpsumDocs(3000), true).Wait();
                var stream = readIndexer.SearchDocuments(s => s.Search(new MatchAllDocsQuery(), int.MaxValue), true);
                Assert.AreEqual(3000, stream.Count());
            }
        }
Exemple #6
0
        public async Task CannotWriteTwoLuceneIndexesOnSameStore()
        {
            var docs = CreateIpsumDocs(1);
            await _indexer.WriteToIndex(docs, true).ConfigureAwait(false);

            var store = new SecureStore(_store);

            using (var indexer2 = new LuceneIndex(store, "testindexer", "basePath", null))
            {
                Assert.ThrowsAsync <LockObtainFailedException>(() =>
                {
                    return(indexer2.WriteToIndex(docs));
                });
            }
        }
    // This method is for testing the encrypted serialization:
    public void saveUserData(SecureStore store, UserDataTest data)
    {
        string filename = Application.persistentDataPath + userDataFile;

        Debug.Log("Saving user data to: " + filename);

        BinaryFormatter bformatter = new BinaryFormatter();

        bformatter.Binder = new VersionDeserializationBinder();

        FileStream fsCrypt = new FileStream(filename, FileMode.Create);

        // Creating crypto stream via the store:
        CryptoStream cs = store.encryptStream(fsCrypt);

        bformatter.Serialize(cs, data);

        cs.Close();
        fsCrypt.Close();
    }
    // This method is for testing the decrypted deserialization:
    public UserDataTest loadUserData(SecureStore store)
    {
        string filename = Application.persistentDataPath + userDataFile;

        Debug.Log("Loading user data from: " + filename);

        BinaryFormatter bformatter = new BinaryFormatter();

        bformatter.Binder = new VersionDeserializationBinder();

        FileStream fsCrypt = new FileStream(filename, FileMode.Open);

        // Creating crypto stream via the store:
        CryptoStream cs   = store.decryptStream(fsCrypt);
        UserDataTest data = (UserDataTest)bformatter.Deserialize(cs);

        cs.Close();
        fsCrypt.Close();

        return(data);
    }