public void AddBus(int n) { List <SimpleMan> newPassengers = new List <SimpleMan>(); for (int i = 0; i < n; i++) { newPassengers.Add(new SimpleMan()); } Random rnd = new Random(); Bus bus = new Bus(BusStops[rnd.Next(0, 2)].X, BusStops[rnd.Next(0, 2)].Y + 76, X, 100, firstLevel, secondLevel, newPassengers); if (Passengers == null) { Passengers = new List <SimpleMan>(); } Passengers.AddRange(newPassengers); Buses.Add(bus); TimeEvent += bus.Time; //List<SimpleMan> newPassengers = new List<SimpleMan>(); //for (int i = 0; i < n; i++) //{ // newPassengers.Add(new SimpleMan()); //} //Bus bus = new Bus(newPassengers); //if (Passengers == null) // Passengers = new List<SimpleMan>(); //Passengers.AddRange(newPassengers); //Buses.Add(bus); //TimeTickEvent += bus.TimeTick; }
public void RandomBusesAndPassengers() { Random rnd = new Random(); //Buses.Add(new Bus(BusStops[0].X, BusStops[0].Y + 76, X, 100, firstLevel, secondLevel)); foreach (var busstop in BusStops) { int N = rnd.Next(1, 2); for (int i = 0; i < N; i++) { Buses.Add(new Bus(busstop.X + 127 * i, busstop.Y + 76, X, 100, firstLevel, secondLevel)); } int P = rnd.Next(4, 7); for (int i = 0; i < P; i++) { busstop.AddPassenger(busstop.X + (108) * i, busstop.Y + 90); //busstop.Passengers[i].BusStop = busstop; } } Buses[0].Passengers = new List <SimpleMan>(); SimpleMan simpleMan = new SimpleMan(); simpleMan.Bus = Buses[0]; Buses[0].BusStopEvent += simpleMan.FromBus; Buses[0].FullEvent += simpleMan.CheckOnFull; Buses[0].Passengers.Add(simpleMan); background.Start(); }
//public static IStudentTransactionRepository transactions; //public IStudentTransactionRepository Transactions => transactions ??= new StudentTransactionRepository(); private static Buses ReadBuses() { var buses = DataReader.ReadBuses("Buses") .Distinct(x => x.RegistrantionNo, x => x.State); var voucher = new Buses(3000); foreach (var u in buses) { voucher.Add(u); } return(voucher); }
protected virtual IServiceBus SetupServiceBus(Uri uri, Action <ServiceBusConfigurator> configure) { IServiceBus bus = ServiceBusFactory.New(x => { x.ReceiveFrom(uri); configure(x); }); Buses.Add(bus); return(bus); }
public void GetTestData() { Buses.Clear(); Moves.Clear(); Buses.Add(new Bus(Buses.Count() + 1, 10, 10 * Constans.MinutesInHour)); Buses.Add(new Bus(Buses.Count() + 1, 20, 12 * Constans.MinutesInHour)); Moves.Add(new Move(1, 1, 3, 5)); Moves.Add(new Move(1, 3, 1, 7)); Moves.Add(new Move(2, 1, 2, 10)); Moves.Add(new Move(2, 2, 4, 5)); Moves.Add(new Move(2, 4, 1, 20)); SetPeriods(); StationCount = 5; }
/// <summary> /// Gets bus by type /// </summary> /// <param name="type">Type of bus</param> /// <returns>Instance on success; <see langword="null"/> otherwise</returns> public static IMessageBus GetBus(Type type) { // Validate input if (!typeof(IMessageBus).IsAssignableFrom(type)) { return(null); } if (!type.IsClass || type.IsAbstract) { return(null); } // Lazily initialize container if (Buses == null) { Buses = new List <IMessageBus>(); } // Return instance if found foreach (var bus in Buses) { if (bus.GetType() == type) { return(bus); } } // Create new instance { var bus = Activator.CreateInstance(type) as IMessageBus; if (bus != null) { Buses.Add(bus); return(bus); } } return(null); }
public void AddBus(int n) { List <IMechanic> NewMen = new List <IMechanic>(); for (int i = 0; i < n; i++) { NewMen.Add(new SimpleMan()); } Random rnd = new Random(); int index = rnd.Next(0, 3); Bus bus = new Bus(BusStops[index].X + 127, BusStops[index].Y + 76, X, 100, firstLevel, secondLevel); Passengers.AddRange(NewMen); Buses.Add(bus); TimeTickEvent += bus.TimeTick; }
public void ReadData(StreamReader myStream)// Метод парсинга текстового файла для получения исходных данных к задаче { string lineFile; List <String> data = new List <String>(); do { lineFile = myStream.ReadLine(); data.Add(lineFile); }while (lineFile != null); BusesCount = Convert.ToInt32(data[0]); StationCount = Convert.ToInt32(data[1]); Moves.Clear(); Buses.Clear(); var busesStarts = data[2].Split(' ').Select(x => Convert.ToInt32(Convert.ToDateTime(x).Hour *Constans.MinutesInHour + Convert.ToDateTime(x).Minute)).ToList(); var costs = data[3].Split(' ').Select(x => Convert.ToInt32(x)).ToList(); for (int i = 1; i <= BusesCount; i++) { Buses.Add(new Bus(i, costs[i - 1], busesStarts[i - 1])); } int currentBus = 1; for (int i = 4; i < BusesCount + 4; i++) { var moves = data[i].Split(' '); int count = Convert.ToInt32(moves[0]); List <int> stations = new List <int>(); for (int j = 1; j < count + 1; j++)//Станции, которые входят в конкретный маршрут { stations.Add(Convert.ToInt32(moves[j])); } List <int> times = new List <int>(); for (int k = count + 1; k < moves.Count(); k++)//Время переездов между станциями { times.Add(Convert.ToInt32(moves[k])); } for (int u = 0; u < count - 1; u++) { Moves.Add(new Move(currentBus, stations[u], stations[u + 1], times[u])); } Moves.Add(new Move(currentBus, stations[stations.Count - 1], stations[0], times[times.Count - 1])); currentBus++; } SetPeriods(); }
public void RandomBusesAndPassengers() { int buscount = 0; Random rnd = new Random(); foreach (var busstop in BusStops) { buscount++; if (buscount > 2) { Buses.Add(new Bus(busstop.X + 127, busstop.Y + 76, X, 100, firstLevel, secondLevel)); } int P = rnd.Next(0, 4); for (int i = 0; i < P; i++) { busstop.AddPassenger(); busstop.Passengers[i].BusStop = busstop; } } }
//get schedules for a specidic day private async Task DoUpdateOn(string date, string hour, string minute, bool forcelimited = false) { buses = new List <IDictionary <string, string> >(); error = false; string responseString; string napszak = forcelimited ? "3" : "0"; using (var client = new HttpClient()) // query the server for the bus-line based on LineData { Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; var content = new StringContent( "{\"func\":\"getRoutes\",\"params\":{\"datum\":\"" + date + "\",\"erk_stype\":\"megallo\",\"ext_settings\":\"block\",\"filtering\":0,\"helyi\":\"No\",\"honnan\":\"" + from + "\",\"honnan_eovx\":\"0\",\"honnan_eovy\":\"0\",\"honnan_ls_id\":" + FromlsID + ",\"honnan_settlement_id\":\"" + FromsID + "\",\"honnan_site_code\":0,\"honnan_zoom\":0,\"hour\":\"" + hour + "\",\"hova\":\"" + to + "\",\"hova_eovx\":\"0\",\"hova_eovy\":\"0\",\"hova_ls_id\":" + TolsID + ",\"hova_settlement_id\":" + TosID + ",\"hova_site_code\":0,\"hova_zoom\":0,\"ind_stype\":\"megallo\",\"keresztul_stype\":\"megallo\",\"maxatszallas\":\"" + (String)roamingSettings.Values["change"] + "\",\"maxvar\":\"" + (String)roamingSettings.Values["wait"] + "\",\"maxwalk\":\"" + (String)roamingSettings.Values["walk"] + "\",\"min\":\"" + minute + "\",\"napszak\":" + napszak + ",\"naptipus\":0,\"odavissza\":0,\"preferencia\":\"1\",\"rendezes\":\"1\",\"submitted\":1,\"talalatok\":1,\"target\":0,\"utirany\":\"oda\",\"var\":\"0\"}}" , System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync("http://menetrendek.hu/menetrend/interface/index.php", content); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw new HttpRequestException(); } responseString = await response.Content.ReadAsStringAsync(); } string raw = Regex.Unescape(responseString); // process recieved data JsonObject json = JsonObject.Parse(raw); string status = ""; try { status = json.GetNamedString("status"); } catch (Exception) { status = "error"; } if (status == "success") { //try { JsonObject results = json.GetNamedObject("results"); JsonObject talalatok = results.GetNamedObject("talalatok"); int t = 1; while (t > 0) { JsonObject talalat = null; try { talalat = talalatok.GetNamedObject(t.ToString()); } catch (Exception) { t = 0; break; } Dictionary <string, string> jarat = new Dictionary <string, string>(); jarat.Add("indulasi_hely", talalat.GetObject().GetNamedString("indulasi_hely")); jarat.Add("erkezesi_hely", talalat.GetObject().GetNamedString("erkezesi_hely")); jarat.Add("indulasi_ido", talalat.GetObject().GetNamedString("indulasi_ido")); jarat.Add("erkezesi_ido", talalat.GetObject().GetNamedString("erkezesi_ido")); jarat.Add("osszido", talalat.GetObject().GetNamedString("osszido")); jarat.Add("ossztav", talalat.GetObject().GetNamedString("ossztav")); JsonObject jaratinfok = talalat.GetObject().GetNamedObject("jaratinfok"); JsonArray nativedata = talalat.GetObject().GetNamedArray("nativeData"); int fare_total = 0, fare50_total = 0, fare90_total = 0, extra_total = 0, j = 0; string fare = "", fare50 = "", fare90 = "", extra = "", num = ""; while (j > -1) { JsonObject jaratinfo = null; try { jaratinfo = jaratinfok.GetObject().GetNamedObject(j.ToString()); } catch (Exception) { if (j == 1) { num = num.Substring(1) + num; } j = -1; break; } fare += "|" + jaratinfo.GetObject().GetNamedNumber("fare").ToString(); fare50 += "|" + jaratinfo.GetObject().GetNamedNumber("fare_50_percent").ToString(); fare90 += "|" + jaratinfo.GetObject().GetNamedNumber("fare_90_percent").ToString(); extra += "|" + jaratinfo.GetObject().GetNamedNumber("additional_ticket_price").ToString(); if (j == 1) { num = " ∙∙∙" + num; } //num += "|" + jaratinfo.GetObject().GetNamedString("vonalnev").ToString(); string domain = nativedata[j].GetObject().GetNamedString("Domain_code").ToString(); num += "|" + (domain.Length < 4 ? domain : ""); fare_total += (int)jaratinfo.GetObject().GetNamedNumber("fare"); fare50_total += (int)jaratinfo.GetObject().GetNamedNumber("fare_50_percent"); fare90_total += (int)jaratinfo.GetObject().GetNamedNumber("fare_90_percent"); extra_total += (int)jaratinfo.GetObject().GetNamedNumber("additional_ticket_price"); j++; } jarat.Add("fare", fare_total + fare); jarat.Add("fare_50_percent", fare50_total + fare50); jarat.Add("fare_90_percent", fare90_total + fare90); jarat.Add("extra", extra_total + extra); jarat.Add("vonalnev", num); jarat.Add("details", talalat.GetObject().GetNamedObject("kifejtes_postjson").Stringify().Replace(Convert.ToChar(0x0).ToString(), "")); Buses.Add(jarat); t++; } } //catch (Exception) { } } else { error = true; } }
public void LoadConfiguration() { var dlg = new OpenFileDialog(); dlg.Title = "Open Configuration File"; dlg.DefaultExt = ".xml"; dlg.Filter = "XML files (.xml)|*.xml"; dlg.CheckFileExists = true; //for testing //CSPBus bus1; //CSPBus CSPBus1 = new CSPBus("CANBUS", 100); if (dlg.ShowDialog() == true) { //Open script file if (File.Exists(dlg.FileName)) { try { //using the selected filename, adds modules to list for modules XDocument doc = XDocument.Parse(File.ReadAllText(dlg.FileName)); IEnumerable <Module> ModuleResult = from c in doc.Descendants("Module") select new Module() { Name = c.Element("name").Value, Address = int.Parse(c.Element("address").Value), Priority = int.Parse(c.Element("priority").Value), BusConnections = new ObservableCollection <Bus>(), //BusConnections.Add(new CSPBus(c.Element("connectedBuses").Value)), RegisteredErrors = new ObservableCollection <ErrorObject>(), Idle = true, Crashed = false }; foreach (Module mo in ModuleResult) { Modules.Add(mo); } //using the selected filename, adds bus to list for bus XDocument doc2 = XDocument.Parse(File.ReadAllText(dlg.FileName)); IEnumerable <CSPBus> BusResult = from c in doc2.Descendants("Bus") select new CSPBus() { Name = c.Element("name").Value, DataRate = int.Parse(c.Element("dataRate").Value), ConnectedModules = new ObservableCollection <Module>() }; IEnumerable <string> textSegs; string str; foreach (Bus bo in BusResult) { foreach (XElement xe in doc.Descendants("connectedModules")) { //get module where Modules.name == xe.ToString foreach (Module mod in Modules) { textSegs = from seg in xe.Descendants("name") select(string) seg; str = textSegs.Aggregate(new StringBuilder(), (sb, i) => sb.Append(i), sp => sp.ToString() ); //add module to bo.ConnectModule(Modules(x)) if (mod.Name.Equals(str)) { mod.ConnectBus(bo); } } } Buses.Add(bo); } } catch (Exception ex) { MessageBox.Show( "An error occured while trying to read the script file: " + ex.Message, "Error Reading File", MessageBoxButton.OK, MessageBoxImage.Error ); } } } }//end of LoadConfiguration