public static void Init <TOTService>() where TOTService : IOTService { otServiceType = typeof(TOTService); List <Device> devices = new List <Device>(); lock (_deviceConnectorLock) { try { //http://161.27.206.191/HMIHub/api/SubscriptionHub/ServerConnect string ipHub = ConfigurationManager.AppSettings["HubIp"]; _deviceConnector = new DeviceConnector("OTWeb", $"{ipHub}/HMIHub/api/"); _deviceConnector.OnClientConnectedMethod += OnSmartWatchConnected; _deviceConnector.OnClientReConnectedMethod += OnSmartWatchConnected; _deviceConnector.OnMessageReceivedMethod += OnSmartWatchAcknowledge; _deviceConnector.Connect(); devices.AddRange(_deviceConnector.GetAllDevices().Where(kvp => kvp.Value.Connected).Select(kvp => kvp.Value)); StaticRepository.CheckRepository(ConfigurationManager.AppSettings["DataPath"], ConfigurationManager.AppSettings["DataFileName"]); } catch (Exception e) { var x = e.Message; } } foreach (var device in devices) { //device.Username = "******"; //device.Password = "******"; OnSmartWatchConnected(device); } }
//Trying to using SQL Repository but thowing error regarding lack of connection to DB? //handling this by loading data from Static Repository; //ToDo: check why SQLRepository cannot find connection to DB? #region Private Methods private void LoadData() { try { var repo = new SQLRepository(); _patients = repo.GetPatients(); } catch (Exception ex) { //Log details of exception and proide meaningful information to the end user; var localRepo = new StaticRepository(); _patients = localRepo.GetPatients(); } }
public APIBaseResponse AddProduct([FromBody] ProductRequest request) { if (request == null) { return(new APIBaseResponse { Message = "Invalid data was received" }); } if (string.IsNullOrWhiteSpace(request.ProductName) || request.MOQ < 1 || request.Price <= 0) { return(new APIBaseResponse { Message = "We received an invalid request. Please ensure that you provide name, the MOQ and a price greater than 0 (zero)." }); } IRepository <RetailProduct> productRepo = null; if (IsStaticRepo) { productRepo = new StaticRepository <RetailProduct>(); } else { productRepo = new SQLRepository <RetailProduct>(); } var products = ProcessRequest.GetProducts(productRepo, "select * from RetailProduct"); return(new APIBaseResponse { IsSuccessful = true, Data = products }); }