Exemplo n.º 1
0
    /// <summary>
    /// Read the request body as a form with the given options. These options will only be used
    /// if the form has not already been read.
    /// </summary>
    /// <param name="request">The request.</param>
    /// <param name="options">Options for reading the form.</param>
    /// <param name="cancellationToken"></param>
    /// <returns>The parsed form.</returns>
    public static Task <IFormCollection> ReadFormAsync(this HttpRequest request, FormOptions options,
                                                       CancellationToken cancellationToken = new CancellationToken())
    {
        if (request == null)
        {
            throw new ArgumentNullException(nameof(request));
        }
        if (options == null)
        {
            throw new ArgumentNullException(nameof(options));
        }

        if (!request.HasFormContentType)
        {
            throw new InvalidOperationException("Incorrect Content-Type: " + request.ContentType);
        }

        var features    = request.HttpContext.Features;
        var formFeature = features.Get <IFormFeature>();

        if (formFeature == null || formFeature.Form == null)
        {
            // We haven't read the form yet, replace the reader with one using our own options.
            features.Set <IFormFeature>(new FormFeature(request, options));
        }
        return(request.ReadFormAsync(cancellationToken));
    }
 public RequestFormSizeLimitAttribute(int valueCountLimit)
 {
     _formOptions = new FormOptions()
     {
         ValueCountLimit = valueCountLimit
     };
 }
 public DefaultHttpContextFactory(IServiceProvider serviceProvider)
 {
     // May be null
     _httpContextAccessor = serviceProvider.GetService <IHttpContextAccessor>();
     _formOptions         = serviceProvider.GetRequiredService <IOptions <FormOptions> >().Value;
     _serviceScopeFactory = serviceProvider.GetRequiredService <IServiceScopeFactory>();
 }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="hostingEnvironment"></param>
 public HighlightsController(IHostingEnvironment hostingEnvironment,
                             INotificationService notificationService)
 {
     FormOptions         = new FormOptions();
     HostingEnvironment  = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
     NotificationService = notificationService ?? throw new ArgumentNullException(nameof(notificationService));
 }
        public FormOptions LoadFormOptionsFromFile(MetroMainForm _form)
        {
            if (!_fileSystemService.FileExists(_configService.ConfigFile))
            {
                var defaultOptions = new FormOptions
                {
                    ImagesSoureDirectory   = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
                    ClearDatabase          = false,
                    StatsAnalysisRange     = 1,
                    ConfirmMoveDuplicates  = false,
                    ExtraSetAnalysis       = true,
                    MinimumSimilarityScore = 0.85m
                };
                File.WriteAllText(_configService.ConfigFile,
                                  JsonConvert.SerializeObject(defaultOptions, Formatting.Indented));
            }

            var options = ReadFromFile();

            _form.imagesDirectoryTextBox.Text           = options.ImagesSoureDirectory;
            _form.clearDatabaseCheckbox.Checked         = options.ClearDatabase;
            _form.statsAnalysisRange.Value              = (int)options.StatsAnalysisRange;
            _form.confirmCleanupCheckbox.Checked        = options.ConfirmMoveDuplicates;
            _form.extraSetAnalysisCheckbox.Checked      = options.ExtraSetAnalysis;
            _form.minSimilarityScoreNumericUpDown.Value = options.MinimumSimilarityScore < 1
                ? (int)(options.MinimumSimilarityScore * 100)
                : (int)(options.MinimumSimilarityScore);
            return(options);
        }
Exemplo n.º 6
0
 public GridForm(FormOptions options)
 {
     Options = options;
     InitializeComponent();
     itemlist = FillFormItem();
     this.Controls.Add(InitOptions(Options.Groups, true));
 }
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 public AllowLargePostsAttribute()
 {
     this.FormOptions = new FormOptions
     {
         ValueLengthLimit = 200 * 1024 * 1024 // 200MB
     };
 }
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            var assetOptions = context.HttpContext.RequestServices.GetService <IOptions <AssetOptions> >();

            var maxRequestBodySizeFeature = context.HttpContext.Features.Get <IHttpMaxRequestBodySizeFeature>();

            if (maxRequestBodySizeFeature?.IsReadOnly == false)
            {
                if (assetOptions?.Value.MaxSize > 0)
                {
                    maxRequestBodySizeFeature.MaxRequestBodySize = assetOptions.Value.MaxSize;
                }
                else
                {
                    maxRequestBodySizeFeature.MaxRequestBodySize = null;
                }
            }

            if (assetOptions?.Value.MaxSize > 0)
            {
                var options = new FormOptions
                {
                    MultipartBodyLengthLimit = assetOptions.Value.MaxSize
                };

                context.HttpContext.Features.Set <IFormFeature>(new FormFeature(context.HttpContext.Request, options));
            }
        }
Exemplo n.º 9
0
        private async Task <ServerInfo> CollectServerInfoFromUser()
        {
            var serverInfo = new ServerInfo {
                Server = "192.168.1.16", Port = 8080
            };
            Task dialogTask = null;

            await QueueAction(() =>
            {
                var panel = new ConsolePanel()
                {
                    Height = 10
                };
                var form     = panel.Add(new Form(FormOptions.FromObject(serverInfo))).Fill(padding: new Thickness(1, 1, 1, 2));
                var okButton = panel.Add(new Button()
                {
                    X = 1, Text = "OK".ToConsoleString(), Shortcut = new KeyboardShortcut(ConsoleKey.Enter)
                }).DockToBottom(padding: 1);
                var dialog       = new Dialog(panel);
                dialog.MaxHeight = 8;
                okButton.Pressed.SubscribeOnce(() => LayoutRoot.Controls.Remove(dialog));
                dialogTask = dialog.Show().AsAwaitable();
            }).AsAwaitable();

            await dialogTask;

            return(serverInfo);
        }
Exemplo n.º 10
0
        private void InitLeftPane()
        {
            var stack = grid.Add(new StackPanel()
            {
                AutoSize = false, Orientation = Orientation.Vertical
            }, 0, 0);
            var formOptions = FormOptions.FromObject(Settings);

            formOptions.LabelColumnPercentage = .7f;
            var settingsForm = stack.Add(new Form(formOptions)
            {
                Height = 10
            }).FillHorizontally();

            Settings.SuppressEqualChanges = true;
            Settings.SubscribeForLifetime(AnyProperty, () =>
            {
                settingsHasChanged = true;
            }, this);

            ConsoleApp.Current.SetTimeout(() =>
            {
                foreach (var control in settingsForm.Descendents)
                {
                    control.Unfocused.SubscribeForLifetime(() =>
                    {
                        if (settingsHasChanged)
                        {
                            RefreshChart();
                            settingsHasChanged = false;
                        }
                    }, this);
                }
            }, TimeSpan.FromSeconds(1));
        }
Exemplo n.º 11
0
 public FileUploadHandler(
     ILogger <FileUploadHandler> logger
     )
 {
     _logger      = logger;
     _formOptions = new FormOptions();
 }
        /// <summary>
        /// Read the request body as a form with the given options. These options will only be used
        /// if the form has not already been read.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="options">Options for reading the form.</param>
        /// <param name="cancellationToken"></param>
        /// <returns>The parsed form.</returns>
        public static Task<IFormCollection> ReadFormAsync(this HttpRequest request, FormOptions options,
            CancellationToken cancellationToken = new CancellationToken())
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (!request.HasFormContentType)
            {
                throw new InvalidOperationException("Incorrect Content-Type: " + request.ContentType);
            }

            var features = request.HttpContext.Features;
            var formFeature = features.Get<IFormFeature>();
            if (formFeature == null || formFeature.Form == null)
            {
                // We haven't read the form yet, replace the reader with one using our own options.
                features.Set<IFormFeature>(new FormFeature(request, options));
            }
            return request.ReadFormAsync(cancellationToken);
        }
Exemplo n.º 13
0
        private void button2_Click(object sender, EventArgs e)
        {
            FormOptions formoptions = new FormOptions();

            switch (formoptions.ShowDialog())
            {
            case DialogResult.Retry:
                AddDebugInfo(DEBUG_TYPE.warning, "restoring default XML");
                for (int i = 0; i < iSheeps; i++)
                {
                    sheeps[i].Close();
                    sheeps[i].Dispose();
                }
                iSheeps    = 0;
                xml        = new Xml();
                animations = new Animations(xml);

                DesktopPet.Properties.Settings.Default.xml    = "";
                DesktopPet.Properties.Settings.Default.Home   = "";
                DesktopPet.Properties.Settings.Default.Icon   = "";
                DesktopPet.Properties.Settings.Default.Images = "";
                DesktopPet.Properties.Settings.Default.Save();

                xml.readXML();

                timer1.Tag     = "A";
                timer1.Enabled = true;
                break;
            }
        }
Exemplo n.º 14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 /// <param name="environment"></param>
 /// <param name="formOptions"></param>
 public ArtifactController(APIDatabaseContext context, IHostingEnvironment environment, IOptions <FormOptions> formOptions)
 {
     _defaultFormOptions = formOptions.Value;
     _context            = context;
     _environment        = environment;
     _storagePath        = Path.Combine(_environment.ContentRootPath, "storage", "artifacts");
 }
Exemplo n.º 15
0
 public GridForm(string json)
 {
     Options = FormOptions.FromJson(json);
     InitializeComponent();
     itemlist = FillFormItem();
     this.Controls.Add(InitOptions(Options.Groups, true));
 }
Exemplo n.º 16
0
 public FileUploadMaxSizeAttribute(long maxSize)
 {
     _formOptions = new FormOptions()
     {
         MultipartBodyLengthLimit = maxSize
     };
 }
Exemplo n.º 17
0
 private void InitializeProperties()
 {
     if (FormOptions == null)
     {
         FormOptions = new FormOptions();
     }
     AutoFocus = false;
 }
Exemplo n.º 18
0
 private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // MessageBox.Show("You have the option to ignore this until it is flushed out more...");
     using (FormOptions form = new FormOptions())
     {
         form.ShowDialog();
     }
 }
 public RequestFormSizeLimitAttribute(int valueCountLimit)
 {
     _formOptions = new FormOptions()
     {
         ValueCountLimit          = valueCountLimit,
         MultipartBodyLengthLimit = 5000000
     };
 }
 public RequestFormSizeLimitAttribute()
 {
     _formOptions = new FormOptions()
     {
         ValueLengthLimit         = int.MaxValue,
         MultipartBodyLengthLimit = int.MaxValue
     };
 }
Exemplo n.º 21
0
            public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
            {
                var httpContext        = _httpContextAccessor.HttpContext;
                var defaultFormOptions = new FormOptions();
                var digitalAssets      = new List <DigitalAsset>();

                if (!MultipartRequestHelper.IsMultipartContentType(httpContext.Request.ContentType))
                {
                    throw new Exception($"Expected a multipart request, but got {httpContext.Request.ContentType}");
                }

                var mediaTypeHeaderValue = MediaTypeHeaderValue.Parse(httpContext.Request.ContentType);

                var boundary = MultipartRequestHelper.GetBoundary(
                    mediaTypeHeaderValue,
                    defaultFormOptions.MultipartBoundaryLengthLimit);

                var reader = new MultipartReader(boundary, httpContext.Request.Body);

                var section = await reader.ReadNextSectionAsync();

                while (section != null)
                {
                    DigitalAsset digitalAsset = default;

                    var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out ContentDispositionHeaderValue contentDisposition);

                    if (hasContentDispositionHeader)
                    {
                        if (MultipartRequestHelper.HasFileContentDisposition(contentDisposition))
                        {
                            using (var targetStream = new MemoryStream())
                            {
                                await section.Body.CopyToAsync(targetStream);

                                var name        = $"{contentDisposition.FileName}".Trim(new char[] { '"' }).Replace("&", "and");
                                var bytes       = StreamHelper.ReadToEnd(targetStream);
                                var contentType = section.ContentType;

                                digitalAsset = new DigitalAsset(name, bytes, contentType);
                            }
                        }
                    }

                    _context.DigitalAssets.Add(digitalAsset);

                    digitalAssets.Add(digitalAsset);

                    section = await reader.ReadNextSectionAsync();
                }

                await _context.SaveChangesAsync(cancellationToken);

                return(new()
                {
                    DigitalAssetIds = digitalAssets.Select(x => x.DigitalAssetId).ToList()
                });
            }
Exemplo n.º 22
0
 public RequestFormSizeLimitAttribute()
 {
     _formOptions = new FormOptions()
     {
         MultipartBodyLengthLimit = 4294967296,
         ValueLengthLimit         = 2000000000,
         KeyLengthLimit           = 2000000000
     };
 }
Exemplo n.º 23
0
 public RequestSizeLimitAttribute(int valueCountLimit)
 {
     _formOptions = new FormOptions()
     {
         KeyLengthLimit   = valueCountLimit,
         ValueCountLimit  = valueCountLimit,
         ValueLengthLimit = valueCountLimit
     };
 }
        public async Task <MultipartReader> GetMultipartReader(HttpRequest request)
        {
            FormOptions _defaultFormOptions = new FormOptions();
            var         boundary            = await Task.Run(() => MultipartRequest.GetBoundary(MediaTypeHeaderValue.Parse(request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit));

            var reader = new MultipartReader(boundary, request.Body);

            return(reader);
        }
Exemplo n.º 25
0
 public MediaService(IOptions <WebOptions> options,
                     IOptions <FormOptions> formOptions, ILogger <MediaService> logger,
                     IConnectionMultiplexer connection)
 {
     _options     = options.Value;
     _formOptions = formOptions.Value;
     _logger      = logger;
     _connection  = connection;
 }
Exemplo n.º 26
0
        protected async Task <UploadModel> Upload()
        {
            var formOptions = new FormOptions();
            var result      = new UploadModel();

            result.Boundary = MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType), formOptions.MultipartBoundaryLengthLimit);
            var reader  = new MultipartReader(result.Boundary, HttpContext.Request.Body);
            var section = (MultipartSection)null;

            while ((section = await reader.ReadNextSectionAsync()) != null)
            {
                if (ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition))
                {
                    if (MultipartRequestHelper.HasFile(contentDisposition))
                    {
                        result.FileName = contentDisposition.FileName.ToString();
                        result.Stream   = section.Body;
                        return(result);
                    }
                    else if (MultipartRequestHelper.HasModel(contentDisposition))
                    {
                        using (var factory = new DBItemConverterFactory(HttpContext))
                        {
                            var option = new JsonSerializerOptions();
                            option.InitDefaults(factory);
                            result.Model = await JsonSerializer.DeserializeAsync <T>(section.Body, option);
                        }
                    }
                    else if (MultipartRequestHelper.HasFormData(contentDisposition))
                    {
                        var key      = HeaderUtilities.RemoveQuotes(contentDisposition.Name);
                        var encoding = MultipartRequestHelper.GetEncoding(section);
                        using (var streamReader = new StreamReader(section.Body, encoding, detectEncodingFromByteOrderMarks: true, bufferSize: 2048, leaveOpen: true))
                        {
                            // The value length limit is enforced by MultipartBodyLengthLimit
                            var value = await streamReader.ReadToEndAsync();

                            if (String.Equals(value, "undefined", StringComparison.OrdinalIgnoreCase))
                            {
                                value = String.Empty;
                            }
                            if (StringSegment.Equals(key, "LastWriteTime", StringComparison.OrdinalIgnoreCase) &&
                                DateTime.TryParseExact(value, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var lastWriteTime))
                            {
                                result.ModificationDate = lastWriteTime;
                            }
                            else
                            {
                                result.Content[key.ToString()] = value;
                            }
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 27
0
 public RequestSizeLimitAttribute(int valueCountLimit)
 {
     _formOptions = new FormOptions()
     {
         // tip: you can use different arguments to set each properties instead of single argument
         KeyLengthLimit   = valueCountLimit,
         ValueCountLimit  = valueCountLimit,
         ValueLengthLimit = valueCountLimit
     };
 }
Exemplo n.º 28
0
        public HttpContextFactory(IOptions <FormOptions> formOptions, IHttpContextAccessor httpContextAccessor)
        {
            if (formOptions == null)
            {
                throw new ArgumentNullException(nameof(formOptions));
            }

            _formOptions         = formOptions.Value;
            _httpContextAccessor = httpContextAccessor;
        }
Exemplo n.º 29
0
        private void  择操作项ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //新创建选择操作选项窗体
            FormOptions formOptions = new FormOptions();

            //将当前主窗体中MapControl控件中的Map对象赋值给FormOptions窗体的CurrentMap属性
            formOptions.CurrentSelectionEnvironment = selectionEnvironment;
            //显示选择操作选项窗体
            formOptions.Show();
        }
Exemplo n.º 30
0
 public DefaultRouteValuesBuilder(IOptions <OrleansHttpGatewayOptions> options
                                  , IOptions <OrleansRequesterConfiguration> config
                                  , IOptions <FormOptions> formOptions
                                  , IOcelotLoggerFactory factory)
 {
     this._config  = config?.Value;
     this._options = options.Value;
     _formOptions  = formOptions.Value;
     this._logger  = factory.CreateLogger <DefaultRouteValuesBuilder>();
 }
Exemplo n.º 31
0
 /// <summary>
 /// Size Limit on Request
 /// </summary>
 /// <param name="keyLengthLimit"></param>
 /// <param name="valueCountLimit"></param>
 /// <param name="valueLengthLimit"></param>
 public RequestSizeLimitAttribute(int keyLengthLimit = 1024 *16, int valueCountLimit = 1024, int valueLengthLimit = 1024)
 {
     _formOptions = new FormOptions()
     {
         KeyLengthLimit   = keyLengthLimit,
         ValueCountLimit  = valueCountLimit,
         ValueLengthLimit = valueLengthLimit
                            // MultipartBodyLengthLimit = valueCountLimit
     };
 }
Exemplo n.º 32
0
        public FormFeature(HttpRequest request, FormOptions options)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _request = request;
            _options = options;
        }
        public HttpContextFactory(ObjectPoolProvider poolProvider, IOptions<FormOptions> formOptions, IHttpContextAccessor httpContextAccessor)
        {
            if (poolProvider == null)
            {
                throw new ArgumentNullException(nameof(poolProvider));
            }
            if (formOptions == null)
            {
                throw new ArgumentNullException(nameof(formOptions));
            }

            _builderPool = poolProvider.CreateStringBuilderPool();
            _formOptions = formOptions.Value;
            _httpContextAccessor = httpContextAccessor;
        }
Exemplo n.º 34
0
        private void UpdateActiveForm(FormOptions parts)
        {
            Tools.Forms.tradeAnalysis activeForm = GetActiveStockForm();
            if (activeForm == null) return;

            if ((parts & FormOptions.VolumePane) != 0) 
                activeForm.ChartVolumeVisibility = true;

            if ((parts & FormOptions.ChartType) != 0) 
                activeForm.ChartPriceType = this.ChartType;

            if ((parts & FormOptions.HaveGrid) != 0) 
                activeForm.ChartHaveGrid = this.ChartHaveGrid;

            if ((parts & FormOptions.TimeScale) != 0)
            {
                activeForm.ChartTimeScale = this.ChartTimeScale;
                activeForm.ReloadChart();
            }
        }
Exemplo n.º 35
0
 private void btnNoAll_Click(object sender, EventArgs e)
 {
     m_UserFormOptions = FormOptions.NoAll;
     this.Close();
 }
Exemplo n.º 36
0
 private void btnYes_Click(object sender, EventArgs e)
 {
     m_UserFormOptions = FormOptions.Yes;
     this.Close();
 }
Exemplo n.º 37
0
 private void HasTransectForm_Load(object sender, EventArgs e)
 {
     m_UserFormOptions = FormOptions.None;
 }