Пример #1
0
        /// <summary>
        /// Builds the IServiceProvider for the application and registers available services.
        /// </summary>
        private static void BuildAndRegisterServices()
        {
            IConfigurationRoot config = Program.Configuration;

            if (config == null)
            {
                throw new InvalidOperationException("Application Configuration is null. You must call BuildConfiguration() before calling this method.");
            }
            System.Console.WriteLine($"Connection string: {config["Data:ptvdb:ConnectionString"]}");

            var srvcol = new ServiceCollection();

            srvcol.AddLogging();

            // register console apps db context
            srvcol.AddEntityFrameworkNpgsql().AddDbContext <SourceDbContext>(options => options.UseNpgsql(Program.Configuration[ConfigKeys.SourceConnectionString]));
            srvcol.AddDbContext <SourceDbContext>(options => options.UseNpgsql(Program.Configuration[ConfigKeys.SourceConnectionString]));
            // register ptv db context and PTV services
            RegisterServiceManager.RegisterFromAllAssemblies(srvcol);
            RegisterDataProviderServices.RegisterFromAssembly(srvcol);
            BaseEntityCloners.RegisterBaseEntityCloners(srvcol);
            FrameworksInitializer.RegisterEntityFramework(srvcol, Program.Configuration[ConfigKeys.PTVConnectionString]);

            // for now make it behave like this..
            srvcol.AddTransient <ISourceRepository, SourceRepository>();
            srvcol.AddTransient <IFakePtvRepository, FakePtvJsonFileRepository>();
            srvcol.AddTransient <IHttpContextAccessor, FakeHttpContext>();
            srvcol.AddTransient <IHostingEnvironment, FakeHostingEnv>();
            srvcol.AddSingleton(new ApplicationConfiguration(config));

            Program.ServiceProvider = srvcol.BuildServiceProvider();
        }
Пример #2
0
        /// <summary>
        /// Builds the IServiceProvider for the application and registers available services.
        /// </summary>
        private static void BuildAndRegisterServices()
        {
            IConfigurationRoot config = Configuration;

            if (config == null)
            {
                throw new InvalidOperationException("Application Configuration is null. You must call BuildConfiguration() before calling this method.");
            }
            Console.WriteLine($"Connection string: {config["Data:ptvdb:ConnectionString"]}");

            var services = new ServiceCollection();

            services.AddLogging();

            // register ptv db context and PTV services
            RegisterServiceManager.RegisterFromAllAssemblies(services);
            FrameworksInitializer.RegisterEntityFramework(services, Configuration["Data:ptvdb:ConnectionString"]);
            services.Configure <AppSettings>(options => Configuration.GetSection("AppSettings").Bind(options));
            services.AddSingleton <IConfiguration>(Configuration);
            services.AddOptions();
            services.AddTransient <IDataHandler, DataHandler>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddTransient <IUserIdentification, UserIdentification>();
            //services.AddTransient<IOrganizationService, OrganizationService>();
            //services.AddTransient<IServiceService, ServiceService>();
            //services.AddTransient<IChannelService, ChannelService>();
            //services.AddTransient<IGeneralDescriptionService, GeneralDescriptionService>();
            services.AddSingleton(new ApplicationConfiguration(config));
            ServiceProvider = services.BuildServiceProvider();
        }
Пример #3
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">object responsible for registering of the assemblies</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddMvcCore().AddJsonFormatters();
            //services.AddMvcCore();
            //services.AddAuthorization();
            services.AddSingleton(PtvConfiguration);
            services.AddOptions();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("ui", new Info()
                {
                    Title = "PTV UI API", Version = "ui", Description = "PTV UI Web API",
                });
                var developmentPath = string.Format(Path.Combine(appEnv.ContentRootPath, "bin", "Debug", "netcoreapp1.1"));

                var xmlCommentPath = Path.Combine(appEnv.ContentRootPath, @"PTV.Application.Api.xml");
                var modelsXmlPath  = Path.Combine(appEnv.ContentRootPath, @"PTV.Domain.Model.xml");

                c.DescribeAllEnumsAsStrings();

                if (!File.Exists(xmlCommentPath) || !File.Exists(modelsXmlPath))
                {
                    xmlCommentPath = Path.Combine(developmentPath, @"PTV.Application.Api.xml");
                    modelsXmlPath  = Path.Combine(developmentPath, @"PTV.Domain.Model.xml");
                }

                if (!File.Exists(xmlCommentPath) || !File.Exists(modelsXmlPath))
                {
                    return;
                }

                c.IncludeXmlComments(xmlCommentPath);
                c.IncludeXmlComments(modelsXmlPath);
            });
            //services.AddCors();
            services.Configure <CookieAuthenticationOptions>(options => Configuration.GetSection("Data:CookieAuthenticationConfigurations").Bind(options));
            services.Configure <OpenIdConnectOptions>(options => Configuration.GetSection("Data:OpenIDConnectConfigurations").Bind(options));
            //services.Configure<OAuthOptions>(options => Configuration.GetSection("Data:OpenIDConnectConfigurations").Bind(options));
            services.Configure <IdentityServerAuthenticationOptions>(options => Configuration.GetSection("Data:IdentityServerAuthenticationConfigurations").Bind(options));
            services.Configure <ProxyServerSettings>(options => Configuration.GetSection("Data:ProxyServerSettings").Bind(options));
            services.Configure <DataContextOptions>(options => Configuration.GetSection("Data:DataContextOptions").Bind(options));
            services.Configure <AnnotationServiceConfiguration>(options => Configuration.GetSection("Data:AnnotationService").Bind(options));
            services.Configure <MapServiceConfiguration>(options => Configuration.GetSection("Data:MapService").Bind(options));
            services.Configure <TestAccessUrlConfiguration>(options => Configuration.GetSection("Data:TestInternetAccess").Bind(options));
            services.Configure <MapDNSes>(options => Configuration.GetSection("ApplicationConfiguration:MapDNSNames").Bind(options));
            services.Configure <RequestFilterAppSetting>(options => Configuration.GetSection("RequestFilter").Bind(options));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            RegisterServiceManager.RegisterFromAllAssemblies(services);
            BaseEntityCloners.RegisterBaseEntityCloners(services);
            RegisterDataProviderServices.RegisterFromAssembly(services);
            // Add framework services.
            FrameworksInitializer.RegisterEntityFramework(services, Configuration["Data:DefaultConnection:ConnectionString"]);
        }
Пример #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options =>
            {
                options.RespectBrowserAcceptHeader = true;
                options.OutputFormatters.Add(new XmlDataContractSerializerOutputFormatter());
            }
                            );

            //services.AddTransient<IResolveManager, ResolveManager>();

            RegisterServiceManager.RegisterFromAllAssemblies(services);

            services.AddSingleton(MapServerConfiguration);
            services.AddMvc().AddXmlSerializerFormatters();
            services.AddMvc();
        }
Пример #5
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc().AddJsonOptions(i => i.SerializerSettings.Error += JsonError);
     services.AddWebpack();
     services.AddSingleton(PtvConfiguration);
     services.AddOptions();
     services.Configure <CookieAuthenticationOptions>(options => Configuration.GetSection("Data:CookieAuthenticationConfigurations").Bind(options));
     services.Configure <OpenIdConnectOptions>(options => Configuration.GetSection("Data:OpenIDConnectConfigurations").Bind(options));
     services.Configure <IdentityServerAuthenticationOptions>(options => Configuration.GetSection("Data:IdentityServerAuthenticationConfigurations").Bind(options));
     services.Configure <ProxyServerSettings>(options => Configuration.GetSection("Data:ProxyServerSettings").Bind(options));
     services.Configure <DataContextOptions>(options => Configuration.GetSection("Data:DataContextOptions").Bind(options));
     services.Configure <AnnotationServiceConfiguration>(options => Configuration.GetSection("Data:AnnotationService").Bind(options));
     services.Configure <MapServiceConfiguration>(options => Configuration.GetSection("Data:MapService").Bind(options));
     services.Configure <MapDNSes>(options => Configuration.GetSection("ApplicationConfiguration:MapDNSNames").Bind(options));
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     RegisterServiceManager.RegisterFromAllAssemblies(services);
     BaseEntityCloners.RegisterBaseEntityCloners(services);
     RegisterDataProviderServices.RegisterFromAssembly(services);
     FrameworksInitializer.RegisterEntityFramework(services, Configuration["Data:DefaultConnection:ConnectionString"]);
 }
Пример #6
0
        /// <summary>
        /// Configure and register all services needed for application
        /// </summary>
        /// <param name="services"></param>
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(PtvConfiguration);
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton(Configuration);
            RegisterServiceManager.RegisterFromAllAssemblies(services);
            RegisterDataProviderServices.RegisterFromAssembly(services);
            FrameworksInitializer.RegisterEntityFramework(services, Configuration.GetConnectionString("QuartzConnection"));

            // Add framework services.
            services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.Formatting            = Formatting.Indented;
                options.SerializerSettings.Culture               = CultureInfo.InvariantCulture;
                options.SerializerSettings.DateFormatHandling    = DateFormatHandling.IsoDateFormat;
                options.SerializerSettings.DateParseHandling     = DateParseHandling.DateTime;
                options.SerializerSettings.DateTimeZoneHandling  = DateTimeZoneHandling.Utc;
                options.SerializerSettings.NullValueHandling     = NullValueHandling.Include;
                options.SerializerSettings.MissingMemberHandling = MissingMemberHandling.Ignore;
                options.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
            });
        }
Пример #7
0
        /// <summary>
        /// Configure and register all services needed for application
        /// </summary>
        /// <param name="services"></param>
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc(
                c => c.Conventions.Add(new ControllerModelRemoveVersionPrefixConvention())
                );
            services.AddMvcCore().AddJsonFormatters();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IConfigurationRoot>(Configuration);
            services.Configure <AppSettings>(options => Configuration.GetSection("AppSettings").Bind(options));

            services.AddSingleton(PtvConfiguration);
            services.Configure <CookieAuthenticationOptions>(options => Configuration.GetSection("Data:CookieAuthenticationConfigurations").Bind(options));
            services.Configure <OpenIdConnectOptions>(options => Configuration.GetSection("Data:OpenIDConnectConfigurations").Bind(options));
            services.Configure <IdentityServerAuthenticationOptions>(options => Configuration.GetSection("Data:IdentityServerAuthenticationConfigurations").Bind(options));
            services.Configure <ProxyServerSettings>(options => Configuration.GetSection("Data:ProxyServerSettings").Bind(options));
            services.Configure <DataContextOptions>(options => Configuration.GetSection("Data:DataContextOptions").Bind(options));
            services.Configure <AnnotationServiceConfiguration>(options => Configuration.GetSection("Data:AnnotationService").Bind(options));
            services.Configure <MapServiceConfiguration>(options => Configuration.GetSection("Data:MapService").Bind(options));
            services.Configure <TestAccessUrlConfiguration>(options => Configuration.GetSection("Data:TestInternetAccess").Bind(options));
            services.Configure <MapDNSes>(options => Configuration.GetSection("ApplicationConfiguration:MapDNSNames").Bind(options));
            services.Configure <RequestFilterAppSetting>(options => Configuration.GetSection("RequestFilter").Bind(options));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            RegisterServiceManager.RegisterFromAllAssemblies(services);
            BaseEntityCloners.RegisterBaseEntityCloners(services);
            RegisterDataProviderServices.RegisterFromAssembly(services);
            FrameworksInitializer.RegisterEntityFramework(services, Configuration["Data:DefaultConnection:ConnectionString"]);
            services.AddSwaggerGen(
                c => {
                c.SwaggerDoc("v4", new Info
                {
                    Version     = "v4",
                    Title       = "PTV Open Api version 4",
                    Description = "Here you can see listed all the PTV Open Api methods."
                });
                c.SwaggerDoc("v5", new Info
                {
                    Version     = "v5",
                    Title       = "PTV Open Api version 5",
                    Description = "Here you can see listed all the PTV Open Api methods."
                });
                c.SwaggerDoc("v6", new Info
                {
                    Version     = "v6",
                    Title       = "PTV Open Api version 6",
                    Description = "Here you can see listed all the PTV Open Api methods."
                });
                c.SwaggerDoc("v7", new Info
                {
                    Version     = "v7",
                    Title       = "PTV Open Api version 7",
                    Description = "Here you can see listed all the PTV Open Api methods."
                });


                c.OperationFilter <SecurityRequirementsOperationFilter>();
                c.DocInclusionPredicate((version, apiDescription) => ResolveVersionSupportByRouteConstraint(apiDescription, version));
                c.SchemaFilter <SwaggerSchemaFilter>();

                // TODO: PTV-1556:
                //c.DocumentFilter<SwaggerDocumentFilter>();

                // Define the OAuth2.0 scheme that's in use (i.e. Implicit Flow)
                c.AddSecurityDefinition("oauth2", new OAuth2Scheme
                {
                    Type             = "oauth2",
                    Flow             = "implicit",
                    AuthorizationUrl = $"{Configuration["STS"]}/connect/authorize",
                    Scopes           = new Dictionary <string, string>
                    {
                        { "dataEventRecords", "Access event records" }
                    }
                });
            });

            var path           = appEnv.IsDevelopment() ? Path.Combine(appEnv.ContentRootPath, "bin", "Debug", @"netcoreapp1.1") : appEnv.ContentRootPath;
            var xmlCommentPath = Path.Combine(path, @"PTV.Application.OpenApi.xml");
            var modelsXmlPath  = Path.Combine(path, @"PTV.Domain.Model.xml");

            services.ConfigureSwaggerGen(options =>
            {
                options.DescribeAllEnumsAsStrings();
                options.IncludeXmlComments(xmlCommentPath);
                if (File.Exists(modelsXmlPath))
                {
                    options.IncludeXmlComments(modelsXmlPath);
                }
            });
        }
Пример #8
0
        private async void Register_ClickedAsync(object sender, EventArgs e)
        {
            //SnackServiceManager snackService = new SnackServiceManager();
            //var a = await snackService.GetSnacksAsync();

            if (!string.IsNullOrEmpty(usernameEntryR.Text) && !string.IsNullOrEmpty(friendlyNameEntryR.Text) && !string.IsNullOrEmpty(passwordEntryR.Text) && !string.IsNullOrEmpty(testPasswordEntryR.Text))
            {
                bool     nondeveaverespazi = true;
                string[] friend            = friendlyNameEntryR.Text.Split();
                foreach (var a in friend)
                {
                    if (a == "")
                    {
                        nondeveaverespazi = false;
                        break;
                    }
                }

                if (nondeveaverespazi)
                {
                    password      = passwordEntryR.Text;
                    testpassword  = testPasswordEntryR.Text;
                    username      = usernameEntryR.Text;
                    friendly_name = friendlyNameEntryR.Text;

                    if (password == testpassword)
                    {
                        RegisterServiceManager registerService = new RegisterServiceManager();
                        var response = await registerService.RegisterAsync(username, password, friendly_name);

                        if (response == null)
                        {
                        }
                        else if (response.success == true && response.status == 201)
                        {
                            await userService.GetUserData();

                            App.Current.MainPage = new MainPage();
                            MessagingCenter.Send(new EditUserViewCell()
                            {
                            }, "RefreshUF");
                        }
                        else
                        {
                            if (response.status == 400)
                            {
                                await DisplayAlert("Fondo Merende", response.message, "OK");
                            }
                            else
                            {
                                await DisplayAlert("Fondo Merende", "Registrazione fallita", "OK");
                            }
                        }
                    }
                    else
                    {
                        await DisplayAlert("Fondo Merende", "Le password non combaciano", "OK");
                    }
                }
                else
                {
                    await DisplayAlert("Fondo Merende", "Il friendly name non può contenere spazi", "OK");
                }
            }
            else
            {
                await DisplayAlert("Fondo Merende", "Compila tutti i campi", "OK");
            }
        }