BotSharp/BotSharp.Core/PlatformBuilderBase.cs

44 lines
991 B
C#
Raw Normal View History

using BotSharp.Platform.Abstraction;
using BotSharp.Platform.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Core
{
2018-09-29 18:18:34 +00:00
public abstract class PlatformBuilderBase<TStorage, TAgent>
where TStorage : IAgentStorage<TAgent>, new ()
{
protected static TStorage storage;
public PlatformBuilderBase()
{
if (storage == null) storage = new TStorage();
}
2018-09-29 18:18:34 +00:00
public List<TAgent> GetAllAgents()
{
return storage.Query();
}
2018-09-29 18:18:34 +00:00
public TAgent GetAgentById(string agentId)
{
return storage.FetchById(agentId);
}
2018-09-29 18:18:34 +00:00
public TAgent GetAgentByName(string agentName)
{
return storage.FetchByName(agentName);
}
2018-09-29 18:18:34 +00:00
public virtual bool SaveAgent(TAgent agent)
{
// default save agent in FileStorage
storage.Persist(agent);
return true;
}
}
}