Пример #1
0
        internal async Task <bool> RunInternal(Dictionary <Type, object> viewModelsMapping, IPreviewer previewer)
        {
            if (isRunning)
            {
                return(true);
            }
            mainScheduler = TaskScheduler.FromCurrentSynchronizationContext();
            host          = await HttpHost.StartServer(this, Constants.DEFAULT_PORT, PORTS_RANGE);

            if (host == null)
            {
                Log.Error("Couldn't start server");
                return(false);
            }
            broadcaster = new DiscoveryBroadcaster(port, true);
            await broadcaster.Start();

            if (viewModelsMapping == null)
            {
                viewModelsMapping = new Dictionary <Type, object>();
            }
            if (previewer == null)
            {
                previewer = new Previewer(viewModelsMapping);
            }
            this.previewer = previewer;
            vm             = new VM();
            isRunning      = true;
            return(true);
        }
Пример #2
0
        public async Task <bool> Start()
        {
            host = await HttpHost.StartServer(this, Constants.DEFAULT_CLIENT_PORT, 1);

            if (host == null)
            {
                MessageService.ShowError($"XAMLator: Failed to start the server. There seems to be another instance of VS4MAC is running!");
                return(false);
            }
            try
            {
                listener = new UdpClient(Constants.DISCOVERY_BROADCAST_RECEIVER_PORT, AddressFamily.InterNetwork);
            }
            catch (Exception ex)
            {
                MessageService.ShowError($"XAMLator: Failed to start the discovery receiver", ex);
                Debug.WriteLine("XAMLator: Failed to listen: " + ex);
                listener = null;
            }
            if (listener != null)
            {
                thread = new Thread(Run);
                thread.Start();
            }
            running = true;
            return(true);
        }