/// <summary> /// Does setup of AutoCAD IO. /// This method will need to be invoked once before any other methods of this /// utility class can be invoked. /// </summary> /// <param name="autocadioclientid">AutoCAD IO Client ID - can be obtained from developer.autodesk.com</param> /// <param name="autocadioclientsecret">AutoCAD IO Client Secret - can be obtained from developer.autodesk.com</param> public static void SetupAutoCADIOContainer(String autocadioclientid, String autocadioclientsecret) { try { String clientId = autocadioclientid; String clientSecret = autocadioclientsecret; Uri uri = new Uri("https://developer.api.autodesk.com/autocad.io/us-east/v2/"); container = new AIO.Operations.Container(uri); container.Format.UseJson(); using (var client = new HttpClient()) { var values = new List<KeyValuePair<string, string>>(); values.Add(new KeyValuePair<string, string>("client_id", clientId)); values.Add(new KeyValuePair<string, string>("client_secret", clientSecret)); values.Add(new KeyValuePair<string, string>("grant_type", "client_credentials")); var requestContent = new FormUrlEncodedContent(values); var response = client.PostAsync("https://developer.api.autodesk.com/authentication/v1/authenticate", requestContent).Result; var responseContent = response.Content.ReadAsStringAsync().Result; var resValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(responseContent); _accessToken = resValues["token_type"] + " " + resValues["access_token"]; if (!string.IsNullOrEmpty(_accessToken)) { container.SendingRequest2 += (sender, e) => e.RequestMessage.SetHeader("Authorization", _accessToken); } } } catch (System.Exception ex) { Console.WriteLine(String.Format("Error while connecting to https://developer.api.autodesk.com/autocad.io/v2/", ex.Message)); container = null; throw; } }
/// <summary> /// Does setup of AutoCAD IO. /// This method will need to be invoked once before any other methods of this /// utility class can be invoked. /// </summary> /// <param name="autocadioclientid">AutoCAD IO Client ID - can be obtained from developer.autodesk.com</param> /// <param name="autocadioclientsecret">AutoCAD IO Client Secret - can be obtained from developer.autodesk.com</param> public static void SetupAutoCADIOContainer(String autocadioclientid, String autocadioclientsecret) { try { String clientId = autocadioclientid; String clientSecret = autocadioclientsecret; Uri uri = new Uri(ForgeDesignAutoSrv.containerUrl); container = new AIO.Operations.Container(uri); container.Format.UseJson(); using (var client = new HttpClient()) { var values = new List <KeyValuePair <string, string> >(); values.Add(new KeyValuePair <string, string>("client_id", clientId)); values.Add(new KeyValuePair <string, string>("client_secret", clientSecret)); values.Add(new KeyValuePair <string, string>("grant_type", "client_credentials")); values.Add(new KeyValuePair <string, string>("scope", "code:all")); var requestContent = new FormUrlEncodedContent(values); var response = client.PostAsync(ForgeDesignAutoSrv.autenticationUrl, requestContent).Result; var responseContent = response.Content.ReadAsStringAsync().Result; var resValues = JsonConvert.DeserializeObject <Dictionary <string, string> >(responseContent); _accessToken = resValues["token_type"] + " " + resValues["access_token"]; if (!string.IsNullOrEmpty(_accessToken)) { container.SendingRequest2 += (sender, e) => e.RequestMessage.SetHeader("Authorization", _accessToken); } } } catch (System.Exception ex) { Console.WriteLine(String.Format("Error while connecting to https://developer.api.autodesk.com/autocad.io/v2/", ex.Message)); container = null; throw; } }