Beispiel #1
0
        public InputControl(string propertyName, Type type, RequiredAttribute requiredAttribute, MinLengthAttribute minlengAttribute,
                            MaxLengthAttribute maxlengAttribute, DialogDataAttribute dialogDataAttribute)
        {
            _type = type;

            PropertyName = String.IsNullOrEmpty(dialogDataAttribute.OverridePropertyName) ? propertyName : dialogDataAttribute.OverridePropertyName;
            Required     = requiredAttribute != null;
            MinLength    = minlengAttribute != null ? (int?)minlengAttribute.Length : null;
            MaxLength    = maxlengAttribute != null ? (int?)maxlengAttribute.Length : null;

            DataSource = dialogDataAttribute.Source != UIAnnotations.DataSource.None
                ? new SimpleNamedEntity {
                Id = ((int)dialogDataAttribute.Source).ToString(), Name = dialogDataAttribute.Source.ToString()
            }
                : null;
            DefaultValue            = dialogDataAttribute.DefaultValue;
            DependsOn               = dialogDataAttribute.DependsOn;
            Group                   = dialogDataAttribute.Group;
            Mask                    = dialogDataAttribute.Mask;
            Unmask                  = dialogDataAttribute.Unmask;
            CharacterPattern        = dialogDataAttribute.CharacterPattern;
            FileAccept              = dialogDataAttribute.FileAccept;
            Name                    = dialogDataAttribute.Name;
            IsVisible               = dialogDataAttribute.IsVisible ? null : (bool?)false;
            ExcludeFromResponse     = dialogDataAttribute.ExcludeFromResponse;
            SourceName              = dialogDataAttribute.SourceName;
            EntityLabelPropertyName = dialogDataAttribute.EntityLabelPropertyName;

            var control = dialogDataAttribute.ForcedType != DialogControlTypes.Default ? dialogDataAttribute.ForcedType : GetControlType();

            ControlType = new SimpleNamedEntity {
                Id = ((int)control).ToString(), Name = control.ToString()
            };

            if (control == DialogControlTypes.DropDown || control == DialogControlTypes.MultiSelect || control == DialogControlTypes.LinkedDropDown)
            {
                PropertyName    = FixDropDownName(propertyName);
                ShowFilter      = dialogDataAttribute.ShowFilter;
                FilterMatchMode = dialogDataAttribute.FilterMatchMode;
            }

            if (control == DialogControlTypes.TextArea)
            {
                TextAreaRows = dialogDataAttribute.TextAreaRows > 0 ? dialogDataAttribute.TextAreaRows: 5;
            }

            if (_type.IsEnum)
            {
                Data = EnumToSimpleNamedList(_type);
            }
        }
Beispiel #2
0
        public static int Main(string[] args)
        {
            //// Create the Serilog logger, and configure the sinks
            //Serilog.Log.Logger = new LoggerConfiguration()
            //    .MinimumLevel.Information()
            //    .MinimumLevel.Override("Microsoft", LogEventLevel.Error)
            //    // .Enrich.FromLogContext()
            //    // .Enrich.With<ReleaseNumberEnricher>()
            //    .WriteTo.Console()
            //    .WriteTo.File(new CompactJsonFormatter(), "d:\\serilog.json")
            //    .CreateLogger();

            try
            {
                var test = new SimpleNamedEntity {
                    Id = "1", Name = "Oi"
                };

                // Serilog.Log.Logger.Information("Starting host {@SimpleNamedEntity}", test);

                var host = CreateHostBuilder(args).Build();

                using (var scope = host.Services.CreateScope())
                {
                    var services = scope.ServiceProvider;
                    try
                    {
                        var context1 = services.GetRequiredService <DatabaseContext>();
                        context1.Database.Migrate();

                        var user = context1.Set <User>().SingleOrDefault(x => x.Username == "admn");

                        if (user == null)
                        {
                            user = new User("admn", "123123", false, new Client("Administrador", DateTime.Now));
                            context1.Set <User>().Add(user);
                        }

                        var claims = new List <Claim>
                        {
                            new Claim("SAMPLE_CLAIM", "Exemplo de Controle de Acesso")
                        };

                        foreach (var claim in claims)
                        {
                            if (!context1.Set <Claim>().Any(x => x.Name == claim.Name))
                            {
                                context1.Set <Claim>().Add(claim);

                                user.AddClaim(claim, ClaimAcessType.Allow);
                            }
                        }

                        context1.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        // Serilog.Log.Logger.Fatal(ex, "An error occurred while seeding the database.");
                    }
                }

                host.Run();

                return(0);
            }
            catch (Exception ex)
            {
                // Serilog.Log.Logger.Fatal(ex, "Host terminated unexpectedly");
                return(1);
            }
            finally
            {
                // Serilog.Log.Logger.CloseAndFlush();
            }
        }