Esempio n. 1
0
    public GoogleAnalyticThread(String name, String proxy,
                                bool sendToGa, bool logToFile, string logFile)

    /*public GoogleAnalyticThread(String name, Queue theQueue, String proxy,
     *  bool sendToGa, bool logToFile, string logFile)*/
    {
        this.name = name;
        //this.threadGaRequestQueue = theQueue;
        this.threadGaRequestQueue = GaQueue.Instance();
        this.client = new WebClient();
        WebProxy wp = new WebProxy(proxy);

        client.Proxy = wp;
        client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36");

        this.sendToGa  = sendToGa;
        this.logToFile = logToFile;
        this.logFile   = logFile;

        date = System.DateTime.Now;

        /*if (logToFile)
         * {
         *  lock (this.threadGaRequestQueue.SyncRoot)
         *  {
         *      //this.file = new System.IO.StreamWriter(logFile + "gaLogFile" + date.Year + date.Month + date.Day + ".log", true);
         *      this.file = TextWriter.Synchronized(File.AppendText(logFile + "gaLogFile" + date.Year + date.Month + date.Day + ".log"));
         *  }
         * }*/
        if (logToFile)
        {
            logger = Logger.Instance(logFile, date);
            logger.writeToFile("creating : " + name);
        }
    }
Esempio n. 2
0
 public static GaQueue Instance()
 {
     lock (padlock)
     {
         if (instance == null)
         {
             instance = new GaQueue();
         }
         return(instance);
     }
 }
Esempio n. 3
0
    // In the Init function, register for HttpApplication
    // events by adding your handlers.
    public void Init(HttpApplication application)
    {
        //Debug.WriteLine("Init ");
        //application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
        application.EndRequest -=
            (new EventHandler(this.Application_EndRequest));
        application.EndRequest +=
            (new EventHandler(this.Application_EndRequest));

        application.Error +=
            (new EventHandler(this.Application_Error));

        HttpApplicationState theApp = application.Application;

        //if (theApp.Get("gaRequestQueue") != null)
        //    this.gaRequestQueue = (Queue)theApp.Get("gaRequestQueue");

        /*if (this.gaRequestQueue == null)
         * {
         *  //this.gaRequestQueue = new Queue<GARequestObject>();
         *  this.gaRequestQueue = new Queue();
         *  theApp.Add("gaRequestQueue", this.gaRequestQueue);
         * }*/
        this.gaRequestQueue = GaQueue.Instance();


        Object lGaThread = theApp.Get("gaThread");

        //logger.writeToFile("lGaThread :" + lGaThread);
        if (lGaThread == null)
        {
            logger.writeToFile("lGaThread is null");
            //THREAD_NUMBER
            for (int i = 1; i <= this.THREAD_NUMBER; i++)
            {
                String theTime = System.DateTime.Now.ToUniversalTime().Hour + "_" + System.DateTime.Now.ToUniversalTime().Minute + "_" + System.DateTime.Now.ToUniversalTime().Second;
                //GoogleAnalyticThread gaThread = new GoogleAnalyticThread(theTime + "_" + i, this.gaRequestQueue, OECD_PROXY, SEND_TO_GA, LOG_TO_FILE, LOG_FILE_DIR);
                GoogleAnalyticThread gaThread = new GoogleAnalyticThread(theTime + "_" + i, OECD_PROXY, SEND_TO_GA, LOG_TO_FILE, LOG_FILE_DIR);
                Thread oThread = new Thread(new ThreadStart(gaThread.ThreadRun));
                oThread.Start();
                //Debug.WriteLine("starting thread(" + theTime + ") ...");
            }
            theApp.Add("gaThread", this.THREAD_NUMBER);
        }
        else if (lGaThread != null)
        {
            int threadNumber = this.THREAD_NUMBER;
            threadNumber = Convert.ToInt32(lGaThread);
            if (threadNumber > this.THREAD_NUMBER)
            {
                int count = this.THREAD_NUMBER - threadNumber;
                logger.writeToFile("count : " + count);
                for (int i = 1; i <= count; i++)
                {
                    String theTime = System.DateTime.Now.ToUniversalTime().Hour + "_" + System.DateTime.Now.ToUniversalTime().Minute + "_" + System.DateTime.Now.ToUniversalTime().Second;
                    int    lCount  = i + this.THREAD_NUMBER;
                    logger.writeToFile("lCount : " + lCount);
                    //GoogleAnalyticThread gaThread = new GoogleAnalyticThread(theTime + "_" + lCount, this.gaRequestQueue, OECD_PROXY, SEND_TO_GA, LOG_TO_FILE, LOG_FILE_DIR);
                    GoogleAnalyticThread gaThread = new GoogleAnalyticThread(theTime + "_" + lCount, OECD_PROXY, SEND_TO_GA, LOG_TO_FILE, LOG_FILE_DIR);
                    Thread oThread = new Thread(new ThreadStart(gaThread.ThreadRun));
                    oThread.Start();
                    //Debug.WriteLine("starting thread(" + theTime + ") ...");
                }
                this.THREAD_NUMBER = threadNumber;
            }
            theApp.Add("gaThread", this.THREAD_NUMBER);
        }
        logger.writeToFile("Finishing Init : " + Thread.CurrentThread.ManagedThreadId);
    }