public MicroServicesDataEventAction GetEventAction(IDataEvent eventInfo) { if (eventInfo == null) { throw new ArgumentNullException("eventInfo"); } var itemAction = eventInfo.Action; var workFlowStatus = sitefinityDataEventProxy.GetPropertyValue <string>(eventInfo, Constants.ApprovalWorkflowState); var itemStatus = sitefinityDataEventProxy.GetPropertyValue <string>(eventInfo, Constants.ItemStatus); var recycleBinAction = sitefinityDataEventProxy.GetPropertyValue <RecycleBinAction>(eventInfo, Constants.RecycleBinAction); if (itemAction == Constants.ItemActionDeleted || (workFlowStatus == Constants.WorkflowStatusUnpublished && recycleBinAction != RecycleBinAction.RestoreFromRecycleBin)) { //Unpublished or deleted Check for this first return(MicroServicesDataEventAction.UnpublishedOrDeleted); } else if (workFlowStatus == Constants.WorkflowStatusPublished && itemStatus == Constants.ItemStatusLive) { //Published return(MicroServicesDataEventAction.PublishedOrUpdated); } else if (workFlowStatus == Constants.WorkflowStatusDraft && itemStatus == Constants.ItemStatusMaster) { return(MicroServicesDataEventAction.Draft); } return(MicroServicesDataEventAction.Ignored); }
private void Hub_OnHealthEvent(IHealthHub hub, IDataEvent data) { currentMeasure.BeginInvoke((Action)(() => { currentMeasure.Text = $"{data.Data} {data.Unit} ({(data.Status == DataKind.Final ? "!" : "~")})"; })); }
private static void Content_Action(IDataEvent eventInfo) { var autofacLifetimeScope = AutofacDependencyResolver.Current.RequestLifetimeScope; var dataEventHandler = autofacLifetimeScope.Resolve <DataEventProcessor>(); dataEventHandler.ExportContentData(eventInfo); }
/// <summary> /// Handler for Sitefinity content module generic data event. /// </summary> /// <param name="EventData">The event data.</param> private void DataEvent_Handler(IDataEvent EventData) { var sb = new StringBuilder(); sb.AppendFormat("Event Data Type: {0}\n", EventData.GetType().ToString()); sb.AppendFormat(" Action: {0}\n", EventData.Action); sb.AppendFormat(" Item Type: {0}\n", EventData.ItemType.FullName); sb.AppendFormat(" Item Id: {0}\n", EventData.ItemId); sb.AppendFormat(" Provider: {0}\n", EventData.ProviderName); sb.AppendFormat(" Origin: {0}\n", EventData.Origin); if (EventData is ILifecycleEvent) { AppendLifeCycleData(EventData, sb); } if (EventData is IMultilingualEvent) { AppendMultilingualData(EventData, sb); } if (EventData is IPropertyChangeDataEvent) { AppendPropertyChangedData(EventData, sb); } LoggerHelper.WriteLog(sb.ToString()); }
public void ExportCompositePage(IDataEvent eventInfo) { if (eventInfo == null) { throw new ArgumentNullException("eventInfo"); } try { var microServicesDataEventAction = dataEventActions.GetEventAction(eventInfo); var itemId = eventInfo.ItemId; var providerName = eventInfo.ProviderName; var contentType = eventInfo.ItemType; var isContentPage = compositePageBuilder.GetContentPageTypeFromPageNode(contentType, itemId, providerName); if (isContentPage && microServicesDataEventAction == MicroServicesDataEventAction.PublishedOrUpdated) { ExportPageNode(providerName, contentType, itemId, Constants.WorkflowStatusPublished); } else if (isContentPage && microServicesDataEventAction == MicroServicesDataEventAction.UnpublishedOrDeleted) { ExportPageNode(providerName, contentType, itemId, Constants.ItemActionDeleted); } } catch (Exception ex) { applicationLogger.ErrorJustLogIt($"Failed to export page data for item id {eventInfo.ItemId}", ex); throw; } }
/// <summary> /// Appends the multilingual data to the log /// </summary> /// <param name="EventData">The event data.</param> /// <param name="sb">StringBuilder containing the current log.</param> private void AppendMultilingualData(IDataEvent EventData, StringBuilder sb) { var multilingual = EventData as IMultilingualEvent; sb.AppendFormat(" Multilingual Info:\n"); sb.AppendFormat(" Language: {0}\n", multilingual.Language); }
private static bool ValidateEventType(IDataEvent @event) { string action = @event.Action; Type contentType = @event.ItemType; if (action != "Updated" || contentType != typeof(Image)) { return(false); } var propertyChangeDataEvent = @event as IPropertyChangeDataEvent; if (propertyChangeDataEvent == null || (!propertyChangeDataEvent.ChangedProperties.Any(p => p.Key == "Thumbnails") && !propertyChangeDataEvent.ChangedProperties.Any(p => p.Key == ImageOptimizationConstants.IsOptimizedFieldName))) { return(false); } if (propertyChangeDataEvent.ChangedProperties.Any(p => p.Key == ImageOptimizationConstants.IsOptimizedFieldName)) { var changedIsOptimized = propertyChangeDataEvent.ChangedProperties.FirstOrDefault(p => p.Key == ImageOptimizationConstants.IsOptimizedFieldName); if ((bool)changedIsOptimized.Value.NewValue == Startup.hassImageOptimizationProcessorEnabled) { return(false); } } return(true); }
void OnBackArticle() { //if (listMenuIdx.Count == 0) return; BookState = BookLoaderState.MenuPage; DataEventState = new DataEventLoadMenu(); Notify(); }
void OnBackMenu() { try { if (listMenuIdx.Count == 0) { return; } //IsRightToLeftTransition = false; //get currentTiles Data.CurrentMenuPage = Data.MenuPage; for (int i = 0; i < listMenuIdx.Count - 1; i++) { Data.CurrentMenuPage = (TileMenu)(Data.CurrentMenuPage.ListSubMenu[listMenuPage[i]].ListSubMenu[listMenuIdx[i]]); } listMenuIdx.RemoveAt(listMenuIdx.Count - 1); listMenuPage.RemoveAt(listMenuPage.Count - 1); if (Data.listMenuBackImageSource.Count >= 1) { Data.listMenuBackImageSource.RemoveAt(Data.listMenuBackImageSource.Count - 1); } BookState = BookLoaderState.MenuPage; //LoadMenu(0); DataEventState = new DataEventLoadMenu(); Notify(); } catch (Exception ex) { MessageBox.Show("OnBackMenu: " + ex.Message); } }
async Task PostEventOnceAsync(IDataEvent evnt) { if (BuildInfo.IsLocalDebugBuild) { eventsSent++; Log.Verbose(TAG, $"(not-sent: {eventsSent}): {evnt}"); return; } var response = await httpClient.PostAsync( "addlog", new EventObjectStreamContent (this, evnt)); if (response.StatusCode == HttpStatusCode.Forbidden) { Log.Info(TAG, "Disabling telemetry at service's direction (403)."); DisableTelemetry(); return; } response.EnsureSuccessStatusCode(); eventsSent++; Log.Verbose(TAG, $"({eventsSent}): {evnt}"); }
/// <summary> /// Determines should the data event be processed. There are two /// conditions that an event must meet in order to be processed: /// * The ItemType for which event was raised must be of type /// <see cref="Product"/> or one of its derivatives /// * The Item being processed should be the live version of the product. /// As Sitefinity supports life-cycle of data items, several versions, /// such as draft, live, master, temp... may be created. We want to /// create items only once, however. /// * The ProviderName from which event was fired should be the default /// provider of the catalog module, which we are using as the master /// catalog. Changes on the regional providers should be isolated /// and hence we are not interested in them /// * The action for which event was fired must be Created or Deleted /// as we are not interested in updates or custom actions /// </summary> /// <param name="evt"> /// The instance of the <see cref="IDataEvent"/> type which represents /// the event to be examined. /// </param> /// <returns> /// True if all conditions were met and event should be processed; otherwise /// false. /// </returns> private bool ShouldProcess(IDataEvent evt) { if (!typeof(Product).IsAssignableFrom(evt.ItemType)) { return(false); } var lifecycleEvt = evt as ILifecycleEvent; if (lifecycleEvt != null && lifecycleEvt.Status != ContentLifecycleStatus.Live.ToString()) { return(false); } if (evt.ProviderName != CatalogManager.GetDefaultProviderName()) { return(false); } if (!(evt.Action == DataEventAction.Created || evt.Action == DataEventAction.Deleted)) { return(false); } return(true); }
public void OnClickedTile(int Lvl, int PageIdx, int Idx) {//OnForwadMenu //if (Lvl != -1 && ((MenuItem)(Data.CurrentMenuPage.ListSubMenu[Data.iCurrentMenuPage].ListSubMenu[Idx])).ListSubMenu.Count == 0) return; if (Lvl != -1 && ((MenuItem)(Data.CurrentMenuPage.ListSubMenu[PageIdx].ListSubMenu[Idx])).ListSubMenu.Count == 0) { return; } // IsRightToLeftTransition = true; if (Lvl == -1) { } else { listMenuIdx.Add(Idx); //listMenuPage.Add(Data.iCurrentMenuPage); listMenuPage.Add(PageIdx); } //get currentTiles Data.CurrentMenuPage = Data.MenuPage; for (int i = 0; i < listMenuIdx.Count; i++) { Data.CurrentMenuPage = (TileMenu)(Data.CurrentMenuPage.ListSubMenu[listMenuPage[i]].ListSubMenu[listMenuIdx[i]]); } Data.iCurrentMenuPage = 0; DataEventState = new DataEventLoadMenu(); Notify(); }
/// <summary> /// Appends the life cycle data to the log /// </summary> /// <param name="EventData">The event data.</param> /// <param name="sb">StringBuilder containing the current log.</param> private void AppendLifeCycleData(IDataEvent EventData, StringBuilder sb) { var lifecycle = EventData as ILifecycleEvent; sb.Append(" Lifecycle Info:\n"); sb.AppendFormat(" Status: {0}\n", lifecycle.Status); sb.AppendFormat(" OriginalId: {0}\n", lifecycle.OriginalContentId); }
public void OnClickedImage(Image img) { //Data.CurrentMenuPage.bt_Click(new object(), new RoutedEventArgs()); Data.ClickedImage = img; DataEventState = new DataEventClickOnArticleImage(); Notify(); }
public void OnNextArticlePage() { if (Data.CurrentArticlePage + 3 < Data.CurrentArticle.ListSubMenu.Count) { //IsRightToLeftTransition = true; DataEventState = new DataEventNextMenu(); Notify(); } }
public void OnPreviousMenu() { //IsRightToLeftTransition = true; if (Data.iCurrentMenuPage - 2 >= 0) { DataEventState = new DataEventPreviousMenu(); Notify(); } }
public bool ShouldExportPage(IDataEvent dataEvent) { //Ignore any workflow property changes var changedProperties = sitefinityDataEventProxy.GetPropertyValue <IDictionary <string, PropertyChange> >(dataEvent, Constants.ChangedProperties); var filteredProperties = changedProperties.Where(p => p.Key != Constants.ApprovalWorkflowState).Count(); var hasPageChanged = sitefinityDataEventProxy.GetPropertyValue <bool>(dataEvent, Constants.HasPageDataChanged); return(hasPageChanged || filteredProperties > 0); }
public void Post(IDataEvent evnt) { if (httpClient == null || !enabled) { return; } PostEventAsync(evnt).Forget(); }
private void OnBlogPostCreated(IDataEvent @event) { if (@event.ItemType == typeof(BlogPost) && @event.Action == "New") { var blogsManager = BlogsManager.GetManager(@event.ProviderName); var currentBlogPost = blogsManager.GetBlogPost(@event.ItemId); currentBlogPost.Content = currentBlogPost + "<br/><i>This is the disclaimer!</i>"; } }
private static void OnDataEvent(IDataEvent e) { var action = e.Action; var contentType = e.ItemType; var itemId = e.ItemId; var providerName = e.ProviderName; var manager = ManagerBase.GetMappedManager(contentType, providerName); var item = manager.GetItemOrDefault(contentType, itemId); Trace.WriteLine($"AzureServicePublisher: Executing data event {action} {contentType} {itemId} {providerName} - {item.Dump()}"); }
public EventObjectStreamContent(Client client, IDataEvent evnt) { if (evnt == null) { throw new ArgumentNullException(nameof(evnt)); } this.client = client; this.evnt = evnt; EnsureHeaders(); }
void Article_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { StringReader stream = new StringReader(e.Result); Data.CurrentArticle = (MenuItem)MenuItem.Load(stream)[0]; Data.CurrentArticlePage = 0; //LoadArticlePage(0); DataEventState = new DataEventLoadArticlePage(); Notify(); } }
/// <summary> /// Appends the property changed data to the log. /// </summary> /// <param name="EventData">The event data.</param> /// <param name="sb">StringBuilder containing the current log.</param> private void AppendPropertyChangedData(IDataEvent EventData, StringBuilder sb) { var changed = EventData as IPropertyChangeDataEvent; if (changed.ChangedProperties.Count > 0) { sb.Append(" Changed Properties:\n"); foreach (var property in changed.ChangedProperties) { sb.AppendFormat(" Property: {0}\n", property); } } }
private static void Content_Action(IDataEvent @event) { try { Type contentType = @event.ItemType; Guid itemId = @event.ItemId; string providerName = @event.ProviderName; string language = @event.GetLanguage(); if (!ValidateEventType(@event)) { return; } if (ObjectFactory.GetArgsByName(typeof(ImageOptimizationConfig).Name, typeof(ImageOptimizationConfig)) == null) { return; } ImageOptimizationConfig imageOptimizationConfig = Config.Get <ImageOptimizationConfig>(); LibrariesManager manager = ManagerBase.GetMappedManager(contentType, providerName) as LibrariesManager; if (manager == null) { return; } var item = manager.GetItemOrDefault(contentType, itemId); Image image = item as Image; if (image.Status == ContentLifecycleStatus.Master) { var imageTemp = manager.Lifecycle.CheckOut(image) as Image; imageTemp.SetValue(ImageOptimizationConstants.IsOptimizedFieldName, Startup.hassImageOptimizationProcessorEnabled); manager.Lifecycle.CheckIn(imageTemp); } else if (image.Status == ContentLifecycleStatus.Temp) { image.SetValue(ImageOptimizationConstants.IsOptimizedFieldName, Startup.hassImageOptimizationProcessorEnabled); Image master = manager.Lifecycle.GetMaster(image) as Image; master.SetValue(ImageOptimizationConstants.IsOptimizedFieldName, Startup.hassImageOptimizationProcessorEnabled); } manager.SaveChanges(); } catch (Exception ex) { Log.Write(string.Format("Error occurred while setting image optimization field value: {0}", ex.Message), ConfigurationPolicy.ErrorLog); } }
/// <summary> /// Event handler for the IDataEvent which Sitefinity fires /// any time a CRUD operation is performed on any entity /// that implements <see cref="IDataEvent"/>. /// </summary> /// <param name="evt"> /// The instance of the <see cref="IDataEvent"/> which provides /// the information about the raised event. /// </param> private void HandleDataEvent(IDataEvent evt) { if (this.ShouldProcess(evt)) { if (evt.Action == DataEventAction.Created) { this.CreateProductAccrossRegions(evt.ItemId, evt.ItemType); } else if (evt.Action == DataEventAction.Deleted) { this.DeleteProductAccrossRegions(evt.ItemId, evt.ItemType); } } }
public void OnClickedTile(int Lvl, int PageIdx, int Idx) { //OnForwadMenu try { //if (Lvl != -1 && ((MenuItem)(Data.CurrentMenuPage.ListSubMenu[Data.iCurrentMenuPage].ListSubMenu[Idx])).ListSubMenu.Count == 0) return; if (Lvl != -1 && ((MenuItem)(Data.CurrentMenuPage.ListSubMenu[PageIdx].ListSubMenu[Idx])).ListSubMenu.Count == 0) { MessageBox.Show("OnClickedTile: no sub menu!!!"); return; } // IsRightToLeftTransition = true; if (Lvl == -1) { } else { listMenuIdx.Add(Idx); //listMenuPage.Add(Data.iCurrentMenuPage); listMenuPage.Add(PageIdx); } //get currentTiles Data.CurrentMenuPage = Data.MenuPage; for (int i = 0; i < listMenuIdx.Count; i++) { Data.CurrentMenuPage = (TileMenu)(Data.CurrentMenuPage.ListSubMenu[listMenuPage[i]].ListSubMenu[listMenuIdx[i]]); } if (Lvl != -1) { //get back button image source string str = Data.CurrentMenuPage.BackImageSource; if (str != string.Empty) { Data.listMenuBackImageSource.Add(str); } } Data.iCurrentMenuPage = 0; DataEventState = new DataEventLoadMenu(); BookState = BookLoaderState.MenuPage; Notify(); } catch (Exception ex) { MessageBox.Show("OnClicked [Menu] Tile: " + ex.Message); } }
public DataEventProcessorTests() { fakeApplicationLogger = A.Fake <IApplicationLogger>(); fakeCompositePageBuilder = A.Fake <ICompositePageBuilder>(); fakeDataEventActions = A.Fake <IDataEventActions>(ops => ops.Strict()); fakeAsyncHelper = new AsyncHelper(); fakeDataEvent = A.Fake <IDataEvent>(); fakeSitefinityManagerProxy = A.Fake <ISitefinityManagerProxy>(); fakeServiceBusMessageProcessor = A.Fake <IServiceBusMessageProcessor>(); fakeDynamicContentExtensions = A.Fake <IDynamicContentExtensions>(); fakeDynamicContentConverter = A.Fake <IDynamicModuleConverter <JobProfileMessage> >(); fakeDynamicContentAction = A.Fake <IDynamicContentAction>(); A.CallTo(() => fakeDataEvent.ItemType).Returns(typeof(PageNode)); }
public override void OnDataChanged(DataEventBuffer dataEvents) { for (int i = 0; i < dataEvents.Count; i++) { IDataEvent dataEvent = Java.Interop.JavaObjectExtensions.JavaCast <IDataEvent>(dataEvents.Get(i)); if (dataEvent.Type == DataEvent.TypeDeleted) { if (Constants.BothPath.Equals(dataEvent.DataItem.Uri.Path)) { // Notification on the phone should be dismissed NotificationManagerCompat.From(this).Cancel(Constants.BothId); } } } }
public override void OnDataChanged(DataEventBuffer buffer) { if (Log.IsLoggable(TAG, LogPriority.Debug)) { Log.Debug(TAG, "OnDataChanged: " + buffer + " for " + PackageName); } for (int i = 0; i < buffer.Count; i++) { IDataEvent e = Android.Runtime.Extensions.JavaCast <IDataEvent>(buffer.Get(i)); if (e.Type == DataEvent.TypeDeleted) { Log.Info(TAG, e + " deleted"); } else if (e.Type == DataEvent.TypeChanged) { bool alarmOn = (bool)DataMap.FromByteArray(e.DataItem.GetData()).Get(FIELD_ALARM_ON); if (!alarmOn) { orig_volume = audio_manager.GetStreamVolume(Android.Media.Stream.Alarm); media_player.Reset(); max_volume = 0; audio_manager.SetStreamVolume(Android.Media.Stream.Alarm, max_volume, 0); media_player.SetAudioStreamType(Android.Media.Stream.Alarm); try { media_player.SetDataSource(ApplicationContext, alarm_sound); media_player.Prepare(); } catch (IOException ex) { Log.Error(TAG, "Failed to prepare media player to play alarm.", ex); } media_player.Start(); } else { audio_manager.SetStreamVolume(Android.Media.Stream.Alarm, orig_volume, 0); if (media_player.IsPlaying) { media_player.Stop(); } } } } buffer.Close(); }
/// <summary> /// Modifies newly created <see cref="ControlPresentation"/> by adding suffix, when creating a widget template for MVC Widget. /// </summary> /// <param name="eventArgs">The event args.</param> public void HandleIDataEvent(IDataEvent eventArgs) { var action = eventArgs.Action; var contentType = eventArgs.ItemType; if (action == DataEventAction.Created && contentType.BaseType == typeof(PresentationData)) { var itemId = eventArgs.ItemId; var providerName = eventArgs.ProviderName; var manager = PageManager.GetManager(providerName); var controlPresentationItem = manager.GetPresentationItem<ControlPresentation>(itemId); var controlType = TypeResolutionService.ResolveType(controlPresentationItem.ControlType, throwOnError: false); if (controlType != null && typeof(IController).IsAssignableFrom(controlType) && !controlPresentationItem.FriendlyControlName.Contains(MvcConstants.MvcSuffix)) controlPresentationItem.FriendlyControlName = string.Format(CultureInfo.InvariantCulture, MvcConstants.MvcFieldControlNameTemplate, controlPresentationItem.FriendlyControlName); manager.SaveChanges(); } }
public void ExportContentData(IDataEvent eventInfo) { if (eventInfo == null) { throw new ArgumentNullException("eventInfo"); } if (eventInfo.ItemType == typeof(PageNode)) { ExportCompositePage(eventInfo); } else if (eventInfo.ItemType == typeof(FlatTaxon)) { //Don't do this for deletes as the TaxonItem will not exist by now, linked JPs will fire updated events. if (eventInfo.Action != Constants.ItemActionDeleted) { GetClassificationRelatedItems(eventInfo); } } }
public static void ContentActionEventHandler(IDataEvent evt) { var action = evt.Action; var contentType = evt.ItemType; if (contentType == typeof(Image) && (action == "Publish" || action == "Updated")) { var itemId = evt.ItemId; var providerName = evt.ProviderName; var manager = ManagerBase.GetMappedManager(contentType, providerName) as LibrariesManager; var item = manager.GetItemOrDefault(contentType, itemId) as Image; if (item.Status == ContentLifecycleStatus.Temp) { var master = manager.Lifecycle.GetMaster(item) as Image; if (master.FileId == item.FileId) { var focalPointChanged = false; focalPointChanged = master.GetValue<int>("FocalPointX") != item.GetValue<int>("FocalPointX"); focalPointChanged = focalPointChanged ? true : master.GetValue<int>("FocalPointY") != item.GetValue<int>("FocalPointY"); focalPointChanged = focalPointChanged ? true : master.GetValue<int>("FocalPointWidth") != item.GetValue<int>("FocalPointWidth"); focalPointChanged = focalPointChanged ? true : master.GetValue<int>("FocalPointHeight") != item.GetValue<int>("FocalPointHeight"); if (focalPointChanged) { // need to regenerate thumbnail...somehow } } else { // the image changed, need to set focal point to 0...somehow } } if (item.Status == ContentLifecycleStatus.Master) { var entry = IOManager.GetImageOptimizationLogEntrys().Where(e => e.ImageId == item.Id).FirstOrDefault(); if (entry == null) { entry = IOManager.CreateImageOptimizationLogEntry(); entry.ImageId = item.Id; entry.Fingerprint = ImageOptimizationHelper.GetImageFingerprint(item.Id); entry.InitialFileExtension = item.Extension; entry.InitialTotalSize = item.TotalSize; IOManager.SaveChanges(); } else { if (entry.OptimizedFileId != Guid.Empty && item.FileId != entry.OptimizedFileId) { entry.Fingerprint = ImageOptimizationHelper.GetImageFingerprint(item.Id); entry.OptimizedFileId = Guid.Empty; IOManager.SaveChanges(); } } } } }