Пример #1
0
        /// <summary>
        /// Insert a new gateway named "TEST: C#-api-gateway-insert"
        /// </summary>
        /// <param name="parkingLotId">The Id of the parking lot inserted earlier</param>
        /// <returns>New gateway's Id</returns>
        private static async Task <string> InsertGateway(string parkingLotId)
        {
            Console.WriteLine("Testing '/api/gateway/insert'");

            const string gatewayName = "TEST: C#-api-gateway-insert";

            // Sample JSON to send
            JObject json = new JObject {
                ["gatewayMac"]   = "cdef78904321dcb0",
                ["gatewayName"]  = gatewayName,
                ["parkingLotId"] = parkingLotId
            };

            await GatewayApi.InsertGateway(json.ToString());

            Console.WriteLine("Gateway Insert Success");

            // Get the gateway Id of the inserted gateway
            List <Gateway> gateways = await GatewayApi.GetGateways();

            string gatewayId = null;

            foreach (Gateway gateway in gateways)
            {
                if (gateway.Name == gatewayName)
                {
                    gatewayId = gateway.Id;
                    break;
                }
            }
            Console.WriteLine("ID of inserted gateway: " + gatewayId + "\n");
            return(gatewayId);
        }
Пример #2
0
 public WorkBenchService()
 {
     _apiGateway = new GatewayApi
     {
         SiteUrl = blockChainApiUrl
     };
 }
Пример #3
0
        static void Main(string[] args)
        {
            int distance   = GetDistance();
            var gatewayApi = new GatewayApi();

            try
            {
                var starships = gatewayApi.GetAllStarships();

                foreach (StarshipModel item in starships)
                {
                    StarshipModel stops = MainCalculator.CalculateStops(distance, item);
                    if (int.TryParse(stops.Stops, out int stop))
                    {
                        if (Convert.ToInt32(stops.Stops) >= 0)
                        {
                            Console.WriteLine($"{item.Name}: {stops.Stops}");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"An error occurred. {e}");
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey(true);
        }
Пример #4
0
        /// <summary>
        /// Remove that updated gateway
        /// </summary>
        /// <param name="gatewayId">The Id of the updated gateway</param>
        private static async Task RemoveGateway(string gatewayId)
        {
            Console.WriteLine("Testing '/api/gateway/remove'");

            // Sample JSON to send
            JObject json = new JObject {
                ["id"] = gatewayId
            };

            await GatewayApi.RemoveGateway(json.ToString());

            Console.WriteLine("Gateway Remove Success\n");
        }
Пример #5
0
        /// <summary>
        /// Update that new gateway's name to "TEST: C#-api-gateway-update"
        /// </summary>
        /// <param name="gatewayId">The Id of the inserted gateway</param>
        private static async Task UpdateGateway(string gatewayId)
        {
            Console.WriteLine("Testing '/api/gateway/update'");

            // Sample JSON to send
            JObject json = new JObject {
                ["id"]          = gatewayId,
                ["gatewayName"] = "TEST: C#-api-gateway-update"
            };

            await GatewayApi.UpdateGateway(json.ToString());

            Console.WriteLine("Gateway Update Success\n");
        }
Пример #6
0
        /// <summary>
        /// Fetch all of the gateways and print them out
        /// </summary>
        private static async Task GetGateways()
        {
            Console.WriteLine("Testing '/api/gateways'");

            List <Gateway> gateways = await GatewayApi.GetGateways();

            Console.WriteLine("Got " + gateways.Count + " Gateways:");

            foreach (Gateway gateway in gateways)
            {
                Console.WriteLine("--> " + gateway.GatewayMac + ": " + gateway.Name);
            }
            Console.WriteLine();
        }