mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using MyCore.DTO.MyControlPanel;
|
|
using MyCore.Models.MyControlPanel.Database;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MyCore.Services.MyControlPanel
|
|
{
|
|
public class ProviderService
|
|
{
|
|
static List<string> supportedProviders = new List<string>() {
|
|
"Arlo",
|
|
"Meross",
|
|
"Yeelight",
|
|
"ZigBee"
|
|
};
|
|
|
|
public static bool IsExist(ProviderDatabaseService _ProviderDatabaseService, string userId, string providerId)
|
|
{
|
|
return _ProviderDatabaseService.GetById(userId, providerId) != null ? true : false;
|
|
}
|
|
|
|
public static List<Provider> GetAll(ProviderDatabaseService _ProviderDatabaseService, string userId)
|
|
{
|
|
return _ProviderDatabaseService.GetAll(userId);
|
|
}
|
|
|
|
public static ProviderDTO CreateOrUpdate(ProviderDatabaseService _ProviderDatabaseService, string userId, ProviderDTO providerDTO, bool create)
|
|
{
|
|
Provider provider;
|
|
if (create)
|
|
provider = new Provider();
|
|
else
|
|
{
|
|
provider = _ProviderDatabaseService.GetById(userId, providerDTO.Id);
|
|
}
|
|
|
|
if (!IsProviderSupported(providerDTO.Name))
|
|
throw new KeyNotFoundException("Provider is not yet supported");
|
|
|
|
provider.Name = providerDTO.Name;
|
|
provider.UserId = providerDTO.UserId;
|
|
provider.Username = providerDTO.Username;
|
|
provider.Password = providerDTO.Password;
|
|
provider.ApiKey = providerDTO.ApiKey;
|
|
provider.Active = true;
|
|
|
|
if (create)
|
|
return _ProviderDatabaseService.Create(provider).ToDTO();
|
|
else
|
|
return _ProviderDatabaseService.Update(provider.Id, provider).ToDTO();
|
|
}
|
|
|
|
public static Provider GetProviderById(ProviderDatabaseService _ProviderDatabaseService, string userId, string providerId)
|
|
{
|
|
return _ProviderDatabaseService.GetById(userId, providerId);
|
|
}
|
|
|
|
// TODO Get supported services
|
|
public static List<string> GetSupportedProvider()
|
|
{
|
|
return supportedProviders;
|
|
}
|
|
|
|
public static bool IsProviderSupported(string providerName)
|
|
{
|
|
return supportedProviders.Contains(providerName) ? true : false;
|
|
}
|
|
}
|
|
}
|
|
|