public string GetOAuthURL()
        {
            // prepare the sign in URL
            Scope[]        scopes          = { Scope.DataRead };
            ThreeLeggedApi _threeLeggedApi = new ThreeLeggedApi();
            string         oauthUrl        = _threeLeggedApi.Authorize(
                Credentials.GetAppSetting("FORGE_CLIENT_ID"),
                oAuthConstants.CODE,
                Credentials.GetAppSetting("FORGE_CALLBACK_URL"),
                new Scope[] { Scope.DataRead, Scope.DataCreate, Scope.DataWrite, Scope.ViewablesRead });

            return(oauthUrl);
        }
예제 #2
0
        //public async Task<IActionResult> Testing(string id)
        public async Task <IList <jsTreeNode> > Testing(string id)
        {
            IList <jsTreeNode> nodes = new List <jsTreeNode>();
            // the API SDK
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            ItemsApi itemApi = new ItemsApi();

            itemApi.Configuration.AccessToken = credentials.TokenInternal;

            // extract the projectId & itemId from the href
            string[] idParams  = id.Split('/');
            string   itemId    = idParams[idParams.Length - 1];
            string   projectId = idParams[idParams.Length - 3];

            var versions = await itemApi.GetItemVersionsAsync(projectId, itemId);

            dynamic item = await itemApi.GetItemAsync(projectId, itemId);

            string folderId        = item.data.relationships.parent.data.id;
            string displayFileName = item.data.attributes.displayName;
            string versionId       = null;

            foreach (KeyValuePair <string, dynamic> version in new DynamicDictionaryItems(versions.data))
            {
                DateTime versionDate = version.Value.attributes.lastModifiedTime;
                string   verNum      = version.Value.id.Split("=")[1];
                string   userName    = version.Value.attributes.lastModifiedUserName;
                versionId = version.Value.id;
                if (verNum == "1")
                {
                    break;
                }
                string urn = string.Empty;
                try { urn = (string)version.Value.relationships.derivatives.data.id; }
                catch { }
            }
            //get user id
            UserController user = new UserController();

            user.Credentials = credentials;
            dynamic userProfile = await user.GetUserProfileAsync();

            string userId = userProfile.id;
            //// Prepare the DA input from BIM 360
            //var input = await BuildBIM360DownloadURL(credentials.TokenInternal, projectId, versionId);
            //// Prepare the DA output to BIM 360
            //var storageInfo = await PreWorkNewVersion(credentials.TokenInternal, projectId, versionId);
            //string storageId = storageInfo.storageId;
            //string fileName = storageInfo.fileName;
            //try
            //{
            //    BackgroundJob.Schedule(() => PostProcessFile(credentials.TokenInternal, userId, projectId, itemId, storageId, fileName), TimeSpan.FromSeconds(1));
            //}
            //catch (Exception e) { }
            //
            StorageInfo info = await PreWorkNewVersion(credentials.TokenInternal, projectId, versionId);

            string callbackUrl = string.Format("{0}/api/forge/callback/designautomation/revit/{1}/{2}/{3}/{4}/{5}", Credentials.GetAppSetting("FORGE_WEBHOOK_URL"), userId, projectId, info.itemId.Base64Encode(), info.storageId.Base64Encode(), info.fileName.Base64Encode());

            WorkItem workItemSpec = new WorkItem()
            {
                ActivityId = ActivityFullName,
                Arguments  = new Dictionary <string, IArgument>()
                {
                    { "inputFile", await BuildBIM360DownloadURL(credentials.TokenInternal, projectId, versionId) },
                    { "outputFile", await BuildBIM360UploadURL(credentials.TokenInternal, info) },
                    { "onComplete", new XrefTreeArgument {
                          Verb = Verb.Post, Url = callbackUrl
                      } }
                }
            };
            WorkItemStatus workItemStatus = await _designAutomation.CreateWorkItemsAsync(workItemSpec);

            try
            {
                var storageInfo = await PreWorkNewVersion(credentials.TokenInternal, projectId, versionId);

                string storageId = storageInfo.storageId;
                string fileName  = storageInfo.fileName;
                BackgroundJob.Schedule(() => PostProcessFile(credentials.TokenInternal, userId, projectId, itemId, storageId, fileName), TimeSpan.FromSeconds(1));
            }
            catch (Exception e) { }

            //
            return(nodes);
        }
 //GetAppSetting
 public static string GetAppSetting(string settingKey)
 {
     return(Credentials.GetAppSetting(settingKey));
 }
 [Route("api/forge/clientid")] // see Web.Config FORGE_CALLBACK_URL variable
 public dynamic GetClientID()
 {
     return(new { id = Credentials.GetAppSetting("FORGE_CLIENT_ID") });
 }