Aggiunti metodi override x cache HTTP/Redis

This commit is contained in:
Samuele E. Locatelli
2018-10-22 15:23:45 +02:00
parent 2441b6f370
commit 944d470c1e
4 changed files with 120 additions and 45 deletions
+4 -4
View File
@@ -358,7 +358,7 @@ SELECT sorgente, chiave, valore, note FROM ConfigTmp WHERE (chiave = @chiave) AN
<xs:element name="DS_Utility" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:EnableTableAdapterManager="true" msprop:Generator_DataSetName="DS_Utility" msprop:Generator_UserDSName="DS_Utility">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="ListValues" msprop:Generator_TableClassName="ListValuesDataTable" msprop:Generator_TableVarName="tableListValues" msprop:Generator_TablePropName="ListValues" msprop:Generator_RowDeletingName="ListValuesRowDeleting" msprop:Generator_RowChangingName="ListValuesRowChanging" msprop:Generator_RowEvHandlerName="ListValuesRowChangeEventHandler" msprop:Generator_RowDeletedName="ListValuesRowDeleted" msprop:Generator_UserTableName="ListValues" msprop:Generator_RowChangedName="ListValuesRowChanged" msprop:Generator_RowEvArgName="ListValuesRowChangeEvent" msprop:Generator_RowClassName="ListValuesRow">
<xs:element name="ListValues" msprop:Generator_TableClassName="ListValuesDataTable" msprop:Generator_TableVarName="tableListValues" msprop:Generator_RowChangedName="ListValuesRowChanged" msprop:Generator_TablePropName="ListValues" msprop:Generator_RowDeletingName="ListValuesRowDeleting" msprop:Generator_RowChangingName="ListValuesRowChanging" msprop:Generator_RowEvHandlerName="ListValuesRowChangeEventHandler" msprop:Generator_RowDeletedName="ListValuesRowDeleted" msprop:Generator_RowClassName="ListValuesRow" msprop:Generator_UserTableName="ListValues" msprop:Generator_RowEvArgName="ListValuesRowChangeEvent">
<xs:complexType>
<xs:sequence>
<xs:element name="TableName" msprop:Generator_ColumnVarNameInTable="columnTableName" msprop:Generator_ColumnPropNameInRow="TableName" msprop:Generator_ColumnPropNameInTable="TableNameColumn" msprop:Generator_UserColumnName="TableName">
@@ -393,7 +393,7 @@ SELECT sorgente, chiave, valore, note FROM ConfigTmp WHERE (chiave = @chiave) AN
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="v_selListVal" msprop:Generator_TableClassName="v_selListValDataTable" msprop:Generator_TableVarName="tablev_selListVal" msprop:Generator_TablePropName="v_selListVal" msprop:Generator_RowDeletingName="v_selListValRowDeleting" msprop:Generator_RowChangingName="v_selListValRowChanging" msprop:Generator_RowEvHandlerName="v_selListValRowChangeEventHandler" msprop:Generator_RowDeletedName="v_selListValRowDeleted" msprop:Generator_UserTableName="v_selListVal" msprop:Generator_RowChangedName="v_selListValRowChanged" msprop:Generator_RowEvArgName="v_selListValRowChangeEvent" msprop:Generator_RowClassName="v_selListValRow">
<xs:element name="v_selListVal" msprop:Generator_TableClassName="v_selListValDataTable" msprop:Generator_TableVarName="tablev_selListVal" msprop:Generator_RowChangedName="v_selListValRowChanged" msprop:Generator_TablePropName="v_selListVal" msprop:Generator_RowDeletingName="v_selListValRowDeleting" msprop:Generator_RowChangingName="v_selListValRowChanging" msprop:Generator_RowEvHandlerName="v_selListValRowChangeEventHandler" msprop:Generator_RowDeletedName="v_selListValRowDeleted" msprop:Generator_RowClassName="v_selListValRow" msprop:Generator_UserTableName="v_selListVal" msprop:Generator_RowEvArgName="v_selListValRowChangeEvent">
<xs:complexType>
<xs:sequence>
<xs:element name="value" msdata:ReadOnly="true" msprop:Generator_ColumnVarNameInTable="columnvalue" msprop:Generator_ColumnPropNameInRow="value" msprop:Generator_ColumnPropNameInTable="valueColumn" msprop:Generator_UserColumnName="value" minOccurs="0">
@@ -413,7 +413,7 @@ SELECT sorgente, chiave, valore, note FROM ConfigTmp WHERE (chiave = @chiave) AN
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Config" msprop:Generator_TableClassName="ConfigDataTable" msprop:Generator_TableVarName="tableConfig" msprop:Generator_RowChangedName="ConfigRowChanged" msprop:Generator_TablePropName="Config" msprop:Generator_RowDeletingName="ConfigRowDeleting" msprop:Generator_RowChangingName="ConfigRowChanging" msprop:Generator_RowEvHandlerName="ConfigRowChangeEventHandler" msprop:Generator_RowDeletedName="ConfigRowDeleted" msprop:Generator_RowClassName="ConfigRow" msprop:Generator_UserTableName="Config" msprop:Generator_RowEvArgName="ConfigRowChangeEvent">
<xs:element name="Config" msprop:Generator_TableClassName="ConfigDataTable" msprop:Generator_TableVarName="tableConfig" msprop:Generator_TablePropName="Config" msprop:Generator_RowDeletingName="ConfigRowDeleting" msprop:Generator_RowChangingName="ConfigRowChanging" msprop:Generator_RowEvHandlerName="ConfigRowChangeEventHandler" msprop:Generator_RowDeletedName="ConfigRowDeleted" msprop:Generator_UserTableName="Config" msprop:Generator_RowChangedName="ConfigRowChanged" msprop:Generator_RowEvArgName="ConfigRowChangeEvent" msprop:Generator_RowClassName="ConfigRow">
<xs:complexType>
<xs:sequence>
<xs:element name="chiave" msprop:Generator_ColumnVarNameInTable="columnchiave" msprop:Generator_ColumnPropNameInRow="chiave" msprop:Generator_ColumnPropNameInTable="chiaveColumn" msprop:Generator_UserColumnName="chiave">
@@ -440,7 +440,7 @@ SELECT sorgente, chiave, valore, note FROM ConfigTmp WHERE (chiave = @chiave) AN
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ConfigTmp" msprop:Generator_TableClassName="ConfigTmpDataTable" msprop:Generator_TableVarName="tableConfigTmp" msprop:Generator_TablePropName="ConfigTmp" msprop:Generator_RowDeletingName="ConfigTmpRowDeleting" msprop:Generator_RowChangingName="ConfigTmpRowChanging" msprop:Generator_RowEvHandlerName="ConfigTmpRowChangeEventHandler" msprop:Generator_RowDeletedName="ConfigTmpRowDeleted" msprop:Generator_UserTableName="ConfigTmp" msprop:Generator_RowChangedName="ConfigTmpRowChanged" msprop:Generator_RowEvArgName="ConfigTmpRowChangeEvent" msprop:Generator_RowClassName="ConfigTmpRow">
<xs:element name="ConfigTmp" msprop:Generator_TableClassName="ConfigTmpDataTable" msprop:Generator_TableVarName="tableConfigTmp" msprop:Generator_RowChangedName="ConfigTmpRowChanged" msprop:Generator_TablePropName="ConfigTmp" msprop:Generator_RowDeletingName="ConfigTmpRowDeleting" msprop:Generator_RowChangingName="ConfigTmpRowChanging" msprop:Generator_RowEvHandlerName="ConfigTmpRowChangeEventHandler" msprop:Generator_RowDeletedName="ConfigTmpRowDeleted" msprop:Generator_RowClassName="ConfigTmpRow" msprop:Generator_UserTableName="ConfigTmp" msprop:Generator_RowEvArgName="ConfigTmpRowChangeEvent">
<xs:complexType>
<xs:sequence>
<xs:element name="sorgente" msprop:Generator_ColumnVarNameInTable="columnsorgente" msprop:Generator_ColumnPropNameInRow="sorgente" msprop:Generator_ColumnPropNameInTable="sorgenteColumn" msprop:Generator_UserColumnName="sorgente">
+2 -2
View File
@@ -4,10 +4,10 @@
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.
</autogenerated>-->
<DiagramLayout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ex:showrelationlabel="False" ViewPortX="0" ViewPortY="0" xmlns:ex="urn:schemas-microsoft-com:xml-msdatasource-layout-extended" xmlns="urn:schemas-microsoft-com:xml-msdatasource-layout">
<DiagramLayout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ex:showrelationlabel="False" ViewPortX="-10" ViewPortY="0" xmlns:ex="urn:schemas-microsoft-com:xml-msdatasource-layout-extended" xmlns="urn:schemas-microsoft-com:xml-msdatasource-layout">
<Shapes>
<Shape ID="DesignTable:ListValues" ZOrder="4" X="70" Y="70" Height="248" Width="300" AdapterExpanded="true" DataTableExpanded="true" OldAdapterHeight="0" OldDataTableHeight="0" SplitterPosition="121" />
<Shape ID="DesignTable:v_selListVal" ZOrder="3" X="440" Y="70" Height="153" Width="300" AdapterExpanded="true" DataTableExpanded="true" OldAdapterHeight="0" OldDataTableHeight="0" SplitterPosition="64" />
<Shape ID="DesignTable:v_selListVal" ZOrder="3" X="198" Y="468" Height="181" Width="259" AdapterExpanded="true" DataTableExpanded="true" OldAdapterHeight="0" OldDataTableHeight="0" SplitterPosition="76" />
<Shape ID="DesignTable:Config" ZOrder="2" X="800" Y="249" Height="181" Width="216" AdapterExpanded="true" DataTableExpanded="true" OldAdapterHeight="0" OldDataTableHeight="0" SplitterPosition="99" />
<Shape ID="DesignTable:ConfigTmp" ZOrder="1" X="735" Y="558" Height="250" Width="300" AdapterExpanded="true" DataTableExpanded="true" OldAdapterHeight="0" OldDataTableHeight="0" SplitterPosition="122" />
</Shapes>
+1 -1
View File
@@ -55,7 +55,7 @@
connectionString="Data Source=SQL2012DEV;Initial Catalog=Equa_Anagrafica;Persist Security Info=True;User ID=sa;Password=keyhammer16;"
providerName="System.Data.SqlClient" />
<add name="SteamWare.Properties.Settings.DbConfConnectionString"
connectionString="Data Source=SQLSTEAM;Initial Catalog=SEL_fatture_SteamWare;Persist Security Info=True;User ID=sa;Password=keyhammer;"
connectionString="Data Source=SQL2016DEV;Initial Catalog=MoonPro;Persist Security Info=True;User ID=sa;Password=keyhammer16;"
providerName="System.Data.SqlClient" />
<add name="SteamWare.Properties.Settings.GMWConnectionString"
connectionString="Data Source=SQL2012DEV;Initial Catalog=GMW;Persist Security Info=True;User ID=sa;Password=keyhammer16;"
+113 -38
View File
@@ -926,8 +926,16 @@ namespace SteamWare
#region cache
// !!!FARE!!! utilizzare DIRETTAMENTE REDIS coem cache SE disponibile?!?!?
/// <summary>
/// Indica se usare la cache su REDIS (true) oppure cache applicativo IIS (false)
/// </summary>
protected bool cacheOnRedis
{
get
{
return CRB("cacheOnRedis");
}
}
/// <summary>
/// carica dalla Cache un dato di tipo object generico
/// </summary>
@@ -935,16 +943,25 @@ namespace SteamWare
/// <returns></returns>
public object objCacheObj(string nomeVar)
{
if (HttpContext.Current.Cache[nomeVar] != null)
object answ = null;
// ...se uso redis...
if (cacheOnRedis)
{
return HttpContext.Current.Cache[nomeVar];
answ = JsonConvert.DeserializeObject(getRSV(redHash(nomeVar)));
}
else
{
return "";
if (HttpContext.Current.Cache[nomeVar] != null)
{
answ = HttpContext.Current.Cache[nomeVar];
}
else
{
answ = "";
}
}
return answ;
}
/// <summary>
/// carica dalla Cachee un dato di tipo boolean (se vuoto false)
/// </summary>
@@ -952,16 +969,26 @@ namespace SteamWare
/// <returns></returns>
public bool BoolCacheObj(string nomeVar)
{
if (HttpContext.Current.Cache[nomeVar] != null)
bool answ = false;
// ...se uso redis...
if (cacheOnRedis)
{
return (bool)HttpContext.Current.Cache[nomeVar];
string redVal = JsonConvert.DeserializeObject(getRSV(redHash(nomeVar))).ToString();
bool.TryParse(redVal, out answ);
}
else
{
return false;
if (HttpContext.Current.Cache[nomeVar] != null)
{
answ = (bool)HttpContext.Current.Cache[nomeVar];
}
else
{
answ = false;
}
}
return answ;
}
/// <summary>
/// carica dalla Cachee un dato di tipo string
/// </summary>
@@ -969,31 +996,50 @@ namespace SteamWare
/// <returns></returns>
public string StringCacheObj(string nomeVar)
{
if (HttpContext.Current.Cache[nomeVar] != null)
string answ = "";
// ...se uso redis...
if (cacheOnRedis)
{
return HttpContext.Current.Cache[nomeVar].ToString();
answ = JsonConvert.DeserializeObject(getRSV(redHash(nomeVar))).ToString();
}
else
{
return "";
if (HttpContext.Current.Cache[nomeVar] != null)
{
answ = HttpContext.Current.Cache[nomeVar].ToString();
}
else
{
answ = "";
}
}
return answ;
}
/// <summary>
/// inserisce in Cache un valore
/// </summary>
/// <param name="nome">nome della variabile</param>
/// <param name="nomeVar">nome della variabile</param>
/// <param name="valore">valore</param>
public bool setCacheVal(string nome, object valore)
public bool setCacheVal(string nomeVar, object valore)
{
bool _done = false;
try
if (cacheOnRedis)
{
HttpContext.Current.Cache[nome] = valore;
// serializzo
string serVal = JsonConvert.SerializeObject(valore);
setRSV(redHash(nomeVar), serVal);
_done = true;
}
catch
{ }
else
{
try
{
HttpContext.Current.Cache[nomeVar] = valore;
_done = true;
}
catch
{ }
}
return _done;
}
/// <summary>
@@ -1015,17 +1061,25 @@ namespace SteamWare
/// <summary>
/// svuota una variabile dalla Cache
/// </summary>
/// <param name="nomeVar"></param>
/// <param name="nome"></param>
public bool emptyCacheVal(string nome)
public bool emptyCacheVal(string nomeVar)
{
bool _done = false;
try
if (cacheOnRedis)
{
HttpContext.Current.Cache.Remove(nome);
_done = true;
redDelKey(redHash(nomeVar));
}
else
{
try
{
HttpContext.Current.Cache.Remove(nomeVar);
_done = true;
}
catch
{ }
}
catch
{ }
return _done;
}
@@ -1038,20 +1092,27 @@ namespace SteamWare
{
bool answ = false;
bool stringAnsw = false;
// cerco di fare cast a stringa...
try
if (cacheOnRedis)
{
stringAnsw = HttpContext.Current.Cache[nomeVar].ToString() != "";
answ = redHashPresent(redHash(nomeVar));
}
catch
{ }
// infine condizione doppia...
try
else
{
answ = (HttpContext.Current.Cache[nomeVar] != null && stringAnsw);
// cerco di fare cast a stringa...
try
{
stringAnsw = HttpContext.Current.Cache[nomeVar].ToString() != "";
}
catch
{ }
// infine condizione doppia...
try
{
answ = (HttpContext.Current.Cache[nomeVar] != null && stringAnsw);
}
catch
{ }
}
catch
{ }
return answ;
}
/// <summary>
@@ -1150,9 +1211,23 @@ namespace SteamWare
// elimino tutte le tab nella pos tabInCache...
foreach (KeyValuePair<string, string> kvp in tabelleInCache)
{
HttpContext.Current.Cache.Remove(kvp.Value);
if (cacheOnRedis)
{
redDelKey(redHash(kvp.Value));
}
else
{
HttpContext.Current.Cache.Remove(kvp.Value);
}
}
if (cacheOnRedis)
{
redDelKey(redHash("tabelleInCache"));
}
else
{
HttpContext.Current.Cache.Remove("tabelleInCache");
}
HttpContext.Current.Cache.Remove("tabelleInCache");
}
#endregion