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 SyncDoc : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // verifico se vado in modalità demo o meno...
            bool demoMode = false;
            string DOC = "";
            string Anno = "";
            try
            {
                demoMode = Convert.ToBoolean(Request.QueryString["DemoMode"]);
                DOC = Request.QueryString["DOC"];
                Anno = Request.QueryString["Anno"];
            }
            catch
            { }
            // recupero numero doc da cod documento + anno...
            if (DOC != "" && Anno != "")
            {
                // recupero i dati da caricare...
                string[] urlsUpdate = GestData.proc.getDocsUrls(DOC, Anno);
                if (demoMode)
                {
                    lblOut.Text = string.Format("DEMO MODE!<br/>DOC: {0}/{1}", DOC, Anno);
                    for (int i = 0; i < urlsUpdate.Length; i++)
                    {
                        lblOut.Text += string.Format("<br/>{0:000}) {1}", i + 1, urlsUpdate[i]);
                    }
                }
                else
                {
                    lblOut.Text = string.Format("Normal MODE!<br/>DOC: {0}/{1}", DOC, Anno);
                    var client = new WebClient();
                    for (int i = 0; i < urlsUpdate.Length; i++)
                    {
                        try
                        {
                            var content = client.DownloadString(urlsUpdate[i]);
                        }
                        catch
                        { }
                    }
                }
            }
        }
    }
}