Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "guillaumemorin"

Many thanks for the ideas.

I would like to add a "bool NeedsConfirmation" on my output DTO, but how can I undo the current UOW and still return a DTO ?

The only way I know is to throw and Exception, but then my DTO is not returned, it is the ABP builtin Exception filter that serialise the response.

Bump

We had to create a ApiController that receive the file and store it into a database table FileUpload. Then the newly created record id is returned to client. We plan to change this architecture so the file is stored somewhere else than the database, like Azure Storage.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using Abp.Utils.Extensions;
using Nito.AsyncEx.Synchronous;
using PMP.FileUpload.Command.Remove;
using PMP.FileUpload.Command.Upload;

namespace PMP.Web.Controllers
{
    public class FileUploadController : ApiController
    {
        private readonly IUploadService _uploadService;
        
        public FileUploadController(
            IUploadService uploadService)
        {
            _uploadService = uploadService;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns>Return the list of fileId uploaded</returns>
        [HttpPost]
        public async Task<List<int>> Upload()
        {
            var output = new List<int>();
            
            // Check if the request contains multipart/form-data. 
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var streamContent = GetStreamContent();
            var streamProvider = await streamContent.ReadAsMultipartAsync();

            foreach (var item in streamProvider.Contents)
            {
                if (item.Headers.ContentDisposition.Name.Contains("file"))
                {
                    var fileName = item.Headers.ContentDisposition.FileName.Replace("\"", string.Empty);
                    var bytes = item.ReadAsByteArrayAsync().WaitAndUnwrapException();

                    // With IE, filename is a fullpath, so we take just the filename
                    fileName = Path.GetFileName(fileName);

                    var uploadOutput = _uploadService.Execute(new UploadInput()
                    {
                        FileBytes = bytes,
                        FileName = fileName
                    });

                    output.Add(uploadOutput.FileId);
                }
            }

            return output;
        }

        /// <summary>
        /// ReadAsMultipartAsync() throws an exception if we do not do this. It adds a \r\n at the end of the stream.
        /// See http://stackoverflow.com/a/27050229
        /// </summary>
        /// <returns>StreamContent</returns>
        private StreamContent GetStreamContent()
        {
            Stream reqStream = Request.Content.ReadAsStreamAsync().WaitAndUnwrapException();
            MemoryStream tempStream = new MemoryStream();
            reqStream.CopyTo(tempStream);

            tempStream.Seek(0, SeekOrigin.End);
            StreamWriter writer = new StreamWriter(tempStream);
            writer.WriteLine();
            writer.Flush();
            tempStream.Position = 0;


            StreamContent streamContent = new StreamContent(tempStream);
            foreach (var header in Request.Content.Headers)
            {
                streamContent.Headers.Add(header.Key, header.Value);
            }
            return streamContent;
        }

        
    }

    
}

Can you put your Logs.txt into your App_Data folder, then you can check 'Exclude files from the App_Data folder' option on publish.

The more third party libraries you have referenced, the more slow it gets. We had this extact problem and we did this quick hack in the class WebAssemblyFinder. It reads only Abp .dlls and our own .dlls which all starts by 'PMP' in our case. So if you can find a similar pattern to read only your app .dlls, you should gain a lot of speed.

// Filters out non-applicative dll to improve startup performance
dllFiles = dllFiles.Where(x => Path.GetFileName(x).StartsWith("Abp", StringComparison.OrdinalIgnoreCase) || Path.GetFileName(x).StartsWith("PMP", StringComparison.OrdinalIgnoreCase)).ToList();

Hi all,

I have an ApplicationService action that may raise a warning based on some conditions, which must abort and undo the current UOW, then return a warning to the user. The user then confirm the warning and re-submit the same request (with a flag confirmed:true so the warning isn't raised again).

The simplest way is to throw an UserFriendlyException, but then on the client I need to distinguish Error and Warning. My first idea is to extend the ABP framework with a UserFriendlyWarningException that I could throw and I could serialized it in a different way than the UserFriendlyException.

But before going through this, I was wondering how do you guys would handle this and if there is something already built-in for warning/confirmation like that.

Thanks !

Look at entity framework Index attribute.

public class VersaoDado : FullAuditedEntity
    {
        [Index("IX_GenericoId_VersaoId", 1, IsUnique = true)]
        public virtual Guid GenericoId { get; set; }

        [Index("IX_GenericoId_VersaoId", 2, IsUnique = true)]
        [ForeignKey("VersaoId")]
        public virtual int VersaoId { get; set; }
        public virtual Versao Versoes { get; set; }

    }

+1.

I would like ABP Permissions to be applicable at an "Entity" level. Each different Entity level should have its own set of PermissionProvider, different from the System wide Provider (Maybe we can use the existing Parent/Child capability for that instead).

In my case I need to grant Permissions for WorkCenters. So a Permission is granted for a RoleID and a WorkCenterID. There is also a need to grant Permissions for Queues. So a Permission is granted for a RoleID and a QueueID.

In this example, I could have 3 'root' Permissions:

  • System
  • WorkCenter
  • Queue And they would contains child permission that would define the list of available permissions for each 'level'.
Answer

I'm also interested if you can share this code.

Question

I see very slow startup time with my ABP based app. This is caused mainly by TypeFinder.cs.

Please see my comment on this issue: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/pull/524">https://github.com/aspnetboilerplate/as ... e/pull/524</a>

Thanks.

Showing 1 to 10 of 18 entries