Example #1
0
        public static void LoadRoutesFromXML(ref List <cRoute> pRoutes, ref List <cVehicle> pVehicles_sumo)
        {
            if (pRoutes != null)
            {
                if (pRoutes.Count > 0)
                {
                    return;
                }
            }
            if (pRoutes == null)
            {
                pRoutes        = new List <cRoute>();
                pVehicles_sumo = new List <cVehicle>();
            }
            string lPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;

            if (File.Exists(lPath += "\\Files\\joined.rou.xml"))
            {
                XmlDocument lDoc = new XmlDocument();
                lDoc.Load(lPath);

                // int lID = 0;
                foreach (XmlNode lNode in lDoc.DocumentElement.ChildNodes)
                {
                    string lRouteStr = lNode.InnerXml;
                    if (lRouteStr == "")
                    {
                        continue;
                    }

                    string lVehicleID = Regex.Split(Regex.Split(lNode.OuterXml, "id=\"")[1], "\"")[0];

                    cVehicle lVehicle = new cVehicle();
                    lVehicle.SerijskaStevilka = lVehicleID;

                    string lTemp = Regex.Split(lRouteStr, "=\"")[1];
                    lTemp = Regex.Split(lTemp, " \" />")[0];

                    cRoute lRoute = new cRoute();
                    //lRoute.Id = "ID_0" + lID.ToString();
                    lRoute.Id = "!" + lVehicleID;

                    lVehicle.Route = lRoute;

                    List <string> lList = new List <string>();
                    foreach (string lS in lTemp.Split(' '))
                    {
                        lList.Add(lS);
                    }

                    lRoute.Edges = lList;
                    pVehicles_sumo.Add(lVehicle);
                    //lID++;
                    pRoutes.Add(lRoute);
                }
            }
        }
Example #2
0
        public static bool RouteExists(cRoute pRoute, ref string pAddressObj, ref List <cRoute> pRoutes,
                                       ref List <cVehicle> pVehicles_sumo, string pAddress = "")
        {
            ServiceLogic.TraasWS.ServiceImplClient lClient = new ServiceLogic.TraasWS.ServiceImplClient();
            SetEndpoit(ref lClient, pAddress, ref pAddressObj);

            string[] lEdges = lClient.Route_getIDList();
            cNonServiceLogic.LoadRoutesFromXML(ref pRoutes, ref pVehicles_sumo);
            foreach (string s in lEdges)
            {
                if (pRoutes.Exists(y => y.Id == pRoute.Id))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #3
0
 public static bool CheckIfRouteIsValid(List <cRoute> pRoutesXML, cRoute pRoute)
 {
     if (pRoutesXML != null)
     {
         if (pRoute != null)
         {
             if (pRoutesXML.Count > 0)
             {
                 foreach (cRoute lRoute in pRoutesXML)
                 {
                     string lEdgeRouteXML = "";
                     lEdgeRouteXML = ConnectEdges(lRoute.Edges);
                     string lEdgeRoute = ConnectEdges(pRoute.Edges);
                     if (lEdgeRouteXML == lEdgeRoute)
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
Example #4
0
 public static bool RequestRegisterVehicle(cVehicle pVozilo, List <cRoute> pRoutesXML, ref string pAddresObj, string pAddress = "")
 {
     ServiceLogic.TraasWS.ServiceImplClient lClient = new ServiceLogic.TraasWS.ServiceImplClient();
     SetEndpoit(ref lClient, pAddress, ref pAddresObj);
     if (pVozilo != null)
     {
         cRoute lRoute_obj = pVozilo.Route;
         if (lRoute_obj != null)
         {
             if (pVozilo.Type != null)
             {
                 if (lRoute_obj.Edges == null)
                 {
                     return(false);
                 }
                 else if (lRoute_obj.Edges.Count() == 0)
                 {
                     return(false);
                 }
                 string[] lRoute = new string[lRoute_obj.Edges.Count()];
                 if (cNonServiceLogic.CheckIfRouteIsValid(pRoutesXML, lRoute_obj))
                 {
                     for (int i = 0; i < lRoute_obj.Edges.Count(); i++)
                     {
                         lRoute[i] = lRoute_obj.Edges[i];
                     }
                 }
                 if (cNonServiceLogic.CheckIfID_ExistsOnSumo(lRoute_obj.Id, lClient.Route_getIDList()))
                 {
                     lRoute_obj.Id += "_1";
                 }
                 if (!cNonServiceLogic.CheckIfID_ExistsOnSumo(lRoute_obj.Id, lClient.Route_getIDList()) &&
                     !cNonServiceLogic.CheckIfID_ExistsOnSumo(pVozilo.SerijskaStevilka, lClient.Vehicle_getIDList()))
                 {
                     double lSpeed = 0;
                     if (pVozilo.Type.MaxSpeed != "0")
                     {
                         if (!double.TryParse(pVozilo.Type.MaxSpeed, out lSpeed))
                         {
                             lSpeed = 10;
                         }
                     }
                     lClient.Route_add(lRoute_obj.Id, lRoute);
                     lClient.Vehicle_add(pVozilo.SerijskaStevilka, pVozilo.Type.Id, lRoute_obj.Id, 0, 0.0,
                                         lSpeed, 0);
                     return(true);
                 }
                 else
                 {
                     cNonServiceLogic.ThrowNapaka(new StackTrace().GetFrame(1).GetMethod().Name, "Vozilo je še na SUMO");
                 }
             }
             else
             {
                 cNonServiceLogic.ThrowNapaka(new StackTrace().GetFrame(1).GetMethod().Name, "Tip vozila ne obstaja");
             }
         }
         else
         {
             cNonServiceLogic.ThrowNapaka(new StackTrace().GetFrame(1).GetMethod().Name, "Ruta vozila ne obstaja");
         }
     }
     else
     {
         cNonServiceLogic.ThrowNapaka(new StackTrace().GetFrame(1).GetMethod().Name, "Vozilo ne obstaja");
     }
     return(false);
 }