Example #1
0
        public void DoCheck(string baseAsset, string xamlText)
        {
            _appDir = new FileInfo(baseAsset).Directory.FullName;
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            foreach (var asm in Directory.GetFiles(_appDir).Where(f => f.ToLower().EndsWith(".dll") || f.ToLower().EndsWith(".exe")))
            {
                try
                {
                    Assembly.LoadFrom(asm);
                }
                catch (Exception)
                {
                }
            }
            var dic = new Dictionary <string, object>();
            var api = new DesignerApi(dic)
            {
                OnResize = OnResize, OnWindowCreated = OnWindowCreated
            };

            LookupStaticMethod("Avalonia.DesignerSupport.DesignerAssist", "Init").Invoke(null, new object[] { dic });

            api.UpdateXaml2(new DesignerApiXamlFileInfo
            {
                Xaml         = xamlText,
                AssemblyPath = baseAsset
            }.Dictionary);
            if (_window == IntPtr.Zero)
            {
                throw new Exception("Something went wrong");
            }

            SendMessage(_window, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
        }
Example #2
0
        public void DoCheck(string baseAsset, string xamlText)
        {
            _appDir = new FileInfo(baseAsset).Directory.FullName;
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            foreach (var asm in Directory.GetFiles(_appDir).Where(f => f.ToLower().EndsWith(".dll") || f.ToLower().EndsWith(".exe")))
                try
                {
                    Assembly.LoadFrom(asm);
                }
                catch (Exception e)
                {
                }
            var dic = new Dictionary<string, object>();
            var api = new DesignerApi(dic) { OnResize = OnResize, OnWindowCreated = OnWindowCreated };
            LookupStaticMethod("Avalonia.DesignerSupport.DesignerAssist", "Init").Invoke(null, new object[] { dic });
            
            api.UpdateXaml2(new DesignerApiXamlFileInfo
            {
                Xaml = xamlText,
                AssemblyPath = baseAsset
            }.Dictionary);
            if (_window == IntPtr.Zero)
                throw new Exception("Something went wrong");

            SendMessage(_window, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
        }
Example #3
0
        private void DoInit(string targetExe, StringBuilder logger)
        {
            _appDir = Path.GetFullPath(Path.GetDirectoryName(targetExe));
            Directory.SetCurrentDirectory(_appDir);
            Action <string> log = s =>
            {
                UpdateState(s);
                logger.AppendLine(s);
            };

            log("Loading assemblies from " + _appDir);
            var asms = new List <Assembly>();

            foreach (var asm in Directory.GetFiles(_appDir).Where(f => f.ToLower().EndsWith(".dll") || f.ToLower().EndsWith(".exe")))
            {
                try
                {
                    log("Trying to load " + asm);
                    asms.Add(Assembly.LoadFrom(asm));
                }
                catch (Exception e)
                {
                    logger.AppendLine(e.ToString());
                }
            }

            log("Looking up Perspex types");
            BuildMetadataAndSendMessageAsync(asms);

            log("Initializing built-in designer");
            var dic = new Dictionary <string, object>();

            Api = new DesignerApi(dic)
            {
                OnResize = OnResize, OnWindowCreated = OnWindowCreated
            };
            LookupStaticMethod("Perspex.DesignerSupport.DesignerAssist", "Init").Invoke(null, new object[] { dic });

            _window = new Control
            {
                Controls =
                {
                    new ElementHost()
                    {
                        Child = new InProcDesignerView(_appModel),
                        Dock  = DockStyle.Fill
                    }
                }
            };
            _window.CreateControl();

            new Timer {
                Interval = 200, Enabled = true
            }.Tick += delegate { XamlUpdater(); };
            _comm.SendMessage(new WindowCreatedMessage(_window.Handle));
            _initSuccess = true;
        }