Esempio n. 1
0
        public void StartFlightSpy(Flight flight)
        {
            log.Info("Starting up a new ascend spy");
            this._ascendActive = true;
            this._flight = flight;
            this._planetname = FlightGlobals.ActiveVessel.mainBody.name;
            this._threshold = PlanetThresholdManager.ThresholdForPlanet(this._planetname);

            flight.StartAscend(this._planetname, FlightLogger.met, Util.VesselHeightFromTerrain(FlightGlobals.ActiveVessel));
        }
Esempio n. 2
0
        /// <summary>
        /// Basic serialize method
        /// </summary>
        /// <param name="flight"></param>
        /// <param name="path"></param>
        /// <param name="overwrite"></param>
        /// <returns>true if the writing succeeded</returns>
        public static bool SerializeToFile(Flight flight, string path, bool overwrite)
        {
            if (flight == null)
            {
                throw new ArgumentException("Flight cannot be null");
            }

            if (File.Exists(path) && !overwrite)
            {
                return false;
            }

            using (var file = File.Create(path))
            {
                Serializer.Serialize(file, flight);
            }

            return true;
        }
Esempio n. 3
0
        public bool PreRequisitesAreMet(Flight flight)
        {
            bool preReqsAreMet = true;

            bool planetManagerSetUp = PlanetThresholdManager.CorrectlySetUp;

            if(!planetManagerSetUp)
            {
                log.Error("Could not set up the FlightAscendListener because the planet threshold manager did get set up correctly");
                preReqsAreMet = false;
            }

            if(flight.IsAnyAscendActive)
            {
                log.Error("Could not set up the FlightAscendListener because the flight already has an active ascend");
                preReqsAreMet = false;
            }

            return preReqsAreMet;
        }
Esempio n. 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="flight"></param>
        /// <returns>true if the flight has been persisted</returns>
        private bool StartPersistFlightTask(Flight flight)
        {
            if (flight == null)
            {
                log.Warn("A null value flight was passed into the persist flight method");
                return false ;
            }
            else if (!AttemptToPersistFlight(flight))
            {
                return true;
            }

            return false;
        }
Esempio n. 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="flight"></param>
        /// <returns>true if the flight has not been persisted</returns>
        private bool AttemptToPersistFlight(Flight flight)
        {
            log.Info(string.Format("Attempting to insert flight {0} into databse", flight.VesselName));
            bool failed = false;
            try
            {
                _connection.Open();

                using (SqlCommand command = new SqlCommand("INSERT INTO FlightData (InsertTimeStamp, SenderHashID, FlightData) VALUES (GetDate(), @hashID, @flight)", _connection))
                {
                    command.Parameters.AddWithValue("@hashID", _id);
                    SqlParameter param = command.Parameters.Add("@flight", SqlDbType.VarBinary);
                    param.Value = ProtoBufWrapper.ToByteArray(flight);

                    command.ExecuteNonQuery();
                }
            }
            catch (SqlException exception)
            {
                log.Error("Something went wrong while persisting the flight", exception);
               failed = true;
            }
            finally
            {
                _connection.Close();
            }
            log.Info(string.Format("Result of attempt to persist flight operation for flight {0} is {1}", flight.VesselName, !failed));
            return failed;
        }
Esempio n. 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="flight"></param>
        /// <returns>true if the flight has been persisted</returns>
        public bool PersistFlight(Flight flight)
        {
            if (!ConnectionIsValid)
            {
                log.Warn(string.Format("Connection invalid, cannot persist flight {0}", flight.VesselName));
                return false;
            }

            return StartPersistFlightTask(flight);
        }
Esempio n. 7
0
        public static void PersistFlightToSandbox(Flight flight)
        {
            log.Info(string.Format("Persisting flight for vessel {0}", flight.VesselName));

            string fullPath = FilenameForFlight(flight);

            KSP.IO.BinaryWriter writer = KSP.IO.BinaryWriter.CreateForType<Manager>(fullPath);
            byte[] flightData = ProtoBufWrapper.ToByteArray(flight);

            log.Debug(string.Format("Persisting the flight to the following file {0}", fullPath));

            try
            {
                writer.Write(flightData);
                    log.Info(string.Format("Succesfully persisted flight to {0}", fullPath));
                    ConfigurationProvider.Configuration.AddPersistedFlight(fullPath);
            }
            catch (Exception ex)
            {
                log.Fatal(string.Format("Error thrown wile trying to persist flight to {0}", fullPath), ex);
                throw;
            }
        }
Esempio n. 8
0
        private static string FilenameForFlight(Flight flight)
        {
            string fileName = string.Format("Flight {0}", flight.FlightStart.ToString("dd_mm_yyyy mm-HH-ss"));

            string fullPath = string.Format("{0}.{1}", fileName, EXTENSION);
            return fullPath;
        }
Esempio n. 9
0
        public static void RemoveFlightFromSandbox(Flight flight)
        {
            log.Info(string.Format("Deleting a flight for vessel {0}", flight.VesselName));
            string fullPath = FilenameForFlight(flight);

            if(File.Exists<Manager>(fullPath))
            {
                File.Delete<Manager>(fullPath);

                if(!File.Exists<Manager>(fullPath))
                {
                    log.Info("Flight successfuly removed");
                    lock (_persistedFlightsLock)
                    {
                        ConfigurationProvider.Configuration.RemovePersistedFlight(fullPath);
                        PersistedFlights.Remove(flight);
                    }
                }
                else
                {
                    log.Warn(string.Format("Flight {0} was not properly removed. Path: {1}", flight.VesselName, fullPath));
                }
            }
            else
            {
                log.Warn(string.Format("Flight can not be found at path {0}", fullPath));
                ConfigurationProvider.Configuration.RemovePersistedFlight(fullPath);
            }
        }
Esempio n. 10
0
        void FlightSpyStarter_FlightStart()
        {
            _metAtStart = FlightLogger.met;
            string vesselName = FlightGlobals.ActiveVessel.name;
            log.Info(string.Format("Creating a new flight with name {0} and type {1}", vesselName, FlightGlobals.ActiveVessel.protoVessel.vesselType));
            _flight = new Flight(vesselName, FlightGlobals.ActiveVessel.protoVessel.vesselType.ToString());

            log.Debug("Looping through the flight spies for their preReqs");

            for (int i = 0; i < this._registeredFlightSpies.Count; i++)
            {
                if(this._registeredFlightSpies[i].PreRequisitesAreMet(_flight))
                {
                    IFlightSpy flightSpy = this._registeredFlightSpies[i];

                    if(flightSpy.ShouldStartFlightSpy())
                    {
                        log.InfoFormat("Flight spy '{0}' met pre reqs and met the conditions for starting it. Activating it and adding it to the list of active flight spies", flightSpy.ToString());
                        flightSpy.StartFlightSpy(this._flight);
                        flightSpy.Update();
                        this._activeFlightSpies.Add(new Tuple<double, IFlightSpy>(0, flightSpy));
                    }
                    else
                    {
                        log.InfoFormat("Flight spy '{0}' met pre reqs, adding it to the list of valid flight spies", flightSpy.ToString());
                        this._validFlightSpies.Add(new Tuple<double, IFlightSpy>(0, flightSpy));
                    }
                }
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Basic serialize method, won't override if the file already exists
 /// </summary>
 /// <param name="flight"></param>
 /// <param name="path"></param>
 /// <returns>true if the operation succeeded false if it didn't</returns>
 public static bool SerializeToFile(Flight flight, string path)
 {
     return SerializeToFile(flight, path, false);
 }
Esempio n. 12
0
        /// <summary>
        /// Serializes the given flight object to a byte array
        /// </summary>
        /// <param name="flight"></param>
        /// <returns></returns>
        public static byte[] ToByteArray(Flight flight)
        {
            if (flight == null)
            {
                throw new ArgumentException("Flight cannot be null");
            }

            byte[] data;
            using (var ms = new MemoryStream())
            {
                Serializer.Serialize(ms, flight);
                data = ms.ToArray();
            }

            return data;
        }