/// <summary> /// create and initialize a PiCar /// </summary> public static PiCar CreatePiCar(string serverAndPort, string credential) { DiscoverService discoverService = DiscoverService.GetOrCreateService(serverAndPort, credential); SystemClient httpSystem = discoverService.GetClientNode <SystemClient>(); PiCar picar = discoverService.GetClientNode <PiCar>(); if (picar != null) { picar.Server = httpSystem; } return(picar); }
/// <summary> /// Get Or Create Service for the specified server /// </summary> public static DiscoverService GetOrCreateService(string serverAndPort, string credential, bool create = false) { DiscoverService service; if (_serviceDictionary.TryGetValue(serverAndPort, out service)) { if (create) { service = new DiscoverService(serverAndPort, credential); _serviceDictionary[serverAndPort] = service; } } else { service = new DiscoverService(serverAndPort, credential); _serviceDictionary.Add(serverAndPort, service); } return(service); }