예제 #1
0
 /// <summary>
 /// The get data dates.
 /// </summary>
 /// <param name="route">
 /// The route.
 /// </param>
 /// <param name="travelDate">
 /// The travel date.
 /// </param>
 /// <returns>
 /// The <see cref="List"/>.
 /// </returns>
 public List<DatePeriod> GetDataDates(StorageRoute route, DatePeriod travelDate)
 {
     var routeInfo = this.SaveRoute(route);
     return this.GetDataDates(routeInfo, travelDate);
 }
예제 #2
0
        /// <summary>
        /// The get route.
        /// </summary>
        /// <param name="dataPath">
        /// The data path.
        /// </param>
        /// <returns>
        /// The <see cref="StorageRoute"/>.
        /// </returns>
        private StorageRoute GetRoute(string dataPath)
        {
            var d = Path.GetFileName(dataPath);
            var parts = d.Split('|');
            if (parts.Length == 2)
            {
                var newRoute = new StorageRoute(parts[0].Trim(), parts[1].Trim());
                return newRoute;
            }

            return null;
        }
예제 #3
0
        /// <summary>
        /// Save the route to the catalogue
        /// </summary>
        /// <param name="route">
        /// Travel route
        /// </param>
        /// <returns>
        /// The saved route's information
        /// </returns>
        private RouteInfo SaveRoute(StorageRoute route)
        {
            var logger = AppContext.Logger;
            int max = 0;

            using (var fs = File.Open(this.CatalogFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                var formatter = new TolerantBinaryFormatter(logger);
                try
                {
                    while (fs.Position != fs.Length)
                    {
                        var existRoute = formatter.Deserialize(fs) as RouteInfo;
                        if (existRoute != null)
                        {
                            if (existRoute.Id > max)
                            {
                                max = existRoute.Id;
                            }

                            if (existRoute.Route.Equals(route))
                            {
                                return existRoute;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Failed to read route information: " + ex.Message);
                    fs.SetLength(0);
                    fs.Position = 0;
                }

                var newItem = new RouteInfo(++max, route);
                formatter.Serialize(fs, newItem);

                return new RouteInfo(max, route);
            }
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RouteInfo"/> class.
 /// </summary>
 /// <param name="id">
 /// The id.
 /// </param>
 /// <param name="route">
 /// The route.
 /// </param>
 public RouteInfo(int id, StorageRoute route)
 {
     this.Id = id;
     this.Route = route;
 }