100 lines
3.8 KiB
C#
100 lines
3.8 KiB
C#
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace DataUploader
|
|
{
|
|
public partial class FullSync : System.Web.UI.Page
|
|
{
|
|
private static Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
DateTime tick = DateTime.Now;
|
|
var client = new WebClient();
|
|
client.Headers[HttpRequestHeader.Accept] = "text/html, image/png, image/jpeg, image/gif, */*;q=0.1";
|
|
client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12";
|
|
client.Proxy = null;
|
|
ServicePointManager.DefaultConnectionLimit = int.MaxValue;
|
|
// verifico se vado in modalità demo o meno...
|
|
bool demoMode = false;
|
|
try
|
|
{
|
|
demoMode = Convert.ToBoolean(Request.QueryString["DemoMode"]);
|
|
}
|
|
catch
|
|
{ }
|
|
// recupero ultimo numero doc caricato...
|
|
int lastNum = 0;
|
|
try
|
|
{
|
|
var content = client.DownloadString(ConfigurationManager.AppSettings["remoteDocUrl"]); // http://webscr.steamware.net/Rigamonti/Upload/Document
|
|
// converto a int!
|
|
lastNum = Convert.ToInt32(content);
|
|
logger.Info("Recuperato last num: {0}", lastNum);
|
|
}
|
|
catch
|
|
{ }
|
|
// recupero i dati da caricare...
|
|
string[] urlsUpdate = GestData.proc.getNewDocsUrls(lastNum);
|
|
if (demoMode)
|
|
{
|
|
lblOut.Text = string.Format("DEMO MODE!<br/>ultimo NUMERO: {0}", lastNum);
|
|
for (int i = 0; i < urlsUpdate.Length; i++)
|
|
{
|
|
lblOut.Text += string.Format("<br/>{0:000}) {1}", i + 1, urlsUpdate[i]);
|
|
}
|
|
logger.Info("Effettuato DEMO upload FULL SYNC: durata {0} msec", DateTime.Now.Subtract(tick).TotalMilliseconds);
|
|
}
|
|
else
|
|
{
|
|
if (ConfigurationManager.AppSettings["debugMode"] == "true")
|
|
{
|
|
logger.Info("Inizio chiamate URL");
|
|
}
|
|
lblOut.Text = string.Format("Normal MODE!<br/>{0}", lastNum);
|
|
string content = "";
|
|
for (int i = 0; i < urlsUpdate.Length; i++)
|
|
{
|
|
try
|
|
{
|
|
// versione SYNC
|
|
content = client.DownloadString(urlsUpdate[i]);
|
|
if (ConfigurationManager.AppSettings["debugMode"] == "true")
|
|
{
|
|
logger.Info("Chiamata, esito {0}{1}{2}, esito {1}", content, Environment.NewLine, urlsUpdate[i]);
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
try
|
|
{
|
|
logger.Info("Effettuato upload FULL SYNC: durata {0} msec", DateTime.Now.Subtract(tick).TotalMilliseconds);
|
|
}
|
|
catch
|
|
{
|
|
logger.Info("Effettuato upload FULL SYNC: durata {0} sec", DateTime.Now.Subtract(tick).Seconds);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// ricezione risposta URL...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
|
|
{
|
|
if (ConfigurationManager.AppSettings["debugMode"] == "true")
|
|
{
|
|
logger.Info("Chiamata, esito {0}", e.Result);
|
|
}
|
|
}
|
|
}
|
|
} |