Пример #1
0
        private static void RegisterPropertyChanged(BindableObject dependencyObject, object oldValue, object newValue)
        {
            var fe = dependencyObject as Element;

            if (fe == null)
            {
                return;
            }

            StartListenerIfNeeded();

            var componentId = (string)newValue;

            if (!componentId.Equals(RuntimeUpdateHandler.CurrentlyUpdatedTargetId, StringComparison.OrdinalIgnoreCase))
            {
                Device.BeginInvokeOnMainThread(() => {
                    var initialPropertyList = RuntimeUpdateHandler.GetInitialPropertyList(componentId) ?? "";
                    RuntimeUpdateHandler.ClearElement(fe, componentId, initialPropertyList);
                    LoadComponent(fe, componentId);
                });
            }

            Device.BeginInvokeOnMainThread(() => {
                RuntimeUpdateHandler.Register(fe, componentId);
            });
        }
Пример #2
0
        private static void RegisterPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            StartListenerIfNeeded();

            var fe = dependencyObject as FrameworkElement;

            if (fe == null)
            {
                return;
            }

            var componentId       = (string)eventArgs.NewValue;
            var alreadyRegistered = RuntimeUpdateHandler.IsRegistered(componentId);

            if (alreadyRegistered && !componentId.Equals(RuntimeUpdateHandler.CurrentlyUpdatedTargetId, StringComparison.InvariantCultureIgnoreCase))
            {
                AfterInitialize(fe, f => {
                    var initialPropertyList = RuntimeUpdateHandler.GetInitialPropertyList(componentId) ?? "";
                    RuntimeUpdateHandler.ClearElement(fe, componentId, initialPropertyList);
                    LoadComponent(f, componentId);
                });
            }

            AfterLoad(fe, f => {
                RuntimeUpdateHandler.Register(f, componentId);
            });
        }
Пример #3
0
        private static void LoadBamlImpl(object rootObject, Func <Stream> streamFactory, Uri resourceLocator)
        {
            _isInitializing = true;

            try {
                using (var stream = streamFactory()) {
                    var uri           = new Uri(new Uri("pack://application:,,,", UriKind.Absolute), resourceLocator);
                    var parserContext = new ParserContext {
                        BaseUri = uri
                    };
                    var xamlReaderType = typeof(XamlReader);
                    var loadBamlMethod = xamlReaderType.GetMethod("LoadBaml", BindingFlags.NonPublic | BindingFlags.Static);

                    loadBamlMethod.Invoke(null, new object[] { stream, parserContext, rootObject, true });
                }
            } catch (Exception e) {
                var frameworkElement = rootObject as FrameworkElement;
                RuntimeUpdateHandler.ClearChildren(frameworkElement);

                if (frameworkElement != null)
                {
                    frameworkElement.SetValue(Control.BackgroundProperty, Brushes.Red);
                }

                try {
                    if (frameworkElement != null)
                    {
                        frameworkElement.EndInit();
                    }
                } catch { }

                if (e is TargetInvocationException && e.InnerException != null)
                {
                    Debug.WriteLine("Runtime update failed: " + e.InnerException);
                    MessageBox.Show(e.InnerException.ToString());
                }
                else
                {
                    Debug.WriteLine("Runtime update failed: " + e);
                    MessageBox.Show(e.ToString());
                }
            }

            if (InitializationQueue.Count > 0)
            {
                var nextInitializer = InitializationQueue.Dequeue();
                nextInitializer();
            }
            else
            {
                _isInitializing = false;
            }
        }
Пример #4
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;
        }
Пример #5
0
        private static void LoadComponent(Element fe, string componentId, bool selfCall = false)
        {
            var split = componentId.Split(',');

            foreach (var value in split)
            {
                try {
                    var buffer = RuntimeUpdateHandler.FindBuffer(value);
                    if (buffer != null)
                    {
                        RuntimeUpdateHandler.InitializeComponent((View)fe, buffer);
                    }
                    else
                    {
                        fe.LoadFromXaml(fe.GetType());
                    }
                } catch (Exception e) {
                    Debug.WriteLine("Failed to initialize with: " + value);
                    Debug.WriteLine(e.Message);
                }
            }
        }
Пример #6
0
        private void ParserOnMessageReceived(object sender, ListenerParserEventArgs eventArgs)
        {
            var messages = eventArgs.Messages;

            MainThread.Run(() => RuntimeUpdateHandler.ReceiveMessages(messages));
        }