WebMAP From Scratch

When your code is converted, WebMAP performs any necessary changes to start using WebMAP right away.

But if you want to install it from scratch follow these steps:

Using VS 2019

  1. Start Visual Studio 2019

  2. Select File\New\Project...

  3. On the New Project dialog:

    1. Select C# option from Languages box

    2. Select Web From All project types box

  4. Choose ASP.NET Core Web Application

  5. Press Next

  6. Insert your Web Application name

  7. Press Create

  8. On the New ASP.NET Core Web Application choose Empty and press Create

  9. Add the following NuGets:

    • Microsoft.AspNetCore.All

    • Mobilize.Weaving.WebMAPExtensions.All

    • Mobilize.WebMAP.CoreServices.All

    • Mobilize.WebMAP.BundleBasic.All

  10. Modify your Startup.cs to look like the following:

    namespace DemoApp
    {
        using Microsoft.AspNetCore.Builder;
        using Microsoft.AspNetCore.Hosting;
        using Microsoft.AspNetCore.Mvc.ModelBinding;
        using Microsoft.AspNetCore.Server.Kestrel.Core;
        using Microsoft.Extensions.DependencyInjection;
        using Microsoft.Extensions.Hosting;
        using Mobilize.Web;
        using Mobilize.WebMap.Common.Core;
        using Mobilize.WebMap.Common.DCP;
        using Mobilize.WebMap.Host;
        using Mobilize.WebMap.Server;
        using Mobilize.WebMap.Server.ObservableBinder;
        using Newtonsoft.Json.Serialization;
        using TestingDemo;
    
        /// 
        /// Startup
        /// 
        public class Startup
        {
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddWebMap();
                services.RegisterModelMappers();
                services.RegisterWrappers();
                AddDesktopCompatibilityPlatform(services, entry);
                services.AddHttpContextAccessor();
                services.AddDistributedMemoryCache();
                services.AddSession();
                services.AddAntiforgery(options => options.HeaderName = WebMapHeaders.AntiforgeryToken);
                services.AddMvc(options =>
                {
                    options.ModelBinderProviders.Insert(0, new ObservableModelBinderProvider());
                    options.ModelMetadataDetailsProviders.Insert(0, new SuppressChildValidationMetadataProvider(typeof(IObservable)));
                }).AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
                // If using IIS:
                services.Configure<IISServerOptions>(options =>
                {
                    options.AllowSynchronousIO = true;
                });
                // If using Kestrel:
                services.Configure<KestrelServerOptions>(options =>
                {
                    options.AllowSynchronousIO = true;
                });
                services.AddHealthChecks();
                services.AddSignalR();
            }
    
            private static void AddDesktopCompatibilityPlatform(IServiceCollection services, EntryPoint entryPoint)
            {
                services.AddScoped<ICommandFactory, CommandFactory>();
                services.AddScoped<IApplication>((provider) => new ExtApplication(provider) { EntryPoint = entryPoint });
                services.AddTransient<IBackgroundWorkerManager, BackgroundWorkerManager>();
            }
    
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                app.UseDefaultFiles();
                app.UseStaticFiles();
                app.UseSession();
                app.UseAntiforgeryToken();
                app.UseWebMap();
                app.UseRouting();
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllerRoute("DefaultApi", "api/{controller}/{id}");
                    endpoints.MapHealthChecks("/health");
                    endpoints.MapHub<SignalHub>("/bgw");
                });
    
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
            }
        }
    }

The entry point for the application can be set when adding the DCP, for example:

AddDesktopCompatibilityPlatform(services, Program.Start);
  1. (Optional) Add a Registrations.cs file like the following:

    namespace YourNamespace
    {
     using System;
     using System.Collections.Generic;
     using System.Data;
     using System.IO;
     using System.Linq;
     using System.Reflection;
     using Microsoft.Extensions.DependencyInjection;
     using Mobilize.Web.DTOMapper;
     using Mobilize.WebMAP.Common.Core.ObservableWrapper;
     using Mobilize.WebMAP.Common.DCP;
     using Mobilize.WebMAP.Common.Messaging;
     using Mobilize.WebMAP.Core.ObservableWrapper;
     using Mobilize.WebMAP.Messaging;
    
     public static class Registrations
     {
         public static IModelProjectionService RegisterMappers(this IServiceCollection services)
         {
             services.AddSingleton((provider) => GetMappers(provider.GetService()));
         }
    
         public static void RegisterWrappers(this IServiceCollection services)
         {
            services.AddSingleton(
                 (provider) =>
                 {
                     var dlls =
                         new DirectoryInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)).GetFiles("*.dll", SearchOption.AllDirectories);
                     var wrappers = AssemblyWrapperLoader.GetObservablesWrappersTypes(dlls).ToArray();
                     var catalog = new ObservableWrapperCatalog(wrappers);
                     catalog.Register();
                     return catalog;
                 });
         }
    
         public static IMapperService GetMappers(IObservableStorage storage)
         {
             var mapperService = new MapperService(storage);
             mapperService.SetupDefaultMapper(new DefaultMapper());
             mapperService.RegisterMapper(new ButtonMapper());
             mapperService.RegisterMapper(new LabelMapper());
             mapperService.RegisterMapper(new TextBoxMapper());
             mapperService.RegisterMapper(new MessageBoxFormMapper());
             mapperService.RegisterMapper(new KeyPressEventArgsMapper());
             return mapperService;
         }
     }
    }
  2. That's all. Your application is ready to start using WebMAP.

Last updated