示例#1
0
        public async Task <dynamic> DownloadObject([FromBody] DownloadFile input)
        {
            // get the bucket
            dynamic oauth = await OAuthController.GetInternalAsync();

            ObjectsApi objects = new ObjectsApi();

            objects.Configuration.AccessToken = oauth.access_token;

            // collect information about file
            string bucketKey      = input.bucketKey;
            string fileToDownload = input.fileToDownload;

            PostBucketsSigned postBucketsSigned = new PostBucketsSigned(20);

            try
            {
                dynamic result = await objects.CreateSignedResourceAsync(bucketKey, fileToDownload, postBucketsSigned);

                return(result);
            }
            catch (Exception ex) { }

            return(null);
        }
示例#2
0
        public async Task <dynamic> UploadObject([FromForm] UploadFile input)
        {
            // save the file on the server
            var fileSavePath = Path.Combine(_env.WebRootPath, Path.GetFileName(input.FileToUpload.FileName));

            using (var stream = new FileStream(fileSavePath, FileMode.Create))
                await input.FileToUpload.CopyToAsync(stream);


            // 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(input.BucketKey,
                                                              Path.GetFileName(input.FileToUpload.FileName),
                                                              (int)streamReader.BaseStream.Length,
                                                              streamReader.BaseStream,
                                                              "application/octet-stream");
            }

            // cleanup
            System.IO.File.Delete(fileSavePath);

            return(uploadedObj);
        }
示例#3
0
        public async Task <dynamic> CreateBucket([FromBody] BucketModel bucket)
        {
            dynamic    NewBucket = null;
            BucketsApi buckets   = new BucketsApi();
            dynamic    token     = await OAuthController.GetInternalAsync();

            buckets.Configuration.AccessToken = token.access_token;
            PostBucketsPayload bucketPayload = new PostBucketsPayload(string.Format("{0}-{1}", ClientId, bucket.bucketKey.ToLower()), null,
                                                                      PostBucketsPayload.PolicyKeyEnum.Transient);

            try
            {
                NewBucket = await buckets.CreateBucketAsync(bucketPayload, bucketRegion);
            }
            catch (Exception e)
            {
                if (e.Message == "Error calling CreateBucket: {\"reason\":\"Bucket already exists\"}")
                {
                    dynamic allBuckets = await buckets.GetBucketsAsync("US", 100);

                    foreach (KeyValuePair <string, dynamic> actualBucket in new DynamicDictionaryItems(allBuckets.items))
                    {
                        string bucketName = actualBucket.Value.bucketKey;
                        if (bucketName.Contains(BucketName)) //kitchenconfig  designautomation
                        {
                            NewBucket = actualBucket;
                        }
                    }
                }
            }

            return(NewBucket);
        }
示例#4
0
        public async Task DeleteObject([FromBody] ObjectModel objectModel)
        {
            dynamic oauth = await OAuthController.GetInternalAsync();

            ObjectsApi objectForDelete = new ObjectsApi();

            objectForDelete.Configuration.AccessToken = oauth.access_token;

            await objectForDelete.DeleteObjectAsync(objectModel.bucketKey, objectModel.objectKey);
        }
示例#5
0
        public async Task <List <string> > GetAvailableEngines()
        {
            dynamic oauth = await OAuthController.GetInternalAsync();

            // define Engines API
            Page <string> engines = await _designAutomation.GetEnginesAsync();

            engines.Data.Sort();
            // return list of engines
            return(engines.Data);
        }
示例#6
0
        // Constructor, where env and hubContext are specified
        public DesignAutomationController(IWebHostEnvironment env, IHubContext <DesignAutomationHub> hubContext, DesignAutomationClient api)
        {
            // DesignAutomation must be created as new instance.
            DesignAutomationClientBuilder da = new DesignAutomationClientBuilder(
                OAuthController.GetAppSetting("FORGE_CLIENT_ID"),
                OAuthController.GetAppSetting("FORGE_CLIENT_SECRET")
                );

            _designAutomation = da.Client;
            _env        = env;
            _hubContext = hubContext;
        }
        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
                })
            };
            JobPayloadInput jobPayloadInput;

            if (objModel.ObjectType == "zipfile3D")
            {
                jobPayloadInput = new JobPayloadInput(objModel.ObjectName, true, "MyWallShelf.iam");
            }
            else if (objModel.ObjectType == "zipfile2D")
            {
                jobPayloadInput = new  JobPayloadInput(objModel.ObjectName, true, "WallShelfDrawings.idw");
            }
            else
            {
                jobPayloadInput = new JobPayloadInput(objModel.ObjectName);
            }
            // start the translation
            JobPayload job = new JobPayload(jobPayloadInput, new JobPayloadOutput(outputs));

            DerivativesApi derivative = new DerivativesApi();

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

            return(jobPosted);
        }
示例#8
0
        public async Task <IActionResult> StartWorkitem([FromForm] StartWorkitemInput input)
        {
            try
            {
                DataSetBuilder dataSetBuilder = new DataSetBuilder(LocalDataSetFolder, "DataSet");
                dataSetBuilder.SaveJsonData(input.shelfData, "params.json");
                dataSetBuilder.ZipFolder("MyWallShelf.zip");
            }
            catch (Exception ex)
            {
                return(Ok(new { WorkItemId = ex.Message }));;
            }

            JObject connItemData       = JObject.Parse(input.forgeData);
            string  uniqueActivityName = string.Format("{0}.{1}+{2}", NickName, ActivityName, Alias);
            string  browerConnectionId = connItemData["browerConnectionId"].Value <string>();

            // TODO - this piece of cod will be used for sending picture in Visualization module
            // save the file on the server
            var fileSavePath = Path.Combine(LocalDataSetFolder, "MyWallShelf.zip");
            //using (var stream = new FileStream(fileSavePath, FileMode.Create)) await input.inputFile.CopyToAsync(stream);

            // OAuth token
            dynamic oauth = await OAuthController.GetInternalAsync();

            // upload file to OSS Bucket
            // 1. ensure bucket existis
            BucketsApi buckets = new BucketsApi();

            buckets.Configuration.AccessToken = oauth.access_token;
            try
            {
                PostBucketsPayload bucketPayload = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient);
                await buckets.CreateBucketAsync(bucketPayload, bucketRegion);                                                     //TODO - use EMEA buckets also
            }
            catch { };                                                                                                            // in case bucket already exists
                                                                                                                                  // 2. upload inputFile
            string     inputFileNameOSS = string.Format("{0}_input_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), "MyShelf.zip"); // avoid overriding
            ObjectsApi objects          = new ObjectsApi();

            objects.Configuration.AccessToken = oauth.access_token;
            using (StreamReader streamReader = new StreamReader(fileSavePath))
                await objects.UploadObjectAsync(bucketKey, inputFileNameOSS, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream");
            //System.IO.File.Delete(fileSavePath);// delete server copy

            // prepare workitem arguments
            // 1. input file
            XrefTreeArgument inputFileArgument = new XrefTreeArgument()
            {
                Verb      = Verb.Get,
                LocalName = "Wall_shelf",
                PathInZip = "MyWallShelf.iam",
                Url       = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", bucketKey, inputFileNameOSS),
                Headers   = new Dictionary <string, string>()
                {
                    { "Authorization", "Bearer " + oauth.access_token }
                }
            };
            // 2. input json

            /*dynamic inputJson = new JObject();
             * inputJson.Width = widthParam;
             * inputJson.Height = heigthParam;
             * XrefTreeArgument inputJsonArgument = new XrefTreeArgument()
             * {
             *  Url = "data:application/json, " + ((JObject)inputJson).ToString(Formatting.None).Replace("\"", "'")
             * };*/
            // 3. output file
            // TODO - output file name should be passed from client
            string           outputFileNameOSS  = string.Format("{0}_output_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), "Result.zip"); // avoid overriding
            XrefTreeArgument outputFileArgument = new XrefTreeArgument()
            {
                Url     = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", bucketKey, outputFileNameOSS),
                Verb    = Verb.Put,
                Headers = new Dictionary <string, string>()
                {
                    { "Authorization", "Bearer " + oauth.access_token }
                }
            };
            // 3a. output pdf fajl out of zipping
            string           outputPDFFileNameOSS  = string.Format("{0}_output_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), "Result.pdf"); // avoid overriding
            XrefTreeArgument outputPDFFileArgument = new XrefTreeArgument()
            {
                Url     = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", bucketKey, outputPDFFileNameOSS),
                Verb    = Verb.Put,
                Headers = new Dictionary <string, string>()
                {
                    { "Authorization", "Bearer " + oauth.access_token }
                }
            };
            // prepare & submit workitem
            // the callback contains the connectionId (used to identify the client) and the outputFileName of this workitem
            string callbackUrl = string.Format(
                "{0}/api/forge/callback/designautomation?id={1}&outputFileName={2}",
                //OAuthController.GetAppSetting("FORGE_WEBHOOK_URL"),
                "https://webwallshelfbuilder.herokuapp.com",
                browerConnectionId,
                outputFileNameOSS);
            WorkItem workItemSpec = new WorkItem()
            {
                ActivityId = uniqueActivityName,
                Arguments  = new Dictionary <string, IArgument>()
                {
                    { "inputFile", inputFileArgument },
                    //{ "inputJson",  inputJsonArgument },
                    { "outputFile", outputFileArgument },
                    { "outputPDFFile", outputPDFFileArgument },
                    { "onComplete", new XrefTreeArgument {
                          Verb = Verb.Post, Url = callbackUrl
                      } }
                }
            };

            try
            {
                WorkItemStatus workItemStatus = await _designAutomation.CreateWorkItemAsync(workItemSpec);

                return(Ok(new { WorkItemId = workItemStatus.Id }));
            }
            catch (Exception e)
            {
                return(Ok(new { WorkItemId = e.Message }));
            }
        }
示例#9
0
        public async Task <IList <TreeNode> > GetOSSAsync(string id, string fttp)
        {
            IList <TreeNode> nodes = new List <TreeNode>();
            dynamic          oauth = await OAuthController.GetInternalAsync();

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

                // to simplify, let's return only the first 100 buckets
                // TODO - enable usage od EMAE buckets
                dynamic buckets = await appBuckets.GetBucketsAsync(bucketRegion, 100);

                foreach (KeyValuePair <string, dynamic> bucket in new DynamicDictionaryItems(buckets.items))
                {
                    string bucketIdent = bucket.Value.bucketKey;
                    bucketIdent.ToLower();
                    if (bucketIdent.Contains("wallshelfconfig"))
                    {
                        nodes.Add(new TreeNode(
                                      bucket.Value.bucketKey,
                                      bucket.Value.bucketKey.Replace(ClientId + "-", string.Empty),
                                      "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 = await objects.GetObjectsAsync(id, 100);

                foreach (KeyValuePair <string, dynamic> objInfo in new DynamicDictionaryItems(objectsList.items))
                {
                    string fileName = objInfo.Value.objectKey;
                    fileName.ToLower();
                    string fileType;
                    if (fileName.Contains("zip") && fileName.Contains("output") || fileName.Contains("outcopy"))
                    {
                        if (fileName.Contains("output"))
                        {
                            fileType = "zipfile3D";
                        }
                        else
                        {
                            fileType = "zipfile2D";
                        }

                        if (fileType == fttp)
                        {
                            nodes.Add(new TreeNode(
                                          Base64Encode((string)objInfo.Value.objectId),
                                          objInfo.Value.objectKey,
                                          fileType,
                                          false));
                        }
                    }
                    else if (fileName.Contains("pdf") && fileName.Contains("output"))
                    {
                        fileType = "pdfobject";
                        nodes.Add(new TreeNode(Base64Encode((string)objInfo.Value.objectId), objInfo.Value.objectKey, fileType, false));
                    }
                }
            }
            return(nodes);
        }