/// <summary>
 /// Implementation of the TelemetryManifestActionOptOutBase.ExecuteOptOutAction method
 /// We need to include/exclude matched properties from/to event when user is OptedOut
 /// </summary>
 /// <param name="eventProcessorContext"></param>
 protected override void ExecuteOptOutAction(IEventProcessorContext eventProcessorContext)
 {
     foreach (string item in PropertiesImpl)
     {
         ProcessPropertyName(item, eventProcessorContext);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Execute action on event, using eventProcessorContext as a provider of the necessary information.
        /// Return true if it is allowed to execute next actions.
        /// Return false action forbids the event.
        ///
        /// Please note that although we are throttling, the reset actually occurs when the following event
        /// is processed. This means if we sent 1k events under a second, and do not do anything for 10 minutes
        /// and then send an event, the Reset will occur then. This was done to simplify code as this feature
        /// is primarily for events under development.
        /// </summary>
        /// <param name="eventProcessorContext"></param>
        /// <returns>Indicator, whether current action is not explicitely forbid current event</returns>
        public bool Execute(IEventProcessorContext eventProcessorContext)
        {
            CodeContract.RequiresArgumentNotNull <IEventProcessorContext>(eventProcessorContext, "eventProcessorContext");
            TelemetryEvent telemetryEvent = eventProcessorContext.TelemetryEvent;
            DateTimeOffset postTimestamp  = telemetryEvent.PostTimestamp;

            if (bucketStartTime == default(DateTimeOffset))
            {
                bucketStartTime = postTimestamp;
            }
            if (eventProcessorContext.ThrottlingAction == ThrottlingAction.DoNotThrottle || (eventProcessorContext.ThrottlingAction != ThrottlingAction.Throttle && passthroughEvents.Contains(telemetryEvent.Name)))
            {
                if (counter < threshold)
                {
                    counter++;
                }
                else if (whitelistCounter >= threshold)
                {
                    noisyWhiteListEvents.Add(telemetryEvent.Name);
                }
                whitelistCounter++;
                return(true);
            }
            if ((postTimestamp - bucketStartTime).TotalSeconds > resetCounter)
            {
                TelemetrySession hostTelemetrySession = eventProcessorContext.HostTelemetrySession;
                Reset(hostTelemetrySession, hostTelemetrySession.EventProcessor.CurrentManifest, postTimestamp);
            }
            if (counter++ >= threshold)
            {
                droppedEvents.Add(telemetryEvent.Name);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Execute action on event, using eventProcessorContext as a provider of the necessary information.
        /// Return true if it is allowed to execute next actions.
        /// Return false action forbids the event.
        /// </summary>
        /// <param name="eventProcessorContext"></param>
        /// <returns>Indicator, whether current action is not explicitely forbid current event</returns>
        public bool Execute(IEventProcessorContext eventProcessorContext)
        {
            CodeContract.RequiresArgumentNotNull <IEventProcessorContext>(eventProcessorContext, "eventProcessorContext");
            TelemetryEvent telemetryEvent = eventProcessorContext.TelemetryEvent;
            List <KeyValuePair <string, object> > list = new List <KeyValuePair <string, object> >();

            foreach (KeyValuePair <string, object> property in telemetryEvent.Properties)
            {
                if (property.Value != null && property.Value.GetType() == piiPropertyProcessor.TypeOfPiiProperty())
                {
                    list.Add(new KeyValuePair <string, object>(property.Key, piiPropertyProcessor.ConvertToHashedValue(property.Value)));
                    if (piiPropertyProcessor.CanAddRawValue(eventProcessorContext))
                    {
                        list.Add(new KeyValuePair <string, object>(piiPropertyProcessor.BuildRawPropertyName(property.Key), piiPropertyProcessor.ConvertToRawValue(property.Value)));
                    }
                    piiedProperties.Add(property.Key);
                    totalPiiProperties++;
                }
            }
            foreach (KeyValuePair <string, object> item in list)
            {
                telemetryEvent.Properties[item.Key] = item.Value;
            }
            return(true);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Event processor constructor should be provided with session.
 /// This required for start channels.
 /// </summary>
 /// <param name="session"></param>
 /// <param name="eventProcessorContext"></param>
 public EventProcessor(TelemetrySession session, IEventProcessorContext eventProcessorContext)
 {
     CodeContract.RequiresArgumentNotNull <TelemetrySession>(session, "session");
     CodeContract.RequiresArgumentNotNull <IEventProcessorContext>(eventProcessorContext, "eventProcessorContext");
     mainSession = session;
     this.eventProcessorContext = eventProcessorContext;
 }
 /// <summary>
 /// Default Execute method checks if session is OptedOut and call specific method
 /// </summary>
 /// <param name="eventProcessorContext"></param>
 /// <returns></returns>
 public bool Execute(IEventProcessorContext eventProcessorContext)
 {
     if (!eventProcessorContext.HostTelemetrySession.IsOptedIn)
     {
         ExecuteOptOutAction(eventProcessorContext);
     }
     return(true);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Validate coming event
        /// </summary>
        /// <param name="eventProcessorContext"></param>
        /// <returns></returns>
        public bool Execute(IEventProcessorContext eventProcessorContext)
        {
            TelemetryEvent telemetryEvent = eventProcessorContext.TelemetryEvent;

            if (TelemetryContext.IsEventNameContextPostProperty(telemetryEvent.Name))
            {
                return(telemetryEvent.Properties.Any((KeyValuePair <string, object> p) => !TelemetryEvent.IsPropertyNameReserved(p.Key) && !TelemetryContext.IsPropertyNameReserved(p.Key)));
            }
            return(true);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Execute action on event, using telemetryManifestContext as a provider of the necessary information.
 /// Return true if it is allowed to execute next actions.
 /// Return false if it is last action to execute.
 /// </summary>
 /// <param name="eventProcessorContext"></param>
 /// <returns>Indicator, whether is it allowed to the keep executing next actions</returns>
 public bool Execute(IEventProcessorContext eventProcessorContext)
 {
     if (excludeAll)
     {
         return(false);
     }
     CodeContract.RequiresArgumentNotNull <IEventProcessorContext>(eventProcessorContext, "eventProcessorContext");
     foreach (string excludeForChannel in ExcludeForChannels)
     {
         eventProcessorContext.Router.DisableChannel(excludeForChannel);
     }
     return(true);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Execute action on event, using eventProcessorContext as a provider of the necessary information.
        /// Return true if it is allowed to execute next actions.
        /// Return false if it is last action to execute.
        /// </summary>
        /// <param name="eventProcessorContext"></param>
        /// <returns>Indicator, whether is it allowed to the keep executing next actions</returns>
        public bool Execute(IEventProcessorContext eventProcessorContext)
        {
            CodeContract.RequiresArgumentNotNull <IEventProcessorContext>(eventProcessorContext, "eventProcessorContext");
            TelemetryEvent telemetryEvent = eventProcessorContext.TelemetryEvent;

            foreach (string property in Properties)
            {
                if (telemetryEvent.Properties.TryGetValue(property, out object value) && !(value is TelemetryPiiProperty))
                {
                    telemetryEvent.Properties[property] = new TelemetryPiiProperty(value);
                }
            }
            return(true);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Execute action on event, using telemetryManifestContext as a provider of the necessary information.
 /// Return true if it is allowed to execute next actions.
 /// Return false action forbids the event.
 /// By default OptOut set IsEventDropped to the true, and exclude all properties.
 /// </summary>
 /// <param name="eventProcessorContext"></param>
 /// <returns>Indicator, whether current action is not explicitely forbid current event</returns>
 public bool Execute(IEventProcessorContext eventProcessorContext)
 {
     if (!eventProcessorContext.HostTelemetrySession.IsOptedIn)
     {
         TelemetryEvent telemetryEvent = eventProcessorContext.TelemetryEvent;
         if (!telemetryEvent.IsOptOutFriendly && !optoutFriendlyEvents.Contains(telemetryEvent.Name))
         {
             eventProcessorContext.IsEventDropped = true;
         }
         foreach (string item in new List <string>(telemetryEvent.Properties.Keys))
         {
             if ((!telemetryEvent.IsOptOutFriendly || TelemetryEvent.IsPropertyNameReserved(item) || TelemetryContext.IsPropertyNameReserved(item)) && !optoutFriendlyProperties.Contains(item))
             {
                 eventProcessorContext.ExcludePropertyFromEvent(item);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Execute action on event, using eventProcessorContext as a provider of the necessary information.
        /// This action add a suffix DataModelSetting to all Setting property names in the event.
        /// </summary>
        /// <param name="eventProcessorContext"></param>
        /// <returns>
        /// Indicator, whether current action is not explicitely forbid current event.
        /// Return true if it is allowed to execute next actions.
        /// Return false action forbids the event.
        /// </returns>
        public bool Execute(IEventProcessorContext eventProcessorContext)
        {
            CodeContract.RequiresArgumentNotNull <IEventProcessorContext>(eventProcessorContext, "eventProcessorContext");
            TelemetryEvent telemetryEvent = eventProcessorContext.TelemetryEvent;

            KeyValuePair <string, T>[] array = (from prop in telemetryEvent.Properties
                                                where prop.Value is T
                                                select new KeyValuePair <string, T>(prop.Key, prop.Value as T)).ToArray();
            totalPropertyCount += array.Length;
            if (array.Any())
            {
                telemetryEvent.Properties[flagPropertyName] = true;
            }
            KeyValuePair <string, T>[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                KeyValuePair <string, T> keyValuePair = array2[i];
                telemetryEvent.Properties[keyValuePair.Key + SuffixName] = keyValuePair.Value.Value;
                telemetryEvent.Properties.Remove(keyValuePair.Key);
                properties.Add(keyValuePair.Key);
            }
            return(true);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Each deriver should implement this specific OptOut action
 /// </summary>
 /// <param name="eventProcessorContext"></param>
 protected abstract void ExecuteThrottlingAction(IEventProcessorContext eventProcessorContext);
Ejemplo n.º 12
0
 /// <summary>
 /// Default Execute method checks if session is OptedOut and call specific method
 /// </summary>
 /// <param name="eventProcessorContext"></param>
 /// <returns></returns>
 public bool Execute(IEventProcessorContext eventProcessorContext)
 {
     ExecuteThrottlingAction(eventProcessorContext);
     return(true);
 }
 /// <summary>
 /// Implementation of the ProcessPropertyName
 /// </summary>
 /// <param name="propertyName"></param>
 /// <param name="eventProcessorContext"></param>
 protected override void ProcessPropertyName(string propertyName, IEventProcessorContext eventProcessorContext)
 {
     eventProcessorContext.ExcludePropertyFromEvent(propertyName);
 }
 protected override void ExecuteThrottlingAction(IEventProcessorContext eventProcessorContext)
 {
     eventProcessorContext.ThrottlingAction = ThrottlingAction.Throttle;
 }
 protected abstract void ProcessPropertyName(string propertyName, IEventProcessorContext eventProcessorContext);
 /// <summary>
 /// Execute action on event, using telemetryManifestContext as a provider of the necessary information.
 /// Return true if it is allowed to execute next actions.
 /// Return false action forbids the event.
 /// </summary>
 /// <param name="eventProcessorContext"></param>
 /// <returns>Indicator, whether current action is not explicitely forbid current event</returns>
 public bool Execute(IEventProcessorContext eventProcessorContext)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Each deriver should implement this specific OptOut action
 /// </summary>
 /// <param name="eventProcessorContext"></param>
 protected abstract void ExecuteOptOutAction(IEventProcessorContext eventProcessorContext);
Ejemplo n.º 18
0
        /// <summary>
        /// Execute action on event, using eventProcessorContext as a provider of the necessary information.
        /// Return true if it is allowed to execute next actions.
        /// Return false action forbids the event.
        /// </summary>
        /// <param name="eventProcessorContext"></param>
        /// <returns>Indicator, whether current action is not explicitely forbid current event</returns>
        public bool Execute(IEventProcessorContext eventProcessorContext)
        {
            CodeContract.RequiresArgumentNotNull <IEventProcessorContext>(eventProcessorContext, "eventProcessorContext");
            EnsureSerializerIsInitialized();
            TelemetryEvent telemetryEvent = eventProcessorContext.TelemetryEvent;
            List <KeyValuePair <string, string> > list       = new List <KeyValuePair <string, string> >();
            Dictionary <string, string>           dictionary = new Dictionary <string, string>();

            foreach (KeyValuePair <string, object> property in telemetryEvent.Properties)
            {
                if (property.Value is TelemetryComplexProperty)
                {
                    try
                    {
                        SerializeProperty(property.Key, property.Value as TelemetryComplexProperty, eventProcessorContext, list);
                    }
                    catch (ComplexObjectSerializerException ex)
                    {
                        dictionary.Add(property.Key, ex.Message);
                    }
                }
            }
            if (dictionary.Count > 0)
            {
                try
                {
                    SerializeProperty("Reserved.ComplexProperty.FailedToSerialize", new TelemetryComplexProperty(dictionary), eventProcessorContext, list);
                }
                catch
                {
                }
            }
            foreach (KeyValuePair <string, string> item in dictionary)
            {
                telemetryEvent.Properties.Remove(item.Key);
            }
            HashSet <string> hashSet = new HashSet <string>();

            foreach (KeyValuePair <string, string> item2 in list)
            {
                if (item2.Value.Length <= 61440)
                {
                    telemetryEvent.Properties[item2.Key] = item2.Value;
                }
                else
                {
                    telemetryEvent.Properties[item2.Key] = item2.Value.Substring(0, 61437) + "...";
                    hashSet.Add(item2.Key);
                }
            }
            if (hashSet.Count > 0)
            {
                list.Clear();
                try
                {
                    SerializeProperty("Reserved.ComplexProperty.Truncated", new TelemetryComplexProperty(hashSet), eventProcessorContext, list);
                }
                catch
                {
                }
                foreach (KeyValuePair <string, string> item3 in list)
                {
                    telemetryEvent.Properties[item3.Key] = item3.Value;
                }
            }
            return(true);
        }
Ejemplo n.º 19
0
 private void SerializeProperty(string propertyName, TelemetryComplexProperty propertyValue, IEventProcessorContext eventProcessorContext, List <KeyValuePair <string, string> > propertiesToModify)
 {
     serializer.SetTypeConverter(piiProcessor.TypeOfPiiProperty(), converterToHashValue);
     propertiesToModify.Add(new KeyValuePair <string, string>(propertyName, serializer.Serialize(propertyValue.Value)));
     if (serializer.WasConverterUsedForType(piiProcessor.TypeOfPiiProperty()) && piiProcessor.CanAddRawValue(eventProcessorContext))
     {
         serializer.SetTypeConverter(piiProcessor.TypeOfPiiProperty(), converterToRawValue);
         propertiesToModify.Add(new KeyValuePair <string, string>(piiProcessor.BuildRawPropertyName(propertyName), serializer.Serialize(propertyValue.Value)));
     }
 }
Ejemplo n.º 20
0
 private EventProcessor BuildProcessor(TelemetrySession hostSession, IEventProcessorContext context)
 {
     return(new EventProcessor(hostSession, context));
 }
Ejemplo n.º 21
0
 public bool CanAddRawValue(IEventProcessorContext eventProcessorContext)
 {
     return(eventProcessorContext.HostTelemetrySession.CanCollectPrivateInformation);
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Execute action on event, using telemetryManifestContext as a provider of the necessary information.
        /// Return true if it is allowed to execute next actions.
        /// Return false action forbids the event.
        /// </summary>
        /// <param name="eventProcessorContext"></param>
        /// <returns>Indicator, whether current action is not explicitely forbid current event</returns>
        public bool Execute(IEventProcessorContext eventProcessorContext)
        {
            List <string> list = null;
            List <Tuple <string, string> > list2 = null;
            TelemetryEvent telemetryEvent        = eventProcessorContext.TelemetryEvent;

            foreach (KeyValuePair <string, object> property in telemetryEvent.Properties)
            {
                if (!IsPropertyNameValid(property.Key))
                {
                    if (list == null)
                    {
                        list = new List <string>();
                    }
                    list.Add(property.Key);
                }
                else if (property.Value != null && !(property.Value is TelemetryComplexProperty))
                {
                    string text = property.Value.ToString();
                    if (!IsPropertyValueValid(text))
                    {
                        if (list2 == null)
                        {
                            list2 = new List <Tuple <string, string> >();
                        }
                        list2.Add(Tuple.Create(property.Key, text));
                    }
                }
            }
            if (list != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (string item in list)
                {
                    telemetryEvent.Properties.Remove(item);
                    if (stringBuilder.Length + 1 + item.Length <= 1024)
                    {
                        if (stringBuilder.Length > 0)
                        {
                            stringBuilder.AppendFormat(CultureInfo.InvariantCulture, ",{0}", new object[1]
                            {
                                item
                            });
                        }
                        else
                        {
                            stringBuilder.Append(item);
                        }
                    }
                    else if (stringBuilder.Length == 0)
                    {
                        stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}...", new object[1]
                        {
                            item.Substring(0, 147)
                        });
                    }
                }
                telemetryEvent.Properties["Reserved.InvalidEvent.InvalidPropertyNames"] = stringBuilder.ToString();
            }
            if (list2 != null)
            {
                StringBuilder stringBuilder2 = new StringBuilder();
                foreach (Tuple <string, string> item2 in list2)
                {
                    telemetryEvent.Properties[item2.Item1] = string.Format(CultureInfo.InvariantCulture, "{0}...", new object[1]
                    {
                        item2.Item2.Substring(0, 1021)
                    });
                    if (stringBuilder2.Length + 1 + item2.Item1.Length <= 150)
                    {
                        if (stringBuilder2.Length > 0)
                        {
                            stringBuilder2.AppendFormat(CultureInfo.InvariantCulture, ",{0}", new object[1]
                            {
                                item2.Item1
                            });
                        }
                        else
                        {
                            stringBuilder2.Append(item2.Item1);
                        }
                    }
                }
                telemetryEvent.Properties["Reserved.InvalidEvent.TruncatedProperties"] = stringBuilder2.ToString();
            }
            return(true);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Implementation of the TelemetryManifestActionOptOutBase.ExecuteOptOutAction method
 /// Logic is very simple. If event matches current conditions then it is not valid for the OptOut session
 /// </summary>
 /// <param name="eventProcessorContext"></param>
 protected override void ExecuteOptOutAction(IEventProcessorContext eventProcessorContext)
 {
     eventProcessorContext.IsEventDropped = true;
 }