예제 #1
0
        public async Task <dynamic> TranslateObject([FromBody] TranslateObjectModel objModel)
        {
            dynamic oauth = await OAuthController.GetInternalAsync();

            // prepare the payload
            List <JobPayloadItem> outputs = new List <JobPayloadItem>()
            {
                new JobPayloadItem(
                    JobPayloadItem.TypeEnum.Svf,
                    new List <JobPayloadItem.ViewsEnum>()
                {
                    JobPayloadItem.ViewsEnum._2d,
                    JobPayloadItem.ViewsEnum._3d
                })
            };
            JobPayload job;

            job = new JobPayload(new JobPayloadInput(objModel.objectName), new JobPayloadOutput(outputs));

            // start the translation
            DerivativesApi derivative = new DerivativesApi();

            derivative.Configuration.AccessToken = oauth.access_token;
            dynamic jobPosted = await derivative.TranslateAsync(job);

            return(jobPosted);
        }
예제 #2
0
        public async Task <IList <TreeNode> > GetOSSAsync([FromUri] string id)
        {
            IList <TreeNode> nodes = new List <TreeNode>();
            dynamic          oauth = await OAuthController.GetInternalAsync();

            if (id == "#") // root
            {
                // in this case, let's return all buckets
                BucketsApi appBckets = new BucketsApi();
                appBckets.Configuration.AccessToken = oauth.access_token;

                // to simplify, let's return only the first 100 buckets
                dynamic buckets = await appBckets.GetBucketsAsync("US", 100);

                foreach (KeyValuePair <string, dynamic> bucket in new DynamicDictionaryItems(buckets.items))
                {
                    nodes.Add(new TreeNode(bucket.Value.bucketKey, bucket.Value.bucketKey, "bucket", true));
                }
            }
            else
            {
                // as we have the id (bucketKey), let's return all
                ObjectsApi objects = new ObjectsApi();
                objects.Configuration.AccessToken = oauth.access_token;
                var objectsList = objects.GetObjects(id);
                foreach (KeyValuePair <string, dynamic> objInfo in new DynamicDictionaryItems(objectsList.items))
                {
                    nodes.Add(new TreeNode(Base64Encode((string)objInfo.Value.objectId),
                                           objInfo.Value.objectKey, "object", false));
                }
            }
            return(nodes);
        }
예제 #3
0
        public async Task <dynamic> CreateBucket([FromBody] CreateBucketModel bucket)
        {
            BucketsApi buckets = new BucketsApi();
            dynamic    token   = await OAuthController.GetInternalAsync();

            buckets.Configuration.AccessToken = token.access_token;
            PostBucketsPayload bucketPayload = new PostBucketsPayload(bucket.bucketKey, null,
                                                                      PostBucketsPayload.PolicyKeyEnum.Transient);

            return(await buckets.CreateBucketAsync(bucketPayload, "US"));
        }
예제 #4
0
        public async Task DeleteObject([FromBody] ObjectModel objModel)
        {
            dynamic oauth = await OAuthController.GetInternalAsync();


            var apiInstance = new ObjectsApi();
            var bucketKey   = objModel.bucketKey;  // string | URL-encoded bucket key
            var objectName  = objModel.objectName; // string | URL-encoded object name

            try
            {
                apiInstance.DeleteObject(bucketKey, objectName);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling ObjectsApi.DeleteObject: " + e.Message);
            }
        }
예제 #5
0
        public async Task <dynamic> UploadObject()
        {
            // basic input validation
            HttpRequest req = HttpContext.Current.Request;

            if (string.IsNullOrWhiteSpace(req.Params["bucketKey"]))
            {
                throw new System.Exception("BucketKey parameter was not provided.");
            }

            if (req.Files.Count != 1)
            {
                throw new System.Exception("Missing file to upload"); // for now, let's support just 1 file at a time
            }
            string         bucketKey = req.Params["bucketKey"];
            HttpPostedFile file      = req.Files[0];

            // save the file on the server
            var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), file.FileName);

            file.SaveAs(fileSavePath);

            // get the bucket...
            dynamic oauth = await OAuthController.GetInternalAsync();

            ObjectsApi objects = new ObjectsApi();

            objects.Configuration.AccessToken = oauth.access_token;

            // upload the file/object, which will create a new object
            dynamic uploadedObj;

            using (StreamReader streamReader = new StreamReader(fileSavePath))
            {
                uploadedObj = await objects.UploadObjectAsync(bucketKey,
                                                              file.FileName, (int)streamReader.BaseStream.Length, streamReader.BaseStream,
                                                              "application/octet-stream");
            }

            // cleanup
            File.Delete(fileSavePath);

            return(uploadedObj);
        }
예제 #6
0
        public async Task DownloadObject([FromBody] ObjectModel objModel)
        {
            dynamic oauth = await OAuthController.GetInternalAsync();


            var    apiInstance  = new ObjectsApi();
            string pathUser     = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            string pathDownload = Path.Combine(pathUser, "Downloads");

            apiInstance.Configuration.AccessToken = oauth.access_token;
            var bucketKey  = objModel.bucketKey;  // string | URL-encoded bucket key
            var objectName = objModel.objectName; // string | URL-encoded object name

            try
            {
                System.IO.Stream result = apiInstance.GetObject(bucketKey, objectName);
                var fstream             = new System.IO.FileStream(Path.Combine(pathDownload, objectName), FileMode.CreateNew);
                result.CopyTo(fstream);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling ObjectsApi.DownloadObject: " + e.Message);
            }
        }
예제 #7
0
        public async Task ExcelObject([FromBody] ObjectModel objModel)
        {
            // authenticate with Forge Must have data read scope
            dynamic oauth = await OAuthController.GetInternalAsync();

            // get the user selected object
            ObjectsApi objects = new ObjectsApi();

            objects.Configuration.AccessToken = oauth.access_token;
            dynamic selectedObject = await objects.GetObjectDetailsAsync(objModel.bucketKey, objModel.objectName);

            string objectId  = selectedObject.objectId;
            string objectKey = selectedObject.objectKey;


            string xlsFileName = objectKey.Replace(".rvt", ".xls");
            var    xlsPath     = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), objModel.bucketKey, xlsFileName);//.guid, xlsFileName);
            ///////////if (File.Exists(xlsPath))
            ///////////    return SendFile(xlsPath);// if the Excel file was already generated

            DerivativesApi derivative = new DerivativesApi();

            derivative.Configuration.AccessToken = oauth.access_token;

            // get the derivative metadata
            dynamic metadata = await derivative.GetMetadataAsync(objectId.Base64Encode());

            foreach (KeyValuePair <string, dynamic> metadataItem in new DynamicDictionaryItems(metadata.data.metadata))
            {
                dynamic hierarchy = await derivative.GetModelviewMetadataAsync(objectId.Base64Encode(), metadataItem.Value.guid);

                dynamic properties = await derivative.GetModelviewPropertiesAsync(objectId.Base64Encode(), metadataItem.Value.guid);

                Workbook xls = new Workbook();
                foreach (KeyValuePair <string, dynamic> categoryOfElements in new DynamicDictionaryItems(hierarchy.data.objects[0].objects))
                {
                    string    name  = categoryOfElements.Value.name;
                    Worksheet sheet = new Worksheet(name);
                    for (int i = 0; i < 100; i++)
                    {
                        sheet.Cells[i, 0] = new Cell("");                           // unless we have at least 100 cells filled, Excel understand this file as corrupted
                    }
                    List <long> ids = GetAllElements(categoryOfElements.Value.objects);
                    int         row = 1;
                    foreach (long id in ids)
                    {
                        Dictionary <string, object> props = GetProperties(id, properties);
                        int collumn = 0;
                        foreach (KeyValuePair <string, object> prop in props)
                        {
                            sheet.Cells[0, collumn]   = new Cell(prop.Key.ToString());
                            sheet.Cells[row, collumn] = new Cell(prop.Value.ToString());
                            collumn++;
                        }

                        row++;
                    }

                    xls.Worksheets.Add(sheet);
                }


                //Where to save the excel file
                string pathUser     = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                string pathDownload = Path.Combine(pathUser, "Downloads", xlsFileName);

                //try catch save the file to the relevant place
                try
                {
                    var fstream = new System.IO.FileStream(pathDownload, FileMode.CreateNew);
                    xls.SaveToStream(fstream);
                }
                catch (Exception e)
                {
                    Debug.Print("Exception when calling ObjectsApi.DownloadObject: " + e.Message);
                }
            }
            //No need to return anything
            //return SendFile(xlsPath);
        }