示例#1
0
        private static ForgeService CreateForgeService(IConfiguration configuration)
        {
            var forgeCfg           = configuration.GetSection("Forge").Get <ForgeConfiguration>();
            var httpMessageHandler = new ForgeHandler(Options.Create(forgeCfg))
            {
                InnerHandler = new HttpClientHandler()
            };

            return(new ForgeService(new HttpClient(httpMessageHandler)));
        }
        // 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>();
        }
示例#3
0
        private ForgeService CreateForgeService(string forgeClientId, string forgeClientSecret)
        {
            var forgeConfig = new ForgeConfiguration();

            forgeConfig.ClientId     = forgeClientId;
            forgeConfig.ClientSecret = forgeClientSecret;
            var httpMessageHandler = new ForgeHandler(Options.Create(forgeConfig))
            {
                InnerHandler = new HttpClientHandler()
            };

            return(new ForgeService(new HttpClient(httpMessageHandler)));
        }
示例#4
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>();
            }
        }