Exemplo n.º 1
0
        public async Task <IList <TreeNode> > GetTreeDataAsync([FromUri] string id)
        {
            IList <TreeNode> nodes = new List <TreeNode>();

            OAuth oauth = await OAuth2LeggedToken.AuthenticateAsync(Config.FORGE_CLIENT_ID, Config.FORGE_CLIENT_SECRET, new Scope[] { Scope.BucketRead, Scope.DataRead });

            if (id == "#") // root
            {
                // in this case, let's return all buckets
                AppBuckets           appBuckets = new AppBuckets(oauth);
                IEnumerable <Bucket> buckets    = await appBuckets.GetBucketsAsync(int.MaxValue);

                foreach (Bucket b in buckets)
                {
                    nodes.Add(new TreeNode(b.BucketKey, b.BucketKey, "bucket", true));
                }
            }
            else
            {
                // as we have the id (bucketKey), let's return all objects
                Bucket bucket = new Bucket(oauth, id /*bucketKey*/);
                IEnumerable <Autodesk.Forge.OSS.Object> objects = await bucket.GetObjectsAsync(int.MaxValue);

                foreach (Autodesk.Forge.OSS.Object obj in objects)
                {
                    nodes.Add(new TreeNode(obj.ObjectId.Base64Encode(), obj.ObjectKey, "object", false));
                }
            }
            return(nodes);
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <Bucket> > GetBuckets([FromUri] int limit = 100, [FromUri] Region region = Region.US, [FromUri] string startAt = "")
        {
            OAuth oauth = await GetOAuth(new Scope[] { Scope.BucketRead });

            AppBuckets buckets = new AppBuckets(oauth);

            return(await buckets.GetBucketsAsync(limit, region, startAt));
        }
Exemplo n.º 3
0
        public async Task <BucketDetails> CreateBucket([FromBody] CreateBucketModel bucket)
        {
            if (!Bucket.IsValidBucketKey(bucket.bucketKey))
            {
                return(null);
            }

            AppBuckets buckets = new AppBuckets(await GetOAuth(new Scope[] { Scope.BucketCreate }));

            return(await buckets.CreateBucketAsync(bucket.bucketKey, bucket.policyKey, bucket.region));
        }
Exemplo n.º 4
0
        public async Task BucketWorkflow()
        {
            string testFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestFile\Analyze.dwf");

            Assert.IsTrue(File.Exists(testFile), "Test file not found");

            // authenticate
            OAuth.OAuth oauth = await OAuth2LeggedToken.AuthenticateAsync(ForgeClientID, ForgeClientSecret,
                                                                          new Scope[] { Scope.BucketRead, Scope.BucketCreate, Scope.DataRead, Scope.DataCreate, Scope.DataWrite });

            Assert.IsFalse(string.IsNullOrWhiteSpace(oauth.AccessToken), "Access token not as expected");

            // create bucket and get list of buckets in different conditions
            AppBuckets           buckets       = new AppBuckets(oauth);
            IEnumerable <Bucket> listOfBuckets = await buckets.GetBucketsAsync(10);

            buckets = new AppBuckets(oauth);
            await buckets.GetBucketsAsync(120);

            buckets = new AppBuckets(oauth);
            await buckets.GetBucketsAsync(210);

            // create a random bucket
            string bucketKey = string.Format("test{0}", DateTime.Now.ToString("yyyyMMddHHmmss"));

            Assert.IsTrue(BucketDetails.IsValidBucketKey(bucketKey));
            Bucket bucket = await buckets.CreateBucketAsync(bucketKey, PolicyKey.Transient);

            Assert.AreEqual(bucket.BucketKey, bucketKey);

            // get all objects
            IEnumerable <OSS.Object> objects = await bucket.GetObjectsAsync(int.MaxValue);

            // upload new object
            OSS.Object newObject = await bucket.UploadObjectAsync(testFile);

            // the list after should have 1 object...
            IEnumerable <OSS.Object> objectsAfter = await bucket.GetObjectsAsync(int.MaxValue);

            foreach (OSS.Object obj in objectsAfter)
            {
                Assert.AreEqual(newObject.ObjectId, obj.ObjectId); // URNs should be the same
            }
            // as there is just 1 object, bucket and object have the same size
            Assert.AreEqual(await bucket.Size(), newObject.Size, "Bucket size and object size don't match");

            // translate
            HttpStatusCode res = await newObject.Translate(new SVFOutput[] { SVFOutput.Views3d, SVFOutput.Views2d });

            Assert.AreEqual(res, HttpStatusCode.OK, "Translate job posted");
        }