using SteamWare;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace GMW
{
  public partial class Reset : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      string paginaPrec = user_std.pagPrecedente;
      string action = memLayer.ML.QSS("Action");
      string nextPage = memLayer.ML.StringSessionObj("nextPage");
      string testo = "";
      long recPrev = 0;
      long recPost = 0;
      if (action != "")
      {
        if (action.Contains("C"))
        {
          recPrev = Cache.Count;
          // reset dati in cache...
          memLayer.ML.flushRegisteredCache();
          recPost = Cache.Count;
          testo += string.Format("<hr/>Reset Cache: {0} --> {1}</br>", recPrev, recPost);
        }
        if (action.Contains("D"))
        {
          recPrev = memLayer.ML.numRecAppConf;
          // reset dati in cache x DbConfig...
          memLayer.ML.resetAppConf();
          recPost = memLayer.ML.numRecAppConf;
          testo += string.Format("<hr/>Reset DB AppConf: {0} --> {1}</br>", recPrev, recPost);
        }
        if (action.Contains("R"))
        {
          recPrev = memLayer.ML.numRecRedis;
          // reset dati in cache x DbConfig...
          memLayer.ML.redFlushKey("**");
          recPost = memLayer.ML.numRecRedis;
          testo += string.Format("<hr/>Reset Redis: {0} --> {1}</br>", recPrev, recPost);
        }
        if (action.Contains("S"))
        {
          recPrev = Session.Count;
          // reset dati in sessione...
          Session.Clear();
          recPost = Session.Count;
          testo += string.Format("<hr/>Reset Sessione: {0} --> {1}</br>", recPrev, recPost);
        }
        if (action.Contains("V"))
        {
          recPrev = DataWrap.DW.numRecVoc;
          // aggiorno vocabolario
          DataWrap.DW.resetVocabolario();
          recPost = DataWrap.DW.numRecVoc;
          testo += string.Format("<hr/>Reset Vocabolario: {0} --> {1}</br>", recPrev, recPost);
        }
      }
      lblOut.Text = testo;
      if (nextPage != "")
      {
        logger.lg.scriviLog(string.Format("Reset {0} OK: redirect a pag {1}", action, nextPage), tipoLog.INFO);
        Response.Redirect(nextPage);
      }
    }
  }
}