AnsweredAssumed Answered

EventFrame Attributes performance

Question asked by AlistairFrith on Mar 9, 2015
Latest reply on Mar 9, 2015 by Dan Fishman

We are developing an application that uses event frames and we are having performance issues when reading these event frames. Here's the costly code to convert an EventFrame into what we call a ValidationException:

 

   
        /// <summary>
        /// Convert an AF Event Frame into a Validation Exception
        /// </summary>
        /// <param name="frame"></param>
        /// <returns>The request Validation Exception or null the passed in EventFrame is null</returns>
        // Temporarily changed from private to public for unit tests
        // Changed from static to non-static
        public ValidationException ValidationExceptionFromEventFrame(AFEventFrame frame)
        {
            if (frame == null)
            {
                return null;
            }
            ValidationException validationException = new ValidationException();
            validationException.ID = frame.ID;
            validationException.TemplateName = frame.Template.Name;
            validationException.Start = frame.StartTime;
            validationException.End = frame.EndTime;
            //anomaly.CategoriesString = frame.CategoriesString;

            // Get the attributes (doing them individually is slower, apparantly)
            AFAttributeList attributes = new AFAttributeList(frame.Attributes);
            AFValues values = attributes.GetValue();
            int iTrigger = 0;
            int iStatus = 1;
            int iAction = 2;
            int iComment = 3;
            int iType = 4;

            // Get the exception type. We default to 'Unspecified' if the event does not
            // have the appropriate attribute or the attribute value can't be parsed
            ValidationExceptionType exceptionType = ValidationExceptionType.Unspecified;
            AFValue type = values[iType];
            if (type != null && type.Value != null)
            {
                Enum.TryParse(type.Value.ToString(), out exceptionType);
            }
            validationException.ExceptionType = exceptionType;

            // Get the exception status. We default to 'Open' if the event does not
            // have the appropriate attribute or the attribute value can't be parsed
            ValidationExceptionStatus exceptionStatus = ValidationExceptionStatus.Open;
            AFValue status = values[iStatus];
            if (status != null && status.Value != null)
            {
                Enum.TryParse(status.Value.ToString(), out exceptionStatus);
            }
            validationException.Status = exceptionStatus;

            // Get the exception comment
            AFValue comment = values[iComment];
            validationException.Comment = (comment != null && comment.Value != null) ? comment.Value.ToString() : UndefString;
            // Get the element causing the exception
            if (frame.PrimaryReferencedElement == null)
            {
                validationException.ElementPath = UndefString;
            }
            else
            {
                validationException.ElementID = frame.PrimaryReferencedElement.ID;
                validationException.ElementPath = frame.PrimaryReferencedElement.GetPath();
            }

            // Get the attribute causing the exception (first its path, then the attribute itself)
            validationException.AttributePath = UndefString;
            validationException.AttributeID = new Guid();
            AFAttribute trigger = attributes["TriggeringInputPath"];
            if (trigger != null)
            {
                AFValue triggerPath = values[iTrigger];
                validationException.AttributePath = (triggerPath != null && triggerPath.ToString() != "") ? validationException.ElementPath + "|" + triggerPath.ToString() : UndefString;
                if (frame.PrimaryReferencedElement != null) // if the referenced element is null, the path string will be invalid
                {
                    if (validationException.AttributePath != UndefString)
                    {
                        IList<AFAttribute> triggerAttributes = AFAttribute.FindAttributes(validationException.AttributePath, null);
                        if (triggerAttributes != null && triggerAttributes.Count() > 0)
                        {
                            validationException.AttributeID = triggerAttributes[0].ID;
                        }
                    }
                }
            }
            return validationException;
        }







 

 

This function takes several seconds to convert a single event frame and about 2 minutes to convert 350 of them. We were expecting to be able to load several hundred per second from AF. Is there a better way of doing this?

 

Message was edited by: Alistair Frith Re-pasted the code after I realised I was not actually bulk-loading the values! New code performs just as badly though.

 

Message was edited by: Alistair Frith - Re-pasted again since the formatting seems way screwy!

Outcomes