public static void HandleUpdate(object sender, EventNotificationEventArgs e)
        {
            Log.Debug("HandleUpdate called");

            // reload provider to retrieve latest localizations
            LocalizationProviderInitiator.ReInitProvider();
        }
Esempio n. 2
0
        private void CatalogKeyEventUpdated(object sender, EventNotificationEventArgs e)
        {
            if (!KachingConfiguration.Instance.ListenToRemoteEvents && !IsLocalEvent(e))
            {
                return;
            }

            if (!(Deserialize(e) is PriceUpdateEventArgs e1))
            {
                return;
            }

            Logger.Debug("PriceUpdated raised.");

            var contentLinks = new HashSet <ContentReference>(
                e1.CatalogKeys.Select(key => _referenceConverter.GetContentLink(key.CatalogEntryCode)));

            IEnumerable <ContentReference> affectedProductLinks = GetAffectedProductReferences(contentLinks);

            ProductContent[] products = _contentLoader.GetItems(affectedProductLinks, CultureInfo.InvariantCulture)
                                        .OfType <ProductContent>()
                                        .ToArray();

            foreach (ProductContent productContent in products)
            {
                _productExportService.ExportProduct(productContent, null);
            }
        }
 private static void dataStoreInvalidationEvent_Raised(object sender, EventNotificationEventArgs e)
 {
     _log.Debug("dataStoreInvalidationEvent '{2}' handled - raised by '{0}' on '{1}'", e.RaiserId, Environment.MachineName, e.EventId);
     _log.Debug("Begin: Clearing cache on '{0}'", Environment.MachineName);
     CustomRedirectHandler.ClearCache();
     _log.Debug("End: Clearing cache on '{0}'", Environment.MachineName);
 }
Esempio n. 4
0
 public static void RecordEntryChange(object sender, EventNotificationEventArgs e)
 {
     BfEventManager.SendToBF(
         sender.GetOriginalType().Name
         , "Entry changed"
         , e.ToString());
 }
        public static void HandleUpdate(object sender, EventNotificationEventArgs e)
        {
            Log.Debug("HandleUpdate called");

            // reload provider to retrieve latest localizations
            LocalizationProviderInitiator.ReInitProvider();
        }
        protected void LogEventDetails(EventNotificationEventArgs eventNotificationEventArgs, string eventType)
        {
            if (_log.IsDebugEnabled())
            {
                string eventName = eventNotificationEventArgs.EventId.ToString();
                string subType = "";
                string ids = null;

                // Deserialize event, we need more data from it
                bool isRemoteEvent = !IsSelfRaised(eventNotificationEventArgs);
                byte[] param = eventNotificationEventArgs.Param as byte[];
                if (param == null)
                {
                    _log.Debug("{0} '{1}' raised. Cannot deserialize event since Param is null.", eventType, eventName);
                }
                EventArgs args = DeSerialize(param);
                if (args != null)
                {
                    CatalogKeyEventArgs keyArgs = args as CatalogKeyEventArgs;
                    if (keyArgs != null)
                    {
                        subType = "CatalogKey";
                        eventName = keyArgs.Name;
                        if(keyArgs.CatalogKeys != null && keyArgs.CatalogKeys.Any())
                        {
                            ids = string.Join(", ", keyArgs.CatalogKeys.Select(k => k.CatalogEntryCode));
                        }
                    }

                    CatalogContentUpdateEventArgs updateArgs = args as CatalogContentUpdateEventArgs;
                    if (updateArgs != null)
                    {
                        subType = "CatalogContentUpdate";
                        eventName = updateArgs.EventType;
                        if (updateArgs.CatalogEntryIds != null && updateArgs.CatalogEntryIds.Any())
                        {
                            ids = "Entries: " + string.Join(", ", updateArgs.CatalogEntryIds.Select(k => k));
                        }
                        if (updateArgs.CatalogNodeIds != null && updateArgs.CatalogNodeIds.Any())
                        {
                            if (string.IsNullOrEmpty(ids) == false)
                                ids += " ";
                            ids += "Nodes: " + string.Join(", ", updateArgs.CatalogNodeIds.Select(k => k));
                        }
                        if (updateArgs.CatalogAssociationIds != null && updateArgs.CatalogAssociationIds.Any())
                        {
                            if (string.IsNullOrEmpty(ids) == false)
                                ids += " ";
                            ids += "Associations: " + string.Join(", ", updateArgs.CatalogAssociationIds.Select(k => k));
                        }
                    }
                }

                if (string.IsNullOrEmpty(ids))
                    ids += "none";

                _log.Debug("{0} '{1}' raised with data: {2} (remote: {3}, subtype: {4})", eventType, eventName, ids, isRemoteEvent, subType);
            }
        }
 /// <summary>
 /// Removes from cache event raised.
 /// </summary>
 /// <param name="sender">
 /// Source of the event.
 /// </param>
 /// <param name="e">
 /// Page event information.
 /// </param>
 private static void RemoveFromCacheEventRaised(object sender, EventNotificationEventArgs e)
 {
     // We don't want to process events raised on this machine so we will check the raiser id.
     if (e.RaiserId != CacheManager.LocalCacheManagerRaiserId)
     {
         LoadProviders();
     }
 }
 private static void dataStoreInvalidationEvent_Raised(object sender, EventNotificationEventArgs e)
 {
     _log.DebugFormat("dataStoreInvalidationEvent '{2}' handled - raised by '{0}' on '{1}'", e.RaiserId,
         Environment.MachineName, e.EventId);
     _log.DebugFormat("Begin: Clearing cache on '{0}'", Environment.MachineName);
     ClearCache();
     _log.DebugFormat("End: Clearing cache on '{0}'", Environment.MachineName);
 }
Esempio n. 9
0
 private void IndexContent_Raised(object sender, EventNotificationEventArgs e)
 {
     if (e.RaiserId == LocalRaiserId)
     {
         return;
     }
     this.ProcessRequestInternal(IndexRequestItem.Parse((string)e.Param));
 }
 private bool IsSelfRaised(EventNotificationEventArgs e)
 {
     if (!(e.RaiserId == CatalogKeyEventBroadcaster.EventRaiserId))
     {
         return((bool)(e.RaiserId == CatalogEventBroadcaster.EventRaiserId));
     }
     return(true);
 }
 /// <summary>
 /// Starts the listening for event notification.
 /// </summary>
 public void StartListening()
 {
     if (this.eventNotifyCancellationToken == null)
     {
         this.eventNotifyCancellationToken = new CancellationTokenSource();
         // Start the query state loop if Time Shifting
         if (this.CurrentState.TimeShiftingState)
         {
             StartQueryStateLoop();
         }
         // Event notify loop
         Task.Factory.StartNew(async() =>
         {
             while (!this.eventNotifyCancellationToken.IsCancellationRequested)
             {
                 // Query URL
                 var strResponse = await this.GetWebResponseAsync(new Uri(this.RootUri, "/remoteControl/notifyEvent"));
                 if (!string.IsNullOrEmpty(strResponse))
                 {
                     // Read the JSON response
                     var response = JsonConvert.DeserializeObject <BaseResponse <EventNotification> >(strResponse, OrangeContractResolver.Settings).Result;
                     if (response.Code == ResponseCode.EventNotification)
                     {
                         // Find the custom notification
                         var eventType = Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(t => t.GetCustomAttribute <EventNotificationAttribute>()?.EventType == response.Data.EventType);
                         if (eventType != null)
                         {
                             response.Data = (EventNotification)JsonConvert.DeserializeObject(JObject.Parse(strResponse).SelectToken("result.data").ToString(), eventType, OrangeContractResolver.Settings);
                         }
                         // Update the current state with the event notification
                         response.Data.UpdateState(this.CurrentState);
                         this.StateUpdated?.Invoke(this, EventArgs.Empty);
                         // Start the loop to query the state in timeshifting mode
                         if (response.Data is TimeShiftingChanged)
                         {
                             this.StartQueryStateLoop();
                         }
                         // Query the state if the context changed
                         if (response.Data is ContextChanged)
                         {
                             await this.GetCurrentState();
                         }
                         // Raise event notification
                         if (this.EventNotificationReceived != null)
                         {
                             var notification = new EventNotificationEventArgs()
                             {
                                 Date = DateTime.Now, Notification = response.Data
                             };
                             Task.Factory.StartNew(() => this.EventNotificationReceived(this, notification));
                         }
                     }
                 }
                 await Task.Delay(100);
             }
         }, this.eventNotifyCancellationToken.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
     }
 }
        static void dataStoreInvalidationEvent_Raised(object sender, EventNotificationEventArgs e)
        {
            _log.Debug("dataStoreInvalidationEvent '{2}' handled - raised by '{0}' on '{1}'", e.RaiserId, Environment.MachineName, e.EventId);
            _log.Debug("Begin: Clearing cache on '{0}'", Environment.MachineName);
            CustomRedirectHandler.ClearCache();
            _log.Debug("End: Clearing cache on '{0}'", Environment.MachineName);
            // CustomRedirectHandler handler = CustomRedirectHandler.Current;

        }
        private void CatalogKeyEventUpdated(object sender, EventNotificationEventArgs e)
        {
            var eventArgs = (CatalogKeyEventArgs)DeSerialize((byte[])e.Param);
            var inventoryUpdatedEventArgs = eventArgs as InventoryUpdateEventArgs;

            if (inventoryUpdatedEventArgs != null)
            {
                DoReIndexProducts(inventoryUpdatedEventArgs.CatalogKeys);
            }
        }
Esempio n. 14
0
        /// <summary>
        ///     Removes from cache event raised.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventNotificationEventArgs" /> instance containing the event data.</param>
        private void TranslationsUpdatedEventRaised(object sender, EventNotificationEventArgs e)
        {
            // We don't want to process events raised on this machine so we will check the raiser id.
            if (e.RaiserId == RaiserId)
            {
                return;
            }

            this.ReloadProvider();
            Log.Info("[Localization] Translations updated on other machine. Reloaded provider.");
        }
Esempio n. 15
0
        static void dataStoreInvalidationEvent_Raised(object sender, EventNotificationEventArgs e)
        {
            _log.Debug("dataStoreInvalidationEvent '{2}' handled - raised by '{0}' on '{1}'", e.RaiserId, Environment.MachineName, e.EventId);
            _log.Debug("Begin: refreshing video items on: '{0}'", Environment.MachineName);
            var provider =
                ServiceLocator.Current.GetInstance <IContentProviderManager>().GetProvider(Constants.ProviderKey) as
                TwentyThreeVideoProvider;
            var intermediateVideoDataRepository = new IntermediateVideoDataRepository();
            var videoItems = intermediateVideoDataRepository.Load();

            provider.RefreshItems(videoItems.ToList());
            _log.Debug("End: refreshing video items on '{0}'", Environment.MachineName);
            // CustomRedirectHandler handler = CustomRedirectHandler.Current;
        }
Esempio n. 16
0
        private static EventArgs Deserialize(EventNotificationEventArgs eventArgs)
        {
            var buffer = eventArgs.Param as byte[];

            if (buffer == null)
            {
                return(EventArgs.Empty);
            }

            var binaryFormatter = new BinaryFormatter();

            using (var serializationStream = new MemoryStream(buffer))
            {
                return(binaryFormatter.Deserialize(serializationStream) as EventArgs);
            }
        }
Esempio n. 17
0
        private void CatalogContentUpdated(object sender, EventNotificationEventArgs e)
        {
            if (!KachingConfiguration.Instance.ListenToRemoteEvents && !IsLocalEvent(e))
            {
                return;
            }

            if (!(Deserialize(e) is CatalogContentUpdateEventArgs e1))
            {
                return;
            }

            switch (e1.EventType)
            {
            case CatalogEventBroadcaster.AssociationDeletedEventType:
                AssociationUpdated(e1);
                break;

            case CatalogEventBroadcaster.AssociationUpdatedEventType:
                AssociationUpdated(e1);
                break;

            case CatalogEventBroadcaster.CatalogEntryDeletedEventType:
                EntryDeleted(e1);
                break;

            case CatalogEventBroadcaster.CatalogEntryUpdatedEventType:
                EntryUpdated(e1);
                break;

            case CatalogEventBroadcaster.CatalogNodeUpdatedEventType:
                NodeUpdated(e1);
                break;

            case CatalogEventBroadcaster.CatalogNodeDeletedEventType:
                NodeDeleted(e1);
                break;

            case CatalogEventBroadcaster.RelationUpdatedEventType:
                RelationUpdated(e1);
                break;
            }
        }
        /// <summary>
        /// Will try to de-serialize the <see cref="P:EPiServer.Events.EventNotificationEventArgs.Param" /> as the typed event argument.
        /// </summary>
        /// <typeparam name="T">The type to de-serialize</typeparam>
        /// <param name="eventNotificationEventArgs">The <see cref="T:EPiServer.Events.EventNotificationEventArgs" /> instance containing the event data.</param>
        /// <param name="deserializedEventArgs">The De-serialized event argument</param>
        /// <returns><c>True</c> if the parameters was De-serialized to event arguments, and validated successfully. Otherwise <c>false</c>.</returns>
        internal bool TryDeserialize <T>(
            EventNotificationEventArgs eventNotificationEventArgs,
            out T deserializedEventArgs)
            where T : EventArgs
        {
            deserializedEventArgs = default;

            if (eventNotificationEventArgs?.Param == null)
            {
                return(false);
            }

            byte[] buffer = eventNotificationEventArgs.Param as byte[];

            if (buffer == null)
            {
                return(false);
            }

            EventArgs eventArgs = DeSerialize(buffer: buffer);

            deserializedEventArgs = (T)eventArgs;
            return(true);
        }
        /// <summary>
        /// The catalog updated event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventNotificationEventArgs"/> instance containing the event data.</param>
        private void CatalogEventUpdated(object sender, EventNotificationEventArgs e)
        {
            CatalogContentUpdateEventArgs deserializedEventArgs;

            if (!this.TryDeserialize(eventNotificationEventArgs: e, deserializedEventArgs: out deserializedEventArgs))
            {
                Log.Error("[Prediction Engine] Failed to deserialize CatalogEventUpdated event args.");
            }
            else
            {
                string eventType = deserializedEventArgs.EventType;

                if (!(eventType.Equals("CatalogEntryDeleted", comparisonType: StringComparison.OrdinalIgnoreCase)
                      | eventType.Equals("RelationDeleted", comparisonType: StringComparison.OrdinalIgnoreCase)))
                {
                    return;
                }

                foreach (int objectId in deserializedEventArgs.CatalogEntryIds)
                {
                    this.recommendationRepository.Delete(productId: objectId);
                }
            }
        }
 private void CatalogEventUpdated(object sender, EventNotificationEventArgs eventNotificationEventArgs)
 {
     LogEventDetails(eventNotificationEventArgs, "Catalog Event");
 }
        protected void LogEventDetails(EventNotificationEventArgs eventNotificationEventArgs, string eventType)
        {
            if (_log.IsDebugEnabled())
            {
                string eventName = eventNotificationEventArgs.EventId.ToString();
                string subType   = "";
                string ids       = null;

                // Deserialize event, we need more data from it
                bool   isRemoteEvent = !IsSelfRaised(eventNotificationEventArgs);
                byte[] param         = eventNotificationEventArgs.Param as byte[];
                if (param == null)
                {
                    _log.Debug("{0} '{1}' raised. Cannot deserialize event since Param is null.", eventType, eventName);
                }
                EventArgs args = DeSerialize(param);
                if (args != null)
                {
                    CatalogKeyEventArgs keyArgs = args as CatalogKeyEventArgs;
                    if (keyArgs != null)
                    {
                        subType   = "CatalogKey";
                        eventName = keyArgs.Name;
                        if (keyArgs.CatalogKeys != null && keyArgs.CatalogKeys.Any())
                        {
                            ids = string.Join(", ", keyArgs.CatalogKeys.Select(k => k.CatalogEntryCode));
                        }
                    }

                    CatalogContentUpdateEventArgs updateArgs = args as CatalogContentUpdateEventArgs;
                    if (updateArgs != null)
                    {
                        subType   = "CatalogContentUpdate";
                        eventName = updateArgs.EventType;
                        if (updateArgs.CatalogEntryIds != null && updateArgs.CatalogEntryIds.Any())
                        {
                            ids = "Entries: " + string.Join(", ", updateArgs.CatalogEntryIds.Select(k => k));
                        }
                        if (updateArgs.CatalogNodeIds != null && updateArgs.CatalogNodeIds.Any())
                        {
                            if (string.IsNullOrEmpty(ids) == false)
                            {
                                ids += " ";
                            }
                            ids += "Nodes: " + string.Join(", ", updateArgs.CatalogNodeIds.Select(k => k));
                        }
                        if (updateArgs.CatalogAssociationIds != null && updateArgs.CatalogAssociationIds.Any())
                        {
                            if (string.IsNullOrEmpty(ids) == false)
                            {
                                ids += " ";
                            }
                            ids += "Associations: " + string.Join(", ", updateArgs.CatalogAssociationIds.Select(k => k));
                        }
                    }
                }

                if (string.IsNullOrEmpty(ids))
                {
                    ids += "none";
                }

                _log.Debug("{0} '{1}' raised with data: {2} (remote: {3}, subtype: {4})", eventType, eventName, ids, isRemoteEvent, subType);
            }
        }
 /// <summary>
 /// Removes from cache event raised. 
 /// </summary>
 /// <param name="sender">
 /// Source of the event. 
 /// </param>
 /// <param name="e">
 /// Page event information. 
 /// </param>
 private static void RemoveFromCacheEventRaised(object sender, EventNotificationEventArgs e)
 {
     // We don't want to process events raised on this machine so we will check the raiser id.
     if (e.RaiserId != CacheManager.LocalCacheManagerRaiserId)
     {
         LoadProviders();
     }
 }
        /// <summary>
        ///     Removes from cache event raised.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventNotificationEventArgs" /> instance containing the event data.</param>
        private void TranslationsUpdatedEventRaised(object sender, EventNotificationEventArgs e)
        {
            // We don't want to process events raised on this machine so we will check the raiser id.
            if (e.RaiserId == RaiserId)
            {
                return;
            }

            this.ReloadProvider();
            Log.Info("[Localization] Translations updated on other machine. Reloaded provider.");
        }
 private bool IsSelfRaised(EventNotificationEventArgs e)
 {
     if (!(e.RaiserId == CatalogKeyEventBroadcaster.EventRaiserId))
     {
         return (bool)(e.RaiserId == CatalogEventBroadcaster.EventRaiserId);
     }
     return true;
 }
 private void CatalogKeyEventUpdated(object sender, EventNotificationEventArgs eventNotificationEventArgs)
 {
     LogEventDetails(eventNotificationEventArgs, "Catalog Key Event");
 }
 private void EB(object sender, EventNotificationEventArgs e)
 {
     EventReciever.RecordEntryChange(sender, e);
 }
Esempio n. 27
0
 private static void HandleEvent(object sender, EventNotificationEventArgs e)
 {
     Console.WriteLine($"Raised event: {e.EventId} {e.Param}");
 }
Esempio n. 28
0
 private static bool IsLocalEvent(EventNotificationEventArgs e)
 {
     return(e.RaiserId == CatalogKeyEventBroadcaster.EventRaiserId ||
            e.RaiserId == CatalogEventBroadcaster.EventRaiserId);
 }