/// <summary>
        /// Creates <see cref="LogAccessRule"/> from this attribute
        /// </summary>
        /// <param name="memberInfo">
        /// The member Info.
        /// </param>
        /// <returns>
        /// The <see cref="LogAccessRule"/>
        /// </returns>
        public LogAccessRule CreateRule(MemberInfo memberInfo)
        {
            var logMessage = this.LogMessage;

            if (this.LogMessage == null)
            {
                logMessage = $"The property {memberInfo.Name} of {NamingUtilities.ToCSharpRepresentation(memberInfo.DeclaringType)} with id {{id}} was accessed";
            }

            return(new LogAccessRule
            {
                Type = this.Type,
                ConnectionActions = this.ConnectionActions,
                Severity = this.Severity,
                LogMessage = logMessage
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Process collection requests
        /// </summary>
        /// <typeparam name="TObject">
        /// The type of ef object
        /// </typeparam>
        /// <typeparam name="TId">
        /// The type of object identity field
        /// </typeparam>
        /// <param name="collectionRequest">Collection request</param>
        /// <returns>The list of objects</returns>
        protected virtual async Task OnCollectionRequest <TObject, TId>(CollectionRequest <TObject> collectionRequest)
            where TObject : class
        {
            try
            {
                using (var ds = this.GetContext())
                {
                    int maxLimit;
                    if (!this.classQueryLimits.TryGetValue(
                            NamingUtilities.ToCSharpRepresentation(typeof(TObject)),
                            out maxLimit))
                    {
                        maxLimit = this.defaultQueryLimit;
                    }

                    var limit = maxLimit != 0 && (!collectionRequest.Count.HasValue ||
                                                  collectionRequest.Count.Value > maxLimit)
                                    ? maxLimit
                                    : collectionRequest.Count;

                    var factory = DataFactory <TContext, TObject, TId> .CreateFactory(this.ComponentContext, ds);

                    var response = await factory.GetList(
                        collectionRequest.Filter,
                        collectionRequest.Sort,
                        collectionRequest.Skip,
                        limit,
                        collectionRequest.ApiRequest);

                    if (collectionRequest.AcceptAsParcel)
                    {
                        Context.GetParcelManager().Tell(
                            new Parcel {
                            Payload = response, Recipient = this.Sender
                        },
                            this.Self);
                    }
                    else
                    {
                        this.Sender.Tell(response);
                    }
                }
            }
            catch (Exception exception)
            {
                try
                {
                    Context.GetLogger().Error(
                        exception,
                        "{Type}: Exception on processing CollectionRequest\n\t filter: {FilterExpression}\n\t sort: {SortExpression}\n\t limit: {Limit}\n\t offset: {Offset}",
                        $"BaseCrudActor<{typeof(TObject).Name}>",
                        collectionRequest.Filter?.ToString(),
                        collectionRequest.Sort?.ToString(),
                        collectionRequest.Count,
                        collectionRequest.Skip);
                }
                catch
                {
                    Context.GetLogger().Error(
                        exception,
                        "{Type}: Exception on processing CollectionRequest",
                        $"BaseCrudActor<{typeof(TObject).Name}>");
                }

                var response = new CollectionResponse <TObject> {
                    Items = new List <TObject>()
                };
                if (collectionRequest.AcceptAsParcel)
                {
                    Context.GetParcelManager().Tell(
                        new Parcel {
                        Payload = response, Recipient = this.Sender
                    },
                        this.Self);
                }
                else
                {
                    this.Sender.Tell(response);
                }
            }
        }