Пример #1
0
        public void StartUdpServer (Form2 form2)
        {
            //myTimer.Interval = 50;
            //myTimer.Tick += new EventHandler(myTimerTick);
            publicForm2 = form2;
            JsonHelper jsh = new JsonHelper();
            Task.Run(async () =>
            {

                using (var udpClient = new UdpClient(9992))
                {
                    StartConversation2(udpClient);
                   // SetTime(udpClient);
                    //string path = @"Jsons/" + jsh.deleteAllButNumbers(DateTime.Now.ToString()) + ".txt";
                    //File.Create(path);
                    string udpString = "";
                    while (true)
                    {
                        //IPEndPoint object will allow us to read datagrams sent from any source.
                        var receivedResults = await udpClient.ReceiveAsync();
                        udpString = Encoding.ASCII.GetString(receivedResults.Buffer);

                        //using (StreamWriter writetext = new StreamWriter(path, true))
                        //{
                        //    writetext.WriteLine(udpString);
                        //}

                        // Blink(form2);

                        form2.Controls.Find("label3", true).FirstOrDefault().BackColor = Color.Green;
                        //   TODO: timer, ktery za chvilku zmeni barvu zpet na cervenou

                       
                        //myTimer.Start();

                        Monitor.Enter(lstBuffer);
                            lstBuffer.Add(udpString);
                            Monitor.Exit(lstBuffer);
                         //  MessageBox.Show(loggingEvent);
                        
                        
                                               
                    }
                }
            });
        }
Пример #2
0
        public async void sendJsonToWeb()
        {
            try
            {
                await Task.Run(() =>
                {

                    JsonHelper jsonHelper = new JsonHelper();
                    //wholeRace = jsonHelper.getExactWholeRaceFromJson("05062016-213554");
                    List<WholeRace> lstWholeRace = jsonHelper.getAllWholeRacesFromDirectory(@"Jsons/NotCopied");




                    if (CheckForInternetConnection())
                    {
                        HttpWebRequest httpWebRequest;
                        foreach (var item in lstWholeRace)
                        {
                            //    item.timeOfstart = DateTime.Parse(item.timeOfstartString);
                            //http://localhost:49747/
                            if (ConfigurationManager.AppSettings[ConfigKeys.SendeToServer].Equals("true"))
                            {
                                 httpWebRequest = (HttpWebRequest)WebRequest.Create("http://karts.aspone.cz/Json/ReceiveJson");
                            }
                            else
                            {
                                httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:49747/Json/ReceiveJson");
                            }
                             //var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://karts.aspone.cz/Json/ReceiveJson");
                            
                            httpWebRequest.ContentType = "application/json";
                            httpWebRequest.Method = "POST";
                            httpWebRequest.Timeout = Timeout.Infinite;
                            httpWebRequest.KeepAlive = true;
                            //      httpWebRequest.ReadWriteTimeout = 300000;

                            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                            {
                                string json = new JavaScriptSerializer().Serialize(item);

                                streamWriter.Write(json);
                                streamWriter.Flush();
                                streamWriter.Close();

                                // If you need to read response
                                try
                                {
                                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();


                                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                                    {
                                        var result = streamReader.ReadToEnd();
                                    }
                                }
                                catch (Exception)
                                {

                                   
                                }
                                


                            }


                            if (item.nameOfJson != null)
                            {
                                moveJsonFromNotCopiedToCopied(item.nameOfJson);
                            }

                        }

                    }
                });
            }
            catch (Exception)
            {

                sendJsonToWeb();
            }
           
        }
Пример #3
0
        private void bttnStats_Click(object sender, EventArgs e)
        {
            string showString = "";
            JsonHelper jsonHelper = new JsonHelper();
            int[] KartLaps = jsonHelper.getStatsOfAllKartsToday();

            for (int i = 0; i < KartLaps.Length; i++)
            {
                showString += "Motokára č. " + ( i+1) + " dnes ujela " + KartLaps[i] + " kol." + Environment.NewLine;
            }

            MessageBox.Show(showString);
        }
Пример #4
0
        public void saveToJsonAndPrint()
        {
            if (ConfigurationManager.AppSettings[ConfigKeys.TesterMode].Equals("true"))
            {
                wholeRace.testerMode = true;
            }
            wholeRace.timeOfstartString = wholeRace.timeOfStartFromPc.ToString();
            deleteAllDisqualifiedRacers();
            keeper.sortPlayersByRank(wholeRace, lstUserControlRacers);
            wholeRace.totalTime = new TimeSpan();
            wholeRace.timeOfstartString = wholeRace.timeOfstart.ToString();
            foreach (var item in wholeRace.lstWholePlayers)
            {
                if (item.totalTime > wholeRace.totalTime)
                {
                    wholeRace.totalTime = item.totalTime;
                }
            }
            JsonHelper jsonHelper = new JsonHelper();
            jsonHelper.convertLstTimeSpansToStrings(wholeRace);
               // wc.sendJsonToWeb(wholeRace);
            jsonHelper.TestWriteToJson(wholeRace);
            //  keeper.SaveFinishedRaceToDb(wholeRace);
            Controls.Find("btnPrintResults", true).FirstOrDefault().Enabled = true;

            printBttn.Location = new Point(500, 650);
            printBttn.Height = 50;
            printBttn.Width = 150;
            printBttn.Text = "tisk výsledku";

            printBttn.Click += new EventHandler(printButton_Click);
        }