Example #1
0
 /// <summary>
 /// TODO, this file doesn't exist.
 /// </summary>
 private void UpdatePreviousIdCount()
 {
     if (this.OldNumbersCount > this.OldNumbersCountUpdate)
     {
         DialogService dialogService = new DialogService();
         if (dialogService.ShowDialog("New value is less then the old one, this may cause loss of data. Confirm?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
         {
             if (WriteFile(BasePathReader.GetBasePath() +
                           StaticResources.miscellaneousPath +
                           StaticResources.FileNameOldNumbersAvailable,
                           this.OldNumbersCountUpdate.ToString(),
                           false))
             {
                 this.OldNumbersCount = this.OldNumbersCountUpdate;
             }
         }
     }
     else
     {
         if (WriteFile(BasePathReader.GetBasePath() +
                       StaticResources.miscellaneousPath +
                       StaticResources.FileNameOldNumbersAvailable,
                       this.OldNumbersCountUpdate.ToString(),
                       false))
         {
             this.OldNumbersCount = this.OldNumbersCountUpdate;
         }
     }
     //    }
     //  }
     //}
 }
Example #2
0
        /// <summary>
        /// saves the current set of mileage details.
        /// </summary>
        public void SaveMileageDetails()
        {
            StreamWriter  writer       = null;
            string        basePath     = BasePathReader.GetBasePath();
            List <string> mileageLines = new List <string>();

            // Make a back up of the Milage file.
            System.IO.File.Copy(basePath + StaticResources.mileagePath + "Milage.txt",
                                basePath + StaticResources.mileagePath + "Milage_backup.txt",
                                true);

            foreach (RouteDetailsType route in this.routes)
            {
                mileageLines.Add(route.ToString());
            }

            mileageLines.Sort();

            using (writer = new StreamWriter(basePath + StaticResources.mileagePath + "Milage.txt"))
            {
                foreach (string line in mileageLines)
                {
                    writer.WriteLine(line);
                }
            }

            // TODO - why initialise
            //this.InitialiseMileageDetails();
        }
Example #3
0
        // ---------- ---------- ---------- ---------- ---------- ----------
        // The following methods are used to search through the raw data
        //   and compile the lists of first examples. They will be used
        //   by the configuration form.
        // ---------- ---------- ---------- ---------- ---------- ----------

        /// <summary>
        /// Search though everything to determine a complete list of first
        ///   examples
        /// </summary>
        public void RunSearchAll()
        {
            string[] dirNamesArray = System.IO.Directory.GetDirectories(BasePathReader.GetBasePath() + StaticResources.baPath);
            string   dirName       = string.Empty;
            int      currentYear   = 0;

            m_listNumber   = new List <FirstExampleType>();
            m_listLocation = new List <FirstExampleType>();

            // looping through years
            for (int index = 0; index < dirNamesArray.Count(); ++index)
            {
                dirName = dirNamesArray[index].Substring(dirNamesArray[index].LastIndexOf('\\') + 1);
                if (int.TryParse(dirName, out currentYear))
                {
                    string[] fileNamesArray = System.IO.Directory.GetFiles(dirNamesArray[index]);
                    SearchThroughSingleYear(currentYear, fileNamesArray);
                }
            }

            FirstExampleIOController firstExampleController = FirstExampleIOController.GetInstance();

            firstExampleController.WriteFileNumber(m_listNumber);
            firstExampleController.WriteFileLocation(m_listLocation);
        }
Example #4
0
        ///// ---------- ---------- ---------- ---------- ---------- ----------
        ///// <name>refreshMileageDetails</name>
        ///// <date>09/12/12</date>
        ///// <summary>
        /////   reset everything
        ///// </summary>
        ///// ---------- ---------- ---------- ---------- ---------- ----------
        //private void RefreshMileageDetails()
        //{
        //  fromStation.Clear();
        //  toStation.Clear();
        //  miles.Clear();
        //  chains.Clear();
        //  viaRoute.Clear();
        //  mileageKey.Clear();

        //  InitialiseMileageDetails();
        //}

        /// <summary>
        ///   Initialise the mileages details.
        /// </summary>
        private void InitialiseMileageDetails()
        {
            routes = new List <RouteDetailsType>();

            using (StreamReader reader = new StreamReader(BasePathReader.GetBasePath() +
                                                          StaticResources.mileagePath +
                                                          "Milage.txt"))
            {
                string currentLine = string.Empty;
                currentLine = reader.ReadLine();
                while (currentLine != null)
                {
                    RouteDetailsType newRoute = new RouteDetailsType(currentLine);
                    if (newRoute.From != null)
                    {
                        this.routes.Add(newRoute);
                    }

                    //string[] cells = currentLine.Split('\t');

                    //fromStation.Add(cells[0]);
                    //toStation.Add(cells[1]);
                    //miles.Add(cells[2]);
                    //chains.Add(cells[3]);
                    //viaRoute.Add(cells[4]);
                    //mileageKey.Add(cells[5]);

                    currentLine = reader.ReadLine();
                }
            }
        }
Example #5
0
        /// <summary>
        ///   Run a report based on a stn. It counts the number of other
        ///     stns visited from the given stn across all records.
        /// </summary>
        /// <param name="stn">stn name</param>
        /// <param name="fullList">full list of locations</param>
        /// <returns>is successful</returns>
        public static ReportCounterManager <LocationCounter> RunSingleStnGeneralReport(
            string stn,
            bool fullList)
        {
            string[] dirNamesArray =
                System.IO.Directory.GetDirectories(
                    BasePathReader.GetBasePath() + StaticResources.baPath);

            ReportCounterManager <LocationCounter> locationTotals =
                LocationReportFactory.CreateLocations();

            for (int i = 0; i < dirNamesArray.Count(); ++i)
            {
                // get directory name from the path and convert it into it's integer value.
                string dirName = dirNamesArray[i].Substring(dirNamesArray[i].LastIndexOf('\\') + 1);
                LocationReportFactory.UpdateStnsForYear(
                    locationTotals,
                    dirName,
                    stn);
            }

            if (!fullList)
            {
                locationTotals.RemoveEmptyClasses();
            }

            return(locationTotals);

            //string writeName = $"{stn}_Report_Gen_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv";
            //string faultMessage = $"ReportBuilder: ReportBuilder: Failed to write General Stn Report for {stn}.";

            //locationTotals.WriteCSVFile(
            //  writeName,
            //  faultMessage);
        }
Example #6
0
        /// <summary>
        ///   Creates a file in the location indicated by the path and
        ///     filename. It creates the dir as well if necessary.
        ///   The column lists should be the same size, the method writes
        ///     comma separated lines based on the columns.
        /// </summary>
        /// <param name="path">file path</param>
        /// <param name="fileName">file name</param>
        /// <param name="lines">contents to write to the file</param>
        /// <returns name="success">success flag</returns>
        public void WriteCSVFile(
            string fileName,
            string faultMessage)
        {
            string path = BasePathReader.GetBasePath() + StaticResources.reportPath;

            // create directory if it doesn't exist
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            try
            {
                using (StreamWriter sw = new StreamWriter(path + fileName))
                {
                    foreach (ICsvOut line in this.CounterCollection)
                    {
                        sw.WriteLine(line.CsvOut);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.WriteLog("ReportFactoryCommon: Report: " + ex.ToString());
                Logger.Instance.WriteLog(faultMessage);
            }
        }
Example #7
0
        /// <summary>
        /// Build the file path.
        /// </summary>
        /// <param name="year">file year</param>
        /// <param name="month">file month</param>
        /// <param name="check">check to see if this file exists, return empty string if it doesn't</param>
        /// <returns>path to file</returns>
        private static string BuildFilePath(
            int year,
            int month,
            bool check = true)
        {
            string directory =
                $"{BasePathReader.GetBasePath()}{StaticResources.baPath}{year}";
            string filePath =
                $"{directory}\\{filePrefix}{month.ToString(monthFormat)}.txt";

            if (check)
            {
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                if (!File.Exists(filePath))
                {
                    File.Create(filePath).Dispose();
                }
            }

            return(filePath);
        }
Example #8
0
        /// <summary>
        ///   Run a stn report. It counts the number of occurrences of each
        ///     stn across all records.
        /// </summary>
        /// <returns>is successful</returns>
        public static ReportCounterManager <LocationCounter> RunStnGeneralReport()
        {
            string[] dirNamesArray =
                System.IO.Directory.GetDirectories(
                    $"{BasePathReader.GetBasePath()}{StaticResources.baPath}");

            ReportCounterManager <LocationCounter> locationTotals =
                LocationReportFactory.CreateLocations();

            for (int index = 0; index < dirNamesArray.Count(); ++index)
            {
                // get directory name from the path and convert it into it's integer value.
                string dirName =
                    dirNamesArray[index].Substring(
                        dirNamesArray[index].LastIndexOf('\\') + 1);
                LocationReportFactory.UpdateStnsForYear(
                    locationTotals,
                    dirName);
            }

            return(locationTotals);
            //locationTotals.WriteCSVFile(
            //  $"StnReport_Gen_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv",
            //  "ReportBuilder: Failed to write General Stn Report.");
        }
        /// <date>10/03/19</date>
        /// <summary>
        /// Determine the full file path
        /// </summary>
        /// <param name="className">name of the class the unit is part of</param>
        /// <param name="fileName">unit file name/unit identifier</param>
        /// <returns>full file path</returns>
        private static string GetFilePath(
            string className,
            string fileName)
        {
            string basePath = BasePathReader.GetBasePath();

            return($"{basePath}{StaticResources.idvlDetailsPath}{className}{Path.DirectorySeparatorChar}{fileName}.txt");
        }
Example #10
0
 /// <summary>
 ///   Checks to see if a file exists.
 /// </summary>
 /// <param name="fileName">file name</param>
 /// <returns>file exists flag</returns>
 public bool DoesFileExist(string fileName)
 {
     return(File.Exists(
                BasePathReader.GetBasePath() +
                StaticResources.classDetailsPath +
                fileName +
                XmlExtensionLabel));
 }
Example #11
0
        /// <summary>
        /// Deserialise the <see cref="ClassDetails"/> from the <paramref name="filename"/>.
        /// </summary>
        /// <param name="filename">name of the file to read</param>
        /// <returns>deserialised file</returns>
        public ClassDetails Read(string filename)
        {
            string       myPath  = BasePathReader.GetBasePath() + StaticResources.classDetailsPath + filename + XmlExtensionLabel;
            ClassDetails results =
                XmlFileIo.ReadXml <ClassDetails>(
                    myPath);

            return(results);
        }
Example #12
0
        /// <summary>
        /// Serialise the <see cref="ClassDetails"/> to <parmref name="filename"/>.
        /// </summary>
        /// <param name="file">file to serialise</param>
        /// <param name="filename">location to save the file to</param>
        public void Write(
            ClassDetails file,
            string filename)
        {
            string myPath = BasePathReader.GetBasePath() + StaticResources.classDetailsPath + filename + XmlExtensionLabel;

            XmlFileIo.WriteXml <ClassDetails>(
                file,
                myPath);
        }
Example #13
0
        /// <summary>
        /// Create the directory for the given year, if it doesn't exist.
        /// </summary>
        /// <param name="year">directory year</param>
        private static void EnsureDirectoryExists(
            int year)
        {
            string path =
                $"{BasePathReader.GetBasePath()}{StaticResources.baPath}{year}";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
Example #14
0
        /// <summary>
        /// Determine the all the years with data.
        /// </summary>
        private void PopulateYearCollection()
        {
            DirectoryInfo dirInfo = new DirectoryInfo(BasePathReader.GetBasePath() + StaticResources.baPath);

            DirectoryInfo[] subdirs = dirInfo.GetDirectories();
            this.years = new ObservableCollection <string>();

            foreach (DirectoryInfo di in subdirs)
            {
                this.years.Add(di.ToString());
            }
        }
Example #15
0
        /// <summary>
        /// Run search over everything
        /// </summary>
        /// <param name="currentNumber">current number</param>
        /// <param name="previousNumbersList">collection of previous numbers</param>
        public static SearcherResults RunCompleteSearch(
            string currentNumber,
            List <int> previousNumbersList)
        {
            List <IJourneyDetailsType> foundJourneys = new List <IJourneyDetailsType>();
            DateTime lastCheckedDate = new DateTime();

            string[] yearDirsArray =
                System.IO.Directory.GetDirectories(
                    BasePathReader.GetBasePath() + StaticResources.baPath);

            for (int yearIndex = 0; yearIndex < yearDirsArray.Count(); ++yearIndex)
            {
                int?currentYear = Searcher.ConvertYearDirectory(yearDirsArray[yearIndex]);

                if (currentYear == null)
                {
                    continue;
                }

                string[] fileNamesArray =
                    System.IO.Directory.GetFiles(
                        yearDirsArray[yearIndex]);

                for (int monthIndex = 0; monthIndex < fileNamesArray.Count(); ++monthIndex)
                {
                    int?currentMonth = Searcher.ConvertMonthFilename(fileNamesArray[monthIndex]);

                    if (currentMonth == null)
                    {
                        continue;
                    }

                    List <IJourneyDetailsType> found =
                        Searcher.AnalyseMonth(
                            (int)currentYear,
                            (int)currentMonth,
                            currentNumber,
                            previousNumbersList,
                            ref lastCheckedDate);

                    foundJourneys.AddRange(found);
                }
            }

            SearcherResults results =
                new SearcherResults(
                    foundJourneys,
                    lastCheckedDate);

            return(results);
        }
Example #16
0
        /// <summary>
        /// Run a general class report.
        /// This provides the count for each class across all records.
        /// </summary>
        /// <param name="fullList">
        /// return a full list of locations or just none zero ones.
        /// </param>
        /// <returns>success flag</returns>
        public static ReportCounterManager <ClassCounter> RunGeneralReportForAllCls(
            IGroupsAndClassesIOController groupsAndClassesIoController,
            bool fullList)
        {
            // Set up paths.
            string basePath =
                BasePathReader.GetBasePath();

            string[] dirNamesArray =
                System.IO.Directory.GetDirectories(
                    $"{basePath}{StaticResources.baPath}");

            // Load the groups and set up the report class with an entry for each group.
            List <GroupsType> groupsList =
                groupsAndClassesIoController.LoadFile();

            ReportCounterManager <ClassCounter> classTotals =
                new ReportCounterManager <ClassCounter>();

            foreach (GroupsType group in groupsList)
            {
                classTotals.AddNewCounter(
                    new ClassCounter(
                        group.Name));
            }

            // Loop through all paths.
            for (int directoryIndex = 0; directoryIndex < dirNamesArray.Count(); ++directoryIndex)
            {
                // get directory name from the path and convert it into it's integer value.
                string dirName =
                    dirNamesArray[directoryIndex].Substring(
                        dirNamesArray[directoryIndex].LastIndexOf('\\') + 1);
                ClassReportFactory.UpdateClassesForYear(
                    classTotals,
                    groupsList,
                    dirName);
            }

            if (!fullList)
            {
                classTotals.RemoveEmptyClasses();
            }

            return(classTotals);

            //classTotals.WriteCSVFile(
            //  $"ClsReport_Gen_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv",
            //  "ReportBuilder: Failed to write General Cls Report.");
        }
Example #17
0
        /// <summary>
        /// Return the path for an image, based on a specific index.
        /// </summary>
        /// <param name="index">image index</param>
        /// <returns>image path</returns>
        public string GetImagePath(int index)
        {
            if (index >= 0 && index < this.SubClassImageList.Count)
            {
                string returnString = BasePathReader.GetBasePathUri() +
                                      StaticResources.classImgPath +
                                      this.SubClassImageList[index] +
                                      ".jpg";

                return(returnString);
            }

            return(string.Empty);
        }
Example #18
0
        /// <summary>
        /// Search though everything to determine an annual list of first
        ///   examples as determined by the year argument.
        /// </summary>
        /// <param name="year">year to search</param>
        public void RunSearchYear(string year)
        {
            int currentYear = 0;

            m_listNumber   = new List <FirstExampleType>();
            m_listLocation = new List <FirstExampleType>();

            if (int.TryParse(year, out currentYear))
            {
                string[] fileNamesArray = System.IO.Directory.GetFiles(BasePathReader.GetBasePath() +
                                                                       StaticResources.baPath +
                                                                       year);
                SearchThroughSingleYear(currentYear, fileNamesArray);
            }

            FirstExampleIOController firstExampleController = FirstExampleIOController.GetInstance();

            firstExampleController.WriteFileNumber(m_listNumber, year);
            firstExampleController.WriteFileLocation(m_listLocation, year);
        }
Example #19
0
        /// <summary>
        /// TODO This method always returns 0 because this file doesn't exist.
        /// </summary>
        private void PopulateOldNumbersAvailable()
        {
            // populate the oldNumberAvailable label
            if (File.Exists(BasePathReader.GetBasePath() +
                            StaticResources.miscellaneousPath +
                            StaticResources.FileNameOldNumbersAvailable))
            {
                using (StreamReader sr = new StreamReader(BasePathReader.GetBasePath() +
                                                          StaticResources.miscellaneousPath +
                                                          StaticResources.FileNameOldNumbersAvailable))
                {
                    int prevNumbersAvail = 0;
                    if (int.TryParse(sr.ReadLine(), out prevNumbersAvail))
                    {
                        this.oldNumbersCount = prevNumbersAvail;
                        return;
                    }
                }
            }

            oldNumbersCount = 0;
        }
 /// <date>17/11/18</date>
 /// <summary>
 ///   Create a new instance of this class.
 /// </summary>
 public GroupsAndClassesIOController()
 {
     filePath = BasePathReader.GetBasePath() +
                StaticResources.miscellaneousPath +
                GroupsFileName;
 }
Example #21
0
 /// <summary>
 /// Build the filename
 /// </summary>
 /// <param name="year">file year</param>
 /// <param name="month">file month</param>
 /// <returns>standard filename</returns>
 public static string BuildBackupFilePath(
     int year,
     int month)
 {
     return($"{BasePathReader.GetBasePath()}{StaticResources.baPath}{year}\\{filePrefix}{month.ToString(monthFormat)}bac.txt");
 }
Example #22
0
 /// <summary>
 ///   Creates a new example of this class.
 /// </summary>
 private FirstExampleIOController()
 {
     basePath = BasePathReader.GetBasePath();
 }
Example #23
0
 /// ---------- ---------- ---------- ---------- ---------- ----------
 /// <name>PopularStnIOController</name>
 /// <date>28/07/13</date>
 /// <summary>
 /// Creates a new instance of this class
 /// </summary>
 /// ---------- ---------- ---------- ---------- ---------- ----------
 private PopularStnIOController()
 {
     m_filePath = BasePathReader.GetBasePath() +
                  StaticResources.miscellaneousPath +
                  c_popularStns;
 }
Example #24
0
 /// ---------- ---------- ---------- ---------- ---------- ----------
 /// <name>UnitsIOController</name>
 /// <date>28/04/12</date>
 /// <summary>
 ///  Creates a new instance of the UnitsIOController class.
 /// </summary>
 /// ---------- ---------- ---------- ---------- ---------- ----------
 public UnitsIOController()
 {
     this.basePath = BasePathReader.GetBasePath();
 }
Example #25
0
        /// <date>10/03/19</date>
        /// <summary>
        /// Determine the path to save a unit file to.
        /// </summary>
        /// <param name="className">name of the class the unit is part of</param>
        /// <returns>directory path</returns>
        private static string GetDirectoryPath(string className)
        {
            string basePath = BasePathReader.GetBasePath();

            return($"{basePath}{StaticResources.idvlDetailsPath}{className}");
        }
Example #26
0
        /// ---------- ---------- ---------- ---------- ---------- ----------
        /// <name>runYearReportForSingleCls</name>
        /// <date>15/09/13</date>
        /// <summary>
        ///   Run a report based on a cls. It counts all the locations for
        ///     the cls across all records.
        /// </summary>
        /// <param name="cls">cls name</param>
        /// <param name="fullList">full list of locations</param>
        /// <returns>is successful</returns>
        /// ---------- ---------- ---------- ---------- ---------- ----------
        public static ReportCounterManager <LocationCounter> RunReportForASingleClass(
            IGroupsAndClassesIOController groupsAndClassesIoController,
            string cls,
            bool fullList,
            string year = "")
        {
            string faultMessage;
            string writeName;

            // Set up paths.
            string basePath =
                BasePathReader.GetBasePath();

            ReportCounterManager <LocationCounter> locationTotals =
                new ReportCounterManager <LocationCounter>();

            List <FirstExampleType> firstExampleList =
                Stats.FirstExampleIOController.GetInstance().GetFirstExampleListLocation();

            firstExampleList = firstExampleList.OrderBy(loc => loc.Item).ToList();

            foreach (FirstExampleType location in firstExampleList)
            {
                locationTotals.AddNewCounter(
                    new LocationCounter(
                        location.Item));
            }

            if (string.IsNullOrEmpty(year))
            {
                //writeName = $"{cls}_Report_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv";
                //faultMessage = "ReportBuilder: Failed to write General Cls Report.";

                string[] dirNamesArray =
                    System.IO.Directory.GetDirectories(
                        $"{basePath}{StaticResources.baPath}");

                // Loop through all paths.
                for (int directoryIndex = 0; directoryIndex < dirNamesArray.Count(); ++directoryIndex)
                {
                    // get directory name from the path and convert it into it's integer value.
                    string dirName =
                        dirNamesArray[directoryIndex].Substring(
                            dirNamesArray[directoryIndex].LastIndexOf('\\') + 1);
                    ClassReportFactory.UpdateLocationsForYear(
                        groupsAndClassesIoController,
                        dirName,
                        locationTotals,
                        cls);
                }
            }
            else
            {
                //writeName = $"{cls}_Report_{year}_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv";
                //faultMessage = $"ReportBuilder: Failed to write Single Year {year} Cls Report.";

                ClassReportFactory.UpdateLocationsForYear(
                    groupsAndClassesIoController,
                    year,
                    locationTotals,
                    cls);
            }

            if (!fullList)
            {
                locationTotals.RemoveEmptyClasses();
            }

            return(locationTotals);

            //locationTotals.WriteCSVFile(
            //  writeName,
            //  faultMessage);
        }