Exemplo n.º 1
0
        public async Task<FileUploadResult> Upload()
        {
            try
            {
                var uploadPath = IOHelper.GetUploadFileName();

                var multipartFormDataStreamProvider = new MultipartUploadHelper(uploadPath);

                // Read the MIME multipart asynchronously 
                await Request.Content.ReadAsMultipartAsync(multipartFormDataStreamProvider);

                var id = HttpContext.Current.Request.Headers.Get(_configurationIdHeader);
                var clientId = HttpContext.Current.Request.Headers.Get(_clientIdHeader);

                var fileName = Path.GetFileName(uploadPath);
                Guid configurationId;

                if (!Guid.TryParse(id, out configurationId))
                {
                    configurationId = new Guid();
                }

                var actualFileName = "";
                if (multipartFormDataStreamProvider.Contents?.Count > 0)
                {
                    actualFileName = multipartFormDataStreamProvider.Contents[0].Headers?.ContentDisposition?.FileName;
                }

                return ExecuteRules(fileName, configurationId, clientId, actualFileName);
            }
            catch (PledgeRunException error)
            {
                //TODO: Remove inner exception before production release!!
                throw new Exception("Pledge application had an unexpected error.", error);
            }
            catch (PledgeConfigurationRuleException error)
            {
                //TODO: Remove inner exception before production release!!
                throw new Exception("The selected configuration has an invalid or incomplete rule definition.", error);
            }
            catch (PledgeColumnMismatchException error)
            {
                throw new Exception(error.Message);
            }
            catch (Exception error)
            {
                //TODO: Remove inner exception before production release!!
                throw new Exception("There is an unexpected error in processing your request. Please try again.", error);
            }
        }
Exemplo n.º 2
0
        public async Task<ExampleUploadResult> ExampleUpload()
        {
            var uploadPath = IOHelper.GetUploadFileName();

            var multipartFormDataStreamProvider = new MultipartUploadHelper(uploadPath);

            // Read the MIME multipart asynchronously 
            await Request.Content.ReadAsMultipartAsync(multipartFormDataStreamProvider);

            var headerLine = HttpContext.Current.Request.Headers.Get(_headerLine);
            var delimiter = HttpContext.Current.Request.Headers.Get(_delimiter);

            bool hasHeader;

            if (!bool.TryParse(headerLine, out hasHeader))
            {
                hasHeader = false;
            }

            return LoadFileSchemas(uploadPath, delimiter, hasHeader);
        }
        public async Task<bool> ImportConfiguration()
        {
            var importPath = IOHelper.GetUploadFileName();
            var multipartFormDataStreamProvider = new MultipartUploadHelper(importPath);

            // Read the MIME multipart asynchronously 
            await Request.Content.ReadAsMultipartAsync(multipartFormDataStreamProvider);

            var user = AuthenticationManager.User;

            try
            {
                var result = _pledgeManager.ImportConfiguration(importPath, user.Identity.Name);

                return result;
            }
            catch
            {
                return false;
            }
        }