Пример #1
0
        //Function for adding data
        public void AddStep(int StageNumber, int ScenarioNumber)
        {
            try
            {
                foreach (ReadEventsFile.FileData VehiclesBorn in REF.Fdata)
                {
                    VehicleIdentity TempID = new VehicleIdentity();
                    ViDincriment();
                    TempID.ViD          = IDno.ToString("00000");
                    TempID.Tag          = VehiclesBorn.Tag;
                    TempID.Vtype        = VehiclesBorn.Vtype;
                    TempID.BornAt       = VehiclesBorn.AtTime;
                    TempID.BornLink     = VehiclesBorn.OnLink;
                    TempID.BornStage    = StageNumber;
                    TempID.BornScenario = ScenarioNumber;
                    //Destination data are not available, to be added later
                    //Origin data only available in OD

                    if (RouteMethod.Equals("OD"))
                    {
                        TempID.Origin = GetOriginZone(VehiclesBorn.OnLink);
                    }

                    PDB.ViDAddLine(TempID.MakeDBLine());
                }



                foreach (ReadSnapshotFile.FileData SnapShot in RSF.Fdata)
                {
                    string DBcondition = "ABC";

                    if (RouteMethod.Equals("OD"))
                    {
                        //DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype);//+ " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                        DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                    }
                    else if (RouteMethod.Equals("Paths"))
                    {
                        LinkID FirstLink = FirstLinkinRoute(SnapShot);
                        DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND BornLink = '" + FirstLink.MakeString() + "' AND VehicleType = " + SnapShot.Vtype + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                    }

                    List <VehicleIdentity> TempIDL = new List <VehicleIdentity>();
                    TempIDL = PDB.VidGrabLine(DBcondition);
                    VehicleIdentity TempID = new VehicleIdentity();

                    if (TempIDL.Count == 1)
                    {
                        TempID = TempIDL[0];
                    }
                    else if (TempIDL.Count > 1)
                    {
                        try
                        {
                            if (RouteMethod.Equals("OD"))
                            {
                                //DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype);//+ " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                                DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype + " AND MagicNumbers = '" + SnapShot.MagicNumbers + "'" + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                            }
                            else if (RouteMethod.Equals("Paths"))
                            {
                                LinkID FirstLink = FirstLinkinRoute(SnapShot);
                                DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND BornLink = '" + FirstLink.MakeString() + "' AND VehicleType = " + SnapShot.Vtype + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                            }
                            List <VehicleIdentity> TempIDL2 = PDB.VidGrabLine(DBcondition);
                            if (TempIDL2.Count == 0)
                            {
                                throw new Exception();
                            }
                            else if (TempIDL2.Count == 1)
                            {
                                TempID = TempIDL2[0];
                            }
                            else
                            {
                                Console.WriteLine("Something weird is going on");
                            }
                        }
                        catch (Exception e)
                        {
                            if (RouteMethod.Equals("OD"))
                            {
                                //DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype);//+ " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                                DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype + " AND ISNULL(MagicNumbers)" + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                            }
                            else if (RouteMethod.Equals("Paths"))
                            {
                                LinkID FirstLink = FirstLinkinRoute(SnapShot);
                                DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND BornLink = '" + FirstLink.MakeString() + "' AND VehicleType = " + SnapShot.Vtype + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                            }
                            List <VehicleIdentity> TempIDL3 = PDB.VidGrabLine(DBcondition);

                            if (TempIDL3.Count == 0)
                            {
                                Console.WriteLine("Something weird is going on again");
                            }

                            TempID = TempIDL3[(TempIDL3.Count - 1)];
                            TempID.MagicNumbers = SnapShot.MagicNumbers;
                            PDB.ViDAddLine(TempID.MakeDBLine());
                        }
                    }
                    else if (TempIDL.Count == 0)
                    {
                        Console.WriteLine("What is happenning here?");
                    }


                    if (TempID.ViD.Equals("NoID"))
                    {
                        //throw new Exception("Error: Unique vehicle ID was not assigned to vehicle from snapshot");
                        Console.WriteLine("Vehicle id is unassigned");
                    }

                    if (RouteMethod.Equals("OD"))
                    {
                        if (TempID.Destination == 511)
                        {
                            TempID.Destination = SnapShot.Destination;
                            PDB.ViDAddLine(TempID.MakeDBLine());
                        }
                    }
                    else if (RouteMethod.Equals("Paths"))
                    {
                        if (TempID.Routename.Equals("NULL"))
                        {
                            TempID.Routename = SnapShot.RouteName;
                            PDB.ViDAddLine(TempID.MakeDBLine());
                        }
                    }
                    VehiclePosition TempDat = new VehiclePosition();
                    TempDat.ViD      = TempID.ViD;
                    TempDat.OnLink   = SnapShot.OnLink;
                    TempDat.AtTime   = SnapShot.AtTime;
                    TempDat.LinkDist = SnapShot.LinkDist;
                    TempDat.Vspeed   = SnapShot.Vspeed;
                    double[] Position = LinkToCartesian(SnapShot.OnLink, SnapShot.LinkDist);
                    TempDat.X          = Position[0];
                    TempDat.Y          = Position[1];
                    TempDat.Z          = Position[2];
                    TempDat.InStage    = StageNumber;
                    TempDat.InScenario = ScenarioNumber;

                    PDB.VposAddLine(TempDat.MakeDBLine());
                    //CollatedData.Add(TempDat);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }