Пример #1
0
        private static AppBundleResponse UpdateAppBundle(string token, string appId)
        {
            Console.WriteLine($"Updating app {appId}.");

            var request = new RestSharp.RestRequest($"/appbundles/{appId}/versions", RestSharp.Method.POST);

            request.AddHeader("Authorization", $"Bearer {token}");
            request.AddHeader("Content-Type", "application/json");
            request.RequestFormat = RestSharp.DataFormat.Json;
            var body = new NewAppBundleRequest()
            {
                Id          = null,
                Engine      = "Autodesk.Revit+2019",
                Description = "Convert Hypar Models to Revit."
            };

            request.AddBody(body);
            var response = _client.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception($"There was an error creating a new app bundle: {response.StatusCode} - {response.Content}");
            }
            var newVersionResponse = JsonConvert.DeserializeObject <AppBundleResponse>(response.Content);

            return(newVersionResponse);
        }
Пример #2
0
        private static void CreateOrUpdateAppBundle(string token, string appId, string alias, string bundleZipPath, string engine)
        {
            Console.WriteLine("Attempting to create the app.");

            var request = new RestSharp.RestRequest("/appbundles", RestSharp.Method.POST);

            request.AddHeader("Authorization", $"Bearer {token}");
            request.AddHeader("Content-Type", "application/json");
            var body = new NewAppBundleRequest()
            {
                Id          = appId,
                Engine      = engine,
                Description = "Convert Hypar Models to Revit."
            };

            request.RequestFormat = RestSharp.DataFormat.Json;
            request.AddBody(body);
            var response = _client.Execute(request);
            AppBundleResponse appBundleResponse;

            if (response.StatusCode == HttpStatusCode.Conflict)
            {
                Console.WriteLine("App already exists, updating.");

                appBundleResponse = UpdateAppBundle(token, appId);
                UploadAppBundle(appBundleResponse.UploadParameters, bundleZipPath);
            }
            else if (response.StatusCode == HttpStatusCode.Created || response.StatusCode == HttpStatusCode.OK)
            {
                appBundleResponse = JsonConvert.DeserializeObject <AppBundleResponse>(response.Content);
                UploadAppBundle(appBundleResponse.UploadParameters, bundleZipPath);
            }
            else
            {
                throw new Exception($"There was an error creating a new app bundle: {response.StatusCode} - {response.Content}");
            }
            UpdateOrCreateAlias(appBundleResponse.Version, appId, alias, token);
        }