Example #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);
        }
        private async Task <OAuth> GetOAuth(Scope[] scope)
        {
            OAuth oauth = await OAuth2LeggedToken.AuthenticateAsync(
                Config.FORGE_CLIENT_ID, Config.FORGE_CLIENT_SECRET,
                (scope == null ? Config.FORGE_SCOPE_PUBLIC : scope));

            return(oauth);
        }
Example #3
0
        public async Task OAuth()
        {
            // 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");
            Assert.IsTrue(oauth.ExpiresAt > DateTime.Now);
        }
Example #4
0
        public async Task <string> Get()
        {
            OAuth oauth = await OAuth2LeggedToken.AuthenticateAsync(
                Config.FORGE_CLIENT_ID, Config.FORGE_CLIENT_SECRET,
                // only expose data:read access tokens as endpoints
                // this is required for Viewer
                new Scope[] { Scope.DataRead });

            return(oauth.AccessToken);
        }
Example #5
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");
        }