public async Task <IActionResult> GetAsync([FromQuery] string from, [FromQuery] string to, [FromQuery] string start)
        {
            // Check for errors
            if (string.IsNullOrEmpty(from) || string.IsNullOrEmpty(to) || string.IsNullOrEmpty(start))
            {
                _logger.LogWarning("Invalid parameters.");
                return(BadRequest());
            }

            // Get all routes
            var routesResponse = await _client.GetAsync("/data-exchange/htl-homework/travelPlan.json");

            routesResponse.EnsureSuccessStatusCode();
            var responseBody = await routesResponse.Content.ReadAsStringAsync();

            var routes = JsonSerializer.Deserialize <Route[]>(responseBody);

            // Find the connection
            var finder = new ConnectionFinder(routes);
            var trip   = finder.FindConnection(from, to, start);

            if (trip == null)
            {
                _logger.LogWarning("No connection found.");
                return(NotFound());
            }

            return(Ok(trip));
        }
Exemple #2
0
        void Reconnect()
        {
            connection.Close();
            connection = null;

            EV3Directory.Visibility  = Visibility.Hidden;
            BrickNotFound.Visibility = Visibility.Visible;

            ev3path      = "/home/root/lms2012/prjs/";
            EV3Path.Text = ev3path;

            // find connected brick
            try
            {
                connection = ConnectionFinder.CreateConnection(true, false);
                ReadEV3Directory(true);
                ReadEV3DeviceName();
            }
            catch (Exception)
            {
                System.Environment.Exit(1);
            }

            EV3Directory.Visibility  = Visibility.Visible;
            BrickNotFound.Visibility = Visibility.Hidden;

            AdjustDisabledStates();
        }
 public TravelPlanController(IHttpClientFactory clientFactory)
 {
     _clientFactory   = clientFactory;
     client           = clientFactory.CreateClient();
     routes           = GetRoutesFromAPIAsync().Result;
     connectionFinder = new ConnectionFinder(routes);
 }
Exemple #4
0
        // startup
        public MainWindow()
        {
            // find connected brick
            try
            {
                connection = ConnectionFinder.CreateConnection(true, true);
            }
            catch (Exception)
            {
                System.Environment.Exit(1);
            }


            // load peristent settings
            ExplorerSettings settings = new ExplorerSettings();

            settings.Load();

            // create the compiler and assembler instances
            assembler = new Assembler();
            compiler  = new Compiler();

            // initialize common data
            ev3path = "/home/root/lms2012/prjs/";
            try
            {
                pcdirectory = new DirectoryInfo(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal));
            } catch (Exception)
            {
                pcdirectory = null;
            }
            if (settings.localDirectory.Length > 0)
            {
                try
                {
                    pcdirectory = settings.localDirectory.Equals("Computer") ? null : new DirectoryInfo(settings.localDirectory);
                }
                catch (Exception) { }
            }

            // set up all UI controls
            InitializeComponent();
            this.Width                      = settings.windowWidth;
            this.Height                     = settings.windowHeight;
            this.leftColumn.Width           = new GridLength((double)settings.splitterPosition, GridUnitType.Pixel);
            this.OnlyShowPrograms.IsChecked = settings.onlyShowPrograms;

            // retrieve initial data from brick
            EV3Path.Text = ev3path;
            ReadEV3Directory(true);
            ReadEV3DeviceName();

            PCPath.Text = pcdirectory == null ? "Computer" : pcdirectory.FullName;
            RefreshPCList(true);
        }
        public void GivenNodesWithoutMatchingCompany_WhenFindConnectionWorkingForIsInvoked_NullIsReturned()
        {
            // Arrange
            var          node    = GetNodes();
            const string Company = "X";

            // Act
            var result = ConnectionFinder.FindConnectionWorkingFor(node, Company);

            // Assert
            Assert.Null(result);
        }
        public async Task <ActionResult> Get([FromQuery] string from, [FromQuery] string to, [FromQuery] string start)
        {
            var routesResponse = await client.GetAsync("https://cddataexchange.blob.core.windows.net/data-exchange/htl-homework/travelPlan.json");

            routesResponse.EnsureSuccessStatusCode();
            var json = await routesResponse.Content.ReadAsStringAsync();

            var routes          = JsonSerializer.Deserialize <IEnumerable <Route> >(json);
            ConnectionFinder cf = new ConnectionFinder(routes);
            var trips           = cf.FindConnection(from, to, start);

            if (trips == null)
            {
                return(NotFound());
            }
            return(Ok(trips));
        }
Exemple #7
0
        public async Task <IActionResult> Get([FromQuery] string from, [FromQuery] string to, [FromQuery] string start)
        {
            var client = _factory.CreateClient();
            var resp   = await client.GetAsync("https://cddataexchange.blob.core.windows.net/data-exchange/htl-homework/travelPlan.json");

            resp.EnsureSuccessStatusCode();
            var routes = JsonSerializer.Deserialize <Route[]>(await resp.Content.ReadAsStringAsync());
            var finder = new ConnectionFinder(routes);
            var trip   = finder.FindConnection(from, to, start);

            if (trip == null)
            {
                return(NotFound());
            }

            return(Ok(new {
                depart = trip.FromCity,
                departureTime = trip.Leave,
                arrive = trip.ToCity,
                arrivalTime = trip.Arrive,
            }));
        }
        /// <summary>
        /// Marks polygons at one end of this line.
        /// </summary>
        /// <param name="isStart">Start of this line?</param>
        void MarkPolygons(bool isStart)
        {
            // Get a connecting divider
            IDivider d = (isStart ? GetFirstDivider() : GetLastDivider());
            ConnectionFinder cf = new ConnectionFinder(d, isStart);
            IDivider next = cf.Next;
            if (next==null)
                throw new Exception("LineFeature.MarkPolygons - Cannot determine network cycle");

            // If we connected to the start of the connecting divider,
            // mark it's polygons to the right. Otherwise the left.
            if (cf.IsStart)
                Topology.MarkRight(next);
            else
                Topology.MarkLeft(next);
        }
 /// <summary>
 /// Gets the side code for a horizontal segment which is incident on a node,
 /// given any one the boundaries incident on the node.
 /// </summary>
 /// <param name="id">The divider we know about (incident on node).</param>
 /// <param name="isStart">True if it's the start of <c>ib</c>.</param>
 /// <param name="od">The divider the returned side refers to</param>
 /// <returns>Side.Left if the segment is to the left of <c>ob</c>, Side.Right
 /// if segment to the right.</returns>
 internal Side GetSide(IDivider id, bool isStart, out IDivider od)
 {
     ConnectionFinder connect = new ConnectionFinder(id, isStart, this);
     od = connect.Next;
     return (connect.IsStart ? Side.Right : Side.Left);
 }
        static void Main(string[] args)
        {
            foreach (String a in args)
            {
                Console.WriteLine("{0}", a);
            }

            if (args[0].Equals("asmLms"))
            {
                if (args.Length != 3)
                {
                    Console.WriteLine("Error 0: No all params [see help]");
                    return;
                }
                Assembler asm = new Assembler();
                //FileStream fs = new FileStream(f, FileMode.Open, FileAccess.Read);
                FileStream fs   = new FileStream(args[1], FileMode.Open, FileAccess.Read);
                FileStream fout = new FileStream(args[2], FileMode.Create, FileAccess.Write);

                List <String> errors = new List <String>();
                asm.Assemble(fs, fout, errors);
                if (errors.Count != 0)
                {
                    Console.WriteLine("error in assembler for lms2012");
                    foreach (String a  in errors)
                    {
                        Console.WriteLine(a);
                    }
                }
            }
            else if (args[0].Equals("disasmRbf"))
            {
                if (args.Length != 3)
                {
                    Console.WriteLine("Error 0: No all params [see help]");
                    return;
                }

                Assembler  asm  = new Assembler();
                FileStream from = new FileStream(args[1], FileMode.Open, FileAccess.Read);

                asm.Disassemble(from, Console.Out);
            }
            else if (args[0].Contains("download"))
            {
                if (args.Length != 3)
                {
                    Console.WriteLine("Error 0: No all params [see help]");
                    return;
                }
                EV3Connection connection = ConnectionFinder.CreateConnection(true, true);
                Console.WriteLine("Connection {0}", connection.IsOpen());
                byte[] data = null;
                try
                {
                    data = connection.ReadEV3File(args[1]);
                } catch (Exception e)
                {
                    Console.WriteLine("{0}", e.ToString());
                }

                FileStream fileStream = new FileStream(args[2], FileMode.Create, FileAccess.Write);
                fileStream.Write(data, 0, data.Length);
            }
            else if (args[0].Contains("upload"))
            {
                if (args.Length != 3)
                {
                    Console.WriteLine("Error 0: No all params [see help]");
                    return;
                }
                EV3Connection connection = ConnectionFinder.CreateConnection(true, true);
                FileStream    from       = new FileStream(args[2], FileMode.Open, FileAccess.Read);
                byte[]        data       = new byte[from.Length];

                from.Read(data, 0, (int)from.Length);

                connection.CreateEV3File(args[1], data);
                connection.Close();
            }
            else if (args.Contains("execute"))
            {
                if (args.Length != 2)
                {
                    Console.WriteLine("Error 0: No all params [see help]");
                    return;
                }
                EV3Connection connection = ConnectionFinder.CreateConnection(true, true);
                Console.WriteLine("Trying to start: " + args[1]);

                ByteCodeBuffer c = new ByteCodeBuffer();
                // load and start it
                c.OP(0xC0);       // opFILE
                c.CONST(0x08);    // CMD: LOAD_IMAGE = 0x08
                c.CONST(1);       // slot 1 = user program slot
                c.STRING(args[1]);
                c.GLOBVAR(0);
                c.GLOBVAR(4);
                c.OP(0x03);       // opPROGRAM_START
                c.CONST(1);       // slot 1 = user program slot
                c.GLOBVAR(0);
                c.GLOBVAR(4);
                c.CONST(0);

                connection.DirectCommand(c, 10, 0);
            }

            Console.ReadKey();
        }