Exemplo n.º 1
0
        private static void TestAsyncUpload(string folderName)
        {
            //Create the manager object
            using (var service = new SystemConnection())
            {
                //Get/create tenant
                const string TenantName = "Test1";
                var          tenantId   = service.GetOrAddTenant(TenantName);

                //Encrypt all files in Notepad++ folder
                var allFiles = Directory.GetFiles(folderName, "*.*", SearchOption.AllDirectories);
                var timer    = Stopwatch.StartNew();
                var index    = 0;
                Parallel.ForEach(allFiles, (file) =>
                {
                    service.SaveFile(tenantId, Container, file);
                    var fileResults = service.GetFile(tenantId, Container, file);
                    var tempFile    = fileResults.ToFile();
                    var b           = FileUtilities.FilesAreEqual(file, tempFile);
                    Debug.Assert(b);
                    FileUtilities.WipeFile(tempFile);
                    index++;
                    Console.WriteLine(string.Format("Saved file {0} / {1}, Match=" + b, index, allFiles.Length));
                });
                timer.Stop();
                Console.WriteLine(string.Format("Load {0} files in {1} ms", allFiles.Length, timer.ElapsedMilliseconds));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Use a system connection to save a file and then load it from storage
        /// </summary>
        private static void Test1()
        {
            using (var service = new SystemConnection())
            {
                service.FileUpload   += (object sender, FileProgressEventArgs e) => Console.WriteLine("Upload " + e.ChunkIndex + " of " + e.TotalChunks);
                service.FileDownload += (object sender, FileProgressEventArgs e) => Console.WriteLine("Download " + e.ChunkIndex);

                //Get/create tenant
                const string TenantName = "Test1";
                var          tenantId   = service.GetOrAddTenant(TenantName);

                //This is the plain text file to test
                var plainFile = @"c:\temp\test.txt";

                //Save the file (the name is the key)
                service.SaveFile(tenantId, Container, plainFile);

                //Retrieve the file from storage (file name is just the key)
                var fileResults = service.GetFile(tenantId, Container, plainFile);

                //Write to decrypted file
                //In the real world you could work with the stream in memory
                //such that the plaintext file never touches disk
                var tempFile = fileResults.ToFile();

                //Compare the original and download file
                var isEqual = FileUtilities.FilesAreEqual(plainFile, tempFile);
                if (isEqual)
                {
                    Console.WriteLine("Files match");
                }
                else
                {
                    Console.WriteLine("ERROR: Files do not match!");
                }
                Debug.Assert(isEqual);

                //Remove the file from storage (the file name is the key)
                service.RemoveFile(tenantId, Container, plainFile);

                //Remove the plaintext temp file
                FileUtilities.WipeFile(tempFile);
            }
        }