Files
Mapo-IOB-WIN/IOB-UT/RedisMan.cs
T
2020-01-22 14:24:09 +01:00

136 lines
3.1 KiB
C#

using ServiceStack.Redis;
using ServiceStack.Redis.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IOB_UT
{
public class RedisIobCache
{
/// <summary>
/// Pool manager
/// </summary>
protected RedisManagerPool redisManPool;
/// <summary>
/// Client corrente
/// </summary>
protected IRedisClient redisClient;
/// <summary>
/// Oggetto descrizione stato SERVER MP-IO
/// </summary>
protected IRedisTypedClient<ServerMpStatus> redServerStatus;
/// <summary>
/// Oggetto descrizione stato CLIENT IOB
/// </summary>
protected IRedisTypedClient<IobWinStatus> redIobStatus;
/// <summary>
/// Codice server MP
/// </summary>
protected string CodServer = "1";
/// <summary>
/// Cod IOB
/// </summary>
protected string CodIob = "000";
/// <summary>
/// init classe gestione dati IOB su Redis
/// </summary>
/// <param name="codServer"></param>
/// <param name="codIob"></param>
public RedisIobCache(string codServer, string codIob)
{
// init dati di base...
CodServer = codServer;
CodIob = codIob;
// init oggetti connessione
redisManPool = new RedisManagerPool(baseUtils.CRS("SSRedisConf"));
redisClient = redisManPool.GetClient();
// init oggetto server
redServerStatus = redisClient.As<ServerMpStatus>();
var newSrvStatus = new ServerMpStatus()
{
Id = CodServer,
online = false
};
redServerStatus.Store(newSrvStatus);
// init oggetto IOB
redIobStatus = redisClient.As<IobWinStatus>();
var newIobStatus = new IobWinStatus()
{
Id = CodIob,
online = false
};
redIobStatus.Store(newIobStatus);
}
/// <summary>
/// Accesso all'oggetto stato server da esterno
/// </summary>
public ServerMpStatus servStatus
{
get
{
ServerMpStatus answ = redServerStatus.GetById(CodServer);
if(answ==null)
{
answ = new ServerMpStatus()
{
Id = CodServer,
online = false
};
redServerStatus.Store(answ);
}
return answ;
}
set
{
redServerStatus.Store(value);
}
}
/// <summary>
/// Accesso all'oggetto stato IOB da esterno
/// </summary>
public IobWinStatus iobStatus
{
get
{
IobWinStatus answ = redIobStatus.GetById(CodServer);
if (answ == null)
{
answ = new IobWinStatus()
{
Id = CodServer,
online = false
};
redIobStatus.Store(answ);
}
return answ;
}
set
{
redIobStatus.Store(value);
}
}
/// <summary>
/// Variabile in cui viene salvato lo stato del server MP-IO
/// </summary>
public bool MPIO_Online
{
get
{
return servStatus.online;
}
set
{
var currData = servStatus;
currData.online = value;
servStatus = currData;
}
}
}
}