Example #1
0
        internal B2LargeFile(B2Client b2Client, B2UnfinishedLargeFile file)
        {
            _file = file;
            _b2Client = b2Client;

            State = B2LargeFileState.New;
        }
Example #2
0
        internal B2File(B2Client b2Client, B2FileInfo file)
        {
            _b2Client = b2Client;
            _file = file;

            State = B2FileState.Present;
        }
Example #3
0
        public void TestBucketCreateUpdateDelete()
        {
            const string name = "test-bucket-b2lib";

            B2Client client = new B2Client();
            client.Login(TestConfig.AccountId, TestConfig.ApplicationKey);

            // Create
            B2Bucket bucket = client.CreateBucket(name, B2BucketType.AllPrivate);
            TestBucketContents(bucket, B2BucketType.AllPrivate);

            // Verify using a list
            VerifyBucketInList(client, true, name, B2BucketType.AllPrivate);

            // Update
            bucket.Update(B2BucketType.AllPublic);
            TestBucketContents(bucket, B2BucketType.AllPublic);

            // Verify using a list
            VerifyBucketInList(client, true, name, B2BucketType.AllPublic);

            // Delete
            bucket.Delete();
            TestBucketContents(bucket, B2BucketType.AllPublic);

            // Verify using a list
            VerifyBucketInList(client, false, name, B2BucketType.AllPrivate);
        }
Example #4
0
        internal B2Bucket(B2Client b2Client, B2BucketObject bucket)
        {
            _b2Client = b2Client;
            _bucket = bucket;

            State = B2BucketState.Present;
        }
Example #5
0
        protected override void ProcessRecord()
        {
            B2Client client = new B2Client();
            client.LoadState(File);

            B2SaveState state = client.SaveState();
            this.SaveState(state);
            WriteObject(state);
        }
Example #6
0
        private void VerifyBucketInList(B2Client client, bool shouldExist, string bucketName, B2BucketType expectedType)
        {
            IEnumerable<B2Bucket> list = client.GetBuckets();

            bool exists = list.Any(s => s.BucketName == bucketName && s.BucketType == expectedType);
            if (shouldExist)
                Assert.IsTrue(exists);
            else
                Assert.IsFalse(exists);
        }
        protected override void ProcessRecord()
        {
            WriteVerbose("Logging in with " + AccountId);

            B2Client client = new B2Client();
            client.Login(AccountId, ApplicationKey);

            B2SaveState state = client.SaveState();
            this.SaveState(state);

            WriteObject(state);
        }
Example #8
0
        internal B2File(B2Client b2Client, string bucketId, string newName)
        {
            _b2Client = b2Client;
            _file = new B2FileInfo
            {
                Action = B2FileAction.Upload,
                FileName = newName,
                BucketId = bucketId,
                ContentType = B2Constants.AutoContenType
            };

            State = B2FileState.New;
        }
Example #9
0
        internal B2LargeFile(B2Client b2Client, B2FileInfo file)
        {
            _file = new B2UnfinishedLargeFile
            {
                AccountId = file.AccountId,
                BucketId = file.BucketId,
                FileName = file.FileName,
                ContentType = file.ContentType,
                FileId = file.FileId,
                FileInfo = file.FileInfo,
                UploadTimestamp = file.UploadTimestamp
            };
            _b2Client = b2Client;

            State = B2LargeFileState.New;
        }
Example #10
0
        static void Main(string[] args)
        {
            B2Client client = new B2Client();

            if (File.Exists("state"))
                client.LoadState("state");
            else
            {
                // To protect credentials from being committed, they've been put in a text file at: MyDocuments\B2Auth.txt
                // The text goes in two lines, with AccountId being the first, and ApplicationKey the second.
                string[] lines = File.ReadAllLines(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "B2Auth.txt"));

                client.Login(lines[0], lines[1]);
                client.SaveState("state");
            }

            string name = "testbucket-lordmike-123";
            B2Bucket bck = client.GetBucketByName(name);
            if (bck == null)
            {
                bck = client.CreateBucket(name, B2BucketType.AllPrivate);
            }

            client.SaveState("state");

            string path = Path.GetTempFileName();
            File.WriteAllText(path, "Testworld".PadRight(2000, 'A'));

            //var res = bck.CreateFile("Testfile.txt");
            //res.UploadFileData(new FileInfo(path));

            List<B2FileItemBase> files = bck.GetFileVersions().ToList();
            Task.WaitAll(files.Select(s => s.DeleteAsync()).ToArray());

            B2LargeFile largeFile = bck.CreateLargeFile("large-file.txt");

            List<B2File> files1 = bck.GetFiles().ToList();
            List<B2FileItemBase> files2 = bck.GetFileVersions().ToList();
            List<B2LargeFile> files3 = bck.GetUnfinishedLargeFiles().ToList();

            Console.WriteLine();
        }
Example #11
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            WriteVerbose("Beginning outer runner, State: " + State);

            Client = new B2Client();
            Client.LoadState(State);

            WriteVerbose("Running ProcessRecordInternal()");

            ProcessRecordInternal();

            WriteVerbose("Finished running ProcessRecordInternal()");

            B2SaveState newState = Client.SaveState();
            newState.CopyTo(State);

            WriteVerbose("Copied new state back to PS");
        }