2018-09-28 22:25:55 +00:00
|
|
|
|
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 ()
|
2018-09-28 22:25:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
protected static TStorage storage;
|
|
|
|
|
|
|
|
|
|
|
|
public PlatformBuilderBase()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (storage == null) storage = new TStorage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-29 18:18:34 +00:00
|
|
|
|
public List<TAgent> GetAllAgents()
|
2018-09-28 22:25:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
return storage.Query();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-09-29 18:18:34 +00:00
|
|
|
|
public TAgent GetAgentById(string agentId)
|
2018-09-28 22:25:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
return storage.FetchById(agentId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-29 18:18:34 +00:00
|
|
|
|
public TAgent GetAgentByName(string agentName)
|
2018-09-28 22:25:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
return storage.FetchByName(agentName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-29 18:18:34 +00:00
|
|
|
|
public virtual bool SaveAgent(TAgent agent)
|
2018-09-28 22:25:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
// default save agent in FileStorage
|
|
|
|
|
|
storage.Persist(agent);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|