Exemplo n.º 1
0
        private static void LoadComponent(FrameworkElement fe, string componentId, bool selfCall = false)
        {
            // Don't load component in design mode
            var isDesignMode = (bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue;

            if (Application.Current == null || isDesignMode)
            {
                return;
            }

            //if (_isInitializing && !selfCall) {
            //    InitializationQueue.Enqueue(Tuple.Create(fe, componentId));
            //    return;
            //}

            //_isInitializing = true;

            var split            = componentId.Split(',');
            var resourceAssembly = Assembly.GetEntryAssembly();

            if (resourceAssembly == null)
            {
                return;
            }

            foreach (var value in split)
            {
                try {
                    var buffer = RuntimeUpdateHandler.FindBuffer(value);
                    if (buffer != null)
                    {
                        XamlHelper.InitializeComponent(fe, buffer, new Uri(value, UriKind.Relative));
                    }
                    else
                    {
                        XamlHelper.InitializeComponent(fe, value);
                    }
                } catch (Exception e) {
                    Debug.WriteLine("Failed to initialize with: " + value);
                    Debug.WriteLine(e.Message);
                }
            }

            //ProcessQueue();

            //_isInitializing = false;
        }
Exemplo n.º 2
0
        public static void ReceiveMessages(List <Message> messages)
        {
            var pageMessages = new List <Message>();

            foreach (var message in messages)
            {
                var targetId = message.TargetId;

                Buffers[targetId] = message.Buffer;

                if (!targetId.EndsWith(".fun.xaml", StringComparison.InvariantCultureIgnoreCase))
                {
                    pageMessages.Add(message);
                }
            }

            var affectedObjects = pageMessages.Where(page => Nodes.ContainsKey(page.TargetId))
                                  .Select(page => Nodes[page.TargetId])
                                  .ToList();
            var roots = FindRootsOnly(affectedObjects.SelectMany(b => b).ToList());
            var timer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(0.1)
            };

            foreach (var root in roots)
            {
                var    rootElement = root;
                string targetId;

                if (!ObjectToTarget.TryGetValue(rootElement, out targetId))
                {
                    continue;
                }

                var pageMessage = pageMessages.FirstOrDefault(p => p.TargetId == targetId);

                if (pageMessage == null)
                {
                    continue;
                }

                Debug.WriteLine("Updating '" + pageMessage.TargetId + "' as " + rootElement);

                UnregisterChildren(rootElement);

                CurrentlyUpdatedTargetId = pageMessage.TargetId;

                ClearElement(rootElement, pageMessage.TargetId, pageMessage.PropertyList);

                var fe = rootElement as FrameworkElement;

                if (fe != null)
                {
                    fe.SetValue(Control.BackgroundProperty, ConstructionBackground.Value);
                }

                EventHandler timerOnTick = null;
                timerOnTick = (sender, args) => {
                    timer.Tick -= timerOnTick;
                    if (fe != null)
                    {
                        fe.ClearValue(Control.BackgroundProperty);
                    }
                    XamlHelper.InitializeComponent(rootElement, pageMessage.Buffer, new Uri(pageMessage.TargetId, UriKind.Relative));
                };
                timer.Tick += timerOnTick;
            }
            timer.Start();
        }