Exemple #1
0
 public BO.Line GetLine(int lineId)
 {
     try
     {
         DO.Line doLine = dl.GetLine(lineId);
         return(LineDoBoAdapter(doLine));
     }
     catch (DO.BadLineCodeException)
     {
         throw new BO.BadLineCodeException(lineId);
     }
 }
Exemple #2
0
        public void CreateOppositeDirectionLine(long number, string area, List <Stop> stopList)
        {
            string exception      = "";
            bool   foundException = false;

            try
            {
                valid.GoodLong(number);
            }
            catch (BOLineException ex)
            {
                exception     += ex.Message;
                foundException = true;
            }
            try
            {
                valid.GoodString(area);
            }
            catch (BOLineException ex)
            {
                exception     += ex.Message;
                foundException = true;
            }
            //try
            //{
            //    //valid.stopListExist;
            //}
            //catch (Exception ex)
            //{
            //    exception += ex.Message;
            //    foundException = true;
            //}
            if (foundException)
            {
                throw new BOLineException(exception);
            }
            Line lineBO = new Line(number, area, stopList[0].StopCode, stopList[stopList.Count() - 1].StopCode);

            DO.Line lineDO = lineBO.GetPropertiesFrom <DO.Line, BO.Line>();
            try
            {
                dal.CreateOppositeDirectionLine(lineDO);
            }
            catch (DO.DOBadLineIdException ex)
            {
                throw new BODOBadLineIdException("cant create this line", ex);
            }

            UpdateLineStations(stopList, GetIdByNumber(number));
        }
Exemple #3
0
        /// <summary>
        /// Upadate line
        /// </summary>
        /// <param name="line"></param>
        public void UpdateLine(DO.Line line)
        {
            var lineToUp = DS.DataSource.LinesList.Find(l => l.Id == line.Id);

            if (lineToUp != null && !lineToUp.IsDeleted)
            {
                DS.DataSource.LinesList.Remove(lineToUp);
                DS.DataSource.LinesList.Add(line);
            }
            else
            {
                throw new DO.BadLineException(line.Id, "Line not found");
            }
        }
        public void UpdateLine(DO.Line line)
        {
            var lineList = XmlTools.LoadListFromXMLSerializer <DO.Line>(linesPath);
            var lineToUp = lineList.Find(l => l.Id == line.Id);

            if (lineToUp != null && !lineToUp.IsDeleted)
            {
                lineList.Remove(lineToUp);
                lineList.Add(line);
                XmlTools.SaveListToXMLSerializer(lineList, linesPath);
            }
            else
            {
                throw new DO.BadLineException(line.Id, "Line not found");
            }
        }
Exemple #5
0
 public void AddLine(BO.Line line)
 {
     DO.Line doLine = LineBoDoAdapter(line);
     try
     {
         dl.AddLine(doLine);
     }
     catch (DO.BadLineCodeException exp)
     {
         throw new BO.BadLineCodeException(line.ID, line.LineCode, exp.Message);
     }
     catch (DO.BadLineStationKeyException ex)
     {
         throw new BO.BadStationKeyException(ex.Id);
     }
 }
Exemple #6
0
        /// <summary>
        /// Remove line
        /// </summary>
        /// <param name="line"></param>
        public void RemoveLine(DO.Line line)
        {
            var lineToRem = DS.DataSource.LinesList.Find(l => l.Id == line.Id);

            if (lineToRem != null && !lineToRem.IsDeleted)
            {
                // Remove all the line station of this line
                GetAllLineStationBy(ls => ls.LineId == lineToRem.Id).ToList().ForEach(RemoveLineStationOnRemoveline);

                DS.DataSource.LinesList.Remove(lineToRem);
                lineToRem.IsDeleted = true;
                DS.DataSource.LinesList.Add(lineToRem);
            }
            else
            {
                throw new DO.BadLineException(line.Id, "Line not found");
            }
        }
        public void RemoveLine(DO.Line line)
        {
            var lineList  = XmlTools.LoadListFromXMLSerializer <DO.Line>(linesPath);
            var lineToRem = lineList.Find(l => l.Id == line.Id);

            if (lineToRem != null && !lineToRem.IsDeleted)
            {
                GetAllLineStationBy(ls => ls.LineId == lineToRem.Id).ToList().ForEach(RemoveLineStationOnRemoveline);
                lineList.Remove(lineToRem);
                lineToRem.IsDeleted = true;
                lineList.Add(lineToRem);
                XmlTools.SaveListToXMLSerializer(lineList, linesPath);
            }
            else
            {
                throw new DO.BadLineException(line.Id, "Line not found");
            }
        }
        public int AddLine(DO.Line line)
        {
            var counters = XmlTools.LoadListFromXMLSerializer <int>(countersPath);

            DalApi.Counters.LineCounter = counters[0];

            line.Id = DalApi.Counters.LineCounter;

            counters[0] = line.Id;
            XmlTools.SaveListToXMLSerializer(counters, countersPath);

            var lineList = XmlTools.LoadListFromXMLSerializer <DO.Line>(linesPath);

            lineList.Add(line);
            XmlTools.SaveListToXMLSerializer(lineList, linesPath);

            return(line.Id);
        }
        //static void initializStations(int numOfStation = 100)
        //{
        //    StationsList = new List<DO.Station>();
        //    for (int i = 0; i < numOfStation; i++)
        //    {
        //        double latitude, longitude;
        //        RandomValues.getLocation(out latitude, out longitude);
        //        StationsList.Add(new DO.Station()
        //        {
        //            Code = RandomValues.getUniqueStationKey(),
        //            Latitude = latitude,
        //            Longitude = longitude,
        //            Area = RandomValues.getArea(longitude, latitude),
        //            IsDeleted = false
        //        });
        //    }
        //}

        static void initializLines(int numOfLins = 10)
        {
            LinesList        = new List <DO.Line>();
            LineStationsList = new List <DO.LineStation>();
            for (int i = 0; i < numOfLins; i++)
            {
                var newLine = new DO.Line()
                {
                    Id        = DalApi.Counters.LineCounter,
                    Code      = RandomValues.getLineCode(),
                    IsDeleted = false
                };
                var firstAndLastStationCode = initializLineStations(newLine.Id);
                newLine.FirstStation = firstAndLastStationCode[0];
                newLine.LastStation  = firstAndLastStationCode[1];
                newLine.Area         = StationsList.Find(s => s.Code == newLine.FirstStation).Area;
                LinesList.Add(newLine);
            }
        }
Exemple #10
0
        public void UpdateLine(BO.Line line)
        {
            if (line.StationsRoute != null && line.StationsRoute.Count() > 0)
            {
                int place = line.StationsRoute.Count() - 1;
                line.FirstStation = line.StationsRoute.ToList()[0].Station.Code;
                line.LastStation  = line.StationsRoute.ToList()[place].Station.Code;
            }
            else
            {
                line.FirstStation = 0;
                line.LastStation  = 0;
            }

            DO.Line doLine = LineBoDoAdapter(line);
            try
            {
                dl.UpdateLine(doLine);
            }
            catch (DO.BadLineCodeException exp)
            {
                throw new BO.BadLineCodeException(line.ID, line.LineCode, exp.Message);
            }
        }
Exemple #11
0
        private BO.Line LineDoBoAdapter(DO.Line doLine)
        {
            var busLine = (BO.Line)doLine.CopyPropertiesToNew(typeof(BO.Line));

            List <BO.LineStation> route = new List <BO.LineStation>();

            for (int i = 0; i < doLine.RouteLength; i++)
            {
                var doLineStation = dl.GetLineStationByIndex(busLine.ID, i);
                if (doLineStation == null)
                {
                }
                else if (i == 0)
                {
                    route.Add(LineStationDoToBo(doLineStation));
                }
                else
                {
                    route.Add(LineStationDoToBo(doLineStation, route[i - 1]));
                }
            }
            busLine.StationsRoute = route;
            return(busLine);
        }
Exemple #12
0
 /// <summary>
 /// Add new line to the database
 /// </summary>
 /// <param name="line"></param>
 /// <returns>the id of this line that came from the run number in the database</returns>
 public int AddLine(DO.Line line)
 {
     line.Id = DalApi.Counters.LineCounter;
     DS.DataSource.LinesList.Add(line.Clone());
     return(line.Id);
 }
Exemple #13
0
 private DO.Line LineBoDoAdapter(BO.Line boLine)
 {
     DO.Line doLine = new DO.Line();
     boLine.CopyPropertiesTo(doLine);
     return(doLine);
 }
Exemple #14
0
 private IEnumerable <BO.LineStation> GetRouteStationsFromDOLine(DO.Line doLine)
 {
     return(from item1 in dl.GetAllLineStations(doLine.ID)
            orderby item1.IndexInLine
            select LineStationDoToBo(item1));
 }