Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ForgeAppsApi"/> class
        /// using ForgeService object
        /// </summary>
        /// <param name="service">An instance of ForgeService</param>
        /// <returns></returns>
        public ForgeAppsApi(ForgeService service = null, IOptions <Configuration> configuration = null)
        {
            this.Service = service ?? ForgeService.CreateDefault();

            // set BaseAddress from configuration or default
            this.Service.Client.BaseAddress = configuration?.Value.BaseAddress ?? new Configuration().BaseAddress;
        }
Example #2
0
        public void TestDefault()
        {
            var svc = ForgeService.CreateDefault();

            Assert.NotNull(svc);
            Assert.NotNull(svc.Client);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services
            .AddControllersWithViews()
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.IgnoreNullValues = true;
            });

            services.AddSignalR(o =>
            {
                o.EnableDetailedErrors = true;
            });

            // In production, the React files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/build";
            });

            services.AddHttpClient();

            // NOTE: eventually we might want to use `AddForgeService()`, but right now it might break existing stuff
            // https://github.com/Autodesk-Forge/forge-api-dotnet-core/blob/master/src/Autodesk.Forge.Core/ServiceCollectionExtensions.cs
            services
            .Configure <ForgeConfiguration>(Configuration.GetSection(ForgeSectionKey))
            .Configure <AppBundleZipPaths>(Configuration.GetSection(AppBundleZipPathsKey))
            .Configure <DefaultProjectsConfiguration>(Configuration.GetSection(DefaultProjectsSectionKey))
            .Configure <InviteOnlyModeConfiguration>(Configuration.GetSection(InviteOnlyModeKey))
            .Configure <ProcessingOptions>(Configuration.GetSection(ProcessingOptionsKey));

            services.AddSingleton <ResourceProvider>();
            services.AddSingleton <IPostProcessing, PostProcessing>();
            services.AddSingleton <IForgeOSS, ForgeOSS>();
            services.AddSingleton <FdaClient>();
            services.AddTransient <Initializer>();
            services.AddTransient <Arranger>();
            services.AddTransient <ProjectWork>();
            services.AddTransient <DtoGenerator>();
            services.AddSingleton <DesignAutomationClient>(provider =>
            {
                var forge = provider.GetService <IForgeOSS>();
                var httpMessageHandler = new ForgeHandler(Options.Create(forge.Configuration))
                {
                    InnerHandler = new HttpClientHandler()
                };
                var forgeService = new ForgeService(new HttpClient(httpMessageHandler));
                return(new DesignAutomationClient(forgeService));
            });
            services.AddSingleton <Publisher>();
            services.AddScoped <UserResolver>(); // TODO: use interface
            services.AddSingleton <LocalCache>();
            services.AddSingleton <Uploads>();
        }
Example #4
0
        public DesignAutomation4Revit()
        {
            // need to initialize manually as this class runs in background
            ForgeService service =
                new ForgeService(
                    new HttpClient(
                        new ForgeHandler(Microsoft.Extensions.Options.Options.Create(new ForgeConfiguration()
            {
                ClientId     = Credentials.GetAppSetting("FORGE_CLIENT_ID"),
                ClientSecret = Credentials.GetAppSetting("FORGE_CLIENT_SECRET")
            }))
            {
                InnerHandler = new HttpClientHandler()
            })
                    );

            _designAutomation = new DesignAutomationClient(service);
        }
        public DesignAutomationClient(ForgeService service = null, IOptions <Configuration> configuration = null, IActivitiesApi activities = null, IAppBundlesApi appBundles = null, IEnginesApi engines = null, IForgeAppsApi forgeApps = null, IHealthApi health = null, IServiceLimitsApi serviceLimits = null, ISharesApi shares = null, IWorkItemsApi workItems = null)
        {
            this.Configuration = configuration?.Value ?? new Configuration();

            this.Service = service ?? ForgeService.CreateDefault();

            // set BaseAddress from configuration
            this.Service.Client.BaseAddress = Configuration.BaseAddress;

            this.ActivitiesApi    = activities ?? new ActivitiesApi(service, configuration);
            this.AppBundlesApi    = appBundles ?? new AppBundlesApi(service, configuration);
            this.EnginesApi       = engines ?? new EnginesApi(service, configuration);
            this.ForgeAppsApi     = forgeApps ?? new ForgeAppsApi(service, configuration);
            this.HealthApi        = health ?? new HealthApi(service, configuration);
            this.ServiceLimitsApi = serviceLimits ?? new ServiceLimitsApi(service, configuration);
            this.SharesApi        = shares ?? new SharesApi(service, configuration);
            this.WorkItemsApi     = workItems ?? new WorkItemsApi(service, configuration);
        }
Example #6
0
        protected DesignAutomation4Civil3D()
        {
            // need to initialize manually as this class runs in background
            ForgeService service =
                new ForgeService(
                    new HttpClient(
                        new ForgeHandler(Microsoft.Extensions.Options.Options.Create(new ForgeConfiguration()
            {
                ClientId     = Credentials.GetAppSetting("FORGE_CLIENT_ID"),
                ClientSecret = Credentials.GetAppSetting("FORGE_CLIENT_SECRET")
            }))
            {
                InnerHandler = new HttpClientHandler()
            })
                    );

            _designAutomation = new DesignAutomationClient(service);
            //_designAutomation.Configuration.BaseAddress = new Uri("https://developer.api.autodesk.com/preview.da/us-east/");
        }
Example #7
0
        public InitializerTestBase(DefaultProjectsConfiguration defaultProjectsConfiguration)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", false)
                                .AddJsonFile("appsettings.Local.json", optional: true, reloadOnChange: true)
                                .AddEnvironmentVariables()
                                .AddForgeAlternativeEnvironmentVariables()
                                .Build();

            IServiceCollection services = new ServiceCollection();

            services.AddHttpClient();
            var serviceProvider = services.BuildServiceProvider();

            ForgeConfiguration            forgeConfiguration = configuration.GetSection("Forge").Get <ForgeConfiguration>();
            IOptions <ForgeConfiguration> forgeConfigOptions = Options.Create(forgeConfiguration);

            var httpClientFactory = serviceProvider.GetRequiredService <IHttpClientFactory>();

            forgeOSS = new ForgeOSS(httpClientFactory, forgeConfigOptions, new NullLogger <ForgeOSS>());

            var httpMessageHandler = new ForgeHandler(Options.Create(forgeConfiguration))
            {
                InnerHandler = new HttpClientHandler()
            };
            var forgeService           = new ForgeService(new HttpClient(httpMessageHandler));
            var designAutomationClient = new DesignAutomationClient(forgeService);

            projectsBucketKey = Guid.NewGuid().ToString();

            localCache = new LocalCache();
            var bucketPrefixProvider = new BucketPrefixProvider(forgeConfigOptions, configuration);
            var resourceProvider     = new ResourceProvider(forgeConfigOptions, designAutomationClient, configuration, bucketPrefixProvider, projectsBucketKey);
            var postProcessing       = new PostProcessing(httpClientFactory, new NullLogger <PostProcessing>(), localCache, Options.Create(new ProcessingOptions()));
            var publisher            = new Publisher(designAutomationClient, new NullLogger <Publisher>(), resourceProvider,
                                                     postProcessing, Options.Create(new PublisherConfiguration()),
                                                     new WorkItemsApi(forgeService), null, new TaskUtil());

            var appBundleZipPathsConfiguration = new AppBundleZipPaths
            {
                EmptyExe          = "../../../../WebApplication/AppBundles/EmptyExePlugin.bundle.zip",
                DataChecker       = "../../../../WebApplication/AppBundles/DataCheckerPlugin.bundle.zip",
                CreateSVF         = "../../../../WebApplication/AppBundles/CreateSVFPlugin.bundle.zip",
                CreateThumbnail   = "../../../../WebApplication/AppBundles/CreateThumbnailPlugin.bundle.zip",
                ExtractParameters = "../../../../WebApplication/AppBundles/ExtractParametersPlugin.bundle.zip",
                UpdateParameters  = "../../../../WebApplication/AppBundles/UpdateParametersPlugin.bundle.zip",
                CreateRFA         = "../../../../WebApplication/AppBundles/RFAExportRCEPlugin.bundle.zip",
                CreateBOM         = "../../../../WebApplication/AppBundles/ExportBOMPlugin.bundle.zip",
                ExportDrawing     = "../../../../WebApplication/AppBundles/ExportDrawingAsPdfPlugin.bundle.zip",
                UpdateDrawings    = "../../../../WebApplication/AppBundles/UpdateDrawingsPlugin.bundle.zip"
            };
            IOptions <AppBundleZipPaths> appBundleZipPathsOptions = Options.Create(appBundleZipPathsConfiguration);

            var fdaClient = new FdaClient(publisher, appBundleZipPathsOptions);
            IOptions <DefaultProjectsConfiguration> defaultProjectsOptions = Options.Create(defaultProjectsConfiguration);
            var profileProvider   = new ProfileProvider(forgeOSS);
            var bucketKeyProvider = new LoggedInUserBucketKeyProvider(profileProvider, resourceProvider);
            var userResolver      = new UserResolver(forgeOSS, bucketKeyProvider, localCache, NullLogger <UserResolver> .Instance, profileProvider);
            var arranger          = new Arranger(httpClientFactory, userResolver);

            // TODO: linkGenerator should be mocked
            var dtoGenerator = new DtoGenerator(linkGenerator: null, localCache);
            var projectWork  = new ProjectWork(new NullLogger <ProjectWork>(), arranger, fdaClient, dtoGenerator, userResolver);

            var projectService = new ProjectService(new NullLogger <ProjectService>(), userResolver, projectWork, dtoGenerator);

            initializer = new Initializer(new NullLogger <Initializer>(), fdaClient,
                                          defaultProjectsOptions, projectWork, userResolver, localCache,
                                          projectService, bucketPrefixProvider);

            testFileDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            httpClient        = new HttpClient();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services
            .AddControllersWithViews()
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.IgnoreNullValues = true;
            });

            services.AddSignalR(o =>
            {
                o.EnableDetailedErrors = true;
            });

            // In production, the React files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/build";
            });

            services.AddHttpClient();

            services.Configure <FormOptions>(x =>
            {
                x.ValueLengthLimit         = 500 * 1024 * 1024;
                x.MultipartBodyLengthLimit = 500 * 1024 * 1024; // default was 134217728, 500000000 is enough due to FDA quotas (500 MB uncompressed size)
            });

            // NOTE: eventually we might want to use `AddForgeService()`, but right now it might break existing stuff
            // https://github.com/Autodesk-Forge/forge-api-dotnet-core/blob/master/src/Autodesk.Forge.Core/ServiceCollectionExtensions.cs
            services
            .Configure <ForgeConfiguration>(Configuration.GetSection(ForgeSectionKey))
            .Configure <AppBundleZipPaths>(Configuration.GetSection(AppBundleZipPathsKey))
            .Configure <DefaultProjectsConfiguration>(Configuration.GetSection(DefaultProjectsSectionKey))
            .Configure <InviteOnlyModeConfiguration>(Configuration.GetSection(InviteOnlyModeKey))
            .Configure <ProcessingOptions>(Configuration.GetSection(ProcessingOptionsKey));

            services.AddSingleton <ResourceProvider>();
            services.AddSingleton <IPostProcessing, PostProcessing>();
            services.AddSingleton <IForgeOSS, ForgeOSS>();
            services.AddSingleton <FdaClient>();
            services.AddTransient <Initializer>();
            services.AddTransient <Arranger>();
            services.AddTransient <ProjectWork>();
            services.AddTransient <DtoGenerator>();
            services.AddSingleton <DesignAutomationClient>(provider =>
            {
                var forge = provider.GetService <IForgeOSS>();
                var httpMessageHandler = new ForgeHandler(Options.Create(forge.Configuration))
                {
                    InnerHandler = new HttpClientHandler()
                };
                var forgeService = new ForgeService(new HttpClient(httpMessageHandler));
                return(new DesignAutomationClient(forgeService));
            });
            services.AddSingleton <Publisher>();
            services.AddSingleton <BucketPrefixProvider>();
            services.AddSingleton <LocalCache>();
            services.AddSingleton <Uploads>();
            services.AddSingleton <OssBucketFactory>();

            if (Configuration.GetValue <bool>("migration"))
            {
                services.AddHostedService <MigrationApp.Worker>();
                services.AddSingleton <MigrationBucketKeyProvider>();
                services.AddSingleton <IBucketKeyProvider>(provider =>
                {
                    return(provider.GetService <MigrationBucketKeyProvider>());
                });
                services.AddSingleton <UserResolver>();
                services.AddSingleton <ProfileProvider>();
                services.AddSingleton <Migration>();
                services.AddSingleton <ProjectService>();
            }
            else
            {
                services.AddScoped <IBucketKeyProvider, LoggedInUserBucketKeyProvider>();
                services.AddScoped <UserResolver>();
                services.AddScoped <ProfileProvider>();
                services.AddScoped <ProjectService>();
            }
        }
        public DesignAutomationClient(ForgeService service = null, IOptions <Configuration> configuration = null, IActivitiesApi activitiesApi = null, IAppBundlesApi appBundlesApi = null, IEnginesApi enginesApi = null, IForgeAppsApi forgeAppsApi = null, IHealthApi healthApi = null, ISharesApi sharesApi = null, IWorkItemsApi workItemsApi = null)
        {
            this.Service = service ?? ForgeService.CreateDefault();

            // set BaseAddress from configuration or default
            this.Service.Client.BaseAddress = configuration?.Value.BaseAddress ?? new Configuration().BaseAddress;

            if (this.ActivitiesApi == null)
            {
                this.ActivitiesApi = new ActivitiesApi(service, configuration);
            }
            else
            {
                this.ActivitiesApi = activitiesApi;
            }

            if (this.AppBundlesApi == null)
            {
                this.AppBundlesApi = new AppBundlesApi(service, configuration);
            }
            else
            {
                this.AppBundlesApi = appBundlesApi;
            }

            if (this.EnginesApi == null)
            {
                this.EnginesApi = new EnginesApi(service, configuration);
            }
            else
            {
                this.EnginesApi = enginesApi;
            }

            if (this.ForgeAppsApi == null)
            {
                this.ForgeAppsApi = new ForgeAppsApi(service, configuration);
            }
            else
            {
                this.ForgeAppsApi = forgeAppsApi;
            }

            if (this.HealthApi == null)
            {
                this.HealthApi = new HealthApi(service, configuration);
            }
            else
            {
                this.HealthApi = healthApi;
            }

            if (this.SharesApi == null)
            {
                this.SharesApi = new SharesApi(service, configuration);
            }
            else
            {
                this.SharesApi = sharesApi;
            }

            if (this.WorkItemsApi == null)
            {
                this.WorkItemsApi = new WorkItemsApi(service, configuration);
            }
            else
            {
                this.WorkItemsApi = workItemsApi;
            }
        }