/// <summary> /// Load custom animations from animation pane separated by click /// </summary> /// <returns>Queue of CustomClickItem</returns> private Queue <CustomItem> LoadCustomClickItems() { int clickNo = FirstClickNumber; Queue <CustomItem> customItems = new Queue <CustomItem>(); List <Effect> effects = slide.TimeLine.MainSequence.Cast <Effect>().ToList(); int startIdx = 0; bool hasReachedEndOfSequence = effects.Count == 0; do { List <CustomEffect> customEffects = new List <CustomEffect>(); for (int i = startIdx; i < effects.Count; i++) { Effect effect = effects.ElementAt(i); if (i > startIdx && effect.Timing.TriggerType == MsoAnimTriggerType.msoAnimTriggerOnPageClick) { startIdx = i; break; } if (i == effects.Count - 1) { hasReachedEndOfSequence = true; } bool isCustomEffect = SelfExplanationTagService.ExtractTagNo(effect.Shape.Name) == -1; if (isCustomEffect) { if (customEffects.Count == 0 && clickNo > 0) { effect.Timing.TriggerType = MsoAnimTriggerType.msoAnimTriggerOnPageClick; } customEffects.Add(new CustomEffect(effect.Shape.Name, effect.Shape.Id.ToString(), EffectToAnimationTypeConverter.GetAnimationTypeOfEffect(effect))); } } CustomItem customClickBlock = new CustomItemFactory(customEffects).GetBlock() as CustomItem; if (customClickBlock != null) { customClickBlock.ClickNo = clickNo; customItems.Enqueue(customClickBlock); } clickNo++; }while (startIdx <= effects.Count - 1 && !hasReachedEndOfSequence); return(customItems); }
private ObservableCollection <ClickItem> LoadItems(DoWorkEventArgs e) { SelfExplanationTagService.Clear(); int clickNo = FirstClickNumber; ObservableCollection <ClickItem> customItems = new ObservableCollection <ClickItem>(); ObservableCollection <ClickItem> clickItems = new ObservableCollection <ClickItem>(); List <Dictionary <string, string> > explanationItems = ELearningLabTextStorageService.LoadSelfExplanationsFromSlide(slide); ClickItem customClickBlock; SelfExplanationTagService.PopulateTagNos(slide.GetShapesWithNameRegex(ELearningLabText.PPTLShapeNameRegex) .Select(x => x.Name).ToList()); HashSet <int> tagNums = new HashSet <int>(); List <Effect> effects = slide.TimeLine.MainSequence.Cast <Effect>().ToList(); int startIdx = 0; bool hasReachedEndOfSequence = effects.Count == 0; List <CustomEffect> customEffects = new List <CustomEffect>(); List <ELLEffect> pptlEffects = new List <ELLEffect>(); do { if (worker.CancellationPending) { e.Cancel = true; return(clickItems); } customEffects = new List <CustomEffect>(); for (int i = startIdx; i < effects.Count; i++) { Effect effect = effects.ElementAt(i); if (i > startIdx && effect.Timing.TriggerType == MsoAnimTriggerType.msoAnimTriggerOnPageClick) { startIdx = i; break; } if (i == effects.Count - 1) { hasReachedEndOfSequence = true; } bool isPPTLEffect = SelfExplanationTagService.ExtractTagNo(effect.Shape.Name) != -1; if (!isPPTLEffect) { customEffects.Add(new CustomEffect(effect.Shape.Name, effect.Shape.Id.ToString(), EffectToAnimationTypeConverter.GetAnimationTypeOfEffect(effect))); } } customClickBlock = new CustomItemFactory(customEffects).GetBlock(); if (customClickBlock != null) { customClickBlock.ClickNo = clickNo; customItems.Add(customClickBlock); } clickNo++; }while (startIdx <= effects.Count - 1 && !hasReachedEndOfSequence); while (explanationItems != null && explanationItems.Count > 0 && customItems.Count > 0) { if (worker.CancellationPending) { e.Cancel = true; return(clickItems); } ExplanationItem expItem = CreateExpItemFromDictionary(explanationItems.First()); CustomItem customItem = customItems.ElementAt(0) as CustomItem; if (customItem.ClickNo <= expItem.ClickNo) { clickItems.Add(customItem); customItems.RemoveAt(0); } else { clickItems.Add(expItem); explanationItems.RemoveAt(0); } } while (explanationItems != null && explanationItems.Count > 0) { if (worker.CancellationPending) { e.Cancel = true; return(clickItems); } ExplanationItem expItem = CreateExpItemFromDictionary(explanationItems.First()); explanationItems.RemoveAt(0); clickItems.Add(expItem); } while (customItems.Count > 0) { if (worker.CancellationPending) { e.Cancel = true; return(clickItems); } CustomItem customItem = customItems.ElementAt(0) as CustomItem; customItems.RemoveAt(0); clickItems.Add(customItem); } return(clickItems); }
public static IEnumerable <CustomEffect> GetCustomEffectsForClick(this PowerPointSlide slide, int clickNo) { DateTime start = DateTime.Now; List <Effect> effects = slide.TimeLine.MainSequence.Cast <Effect>().ToList(); Sequence sequence = slide.TimeLine.MainSequence; try { Effect effectBefore = sequence.FindFirstAnimationForClick(clickNo); Effect effectAfter = sequence.FindFirstAnimationForClick(clickNo + 1); // from idxStart inclusive, idxEnd exclusive int idxStart = effectBefore == null?effects.Count() : effects.IndexOf(effectBefore); int idxEnd = effectAfter == null?effects.Count() : effects.IndexOf(effectAfter); IEnumerable <Effect> customEffects = effects.GetRange(idxStart, idxEnd - idxStart).Where(x => SelfExplanationTagService.ExtractTagNo(x.Shape.Name) == -1); IEnumerable <CustomEffect> _customEffects = customEffects.Select(x => new CustomEffect(x.Shape.Name, x.Shape.Id.ToString(), EffectToAnimationTypeConverter.GetAnimationTypeOfEffect(x))); if (clickNo > 0 && customEffects.Count() > 0) { customEffects.ElementAt(0).Timing.TriggerType = MsoAnimTriggerType.msoAnimTriggerOnPageClick; } return(_customEffects); } catch { // most likely caused by idxStart out of bound return(new List <CustomEffect>()); } }