/// <summary>
        ///   read the file
        /// </summary>
        /// <param name="path">file path</param>
        /// <param name="firstExamples">First Example Type</param>
        /// <returns>success flag</returns>
        private bool AppendFile(string path,
                                FirstExampleType firstExamples)
        {
            if (!File.Exists(path))
            {
                File.Create(path).Dispose();
            }

            try
            {
                using (StreamWriter writer = new StreamWriter(path, true))
                {
                    writer.WriteLine(firstExamples.ToString());
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.WriteLog("ERROR: FirstExampleIOController: Failed to write (append) "
                                         + path
                                         + ": "
                                         + ex.ToString());
                return(false);
            }
        }
        /// <summary>
        ///   Read file
        /// </summary>
        /// <param name="path">file path</param>
        /// <returns>List of first examples</returns>
        private List <FirstExampleType> ReadFile(string path)
        {
            List <FirstExampleType> fileContents = new List <FirstExampleType>();

            if (File.Exists(path))
            {
                using (StreamReader reader = new StreamReader(path))
                {
                    string currentLine = string.Empty;
                    currentLine = reader.ReadLine();

                    while (currentLine != null)
                    {
                        FirstExampleType firstExample = new FirstExampleType();
                        if (firstExample.Set(currentLine))
                        {
                            fileContents.Add(firstExample);
                        }
                        else
                        {
                            Logger.Instance.WriteLog("ERROR: FirstExampleIOController: error in with line - " + currentLine);
                        }

                        currentLine  = reader.ReadLine();
                        firstExample = null;
                    }
                }
            }

            return(fileContents);
        }
 /// <summary>
 /// Sets up path then calls append file. Used for complete location
 ///   data.
 /// </summary>
 /// <param name="firstExamples">First Example Type</param>
 /// <returns>success flag</returns>
 public bool AppendFileLocation(FirstExampleType firstExamples)
 {
     return(AppendFile(basePath +
                       StaticResources.baPath +
                       c_fileNameLocation,
                       firstExamples));
 }
 /// <summary>
 /// Sets up path then calls append file. Used for annual number
 ///   data, as specified by the year argument.
 /// </summary>
 /// <param name="firstExamples">First Example Type</param>
 /// <param name="year">the year</param>
 /// <returns>success flag</returns>
 public bool AppendFileNumber(FirstExampleType firstExamples,
                              string year)
 {
     return(AppendFile(basePath +
                       StaticResources.baPath +
                       year +
                       "\\" +
                       c_fileNameNumber,
                       firstExamples));
 }
Beispiel #5
0
        /// <summary>
        ///   does first example already exist in the list specified by
        ///   listType.
        /// </summary>
        /// <param name="firstExample">example to compare</param>
        /// <param name="listType">type of list</param>
        /// <returns>is cop flag</returns>
        public bool IsCopNumber(FirstExampleType firstExample,
                                LocalListType listType)
        {
            switch (listType)
            {
            case LocalListType.allPurpose:
                return(!m_listNumber.Any(localExample => localExample.Compare(firstExample)));

            case LocalListType.complete:
                return(!m_completeListNumber.Any(localExample => localExample.Compare(firstExample)));

            case LocalListType.annual:
                return(!m_annualListNumber.Any(localExample => localExample.Compare(firstExample)));

            default:
                return(false);
            }
        }
Beispiel #6
0
        private void CheckNewJnyListVcl(
            string vehicle,
            DateTime date,
            string rowIndex)
        {
            if (string.IsNullOrEmpty(vehicle))
            {
                return;
            }

            if (this.IsCopNumber(vehicle, LocalListType.annual))
            {
                FirstExampleType firstExample =
                    new FirstExampleType()
                {
                    Item  = vehicle,
                    Date  = date,
                    Index = rowIndex
                };

                this.AppendNumber(
                    firstExample,
                    LocalListType.annual,
                    date.Year.ToString());
            }

            if (this.IsCopNumber(vehicle, LocalListType.complete))
            {
                FirstExampleType firstExample =
                    new FirstExampleType()
                {
                    Item  = vehicle,
                    Date  = date,
                    Index = rowIndex
                };

                this.AppendNumber(
                    firstExample,
                    LocalListType.complete);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Appends first example to the relevant list and file. localList
        /// determines which list/file. If looking at a specific year, then
        /// this is defined by the year argument.
        /// </summary>
        /// <param name="firstExamples">first example to append</param>
        /// <param name="localList">type of list</param>
        /// <param name="year">current year</param>
        public void AppendNumber(FirstExampleType firstExamples,
                                 LocalListType localList,
                                 string year = "1970")
        {
            FirstExampleIOController firstExampleController;

            switch (localList)
            {
            case LocalListType.complete:
                m_completeListNumber.Add(firstExamples);
                firstExampleController = FirstExampleIOController.GetInstance();
                firstExampleController.AppendFileNumber(firstExamples);
                break;

            case LocalListType.annual:
                m_annualListNumber.Add(firstExamples);
                firstExampleController = FirstExampleIOController.GetInstance();
                firstExampleController.AppendFileNumber(firstExamples, year);
                break;
            }
        }
Beispiel #8
0
        private void CheckNewJnyListLocation(
            string location,
            DateTime date,
            string rowIndex)
        {
            if (this.IsCopLocation(location, LocalListType.annual))
            {
                FirstExampleType firstExample =
                    new FirstExampleType()
                {
                    Item  = location,
                    Date  = date,
                    Index = rowIndex
                };

                this.AppendLocation(
                    firstExample,
                    LocalListType.annual,
                    date.Year.ToString());
            }

            if (this.IsCopLocation(location, LocalListType.complete))
            {
                FirstExampleType firstExample =
                    new FirstExampleType()
                {
                    Item  = location,
                    Date  = date,
                    Index = rowIndex
                };

                this.AppendLocation(
                    firstExample,
                    LocalListType.complete);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Searches for the numbers in journey and see if they are already
        ///   in the list. If they aren't then it adds them.
        /// </summary>
        /// <param name="journey">journey details</param>
        public void SearchLocationsForMatch(IJourneyDetailsType journey)
        {
            if (IsCopLocation(journey.From, LocalListType.allPurpose))
            {
                FirstExampleType firstExamples = new FirstExampleType();
                firstExamples.Item  = journey.From;
                firstExamples.Date  = journey.Date;
                firstExamples.Index = journey.JnyId.JnyNumber;

                m_listLocation.Add(firstExamples);
                firstExamples = null;
            }

            if (IsCopLocation(journey.To, LocalListType.allPurpose))
            {
                FirstExampleType firstExamples = new FirstExampleType();
                firstExamples.Item  = journey.To;
                firstExamples.Date  = journey.Date;
                firstExamples.Index = journey.JnyId.JnyNumber;

                m_listLocation.Add(firstExamples);
                firstExamples = null;
            }
        }
Beispiel #10
0
 /// <summary>
 /// Compare to see if first example is in the list.
 /// </summary>
 /// <param name="firstExample">value to test</param>
 /// <param name="firstExampleList">list of examples</param>
 /// <returns>match flag</returns>
 private bool CompareFirstExample(
     FirstExampleType firstExample,
     List <FirstExampleType> firstExampleList)
 {
     return(firstExampleList.Any(localExample => localExample.Compare(firstExample)));
 }
Beispiel #11
0
        /// <summary>
        /// Searches for the numbers in journey and see if they are already
        ///   in the list. If they aren't then it adds them.
        /// </summary>
        /// <param name="journey">journey details</param>
        public void SearchNumbersForMatch(IJourneyDetailsType journey)
        {
            foreach (string unit in journey.Units)
            {
                bool cop =
                    this.IsCopNumber(
                        unit,
                        LocalListType.allPurpose);

                if (cop)
                {
                    FirstExampleType firstExamples = new FirstExampleType();
                    firstExamples.Item  = unit;
                    firstExamples.Date  = journey.Date;
                    firstExamples.Index = journey.JnyId.JnyNumber;

                    m_listNumber.Add(firstExamples);
                    firstExamples = null;
                }
            }

            //if (IsCopNumber(journey.GetJourneyFirstNumber(), LocalListType.allPurpose))
            //{
            //  FirstExampleType firstExamples = new FirstExampleType();
            //  firstExamples.Item  = journey.GetJourneyFirstNumber();
            //  firstExamples.Date  = journey.GetJourneyDate();
            //  firstExamples.Index = journey.GetJourneyIndex();

            //  m_listNumber.Add(firstExamples);
            //  firstExamples = null;
            //}

            //if (journey.GetJourneyNumberOfVehicles() >= 2)
            //{
            //  if (IsCopNumber(journey.GetJourneySecondNumber(), LocalListType.allPurpose))
            //  {
            //    FirstExampleType firstExamples = new FirstExampleType();
            //    firstExamples.Item  = journey.GetJourneySecondNumber();
            //    firstExamples.Date  = journey.GetJourneyDate();
            //    firstExamples.Index = journey.GetJourneyIndex();

            //    m_listNumber.Add(firstExamples);
            //    firstExamples = null;
            //  }
            //}

            //if (journey.GetJourneyNumberOfVehicles() >= 3)
            //{
            //  if (IsCopNumber(journey.GetJourneyThirdNumber(), LocalListType.allPurpose))
            //  {
            //    FirstExampleType firstExamples = new FirstExampleType();
            //    firstExamples.Item  = journey.GetJourneyThirdNumber();
            //    firstExamples.Date  = journey.GetJourneyDate();
            //    firstExamples.Index = journey.GetJourneyIndex();

            //    m_listNumber.Add(firstExamples);
            //    firstExamples = null;
            //  }
            //}

            //if (journey.GetJourneyNumberOfVehicles() >= 4)
            //{
            //  if (IsCopNumber(journey.GetJourneyFourthNumber(), LocalListType.allPurpose))
            //  {
            //    FirstExampleType firstExamples = new FirstExampleType();
            //    firstExamples.Item  = journey.GetJourneyFourthNumber();
            //    firstExamples.Date  = journey.GetJourneyDate();
            //    firstExamples.Index = journey.GetJourneyIndex();

            //    m_listNumber.Add(firstExamples);
            //    firstExamples = null;
            //  }
            //}
        }