Exemplo n.º 1
0
 /// <summary>
 /// The get path.
 /// </summary>
 /// <param name="route">
 /// The route.
 /// </param>
 /// <param name="travelDate">
 /// The travel date.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 private string GetPath(RouteInfo route, DatePeriod travelDate)
 {
     return Path.Combine(this.GetPath(route), this.GetDatePeriodFolderName(travelDate));
 }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// The get path.
 /// </summary>
 /// <param name="routeInfo">
 /// The route info.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 private string GetPath(RouteInfo routeInfo)
 {
     return Path.Combine(this.BaseDataPath, routeInfo.Id.ToString(CultureInfo.InvariantCulture));
 }
Exemplo n.º 4
0
        /// <summary>
        /// The get travel dates.
        /// </summary>
        /// <param name="routeInfo">
        /// The route info.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List<DatePeriod> GetTravelDates(RouteInfo routeInfo)
        {
            string routePath = this.GetPath(routeInfo);
            var result = new List<DatePeriod>();

            if (Directory.Exists(routePath))
            {
                var dirs = Directory.GetDirectories(routePath);
                foreach (var d in dirs)
                {
                    var travelDate = this.GetDatePeriod(d);
                    if (travelDate != null)
                    {
                        result.Add(travelDate);
                    }
                }
            }

            return result;
        }
Exemplo n.º 5
0
        /// <summary>
        /// The get data files.
        /// </summary>
        /// <param name="routeInfo">
        /// The route info.
        /// </param>
        /// <param name="travelDate">
        /// The travel date.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List<string> GetDataFiles(RouteInfo routeInfo, DatePeriod travelDate)
        {
            var targetPath = this.GetPath(routeInfo, travelDate);
            var result = new List<string>();
            if (Directory.Exists(targetPath))
            {
                var files = Directory.GetFiles(targetPath, "*.csv");
                foreach (var f in files)
                {
                    var dataDate = this.GetDatePeriod(Path.GetFileNameWithoutExtension(f));
                    if (dataDate != null)
                    {
                        result.Add(f);
                    }
                }
            }

            return result;
        }
Exemplo n.º 6
0
        /// <summary>
        /// The get data file.
        /// </summary>
        /// <param name="routeInfo">
        /// The route info.
        /// </param>
        /// <param name="travelDate">
        /// The travel date.
        /// </param>
        /// <param name="dataPeriod">
        /// The data period.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string GetDataFile(RouteInfo routeInfo, DatePeriod travelDate, DatePeriod dataPeriod)
        {
            var dataFiles = this.GetDataFiles(routeInfo, travelDate);
            if (dataFiles != null)
            {
                foreach (var f in dataFiles)
                {
                    var dataDate = this.GetDatePeriod(Path.GetFileNameWithoutExtension(f));
                    if (dataDate != null && dataPeriod.IsEquals(dataDate))
                    {
                        return f;
                    }
                }
            }

            return null;
        }
Exemplo n.º 7
0
        /// <summary>
        /// The get data dates.
        /// </summary>
        /// <param name="routeInfo">
        /// The route info.
        /// </param>
        /// <param name="travelDate">
        /// The travel date.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List<DatePeriod> GetDataDates(RouteInfo routeInfo, DatePeriod travelDate)
        {
            var dataFiles = this.GetDataFiles(routeInfo, travelDate);
            var result = new List<DatePeriod>();
            if (dataFiles != null)
            {
                foreach (var f in dataFiles)
                {
                    var dataDate = this.GetDatePeriod(Path.GetFileNameWithoutExtension(f));
                    if (dataDate != null)
                    {
                        result.Add(dataDate);
                    }
                }
            }

            return result;
        }