コード例 #1
0
        /// <summary>
        /// Set new flight.
        /// </summary>
        /// <param name="flightName"></param>
        /// <param name="timeoutInMinutes"></param>
        public void SetFlight(string flightName, int timeoutInMinutes)
        {
            CodeContract.RequiresArgumentNotNullAndNotWhiteSpace(flightName, "flightName");
            if (timeoutInMinutes < 0)
            {
                throw new ArgumentException("Flight expiration timeout can't be negative", "timeoutInMinutes");
            }
            flightName = flightName.ToLowerInvariant();
            DateTimeOffset expiration = DateTimeOffset.UtcNow.AddMinutes(timeoutInMinutes);

            lock (lockObject)
            {
                IEnumerable <string> rawFlights = GetRawFlights();
                foreach (string item in rawFlights)
                {
                    FlightInformation flightInformation = FlightInformation.Parse(item);
                    if (flightInformation != null && flightInformation.Flight == flightName)
                    {
                        return;
                    }
                }
                SetRawFlights(rawFlights.Union(new string[1]
                {
                    new FlightInformation(flightName, expiration).ToString()
                }));
            }
        }
コード例 #2
0
        public void Start()
        {
            List <string> list = new List <string>();
            bool          flag = false;

            lock (lockObject)
            {
                foreach (string rawFlight in GetRawFlights())
                {
                    FlightInformation flightInformation = FlightInformation.Parse(rawFlight);
                    if (flightInformation != null && flightInformation.ExpirationTime > DateTimeOffset.UtcNow)
                    {
                        list.Add(rawFlight);
                    }
                    else
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    SetRawFlights(list);
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Raw flight data are in the format: "flight_name#yyyy-MM-dd HH:mm:ssZ".
 /// First part (before '#') is the flight name and second part (after '#') is the expiration date of the flight.
 /// Return clean set of the flight (without expired flights).
 /// </summary>
 /// <param name="rawFlights"></param>
 /// <returns></returns>
 private IEnumerable <string> ConvertRawDataToPlainFlights(IEnumerable <string> rawFlights)
 {
     foreach (string rawFlight in rawFlights)
     {
         FlightInformation flightInformation = FlightInformation.Parse(rawFlight);
         if (flightInformation != null && flightInformation.ExpirationTime > DateTimeOffset.UtcNow)
         {
             yield return(flightInformation.Flight);
         }
     }
 }