public TagToGoalRecordPagesPerVisit(IReadOnlyDictionary <string, int> columnMetadata, IList <object> row)
            : base(columnMetadata, row)
        {
            GoalType = GoalType.PagesPerVisit;

            if (_numberOfPagesOrdinal == -1)
            {
                _numberOfPagesOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "PageVisitGoal");
            }

            if (_comparisonOperatorOrdinal == -1)
            {
                _comparisonOperatorOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "PageVisitOperator");
            }

            var numberOfPages     = (short)row[_numberOfPagesOrdinal];
            var valueOperatorByte = (byte)row[_comparisonOperatorOrdinal];

            if (!GoalUtils.IsValidValueOperator(valueOperatorByte))
            {
                throw new Exception(String.Format("NumberOfPages comparison operator value {0} is outside of range.", valueOperatorByte));
            }

            var valueComparisonOperator = (ValueComparisonOperator)valueOperatorByte;

            if (!GoalUtils.IsValidNumericOperator(valueComparisonOperator))
            {
                throw new Exception(String.Format("Value operator value {0} is not supported by {1} goal type.", valueComparisonOperator.ToString(), GoalType));
            }

            NumberOfPagesProperty = new GoalProperty <short>
            {
                ValueComparisionOperator = valueComparisonOperator,
                PropertyValue            = numberOfPages
            };
        }
Example #2
0
        public TagToGoalRecordCustomEvent(Dictionary <string, int> columnMetadata, object[] row)
            : base(columnMetadata, row)
        {
            GoalType = GoalType.CustomEvent;

            if (_eventCategoryOrdinal == -1)
            {
                _eventCategoryOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventCategory");
            }

            if (_categoryComparisonOperatorOrdinal == -1)
            {
                _categoryComparisonOperatorOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventCategoryOperator");
            }

            if (_eventNameOrdinal == -1)
            {
                _eventNameOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventName");
            }

            if (_nameComparisonOperatorOrdinal == -1)
            {
                _nameComparisonOperatorOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventNameOperator");
            }

            if (_eventLabelOrdinal == -1)
            {
                _eventLabelOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventLabel");
            }

            if (_labelComparisonOperatorOrdinal == -1)
            {
                _labelComparisonOperatorOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventLabelOperator");
            }

            if (_eventValueOrdinal == -1)
            {
                _eventValueOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventValue");
            }

            if (_valueComparisonOperatorOrdinal == -1)
            {
                _valueComparisonOperatorOrdinal = MapFileUtils.GetColumnOrdinal(columnMetadata, "EventValueOperator");
            }

            var eventCategory = (string)row[_eventCategoryOrdinal];
            var categoryComparisonOperatorByte = (byte?)row[_categoryComparisonOperatorOrdinal];

            EventCategoryProperty = CreateCustomEventGoalProperty("Category", eventCategory, categoryComparisonOperatorByte);

            var eventName = (string)row[_eventNameOrdinal];
            var nameComparisonOperatorByte = (byte?)row[_nameComparisonOperatorOrdinal];

            EventActionProperty = CreateCustomEventGoalProperty("Name", eventName, nameComparisonOperatorByte);

            var eventLabel = (string)row[_eventLabelOrdinal];
            var labelComparisonOperatorByte = (byte?)row[_labelComparisonOperatorOrdinal];

            EventLabelProperty = CreateCustomEventGoalProperty("Label", eventLabel, labelComparisonOperatorByte);

            var eventValue = (double?)row[_eventValueOrdinal];
            var valueComparisonOperatorByte = (byte?)row[_valueComparisonOperatorOrdinal];

            if (eventValue != null)
            {
                if (valueComparisonOperatorByte == null)
                {
                    throw new Exception("ValueComparisonOperator value cannot be null when EventValue value is not null.");
                }

                if (!GoalUtils.IsValidValueOperator((byte)valueComparisonOperatorByte))
                {
                    throw new Exception(String.Format("ValueComparisonOperator value {0} is outside of range.", valueComparisonOperatorByte));
                }

                var valueOperator = (ValueComparisonOperator)valueComparisonOperatorByte;

                if (!GoalUtils.IsValidNumericOperator(valueOperator))
                {
                    throw new Exception(String.Format("ValueOperator value {0} is not supported by {1} goal type.", valueOperator.ToString(), GoalType));
                }

                EventValueProperty = new GoalProperty <double>
                {
                    ValueComparisionOperator = valueOperator,
                    PropertyValue            = (double)eventValue
                };
            }
        }