Exemplo n.º 1
0
        public static TreeInfo GetAncestors()
        {
            TreeInfo ti = new TreeInfo();

            CoreDb.DalConfig config = new CoreDb.DalConfig(
                typeof(System.Data.SqlClient.SqlClientFactory)
                , delegate(CoreDb.DalConfig conf)
            {
                System.Data.SqlClient.SqlConnectionStringBuilder csb = new System.Data.SqlClient.SqlConnectionStringBuilder();

                csb.DataSource = "127.0.0.1";

                // Set during installation
                // csb.DataSource = System.Environment.GetEnvironmentVariable("COMPUTERNAME");
                // https://stackoverflow.com/questions/804700/how-to-find-fqdn-of-local-machine-in-c-net

                // https://stackoverflow.com/questions/1233217/difference-between-systeminformation-computername-environment-machinename-and
                // Environment.MachineName : NetBIOS name of local computer read from registry

                // TCP-Based network-name
                csb.DataSource = System.Net.Dns.GetHostName();


                csb.InitialCatalog     = "Ahnen";
                csb.IntegratedSecurity = true;
                if (!csb.IntegratedSecurity)
                {
                    csb.UserID   = "GenealogicalResearchWebServices";
                    csb.Password = "******";
                }

                csb.PersistSecurityInfo = false;
                csb.PacketSize          = 4096;
                csb.Pooling             = true;
                return(csb.ConnectionString);
            }
                );


            CoreDb.ReadDAL DAL = new CoreDb.ReadDAL(config);

            using (System.Data.Common.DbCommand cmd = DAL.CreateCommandFromFile(typeof(Program), "Ahnen.sql"))
            {
                ti.AllData = DAL.GetList <PersonData>(cmd);
            }

            System.Console.WriteLine(ti.AllData);

            var lsAncestorGenerations = (
                from ancestorList in ti.AllData
                orderby ancestorList.generation ascending, ancestorList.Id ascending
                group ancestorList by new { ancestorList.generation } into g
                select new
            {
                Generation = g.Key.generation,
                PresenceCount = g.Count(x => x.Id > -1)
            }
                ).ToList();


            ti.MaxGeneration = lsAncestorGenerations.Max(x => x.Generation);;
            ti.MaxPresence   = lsAncestorGenerations.Max(x => x.PresenceCount);

            System.Console.WriteLine(ti.MaxGeneration);
            System.Console.WriteLine(ti.MaxPresence);



            for (int i = 0; i < ti.MaxGeneration; ++i)
            {
                ti.ls.Add(new System.Collections.Generic.List <PersonData>());
                ti.ls[i].AddRange(
                    (
                        from ancestorList in ti.AllData
                        where ancestorList.generation == i
                        orderby
                        ancestorList.generation ascending
                        , ancestorList.Child ascending
                        , ancestorList.Id ascending
                        , ancestorList.gender descending

                        select ancestorList
                    ).ToList()
                    );
            }

            System.Console.WriteLine(ti);
            return(ti);
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(AuthTest.JwtAuthentication.SetCookieSchemes)
            .AddCookie(AuthTest.JwtAuthentication.SetupCookie)
            // .AddJwtBearer(AuthTest.JwtAuthentication.SetupBearer)
            ;

            /*
             * services.AddAntiforgery(
             *  delegate (Microsoft.AspNetCore.Antiforgery.AntiforgeryOptions options)
             *  {
             *       // https://damienbod.com/2017/05/09/anti-forgery-validation-with-asp-net-core-mvc-and-angular/
             *       options.HeaderName = "X-XSRF-TOKEN";
             *       //options.CookieDomain = "localhost";
             *       options.Cookie.Name = "XSRF";
             *  }
             * );
             */
            // services.AddMvc();

            // https://geeks.ms/clanderas/2016/10/18/asp-net-core-node-services-to-execute-your-nodejs-scripts/
            // https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/
            services.AddNodeServices(options => {
                // options.DebuggingPort
            });

            services.AddRouting(delegate(Microsoft.AspNetCore.Routing.RouteOptions options)
                                { });


            services.AddMvc(

                /*
                 * delegate (Microsoft.AspNetCore.Mvc.MvcOptions config)
                 * {
                 *  Microsoft.AspNetCore.Authorization.AuthorizationPolicy policy =
                 *      new Microsoft.AspNetCore.Authorization.AuthorizationPolicyBuilder()
                 *                   .RequireAuthenticatedUser()
                 *                   // .AddRequirements( new NoBannedIPsRequirement(new HashSet<string>() { "127.0.0.1", "0.0.0.1" } ))
                 *                   .Build();
                 *
                 *  config.Filters.Add(new Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter(policy));
                 * }
                 */
                )
            .AddJsonOptions(options =>
            {
#if DEBUG
                options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
#else
                options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.None;
#endif
            });


            services.Configure <Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions>(options =>
            {
                options.ViewLocationExpanders.Add(new CoreCMS.Routing.SubdomainViewLocationExpander());
            });



            Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions
            .Configure <ConfigData.SmtpConfig>(services, Configuration.GetSection("Smtp"));


            /*
             * Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions
             *  .Configure<Dictionary<string, ConfigData.cConnectionString>>(services
             *  , Configuration.GetSection("ConnectionStrings")
             * );
             *
             * Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions
             *  .Configure<ConfigData.cConnectionStrings>(services
             *      , Configuration.GetSection("DataBase"));
             *
             * string foo = Configuration.GetValue<string>("data:userID");
             * System.Console.WriteLine(foo);
             * // https://msdn.microsoft.com/en-us/magazine/mt632279.aspx
             */

            ConfigData.Databases dbs = Configuration.Get <ConfigData.Databases>();

            // System.Console.WriteLine(cs);
            // services.AddSingleton<ConfigData.Database>(cs);

            DbConfig dbConfig = null;

            if (dbs.ConnectionStrings.ContainsKey(System.Environment.MachineName))
            {
                dbConfig = dbs.ConnectionStrings[System.Environment.MachineName];
            }


            if (dbConfig == null)
            {
                if (dbs.ConnectionStrings.ContainsKey("server"))
                {
                    dbConfig = dbs.ConnectionStrings["server"];
                }
            }


            if (dbConfig == null)
            {
                throw new System.IO.InvalidDataException("Connection string not configured...");
            }


            CoreDb.DalConfig dalConfig =
                new CoreDb.DalConfig(dbConfig.ProviderName, dbConfig.ConnectionString);

            CoreDb.ReadDAL  readData  = new CoreDb.ReadDAL(dalConfig);
            CoreDb.WriteDAL writeData = new CoreDb.WriteDAL(dalConfig);

            services.AddSingleton <CoreDb.ReadDAL>(readData);
            services.AddSingleton <CoreDb.WriteDAL>(writeData);
        }