private void RemoveOptimizedAndPromoteProxy(AnimationProxyManager.AnimationProxyData currentData)
 {
     currentData.ProxyAnimation.IsAnimationProxy = false;
     currentData.ProxyAnimation.ShouldSerialize  = true;
     foreach (SceneNode sceneNode in currentData.ProxyAnimation.KeyFrames)
     {
         sceneNode.ShouldSerialize = true;
     }
     if (currentData.OptimizedAnimation == null || !currentData.OptimizedAnimation.IsInDocument)
     {
         return;
     }
     this.viewModel.AnimationEditor.RemoveAnimation(this.activeStoryboard, (TimelineSceneNode)currentData.OptimizedAnimation);
 }
        private void MovePropertiesFromOptimizedToProxy(AnimationProxyManager.AnimationProxyData data)
        {
            if (data.OptimizedAnimation == null || data.ProxyAnimation == null)
            {
                return;
            }
            KeyFrameSceneNode keyFrameAtIndex = data.ProxyAnimation.GetKeyFrameAtIndex(0);

            if (keyFrameAtIndex == null)
            {
                return;
            }
            SceneNode.CopyPropertyValue((SceneNode)data.OptimizedAnimation, data.OptimizedAnimation.ToProperty, (SceneNode)keyFrameAtIndex, keyFrameAtIndex.ValueProperty);
            SceneNode.CopyPropertyValue((SceneNode)data.OptimizedAnimation, data.OptimizedAnimation.EasingFunctionProperty, (SceneNode)keyFrameAtIndex, keyFrameAtIndex.EasingFunctionProperty);
            keyFrameAtIndex.Time = data.OptimizedAnimation.Duration;
        }
        private void UpdateProxyTable(Dictionary <AnimationProxyManager.TargetNamePropertyPair, AnimationProxyManager.AnimationProxyData> proxyTable, StoryboardTimelineSceneNode storyboard, AnimationProxyManager.AllowedChange allowedChange)
        {
            if (allowedChange != AnimationProxyManager.AllowedChange.Any)
            {
                proxyTable.Clear();
            }
            List <KeyFrameAnimationSceneNode> list1 = new List <KeyFrameAnimationSceneNode>();

            foreach (TimelineSceneNode timeline in (IEnumerable <TimelineSceneNode>)storyboard.Children)
            {
                FromToAnimationSceneNode   animationSceneNode = timeline as FromToAnimationSceneNode;
                KeyFrameAnimationSceneNode nodeToTest         = timeline as KeyFrameAnimationSceneNode;
                if (animationSceneNode != null && animationSceneNode.IsOptimized || nodeToTest != null && nodeToTest.IsAnimationProxy)
                {
                    AnimationProxyManager.TargetNamePropertyPair key = new AnimationProxyManager.TargetNamePropertyPair(timeline);
                    if (key.TargetName != null)
                    {
                        AnimationProxyManager.AnimationProxyData animationProxyData;
                        if (!proxyTable.TryGetValue(key, out animationProxyData))
                        {
                            animationProxyData = new AnimationProxyManager.AnimationProxyData((FromToAnimationSceneNode)null, (KeyFrameAnimationSceneNode)null);
                            proxyTable[key]    = animationProxyData;
                        }
                        if (animationSceneNode != null)
                        {
                            animationProxyData.OptimizedAnimation = animationSceneNode;
                        }
                        else
                        {
                            animationProxyData.ProxyAnimation = nodeToTest;
                        }
                    }
                }
                else if (nodeToTest != null && this.CanOptimizeAnimation(nodeToTest))
                {
                    list1.Add(nodeToTest);
                }
            }
            if (allowedChange != AnimationProxyManager.AllowedChange.OnlyNonSerializing && allowedChange != AnimationProxyManager.AllowedChange.Any)
            {
                return;
            }
            if (allowedChange == AnimationProxyManager.AllowedChange.Any)
            {
                foreach (KeyFrameAnimationSceneNode proxyAnimation in list1)
                {
                    FromToAnimationSceneNode optimizedAnimation      = this.ConvertToOptimizedAnimation(proxyAnimation);
                    AnimationProxyManager.TargetNamePropertyPair key = new AnimationProxyManager.TargetNamePropertyPair((TimelineSceneNode)proxyAnimation);
                    AnimationProxyManager.AnimationProxyData     animationProxyData;
                    if (proxyTable.TryGetValue(key, out animationProxyData))
                    {
                        if (animationProxyData.OptimizedAnimation != null && animationProxyData.OptimizedAnimation.IsInDocument)
                        {
                            animationProxyData.OptimizedAnimation.ControllingStoryboard.Children.Remove((TimelineSceneNode)animationProxyData.OptimizedAnimation);
                        }
                        if (animationProxyData.ProxyAnimation != null && animationProxyData.ProxyAnimation.IsInDocument)
                        {
                            animationProxyData.ProxyAnimation.ControllingStoryboard.Children.Remove((TimelineSceneNode)animationProxyData.ProxyAnimation);
                        }
                        proxyTable.Remove(key);
                    }
                    proxyTable.Add(key, new AnimationProxyManager.AnimationProxyData(optimizedAnimation, proxyAnimation));
                }
            }
            List <AnimationProxyManager.TargetNamePropertyPair> list2 = new List <AnimationProxyManager.TargetNamePropertyPair>();

            foreach (KeyValuePair <AnimationProxyManager.TargetNamePropertyPair, AnimationProxyManager.AnimationProxyData> keyValuePair in proxyTable)
            {
                AnimationProxyManager.AnimationProxyData animationProxyData = keyValuePair.Value;
                int count = list2.Count;
                if (animationProxyData.ProxyAnimation != null && !keyValuePair.Key.Equals((object)new AnimationProxyManager.TargetNamePropertyPair((TimelineSceneNode)animationProxyData.ProxyAnimation)))
                {
                    animationProxyData.ProxyAnimation = (KeyFrameAnimationSceneNode)null;
                }
                if (animationProxyData.OptimizedAnimation != null && !keyValuePair.Key.Equals((object)new AnimationProxyManager.TargetNamePropertyPair((TimelineSceneNode)animationProxyData.OptimizedAnimation)))
                {
                    animationProxyData.OptimizedAnimation = (FromToAnimationSceneNode)null;
                }
                if (animationProxyData.OptimizedAnimation == null && animationProxyData.ProxyAnimation == null)
                {
                    list2.Add(keyValuePair.Key);
                }
                else if (animationProxyData.OptimizedAnimation == null || !animationProxyData.OptimizedAnimation.IsInDocument)
                {
                    if (allowedChange == AnimationProxyManager.AllowedChange.Any)
                    {
                        if (animationProxyData.ProxyAnimation != null && animationProxyData.ProxyAnimation.IsInDocument)
                        {
                            this.viewModel.AnimationEditor.RemoveAnimation(storyboard, (TimelineSceneNode)animationProxyData.ProxyAnimation);
                            if (animationProxyData.OptimizedAnimation != null && animationProxyData.OptimizedAnimation.IsInDocument)
                            {
                                animationProxyData.OptimizedAnimation.IsOptimized = false;
                            }
                        }
                        list2.Add(keyValuePair.Key);
                    }
                }
                else if (animationProxyData.ProxyWasUserDeleted && !animationProxyData.OptimizedAnimationAdded)
                {
                    if (allowedChange == AnimationProxyManager.AllowedChange.Any)
                    {
                        this.viewModel.AnimationEditor.RemoveAnimation(storyboard, (TimelineSceneNode)animationProxyData.OptimizedAnimation);
                        list2.Add(keyValuePair.Key);
                    }
                }
                else if (animationProxyData.ProxyAnimation == null || !animationProxyData.ProxyAnimation.IsInDocument)
                {
                    if (allowedChange == AnimationProxyManager.AllowedChange.OnlyNonSerializing || allowedChange == AnimationProxyManager.AllowedChange.Any)
                    {
                        animationProxyData.OptimizedAnimation.Invalidate();
                        if (animationProxyData.OptimizedAnimation.TargetElement != null)
                        {
                            KeyFrameAnimationSceneNode animationSceneNode = KeyFrameAnimationSceneNode.Factory.InstantiateWithTarget(this.viewModel, animationProxyData.OptimizedAnimation.TargetElement, animationProxyData.OptimizedAnimation.TargetProperty, animationProxyData.OptimizedAnimation.StoryboardContainer, KeyFrameAnimationSceneNode.GetKeyFrameAnimationForType(animationProxyData.OptimizedAnimation.AnimatedType, animationProxyData.OptimizedAnimation.ProjectContext));
                            animationSceneNode.AddKeyFrame(animationProxyData.OptimizedAnimation.Duration, animationProxyData.OptimizedAnimation.To);
                            KeyFrameSceneNode keyFrameAtIndex = animationSceneNode.GetKeyFrameAtIndex(0);
                            SceneNode.CopyPropertyValue((SceneNode)animationProxyData.OptimizedAnimation, animationProxyData.OptimizedAnimation.EasingFunctionProperty, (SceneNode)keyFrameAtIndex, keyFrameAtIndex.EasingFunctionProperty);
                            keyFrameAtIndex.ShouldSerialize     = false;
                            animationSceneNode.ShouldSerialize  = false;
                            animationSceneNode.IsAnimationProxy = true;
                            storyboard.Children.Insert(storyboard.Children.IndexOf((TimelineSceneNode)animationProxyData.OptimizedAnimation) + 1, (TimelineSceneNode)animationSceneNode);
                            animationProxyData.ProxyAnimation = animationSceneNode;
                        }
                    }
                }
                else if (!this.CanOptimizeAnimation(animationProxyData.ProxyAnimation))
                {
                    if (allowedChange == AnimationProxyManager.AllowedChange.Any)
                    {
                        this.RemoveOptimizedAndPromoteProxy(animationProxyData);
                        list2.Add(keyValuePair.Key);
                    }
                }
                else if ((!animationProxyData.OptimizedAnimation.IsOptimized || !AnimationProxyManager.CanFromToAnimationBeOptimized(animationProxyData.OptimizedAnimation)) && allowedChange == AnimationProxyManager.AllowedChange.Any)
                {
                    this.viewModel.AnimationEditor.RemoveAnimation(storyboard, (TimelineSceneNode)animationProxyData.ProxyAnimation);
                    animationProxyData.OptimizedAnimation.IsOptimized = false;
                    list2.Add(keyValuePair.Key);
                }
                if (count == list2.Count && allowedChange == AnimationProxyManager.AllowedChange.Any)
                {
                    if (!animationProxyData.OptimizedAnimationPropertyChanged && !animationProxyData.OptimizedAnimationAdded)
                    {
                        this.MovePropertiesFromProxyToOptimized(animationProxyData);
                    }
                    else
                    {
                        this.MovePropertiesFromOptimizedToProxy(animationProxyData);
                    }
                }
                animationProxyData.ResetUpdateState();
            }
            foreach (AnimationProxyManager.TargetNamePropertyPair key in list2)
            {
                proxyTable.Remove(key);
            }
        }