Esempio n. 1
0
        private void insertNextChangeData(string jsonData)
        {
            DBConnector myConn = new DBConnector();

            myConn.connect();
            poe_change nextChange = JsonConvert.DeserializeObject <poe_change>(jsonData);

            if (myConn.isConnected())
            {
                //Console.WriteLine(DateTime.Now + "--Beginning JSON Insert.");
                MySqlCommand cmd = myConn.getSqlCommand();
                // first update the previous entry to include the json data.
                cmd.CommandText = "UPDATE POE_CHANGE SET JSON_DATA=@JSONDATA, JSON_DATA_RETRIEVED=1, IN_PROCESS=0 WHERE NEXT_CHANGE_ID=@NEXTCHANGEID;";
                cmd.Parameters.AddWithValue("@JSONDATA", jsonData);
                cmd.Parameters.AddWithValue("@NEXTCHANGEID", this.nextUpdateId);

                cmd.Prepare();
                cmd.ExecuteNonQuery();
                //Console.WriteLine(DateTime.Now + "--Json Insert Complete.");
                cmd.Dispose();

                // now insert the next change ID.
                MySqlCommand cmd2 = myConn.getSqlCommand();
                cmd2.CommandText = "INSERT INTO POE_CHANGE (NEXT_CHANGE_ID, CHANGE_RECEIVED, PROCESSED, JSON_DATA_RETRIEVED) " +
                                   "VALUES (@NEXTCHANGEID, @CHANGERECEIVED, 0, 0);";
                cmd2.Parameters.AddWithValue("@NEXTCHANGEID", nextChange.next_change_id);
                cmd2.Parameters.AddWithValue("@CHANGERECEIVED", DateTime.Now);
                cmd2.Prepare();

                cmd2.ExecuteNonQuery();
                //Console.WriteLine(DateTime.Now + "--Insert new change done");
                cmd2.Dispose();
                myConn.close();
            }
            nextChange.Dispose();
        }
Esempio n. 2
0
        public void processPoeUpdate()
        {
            poe_logger.logInfo("Starting up");
            while (keepRunning)
            {
                bool fullDelay = false;

                if (changeList.Count < 5)
                {
                    poe_logger.logInfo("Getting Json");
                    string[] getJsonVals     = getNextJson();
                    string   nextJson        = getJsonVals[0];
                    string   currentChangeId = getJsonVals[1];

                    //poe_logger.logInfo("Start processing next change: " + nextUpdateId);
                    if (nextJson != "")
                    {
                        //poe_logger.logInfo(nextJson.Substring(0,100));
                        Console.WriteLine(nextJson.Substring(0, 100));
                        poe_change myChange = JsonConvert.DeserializeObject <poe_change>(nextJson);
                        //lock (changeList.SyncRoot) { changeList.Add(currentChangeId); }
                        myChange.changeId        = changeId;
                        myChange.currentChangeId = currentChangeId;
                        //myChange.Process();
                        Thread myThread = new Thread(new ThreadStart(myChange.Process));
                        myThread.Start();
                        lock (changeList.SyncRoot) { changeList.Add(myThread); }
                        myChange.changeProcessingFinished += changeFinishedProcessing;
                        nextJson  = "";
                        fullDelay = true;
                    }
                    else
                    {
                        //Console.WriteLine("No json found, delaying 1000 ms and retrying");
                        //Thread.Sleep(1000);
                        //processPoeUpdate();
                        fullDelay = false;
                    }
                }
                else
                {
                    //poe_logger.logInfo("Max number of threads started");
                    Console.WriteLine("Max number of threads started");
                    ArrayList removeThreads = new ArrayList();
                    lock (changeList.SyncRoot)
                    {
                        foreach (Thread theThread in changeList)
                        {
                            if (theThread.ThreadState == ThreadState.Stopped)
                            {
                                removeThreads.Add(theThread);
                            }
                            //Console.WriteLine("Thread: " + theThread.ManagedThreadId + " is in state: " + theThread.ThreadState);
                        }
                    }

                    foreach (Thread aThread in removeThreads)
                    {
                        lock (changeList.SyncRoot)
                        {
                            changeList.Remove(aThread);
                        }
                    }
                }
                if (fullDelay)
                {
                    Thread.Sleep(poe_throttler.calcChangeProcessDelay());
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }
        }