Exemplo n.º 1
0
        public MainWindowViewModel(
            IZApi api,
            ILog logger,
            ISettingsService settingsService,
            IProcessService processService,
            IResolutionRoot kernel,
            IEventService eventService,
            IMainMenuService menuService,
            IUpdateService updateService,
            IGameService gameService,
            IDiscord discordPresence,

            IPageNavigator navigator,
            IApplicationState state,
            IViewModelSource viewModelSource,
            IDialogService dialogService,
            IDialogSystemBase dialogSystemBase,
            IBusyIndicatorBase busyIndicatorBase,
            IBusyIndicatorService busyIndicatorService)
        {
            _navigator            = navigator;
            _state                = state;
            _dialogSystemBase     = dialogSystemBase;
            _dialogService        = dialogService;
            _busyIndicatorBase    = busyIndicatorBase;
            _busyIndicatorService = busyIndicatorService;
            _eventService         = eventService;

            _menuService = menuService;

            _apiConnection   = api.Connection;
            _log             = logger;
            _settingsService = settingsService;
            _processService  = processService;
            _updateService   = updateService;
            _gameService     = gameService;
            _discordPresence = discordPresence;
            _api             = api;

            NonClientDataContext = viewModelSource.Create <WindowNonClientPartViewModel>();
            BottomBarDataContext = viewModelSource.Create <WindowBottomBarPartViewModel>();

            _apiConnection.ConnectionChanged += _apiConnectionConnectionChangedHandler;

            _zClientProcessTracker = new ZProcessTracker(_ZClientProcessName, TimeSpan.FromSeconds(3), true, processes => processes
                                                         .OrderByDescending(process => process.StartTime)
                                                         .First());
            _zClientProcessTracker.ProcessDetected += _zClientProcessDetectedHandler;
            _zClientProcessTracker.ProcessLost     += _zClientProcessLostHandler;

            api.Configure(new ZConfiguration {
                SynchronizationContext = SynchronizationContext.Current
            });

            _gameService.GameCreationError += _GameCreationErrorHandler;
        }
Exemplo n.º 2
0
        internal static void Main(string[] args)
        {
            // setup internal state
            _zloApi      = ZApi.Instance;
            _gameFactory = _zloApi.GameFactory;

            var logger = _zloApi.Logger;

            // configure logging
            logger.SetLogLevelFiltering(ZLogLevel.Debug | ZLogLevel.Warning | ZLogLevel.Error | ZLogLevel.Info);
            logger.LogMessage += (sender, messageArgs) => Console.WriteLine(messageArgs.Message);

            var connection = _zloApi.Connection;

            // configure api thread synchronization
            _zloApi.Configure(new ZConfiguration
            {
                SynchronizationContext = new SynchronizationContext()
            });

            Console.WriteLine("Connecting to ZClient...");

            // create connection
            var resetEvent = new ManualResetEvent(false);

            connection.ConnectionChanged += (sender, changedArgs) => resetEvent.Set();
            connection.Connect();

            // wait for connection
            resetEvent.WaitOne();

            if (_zloApi.Connection.IsConnected)
            {
                Console.WriteLine("Connected\n");

                // call async version of Main(...)
                MainAsync(args).GetAwaiter().GetResult();
            }
            else
            {
                Console.WriteLine("Cannot connect to ZClient\n");
            }

            Console.ReadKey();
        }