示例#1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            int new_time = time--;

            Time.Text = new_time.ToString();

            if (new_time == 0)
            {
                timer1.Stop();
                DisConnectDataSockets();
                generatingLabReport();
                deleteXmlFile();
            }

            counter++;
            if (counter == 2) //elapsed five times
            {
                counter = 0;
                existingLabs();
                if (Directory.Exists(CFGFOLDER_PATH))
                {
                    string runlab = ExistingLabList.GetItemText(ExistingLabList.SelectedItem);
                    File.WriteAllText(labTimeFile, new_time.ToString() + "\n" + runlab);
                    //File.WriteAllText(labTimeFile, "\n" + lab);
                }
                else
                {
                    Directory.CreateDirectory(CFGFOLDER_PATH);
                    File.WriteAllText(labTimeFile, new_time.ToString());
                    //  File.WriteAllText(labTimeFile, "\n" + lab);
                }
            }
        }
 private void ExistingLabList_SelectedIndexChanged(object sender, EventArgs e)
 {
     runlab    = ExistingLabList.GetItemText(ExistingLabList.SelectedItem);
     lab_state = true;
     if (lab_state == true && switch_creation_state == true)
     {
         MessageBox.Show("Please close the running lab");
     }
 }
示例#3
0
        private void startLabToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string         baseAddress = "http://localhost:9000/api/time";
            HttpWebRequest request     = (HttpWebRequest)WebRequest.Create(baseAddress);

            request.Method    = "Get";
            request.KeepAlive = true;

            HttpWebResponse response   = (HttpWebResponse)request.GetResponse();
            string          myResponse = "";

            using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()))
            {
                myResponse = sr.ReadToEnd();
            }

            String   serverdatetime = myResponse.ToString().Substring(1, myResponse.Length - 2);
            DateTime servertime     = DateTime.Parse(serverdatetime, new System.Globalization.CultureInfo("pt-BR"));

            if (ExistingLabList.SelectedIndex > -1)
            {
                lab            = ExistingLabList.GetItemText(ExistingLabList.SelectedItem);
                labzipfile     = lab;
                labfolder_path = Path.Combine(CFGFOLDER_PATH, labzipfile);
                CFGFILE_PATH   = Path.Combine(labfolder_path, "lab.xml");

                if (File.Exists(CFGFILE_PATH))
                {
                    string datetime = (from dev in XDocument.Load(CFGFILE_PATH).Descendants("Setting")
                                       where (string)dev.Attribute("Name") == "DateTime"
                                       select(string) dev.Attribute("Value").Value).FirstOrDefault();

                    DateTime scheduletime = DateTime.Parse(datetime);
                    DateTime duration     = scheduletime.AddMinutes(30);
                    //MessageBox.Show(servertime.ToString("hh:mm"));
                    //MessageBox.Show(scheduletime.ToString("hh:mm"));
                    //MessageBox.Show(duration.ToString("hh:mm"));

                    try
                    {
                        //  MessageBox.Show(myResponse);
                        if (servertime.ToShortDateString().Equals(scheduletime.ToShortDateString()))
                        {
                            if (servertime.TimeOfDay >= scheduletime.TimeOfDay && servertime.TimeOfDay <= duration.TimeOfDay)
                            {
                                timer1.Enabled = true;
                                timer1.Start();
                                LoadCurrentFile(CFGFILE_PATH);
                            }
                            else if (servertime.TimeOfDay >= scheduletime.TimeOfDay && servertime.TimeOfDay > duration.TimeOfDay)
                            {
                                MessageBox.Show("please reschedule");
                            }
                            else
                            {
                                MessageBox.Show("not yet time");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please varify date scheduled");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

                else
                {
                    MessageBox.Show("Upload lab file");
                }
            }
            else
            {
                MessageBox.Show("Please select a lab to do!");
            }
        }