示例#1
0
        private Task WriteToJsonFileAsync(SimVarCollection flightData)
        {
            var json = flightData.ToJson();

            //Console.Write(json + Environment.NewLine);
            File.WriteAllText("flight.json", json, Encoding.UTF8);

            _currentSimVariables   = null;
            _currentPlaneVariables = null;
            _currentPlaneMetadata  = null;
            return(Task.CompletedTask);
        }
示例#2
0
        public async Task WriteToStoreAsync(
            PlaneMetadatas?metadata                 = null,
            PlaneVariables?planeVariables           = null,
            SimulationVariables?simulationVariables = null,
            GpsVariables?gpsVariables               = null,
            bool?planeCrashed = null,
            bool?planeLanded  = null)
        {
            if (planeCrashed.HasValue && planeCrashed.Value ||
                planeLanded.HasValue && planeLanded.Value)
            {
                await EndFlightAsync(planeCrashed, planeLanded);
            }

            if (metadata.HasValue)
            {
                _currentPlaneMetadata = metadata.Value;
            }

            if (planeVariables.HasValue)
            {
                _currentPlaneVariables = planeVariables.Value;
            }

            if (simulationVariables.HasValue)
            {
                _currentSimVariables = simulationVariables.Value;
            }

            if (gpsVariables.HasValue)
            {
                _currentGpsVariables = gpsVariables.Value;
            }

            if (_currentPlaneMetadata.HasValue &&
                _currentPlaneVariables.HasValue &&
                _currentSimVariables.HasValue &&
                _currentGpsVariables.HasValue)
            {
                var flightData = new SimVarCollection(
                    _currentPlaneMetadata.Value,
                    _currentPlaneVariables.Value,
                    _currentSimVariables.Value,
                    _currentGpsVariables.Value);

                await WriteToJsonFileAsync(flightData);
            }
        }