public void AllowMoving(string from, string to) { bl.WriteToLog("Для автобуса " + this.busId + ", движущегося к самолету " + this.planeId + " запрошено передвижение от " + from + " до " + to + "."); var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://groundcontrol.v2.vapor.cloud/askForPermission"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"from\":\"" + from + "\"," + "\"to\":\"" + to + "\"," + "\"service\":\"Buss Service\"," + "\"identifier\":\"" + this.busId + "\"}"; streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); string response; using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { response = streamReader.ReadToEnd(); } if (response != "{\"permission\" : \"Obtained\"}") { bl.WriteToLog("Для автобуса " + this.busId + ", движущегося к самолету " + this.planeId + " запрос на передвижение от " + from + " до " + to + " поставлен в очередь."); bool res = false; while (res != true) { var file = new FileCSV(); var cnt = 0; while (cnt == 0) { cnt = file.ExistsInCSVMoving(this.busId); } res = true; } } bl.WriteToLog("Для автобуса " + this.busId + ", движущегося к самолету " + this.planeId + " разрешено передвижение от " + from + " до " + to + "."); }
public void Execute() { var file = new FileCSV(); var cntformoving = 0; while (cntformoving == 0) { cntformoving = file.ReadFromCSVСnts(this.busId); Thread.Sleep(500); } file.RemoveFromCSVCnts(this.busId); bl.WriteToLog("Автобусу " + this.busId + ", движущемуся к самолету " + this.planeId + " необходимо перевезти " + cntformoving + " пассажиров."); Thread.Sleep(10000); //еду bl.WriteToLog("Автобус " + this.busId + ", движущийся к самолету " + this.planeId + " прибыл к GT1"); SendLocation("BGR", "GT1", "Busy"); //удостоверилась, что сели в автобус все пассажиры var checkcntpas = -1; while (checkcntpas != cntpas) { checkcntpas = file.ReadFromCSVPassanger(this.busId); Thread.Sleep(500); } bl.WriteToLog("Автобус " + this.busId + ", движущийся к самолету " + this.planeId + " принял на борт всех пассажиров."); SendLocation("BGR", "GT1", "Idle"); //запрос на передвижение FindPlaneLocationCode(); AllowMoving("GT1", this.planelocationcode); SendLocation("GT1", this.planelocationcode, "Moving"); Thread.Sleep(10000);//еду bl.WriteToLog("Автобус " + this.busId + ", движущийся к самолету " + this.planeId + " прибыл к " + this.planelocationcode + "."); SendLocation("GT1", this.planelocationcode, "Busy"); //окончание движения EndMoving(); //оповещаю пассажиров в автобусе, что пора сваливать. BusArivedToAirplane(); Thread.Sleep(1000); file.RemoveFromCSVPassangerInBus(this.busId); bl.WriteToLog("Автобус " + this.busId + ", движущийся к самолету " + this.planeId + " пуст. Все пассажиры вышли из автобуса"); SendLocation("GT1", this.planelocationcode, "Idle"); //запрос на передвижение AllowMoving(this.planelocationcode, "SGR"); SendLocation(this.planelocationcode, "SGR", "Moving"); Thread.Sleep(1000); bl.WriteToLog("Автобус " + this.busId + " прибыл на стоянку"); SendLocation(this.planelocationcode, "SGR", "Busy"); SendLocation(this.planelocationcode, "SGR", "Idle"); //окончание движения EndMoving(); //освободила автобус file.ChangeBusStatusCSV(this.busId); bl.WriteToLog("Автобус " + this.busId + " свободен."); }
public void EndMoving() { var file = new FileCSV(); file.RemoveFromCSVMoving(this.busId); }