public IActionResult Create(MeetingClass mc, string Participants, string ParticiNames, string HostName, string HostEmail) { WebexHostInfo meetingHost = new WebexHostInfo("!!ADD WEBEX HOST EMAIL!!", "!!ADD WEBEX HOST PW!!", "!ADD WEBEX HOST ID!!", "!!ADD WEBEX COMPANY NAME!!"); List <string> emails = new List <string>(Participants.Split(',')); List <string> names = new List <string>(ParticiNames.Split(',')); string startDateTimeStr = mc.MeetingStartDateTime.ToString("MM/dd/yyyy HH:mm:ss"); string endDateTimeStr = mc.MeetingEndDateTime.ToString("MM/dd/yyyy HH:mm:ss"); Int64 duration = (Int64)(mc.MeetingEndDateTime - mc.MeetingStartDateTime).TotalMinutes; emails.Add(HostEmail); emails.Add("!!ADD BOT EMAIL ACCOUNT!!"); names.Add(HostName); names.Add("bot"); //emails = emails.Select(s => s.Trim()); for (int i = 0; i < emails.Count; i++) { emails[i] = emails[i].Trim(); } for (int i = 0; i < names.Count; i++) { names[i] = names[i].Trim(); } Microsoft.Graph.EmailAddress delegateEmailAddress = new Microsoft.Graph.EmailAddress(); delegateEmailAddress.Name = HostName.Trim(); delegateEmailAddress.Address = HostEmail.Trim(); var meetingInfo = MeetingController.CreateWebexMeeting(mc.MeetingSubject, names, emails, mc.MeetingStartDateTime, duration.ToString(), meetingHost, delegateEmailAddress); mc.WebExID = meetingInfo.AccessCode; /*try * {C:\repos\Final_Successful\cs319-2019w1-hsbc\WebMVC\Views\ * var attendees = MeetingController.GetAttendeeEmails(access_code, meetingHost); * //MeetingController.SendEmailsToAnyUnregisteredUsers(attendees); * //EmailSender.SendEmailForStartURL(attendees, access_code, mc.MeetingSubject); * } * catch (Exception ex) * { * //Console.WriteLine(ex); * Trace.WriteLine(ex); * } * * try * { * // TODO warning this part is hardcoded * //SchedulerController.ScheduleTask(access_code, mc.MeetingStartDate, "Main.exe", @"C:\cs319_main"); * } * catch (Exception ex) * { * * }*/ //_amc.Add(mc); //_amc.SaveChanges(); ViewBag.message = "The Meeting " + mc.MeetingSubject + " Is Saved Successfully!"; return(View()); }
/// <summary> /// Creates a webex meeting with the specified parameters. Note that duration is in minutes. /// </summary> /// <param name="meetingSubject"></param> /// <param name="names"></param> /// <param name="emails"></param> /// <param name="duration"></param> /// <param name="hostInfo"></param> /// <returns></returns> public static MeetingInfo CreateWebexMeeting(string meetingSubject, List <string> names, List <string> emails, DateTime startTime, string duration, WebexHostInfo hostInfo, Microsoft.Graph.EmailAddress delegateEmail) { string strXMLServer = "https://companykm.my.webex.com/WBXService/XMLService"; WebRequest request = WebRequest.Create(strXMLServer); // Set the Method property of the request to POST. request.Method = "POST"; // Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded"; // Create POST data and convert it to a byte array. // string strXML = GenerateXMLCreateMeeting(); string formattedStartTime = startTime.ToString("MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture); string strXML = XMLHelper.GenerateMeetingXML(meetingSubject, names, emails, formattedStartTime, duration, hostInfo, delegateEmail); //string strXML = XMLHelper.GenerateMeetingXML(meetingSubject, names, emails, formattedStartTime, duration, hostInfo); byte[] byteArray = Encoding.UTF8.GetBytes(strXML); // Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream = request.GetRequestStream(); // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); // Get the response. WebResponse response = request.GetResponse(); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. string accessCode = XMLHelper.RetrieveAccessCode(responseFromServer); // Clean up the streams. reader.Close(); dataStream.Close(); response.Close(); Console.WriteLine("\tMeeting has been successfully created"); var endTime = startTime.AddMinutes(double.Parse(duration)); /*Convert email list to Sendgrid email objects */ var sendGridEmails = EmailListener.ParseEmailList(emails); /*Store meeting record in database for the created meeting */ var meeting = DatabaseController.CreateMeeting(emails, startTime, endTime, accessCode, meetingSubject); MeetingInfo meetingInfo = new MeetingInfo(meeting, sendGridEmails, "", hostInfo); /*Send an email to allow host or delegates to start the meeting */ EmailSender.SendEmailForStartURL(meetingInfo, new EmailAddress(delegateEmail.Address, delegateEmail.Name)); return(meetingInfo); }