protected override void ConfigureIoc(IContainerBuilder builder)
        {
            RemoteBootstrapper.ConfigureIoc(builder);

            builder.PerDependency <MainPageViewModel>();
            builder.PerDependency <FirstPageViewModel>();
            builder.PerDependency <SecondPageViewModel>();
            builder.PerDependency <RootMasterDetailPageViewModel>();
            builder.PerDependency <MasterPageViewModel>();
            builder.PerDependency <DetailPageViewModel>();
            builder.PerDependency <SelectedItemPageViewModel>();
            builder.PerDependency <DialogsRootPageViewModel>();
            builder.PerDependency <ModalPageViewModel>();
            builder.PerDependency <SecondModalPageViewModel>();
            builder.PerDependency <RootFrameNavigationPageViewModel <DrillLevel1PageViewModel> >();
            builder.PerDependency <DrillLevel1PageViewModel>();
            builder.PerDependency <DrillLevel2PageViewModel>();
            builder.PerDependency <AsyncCommandsPageViewModel>();
            builder.PerDependency <PermissionsPageViewModel>();
            builder.PerDependency <ValidationPageViewModel>();
            builder.PerDependency <PaginationSearchPageViewModel>();

            builder.PerDependency <ViewModelFactoryService, IViewModelFactoryService>();

            builder.Singleton <PlaygroundViewLocator, IFormsViewLocator>(IfRegistered.Replace);
        }
        public async Task Stop()
        {
            StopListeners();

            if (_bootstrapper != null)
            {
                _bootstrapper.Stop();
                _bootstrapper = null;
            }

            if (_appDomain != null)
            {
                AppDomain.Unload(_appDomain);
                _appDomain = null;
            }

            foreach (var host in _hosts)
            {
                await host.TearDown(_destination).ConfigureAwait(false);
            }

            if (Directory.Exists(_destination))
            {
                new DirectoryInfo(_destination).DeleteDirectoryAndChildren();
            }
        }
        public async Task Start()
        {
            if (_appDomain != null || _bootstrapper != null)
                await Stop().ConfigureAwait(false);

            StopListeners();

            if (Directory.Exists(_destination))
                new DirectoryInfo(_destination).DeleteDirectoryAndChildren();

            DirectoryCopy(_source, _destination);

            foreach (var host in _hosts)
                await host.Prepare(_destination).ConfigureAwait(false);

            TransformConfigurationsIn(_destination, ".config", _environment);
            TransformConfigurationsIn(_destination, ".xml", _environment);

            _appDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), null, new AppDomainSetup
            {
                ConfigurationFile = $"{ApplicationName}.dll.config",
                PrivateBinPath = _destination,
                ApplicationBase = _destination
            });

            _bootstrapper = (RemoteBootstrapper)_appDomain
                .CreateInstanceAndUnwrap(typeof(RemoteBootstrapper).Assembly.FullName, typeof(RemoteBootstrapper).FullName);

            _bootstrapper.Initialize(_destination);
            _bootstrapper.Start(_environment, _hostArguments);

            var listener = new FileListener();

            var extensionsNeedingReload = new List<string>
            {
                ".dll",
                ".exe",
                ".config",
                ".xml"
            };

            listener.StartListening(_source, "*", async x =>
            {
                var extension = Path.GetExtension(x);
                if (extensionsNeedingReload.Contains(extension))
                {
                    await Recycle().ConfigureAwait(false);

                    return;
                }

                var relativePath = x.Replace(_source, "");

                if (relativePath.StartsWith("\\"))
                    relativePath = relativePath.Substring(1);

                var newPath = Path.Combine(_destination, relativePath);

                for (var i = 0; i < 10; i++)
                {
                    try
                    {
                        if (ShouldCopy(Path.GetDirectoryName(x)))
                            File.Copy(x, newPath, true);

                        break;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Failed copying file: {ex.Message}");
                        await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
                    }
                }
            });

            _fileListeners.Add(listener);
        }
        public async Task Stop()
        {
            StopListeners();

            if (_bootstrapper != null)
            {
                _bootstrapper.Stop();
                _bootstrapper = null;
            }

            if (_appDomain != null)
            {
                AppDomain.Unload(_appDomain);
                _appDomain = null;
            }

            foreach (var host in _hosts)
                await host.TearDown(_destination).ConfigureAwait(false);

            if (Directory.Exists(_destination))
                new DirectoryInfo(_destination).DeleteDirectoryAndChildren();
        }
        public async Task Start()
        {
            if (_appDomain != null || _bootstrapper != null)
            {
                await Stop().ConfigureAwait(false);
            }

            StopListeners();

            if (Directory.Exists(_destination))
            {
                new DirectoryInfo(_destination).DeleteDirectoryAndChildren();
            }

            DirectoryCopy(_source, _destination);

            foreach (var host in _hosts)
            {
                await host.Prepare(_destination).ConfigureAwait(false);
            }

            TransformConfigurationsIn(_destination, ".config", _environment);
            TransformConfigurationsIn(_destination, ".xml", _environment);

            _appDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), null, new AppDomainSetup
            {
                ConfigurationFile = $"{ApplicationName}.dll.config",
                PrivateBinPath    = _destination,
                ApplicationBase   = _destination
            });

            _bootstrapper = (RemoteBootstrapper)_appDomain
                            .CreateInstanceAndUnwrap(typeof(RemoteBootstrapper).Assembly.FullName, typeof(RemoteBootstrapper).FullName);

            _bootstrapper.Initialize(_destination);
            _bootstrapper.Start(_environment, _hostArguments);

            var listener = new FileListener();

            var extensionsNeedingReload = new List <string>
            {
                ".dll",
                ".exe",
                ".config",
                ".xml"
            };

            listener.StartListening(_source, "*", async x =>
            {
                var extension = Path.GetExtension(x);
                if (extensionsNeedingReload.Contains(extension))
                {
                    await Recycle().ConfigureAwait(false);

                    return;
                }

                var relativePath = x.Replace(_source, "");

                if (relativePath.StartsWith("\\"))
                {
                    relativePath = relativePath.Substring(1);
                }

                var newPath = Path.Combine(_destination, relativePath);

                for (var i = 0; i < 10; i++)
                {
                    try
                    {
                        if (ShouldCopy(Path.GetDirectoryName(x)))
                        {
                            File.Copy(x, newPath, true);
                        }

                        break;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Failed copying file: {ex.Message}");
                        await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
                    }
                }
            });

            _fileListeners.Add(listener);
        }