コード例 #1
0
 public List <FlightPlan> UpdateLog([FromBody] FlightPlan FL)
 {
     FL.UserId = DbContext.Users.Where(p => p.Email == User.Claims.Last().Value).Select(p => p.Id).FirstOrDefault();
     DbContext.pl_flightPlan.Update(FL);
     DbContext.SaveChanges();
     return(GetFlightPlanList());
 }
コード例 #2
0
        //Get a point based on interpolation of two segments and x axis of desired point.
        public Tuple <double, double> Interpolation(FlightPlan fp, int index, double distance)
        {
            Segment currSeg = null;

            if (index == 0)
            {
                currSeg = InitLocationToSeg(fp);
            }
            else
            {
                currSeg = fp.Segments[index - 1];
            }
            var endSeg            = fp.Segments[index];
            var relativeTimeInSeg = endSeg.TimespanSeconds / distance;
            //All variables for interpolation.
            var x0 = currSeg.Longitude;
            var y0 = currSeg.Latitude;
            var x1 = endSeg.Longitude;
            var y1 = endSeg.Latitude;
            var x  = x0 + ((x1 - x0) / relativeTimeInSeg);
            var y  = y0 + ((y1 - y0) / relativeTimeInSeg);
            //Longitude and latitude of current flight.
            var point = Tuple.Create(x, y);

            return(point);
        }
コード例 #3
0
        public async Task <FlightPlan> Get(string id)
        {
            //search in internal fligthPlans
            FlightPlan fp = flightsManager.GetFlight(id);

            //search in external fligthPlans
            foreach (Server server in serverManager.GetAllServers())
            {
                //if fp has been found
                if (fp != null)
                {
                    break;
                }

                string URL = server.ServerURL;
                if (server.ServerURL[server.ServerURL.Length - 1] == '/')
                {
                    URL = server.ServerURL.Substring(0, server.ServerURL.Length - 1);
                }
                //building Get request to synchronized servers
                string request = URL + ":" + server.ServerId + "/api/FlightPlan/" + id;
                fp = await Task.Run(() => DowonloadWebsite(request));
            }

            return(fp);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var o          = new FlightPlan();
            var serializer = new XmlSerializer(typeof(FlightPlan));

            serializer.Serialize(Console.Out, o);
        }
コード例 #5
0
        public async Task <ActionResult <FlightPlan> > PostFlightPlan(FlightPlan flightPlan)
        {
            _context.FlightPlans.Add(flightPlan);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFlightPlan", new { id = flightPlan.id }, flightPlan));
        }
コード例 #6
0
    private IEnumerator CreateFlightPlanRequest(Request r)
    {
        CreateFlightPlanRequest c = r as CreateFlightPlanRequest;

        c.Corp = _container._corps[c.CorpID];

        FlightPlan f = null;

        if (c.PlanID == -1)
        {
            f        = new FlightPlan(_container._flightPlanIDs++);
            f.Loaded = true;
            _container._flightPlans.Add(f.ID, f);
            c.Corp.FlightPlans.Add(f.ID);
        }
        else
        {
            f = _container._flightPlans[c.PlanID];
        }

        f.Data = c.Data;
        f.Name = c.Name;

        FinishRequest(c);
        yield break;
    }
コード例 #7
0
    private void Save()
    {
        AjaxResult result = new AjaxResult();

        try
        {
            var planid    = Guid.Parse(Request.Form["id"]);
            var startTime = Request.Form["ActualStartTime"];
            var endTime   = Request.Form["ActualEndTime"];

            FlightPlan model = flyBLL.Get(planid);
            model.GetEntitySearchPars <RepetitivePlan>(this.Context);
            //    model.ActualStartTime = Convert.ToDateTime(startTime);
            //   model.ActualEndTime = Convert.ToDateTime(endTime);
            model.ModifyTime = DateTime.Now;
            flyBLL.Update(model);

            result.IsSuccess = true;
            result.Msg       = "更新成功!";
        }
        catch (Exception ex)
        {
            result.IsSuccess = false;
            result.Msg       = "更新失败!\r\n" + ex.Message;
        }
        Response.Clear();
        Response.Write(result.ToJsonString());
        Response.ContentType = "application/json";
        Response.End();
    }
コード例 #8
0
        public async Task <List <string> > GetDestinationAndLandingTime(string id)
        {
            List <string> locations            = new List <string>();
            int           totalFlightInSeconds = 0;
            FlightPlan    plan = _dataBase.GetById(id);

            if (plan == null)
            {
                plan = await GetExternalFlightPlan(id, _idToServer.Get(id));
            }
            if (plan == null)
            {
                return(null);
            }

            List <Segment> segments    = plan.Segments;
            int            lastSegment = segments.Count() - 1;

            locations.Add(segments[lastSegment].Longitude.ToString());
            locations.Add(segments[lastSegment].Latitude.ToString());


            for (int i = 0; i < segments.Count; i++)
            {
                totalFlightInSeconds += segments[i].TimeSpan;
            }

            DateTime landingTime = plan.InitialLocation.DateTime.AddSeconds(totalFlightInSeconds);

            locations.Add(landingTime.ToString("yyyy-MM-ddTHH:mm:ssZ"));

            return(locations);
        }
コード例 #9
0
        public ActionResult AddNewFlightPlan(FlightPlan newFlightPlan)
        {
            // check if the flight plan is valid
            if (ModelState.IsValid)
            {
                // generate new id
                string flight_id = this.flightPlansModel.GenerateFlightId(newFlightPlan.CompanyName);

                // creating the flight object from the flight plan
                Flight newFlight = flightsModel.CreateFlightByFlightPlan(newFlightPlan, flight_id);
                newFlight.IsExternal = false;

                // adding the new flight to the list
                this.flightsModel.AddNewFlight(newFlight);

                // adding the flight plan
                this.flightPlansModel.AddNewFlightPlan(newFlightPlan, flight_id);

                return(CreatedAtAction(actionName: "AddNewFlightPlan", newFlight));
            }
            else
            {
                return(BadRequest());
            }
        }
        // test for IsValidFlightPlan function.
        // in this scenario - we are adding legal flight and expect to get true as a return value.
        public void IsValidFlightPlanFullFlightReturnsTrue()
        {
            // Arrange
            //new FlightPlan.
            var flightPlan = new FlightPlan();

            //new segment list.
            List <Segment> list     = new List <Segment>();
            var            segments = new Segment();

            segments.Latitude         = 31.12;
            segments.Longitude        = 33.16;
            segments.Timespan_seconds = 500;
            list.Add(segments);
            //new location.
            var location = new LocationAndTime(16, 14, new DateTime());

            flightPlan.Passengers       = 50;
            flightPlan.Company_Name     = "comp-name";
            flightPlan.Initial_Location = location;
            flightPlan.Segments         = list;

            //creating flightPlanController
            var flightPlanTester = new FlightPlanController(new FlightControlManager());

            // Act
            var result = flightPlan.IsValidFlightPlan();

            // Assert
            Assert.IsTrue(result);
        }
コード例 #11
0
 public MissionDebugger(CameraDefinition cameraDefinition, SurveyArea surveyArea, Mission mission, Transform droneTransform)
 {
     this.cameraDefinition = cameraDefinition;
     this.surveyArea       = surveyArea;
     this.flightPlan       = mission.CalculateFlightPlan();
     this.droneTransform   = droneTransform;
 }
コード例 #12
0
        public void ShouldGetFlightPlan()
        {
            using (var mock = AutoMock.GetLoose())
            {
                FlightPlan flightPlan = new FlightPlan()
                {
                    company_name = "sd"
                };

                Task <FlightPlan> task1 = Task <FlightPlan> .FromResult(flightPlan);

                var x = new Mock <IFlightPlanManager>();

                x.Setup(x => x.GetFlightPlanByID("123")).Returns(task1);

                var controller = new FlightPlanController(x.Object);

                var actionResult = controller.GetFlightPlanById("123").Result;
                Microsoft.AspNetCore.Mvc.OkObjectResult okObjectResult = (Microsoft.AspNetCore.Mvc.OkObjectResult)actionResult;
                var        temp   = okObjectResult.Value;
                FlightPlan actual = (FlightPlan)temp;

                var expected = new FlightPlan()
                {
                    company_name = "sd"
                };
                Assert.True(actual != null);
                Assert.Equal(expected.company_name, actual.company_name);
            }
        }
コード例 #13
0
        //This function is responsible for the interpolation.
        private Flight CalcLocation(DateTime relativeDate, DateTime currTimeFlifgt, FlightPlan flightPlan, int index, Segment[] flightSegments)
        {
            double startLongtitude = 0, endLongtitude, startLatitude = 0, endLatitude, finalLongtitude, finalLatitude;
            double timePassed, fracRate;

            // finds the time that passed until now.
            timePassed = relativeDate.Subtract(currTimeFlifgt).TotalSeconds;
            // Find the time ratio.
            fracRate = timePassed / flightSegments[index - 1].TimespanSeconds;
            // the first segment
            if (index == 1)
            {
                startLongtitude = flightPlan.InitialLocation.Longitude;
                startLatitude   = flightPlan.InitialLocation.Latitude;
            }
            else
            {
                startLongtitude = flightSegments[index - 2].Longitude;
                startLatitude   = flightSegments[index - 2].Latitude;
            }
            // The current segment's coordinates.
            endLongtitude = flightSegments[index - 1].Longitude;
            endLatitude   = flightSegments[index - 1].Latitude;
            // calculate the intepolation.
            finalLatitude   = startLatitude + (fracRate * (endLatitude - startLatitude));
            finalLongtitude = startLongtitude + (fracRate * (endLongtitude - startLongtitude));
            Flight flight = new Flight(flightPlan.FlightId, flightPlan.CompanyName,
                                       flightPlan.Passengers, false, finalLatitude, finalLongtitude, flightPlan.InitialLocation.DateTime);

            return(flight);
        }
コード例 #14
0
        public void BuildLocalTest_BuildSuccesfull_ReturnsTrue_()
        {
            //arrange
            FlightPlan plan   = new FlightPlan();
            Flight     flight = new Flight();

            plan.id           = 1;
            plan.flight_id    = "F1";
            plan.company_name = "AllenAir";
            plan.passengers   = 100;
            plan.initial_location_longitude = 0;
            plan.initial_location_latitude  = 0;
            plan.initial_location_date_time = "2020-06-03T20:00:00Z";
            Tuple <double, double> coordinates = new Tuple <double, double>
                                                     (plan.initial_location_longitude, plan.initial_location_latitude);
            string time = "2020-06-03T20:00:00Z";

            //act
            flight.BuildLocal(plan, coordinates, time);

            //assert
            if (!BuildOK(plan, flight))
            {
                Assert.Fail();
            }
        }
コード例 #15
0
        public void Test_GetFlight()
        {
            // Setup
            Location location = new Location(38.112375, 23.879437, DateTime.UtcNow);

            List <Segment> segments = new List <Segment>();

            segments.Add(new Segment(31.922629, 31.522594, 50)); // Egypt
            segments.Add(new Segment(32.426506, 34.743033, 50)); // Cyprus
            segments.Add(new Segment(26.209199, 35.055211, 50)); // Greece
            FlightPlan flightPlan = new FlightPlan(8, "Company", location, segments);

            var stubRemoteServersConnector = new RemoteServersConnector();
            var stubFlightsManager         = new FlightsManager(stubRemoteServersConnector);

            stubFlightsManager.AddFlightPlan(flightPlan);
            var flightsController = new FlightsController(stubFlightsManager);

            Thread.Sleep(1000);

            // Act
            IActionResult getAction = flightsController.GetFlights(DateTime.UtcNow.ToString());

            // Assert
            OkObjectResult okAction   = Assert.IsType <OkObjectResult>(getAction);
            string         flightsStr = Assert.IsType <string>(okAction.Value);
            var            flights    = JsonConvert.DeserializeObject(flightsStr);

            Assert.Single((System.Collections.IEnumerable)flights);
        }
コード例 #16
0
        public ActionResult <string> Post([FromBody] FlightPlan flightPlan)
        {
            if (flightManager.IsSegmentsValid(flightPlan) == false)
            {
                return(BadRequest("Invalid flightplan location"));
            }
            string flightPlanId = flightManager.CreateIdentifier(flightPlan);

            flightPlan.FlightPlanId = flightPlanId;
            memoryCache.Set(flightPlan.FlightPlanId, flightPlan);

            List <string> fpKeys = new List <string>();

            if (!memoryCache.TryGetValue("flightListKeys", out fpKeys))
            {
                fpKeys = new List <string>();
                fpKeys.Add(flightPlan.FlightPlanId);
                memoryCache.Set("flightListKeys", fpKeys);
            }
            else
            {
                fpKeys.Add(flightPlan.FlightPlanId);
            }
            return(Ok(flightPlanId));
        }
コード例 #17
0
        public void Test_DeleteFlight()
        {
            // Setup
            Location location = new Location(38.112375, 23.879437, DateTime.UtcNow);

            List <Segment> segments = new List <Segment>();

            segments.Add(new Segment(31.922629, 31.522594, 50)); // Egypt
            segments.Add(new Segment(32.426506, 34.743033, 50)); // Cyprus
            segments.Add(new Segment(26.209199, 35.055211, 50)); // Greece
            FlightPlan flightPlan = new FlightPlan(8, "Company", location, segments);

            var stubRemoteServersConnector = new RemoteServersConnector();
            var mockFlightsManager         = new FlightsManager(stubRemoteServersConnector);

            mockFlightsManager.AddFlightPlan(flightPlan);
            List <Flight> flights           = mockFlightsManager.GetRelativeFlights(DateTime.UtcNow, false);
            string        flightId          = flights.ToArray()[0].Flight_Id;
            var           flightsController = new FlightsController(mockFlightsManager);

            // Act
            IActionResult delAction = flightsController.DeleteFlight(flightId);

            // Assert
            Assert.IsType <OkResult>(delAction);
            Assert.Empty(mockFlightsManager.GetRelativeFlights(DateTime.UtcNow, false));
        }
コード例 #18
0
        public string Post([FromBody] FlightPlan flightPlan)
        {
            string  x    = flightPlan.ToJson();
            JObject json = JObject.Parse(x);

            string companyName = json["company_name"].ToString();

            flightPlan.FlightId = GenerateFlightID(companyName);

            InitialLocation initialLocation = json["initial_location"].ToObject <InitialLocation>();

            Flight flight = new Flight()
            {
                FlightId    = flightPlan.FlightId,
                Longitude   = initialLocation.Longitude,
                Latitude    = initialLocation.Latitude,
                Passengers  = Int32.Parse(json["passengers"].ToString()),
                CompanyName = json["company_name"].ToString(),
                DateTime    = initialLocation.DateTime,
                IsExternal  = false
            };

            flightsManager.AddFlight(flight);
            flightPlansManager.AddFlightPlan(flightPlan);

            return(flightPlan.FlightId);
        }
コード例 #19
0
        public static void FlightPlan_EqualsEdgeCasesShouldWork()
        {
            // Arrange
            FlightPlan flightPlan = getTestFlightPlan();
            FlightPlan selfReferenceFlightPlan           = flightPlan;
            FlightPlan nullFlightPlan                    = null;
            object     notSameObjectFlightPlan           = new List <double>();
            object     sameFlightDifferentPointerAddress = new FlightPlan()
            {
                CompanyName     = flightPlan.CompanyName,
                Passengers      = flightPlan.Passengers,
                InitialLocation =
                    new Location()
                {
                    Latitude  = flightPlan.InitialLocation.Latitude,
                    Longitude = flightPlan.InitialLocation.Longitude,
                    DateTime  = flightPlan.InitialLocation.DateTime
                },
                Segments = new List <Segment>(flightPlan.Segments)
            };

            // Act

            // Assert
            Assert.Equal(flightPlan, selfReferenceFlightPlan);
            Assert.NotEqual(flightPlan, nullFlightPlan);
            Assert.NotEqual(flightPlan, notSameObjectFlightPlan);
            Assert.Equal(flightPlan, sameFlightDifferentPointerAddress);
        }
コード例 #20
0
        public FlightPlan GetFlightPlan(string id)
        {
            DataRow[] flightIdRowArr;
            string    expressionIdToFind = "Flight_id = '" + id + "'";

            try
            {
                flightIdRowArr = this.planDataTable.Select(expressionIdToFind);
            }
            catch
            {
                throw new IDataBaseFlightPlan.ErrorIdNotExists();
            }
            DataRow    flightIdRow = flightIdRowArr.First();
            FlightPlan idPlan      = new FlightPlan();

            idPlan.Flight_id        = id;
            idPlan.Initial_Location = new Initial_Location();
            idPlan.Initial_Location.Initial_Date_time = TimeZoneInfo.ConvertTimeToUtc(Convert.ToDateTime(flightIdRow["Initial_Date_time"]));
            idPlan.Initial_Location.Initial_Latitude  = Convert.ToDouble(flightIdRow["Initial_Latitude"]);
            idPlan.Initial_Location.Initial_Longitude = Convert.ToDouble(flightIdRow["Initial_Longitude"]);
            idPlan.Passengers      = Convert.ToInt32(flightIdRow["Passengers"]);
            idPlan.End_Flight_Time = TimeZoneInfo.ConvertTimeToUtc(Convert.ToDateTime(flightIdRow["End_Flight_Time"]));
            idPlan.Company_name    = Convert.ToString(flightIdRow["Company_name"]);

            idPlan.Segments = GetFlightPlanSegment(expressionIdToFind);
            return(idPlan);
        }
コード例 #21
0
        private bool CheckSegments(FlightPlan fp, Flight f, DateTime start, DateTime relative)
        {
            bool   isRelevant = false;
            double startLat   = fp.InitialLocation.Latitude;
            double startLong  = fp.InitialLocation.Longitude;

            Segment[] sortArray    = fp.Segments.OrderBy(o => o.Key).ToArray();
            double    totalSeconds = (relative - start).TotalSeconds;
            double    timePassed   = 0;
            int       segNum;

            // Run over the segments.
            for (segNum = 0; segNum < sortArray.Length; segNum++)
            {
                double time = totalSeconds - timePassed;
                // The plan is in this segment at the time is given.
                if (time < sortArray[segNum].TimespanSeconds)
                {
                    double l = time / sortArray[segNum].TimespanSeconds;
                    f.Latitude  = startLat + l * (sortArray[segNum].Latitude - startLat);
                    f.Longitude = startLong + l * (sortArray[segNum].Longitude - startLong);
                    isRelevant  = true;
                    break;
                }
                else
                {
                    // Save the start location of the segment.
                    startLat    = sortArray[segNum].Latitude;
                    startLong   = sortArray[segNum].Longitude;
                    timePassed += sortArray[segNum].TimespanSeconds;
                }
            }
            return(isRelevant);
        }
コード例 #22
0
        public async Task <ActionResult <FlightPlan> > Get(string id)
        {
            FlightPlan p = null;

            if (planModel.GetAllPlans().FirstOrDefault(t => string.Compare(t.Key, id, true) == 0).Value != null)
            {
                p = planModel.GetAllPlans().FirstOrDefault(t => string.Compare(t.Key, id, true) == 0).Value;
            }
            else
            {
                try
                {
                    //search this id in external servers
                    Servers s;
                    serverModel.GetServerToFlightDic().TryGetValue(id, out s);
                    string url      = s.ServerURL + "/api/FlightPlan/" + id;
                    var    contentt = await this.client.GetStringAsync(url);

                    p = JsonConvert.DeserializeObject <FlightPlan>(contentt);
                }
                catch (WebException)
                {
                    return(BadRequest());
                }
                catch (Exception)
                {
                    return(StatusCode(500));
                }
            }
            if (p == null)
            {
                return(StatusCode(400));
            }
            return(p);
        }
コード例 #23
0
        public async Task <IActionResult> PutFlightPlan(int id, FlightPlan flightPlan)
        {
            if (id != flightPlan.id)
            {
                return(BadRequest());
            }

            _context.Entry(flightPlan).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlightPlanExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #24
0
        public FlightPlan Post(FlightPlan p)
        {
            //check FP json validation validation
            bool segmentsIsValid        = false;
            bool initialLocationIsValid = false;

            if ((p.InitialLocation != null))
            {
                initialLocationIsValid = (p.InitialLocation.DateTime == null) || (p.InitialLocation.Latitude > 90) ||
                                         (p.InitialLocation.Latitude < -90) || (p.InitialLocation.Longitude > 180) ||
                                         (p.InitialLocation.Longitude < -180);
            }
            if ((p.Segments != null))
            {
                foreach (var seg in p.Segments)
                {
                    bool result = (seg.Latitude < -90) || (seg.Latitude > 180) ||
                                  (seg.Latitude < -90) || (seg.Longitude > 180) || (seg.TimespanSeconds <= 0);
                    segmentsIsValid = segmentsIsValid || result;
                }
            }

            bool isNull = (p.CompanyName == null) || (p.Passengers <= 0) || (p.Segments == null) || (p.InitialLocation == null) ||
                          initialLocationIsValid || segmentsIsValid;

            if (isNull == true)
            {
                throw new InvalidOperationException();
            }

            planModel.AddPlan(p);
            return(p);
        }
コード例 #25
0
        public void Post(FlightPlan flightPlan)
        {
            FlightDetails fd = new FlightDetails();

            fd.FlightPlan = flightPlan;
            //build new flight for fd
            Flight temp_f = new Flight
            {
                Flight_id    = flightPlan.Company_name + flightManager.GetSize(),
                Longitude    = flightPlan.Initial_location.Longitude,
                Latitude     = flightPlan.Initial_location.Latitude,
                Passengers   = flightPlan.Passengers,
                Company_name = flightPlan.Company_name,
                Date_time    = flightPlan.Initial_location.Date_time,
                Is_external  = false
            };

            fd.Flight = temp_f;

            //build new dateTime for fd
            DateTime temp_d = fd.FlightPlan.Initial_location.Date_time;

            foreach (Segment seg in fd.FlightPlan.Segments)
            {
                temp_d = temp_d.AddSeconds(seg.Timespan_seconds);
            }

            fd.Landing_time = temp_d;

            flightManager.AddEllement(fd);
        }
コード例 #26
0
        // The following function is used for getting the correct Flight Plan according the
        // flight id by a http client request. it will invoke the client side's function which
        // will draw the path of the flight plan.
        private async Task getFlightPlansFromExServerAsync(List <Flight> exFlights, string ur)
        {
            FlightPlan fp     = new FlightPlan();
            var        client = new HttpClient();

            foreach (var flight in exFlights)
            {
                string url = ur + "/api/FlightPlan/";
                flight.is_external = true;
                url = url + flight.flight_id;
                var content = await client.GetStringAsync(url);

                fp = JsonConvert.DeserializeObject <FlightPlan>(content);
                fp.flightPlanID         = flight.flight_id;
                flight.starting_datails = fp.initial_location.date_time.ToString("dd-MM-yyyy");
                flight.initial_location = "Lat: " + fp.initial_location.latitude.ToString() + "  Lon: " + fp
                                          .initial_location.longitude.ToString();
                double end = 0;

                int i;
                for (i = 0; i < fp.segments.Count; i++)
                {
                    // Count the total time in seconds of the whole segments.
                    end += fp.segments[i].timespan_seconds;
                }

                flight.final_location = "Lat: " + fp.segments[i - 1].latitude.ToString() + "  Lon: " +
                                        fp.segments[i - 1].longitude.ToString();
                DateTime landing = new DateTime();
                landing                = fp.initial_location.date_time.AddSeconds(end);
                flight.landing_time    = landing;
                flight.landing_details = landing.ToString("dd-MM-yyyy");
                FlightPlanManager.FlightPlansDic.TryAdd(fp.flightPlanID, fp);
            }
        }
コード例 #27
0
        public string Get(int id)
        {
            FlightPlan flight   = serverM.GetFlightById(id);
            string     response = JsonConvert.SerializeObject(flight);

            return(response);
        }
コード例 #28
0
        public JsonResult Get(string id)
        {
            FlightDetails fd = flightManager.GetEllement(id);

            if (fd == null)
            {
                Server server;
                Dictionary <string, Server> dic = ServerManager.dictionary;
                if (dic.TryGetValue(id, out server))
                {
                    string         strResult;
                    string         url     = server.ServerURL + "/api/FlightPlan/" + id;
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                        using (Stream stream = response.GetResponseStream())
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                strResult = reader.ReadToEnd();
                                reader.Close();
                            }
                    FlightPlan flights = JsonConvert.DeserializeObject <FlightPlan>(strResult);
                    return(new JsonResult(flights));
                }
            }
            JsonResult jr = new JsonResult(fd.FlightPlan);

            return(jr);
        }
コード例 #29
0
        private static string generateFlightId(FlightPlan flightPlan)
        {
            StringBuilder sb  = new StringBuilder();
            int           mod = ModNumber;
            string        trimmedCompanyName = flightPlan.CompanyName.Replace(" ", string.Empty);
            int           length             = trimmedCompanyName.Length;

            if (length < 5)
            {
                for (int i = 0; i < 5 - length; i++)
                {
                    mod *= 10;
                }

                sb.Append(trimmedCompanyName.Substring(0, length));
            }
            else
            {
                sb.Append(trimmedCompanyName.Substring(0, 5));
            }

            // var key = BitConverter.ToUInt64(hashedValue) % mod;
            var key = Math.Abs(flightPlan.GetHashCode()) % mod;

            return(sb.Append($"-{key}").ToString().ToUpper());
        }
コード例 #30
0
        private void crearFlightPlanToolStripMenuItem_Click(object sender, EventArgs e) //opción crear flightplan
        {
            try
            {
                //Abrimos el form que lee los datos del FP, lo crea y lo devuelve
                AñadirFP F = new AñadirFP();
                F.cambiarfondo(fondo);
                F.ShowDialog();

                //Recogemos el FP que ha creado el form anterior
                FlightPlan FP = F.getflightdata();

                if (FP != null)
                {
                    //Usamos el método de añadir FP de la lista. Si el FP ya existe en la lista devuelve true, sino false
                    bool a = listFP.añadirfp(FP);

                    if (a == true) //No añade el FP a la lista porque ya existe (informamos con un MessageBox)
                    {
                        MessageBox.Show("Ese plan de vuelo ya existe");
                    }

                    if (a == false)             //Ha añadido el FP a la lista (informamos con un MessageBox), así que dibujamos su avión
                    {
                        DibujarNuevoFP(listFP); //Para dibujar el avión
                        MessageBox.Show("Plan de vuelo añadido");
                        conflictoscomprobados = false;
                    }
                }
            }
            catch
            {
            }
        }