Esempio n. 1
0
        private async void createGroupButton_Click(object sender, EventArgs e)
        {
            //generate warning
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to create this group?", "Warning", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                //do something
                List <Days> daysSelected = new List <Days>();
                foreach (Object listItem in meetingDaysCheckBox.CheckedItems)
                {
                    if (listItem.ToString().Equals("Monday"))
                    {
                        daysSelected.Add(Days.Monday);
                    }
                    if (listItem.ToString().Equals("Tuesday"))
                    {
                        daysSelected.Add(Days.Tuesday);
                    }
                    if (listItem.ToString().Equals("Wednesday"))
                    {
                        daysSelected.Add(Days.Wednesday);
                    }
                    if (listItem.ToString().Equals("Thursday"))
                    {
                        daysSelected.Add(Days.Thursday);
                    }
                    if (listItem.ToString().Equals("Friday"))
                    {
                        daysSelected.Add(Days.Friday);
                    }
                    if (listItem.ToString().Equals("Saturday"))
                    {
                        daysSelected.Add(Days.Saturday);
                    }
                    if (listItem.ToString().Equals("Sunday"))
                    {
                        daysSelected.Add(Days.Sunday);
                    }
                }

                Semester theSemester;
                if (seasonComboBox.Text.Equals("Spring"))
                {
                    theSemester = Semester.Spring;
                }
                else if (seasonComboBox.Text.Equals("Fall"))
                {
                    theSemester = Semester.Fall;
                }
                else if (seasonComboBox.Text.Equals("Winter"))
                {
                    theSemester = Semester.Winter;
                }
                else
                {
                    theSemester = Semester.Summer;
                }

                //StudyGroup sg = new StudyGroup(theUser.DisplayName, groupName.Text, courseNameTextBox.Text, Convert.ToInt32(timeHourScroll.Value), Convert.ToInt32(timeMinutesScroll.Value), daysSelected, Convert.ToInt32(hoursDurationScroll.Value), theSemester, (DateTime.Now).Year, descriptionTextBook.Text);

                System.Diagnostics.Process newProcess = System.Diagnostics.Process.Start("https://zoom.us/oauth/authorize?response_type=code&client_id=ZBoG2s2JRZSD_FoQZH2Zdg&redirect_uri=https%3A%2F%2Fbyjsxnki07.execute-api.us-west-2.amazonaws.com%2Fdevel%2Fuser");

                // TODO need to check if they actually signed in correctly
                // Wait until person has verified their zoom
                newProcess.WaitForExit();
                //while (newProcess != null && !newProcess.HasExited)
                //{
                //    System.Threading.Thread.Sleep(1000);
                //}

                //TODO send the meeting time and other details
                // request modified from: https://stackoverflow.com/questions/9145667/how-to-post-json-to-a-server-using-c
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Environment.GetEnvironmentVariable("AWS_URL_LINK"));
                request.Method      = "POST";
                request.ContentType = "application/json";
                var joinLink = "";
                try
                {
                    using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                    {
                        string json = "{\"user\":\"test\"," +
                                      "\"password\":\"bla\"}";

                        streamWriter.Write(json);
                    }
                    string responseContent = null;
                    var    httpResponse    = (HttpWebResponse)request.GetResponse();
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        responseContent = streamReader.ReadToEnd();
                    }
                    Console.WriteLine(responseContent);

                    var userObj = JObject.Parse(responseContent);
                    joinLink = Convert.ToString(userObj["join_url"]);
                }
                catch (Exception)
                {
                    joinLink = "No Link Available";
                }

                StudyGroup sg = new StudyGroup(theUser.DisplayName, groupName.Text, courseNameTextBox.Text, Convert.ToInt32(timeHourScroll.Value), Convert.ToInt32(timeMinutesScroll.Value), daysSelected, Convert.ToInt32(hoursDurationScroll.Value), theSemester, (DateTime.Now).Year, descriptionTextBook.Text, joinLink);

                theUser.JoinGroup(sg);
                PopulateActiveGroupList();
                //add to database
                await dbm.CreateNewStudyGroup(theUser.DisplayName, groupName.Text, courseNameTextBox.Text, Convert.ToInt32(timeHourScroll.Value), Convert.ToInt32(timeMinutesScroll.Value), daysSelected, Convert.ToInt32(hoursDurationScroll.Value), theSemester, (DateTime.Now).Year, descriptionTextBook.Text, joinLink);

                MessageBox.Show("Study Group successfully created!", "Group created", MessageBoxButtons.OK);
            }
        }