public void ProcessRequest(HttpContext context) { //write your handler implementation here. context.Response.ContentType = "text/plain"; string Command = context.Request["WagCommand"]; string UserID = context.Request["UI"]; string UserName = context.Request["UN"]; string serverDirectoryOfCalLogs = System.Web.HttpContext.Current.Server.MapPath("..\\WagTapCalLogs\\"); DateTime refNow = DateTime.UtcNow; TimeSpan TimeZoneSpan = new TimeSpan(0); string TimeZoneString = context.Request.Form["TimeZoneOffset"]; if (!string.IsNullOrEmpty(TimeZoneString)) { int TimeSpanint = Convert.ToInt32(TimeZoneString); TimeZoneSpan = TimeSpan.FromMinutes(TimeSpanint); refNow=refNow.Add(-TimeZoneSpan); } /*//forces copying of my log online string serverDirectoryOfFiles = System.Web.HttpContext.Current.Server.MapPath("..\\18.xml"); { Directory.CreateDirectory(serverDirectoryOfCalLogs); File.Copy(serverDirectoryOfFiles, serverDirectoryOfCalLogs + "18.xml", true); } context.Response.Write("Name of Dir: " + UserAccount.WagTapLogLocation + "\nRest Of File:" + serverDirectoryOfCalLogs); //*/ string User = context.Request.Form["UserName"]; string Password = context.Request.Form["Password"]; UserAccount myUser; if (string.IsNullOrEmpty(Password)) { int UserIDEntry =0; try { UserIDEntry = Convert.ToInt32(context.Request.Form["UserID"]); myUser = new UserAccount(User, UserIDEntry, serverDirectoryOfCalLogs); } catch(Exception e) { PostBackData invalid = new PostBackData("Incorrect Username or password", 1); context.Response.Write(invalid.getPostBackData); return; } } else { myUser = new UserAccount(User, Password, serverDirectoryOfCalLogs); } if (Command == "3") { string FirstName = context.Request.Form["FirstName"]; string LastName = context.Request.Form["LastName"]; string Email = context.Request.Form["Email"]; string UserNameRegister = context.Request.Form["UserName"]; string regPasswordPassword = context.Request.Form["Password"]; UserAccount newUser = new UserAccount(serverDirectoryOfCalLogs); string retValue; CustomErrors registerStatus=newUser.Register(FirstName, LastName, Email, UserNameRegister, regPasswordPassword); PostBackData myPostBackData; if (!registerStatus.Status) { newUser.Login(); retValue = "{\"ID\":\"" + newUser.UserID + "\",\"User\":\"" + newUser.UserName + "\"}"; myPostBackData = new PostBackData(retValue, registerStatus.Code); } else { myPostBackData = new PostBackData(registerStatus.Message, registerStatus.Code); } context.Response.Write(myPostBackData.getPostBackData); } else { myUser.Login(); if (!myUser.Status) { PostBackData invalid = new PostBackData("\"\"", 1); context.Response.Write(invalid.getPostBackData); return; } //TimeSpan referenceShift= switch (Command) { case "0"://get user schedule { string MiscCounter = context.Request.Form["Misc"]; string mydirectory = ""; string StartRange = context.Request.Form["StartRange"]; string EndRange = context.Request.Form["EndRange"]; Tuple<Dictionary<string, My24HourTimerWPF.CalendarEvent>, DateTime> ProfileData = myUser.getProfileInfo(); /* if (!string.IsNullOrEmpty(MiscCounter)) { int counter = Convert.ToInt32( MiscCounter); if (counter == 0) { mydirectory = "WagTapCalLogs\\Older18.xml"; } else { mydirectory = "WagTapCalLogs\\Newer18.xml"; } mydirectory = System.Web.HttpContext.Current.Server.MapPath("..\\" + mydirectory); } */ Dictionary<string, My24HourTimerWPF.CalendarEvent> myDict = ProfileData.Item1;// getAllCalendarElements(mydirectory); PostBackData myPostBackData; if (myDict != null) { TimeLine ScheduleRange; DateTime Now=DateTime.Now; DateTime StartWeekDateInMS=DateTime.Parse(Now.Date.ToShortDateString()); int StartOfWeekDay =(int) StartWeekDateInMS.DayOfWeek; StartOfWeekDay = 0 - StartOfWeekDay; TimeSpan OneDayInMs= new TimeSpan(1,0,0,0); TimeSpan OneWeekInMs= new TimeSpan(7,0,0,0); DateTime StartOfRangeDate= StartWeekDateInMS.Add((TimeSpan.FromTicks((StartOfWeekDay *OneDayInMs.Ticks)))); StartOfRangeDate =StartOfRangeDate.AddDays(-7); DateTime EndOfRangeDate=StartOfRangeDate.AddDays(21); if (! (String.IsNullOrEmpty(StartRange) || String.IsNullOrEmpty(EndRange))) { long TotalTIcks = Convert.ToInt64(StartRange) ; TotalTIcks *= TimeSpan.TicksPerMillisecond; StartOfRangeDate = new DateTime(TotalTIcks); StartOfRangeDate=StartOfRangeDate.AddYears(1969); TotalTIcks = Convert.ToInt64(EndRange); TotalTIcks *=TimeSpan.TicksPerMillisecond; EndOfRangeDate = new DateTime(TotalTIcks); EndOfRangeDate = EndOfRangeDate.AddYears(1969); } ScheduleRange = new TimeLine(StartOfRangeDate, EndOfRangeDate); string jsonText = getJSONData(myDict, ScheduleRange, myUser.Usersname, TimeZoneSpan); myPostBackData = new PostBackData(jsonText, 0); context.Response.Write(myPostBackData.getPostBackData); } else { string message = "invalid user"; myPostBackData = new PostBackData(message, 4); context.Response.Write(myPostBackData.getPostBackData); } } break; case "1"://Add new event { string BColor = context.Request.Form["BColor"]; string RColor = context.Request.Form["RColor"]; string GColor = context.Request.Form["GColor"]; string Count = context.Request.Form["Count"]; string DurationDays = context.Request.Form["DurationDays"]; string DurationHours = context.Request.Form["DurationHours"]; string DurationMins = context.Request.Form["DurationMins"]; string EndDay = context.Request.Form["EndDay"]; string EndHour = context.Request.Form["EndHour"]; string EndMins = context.Request.Form["EndMins"]; string EndMonth = context.Request.Form["EndMonth"]; string EndYear = context.Request.Form["EndYear"]; string LocationAddress = context.Request.Form["LocationAddress"]; string LocationTag = context.Request.Form["LocationTag"]; string Name = context.Request.Form["Name"]; string RepeatData = context.Request.Form["RepeatData"]; string RepeatEndDay = context.Request.Form["RepeatEndDay"]; string RepeatEndMonth = context.Request.Form["RepeatEndMonth"]; string RepeatEndYear = context.Request.Form["RepeatEndYear"]; string RepeatStartDay = context.Request.Form["RepeatStartDay"]; string RepeatStartMonth = context.Request.Form["RepeatStartMonth"]; string RepeatStartYear = context.Request.Form["RepeatStartYear"]; string RepeatType = context.Request.Form["RepeatType"]; string RepeatWeeklyData = context.Request.Form["RepeatWeeklyData"]; string Rigid = context.Request.Form["Rigid"]; string StartDay = context.Request.Form["StartDay"]; string StartHour = context.Request.Form["StartHour"]; string StartMins = context.Request.Form["StartMins"]; string StartMonth = context.Request.Form["StartMonth"]; string StartYear = context.Request.Form["StartYear"]; string RepeatFrequency = context.Request.Form["RepeatFrequency"]; string StartTime=StartHour+":"+StartMins; string EndTime=EndHour+":"+EndMins; DateTime StartDateEntry = new DateTime(Convert.ToInt32(StartYear),Convert.ToInt32(StartMonth),Convert.ToInt32( StartDay)); DateTime EndDateEntry = new DateTime(Convert.ToInt32(EndYear),Convert.ToInt32(EndMonth),Convert.ToInt32( EndDay)); TimeSpan fullTimeSpan = new TimeSpan(Convert.ToInt32(DurationDays),Convert.ToInt32(DurationHours),Convert.ToInt32(DurationMins),0); string EventDuration = TimeSpan.FromSeconds(fullTimeSpan.TotalSeconds*Convert.ToInt32(Count)).ToString(); bool RigidScheduleFlag = Convert.ToBoolean(Rigid); Location EventLocation = new Location(LocationAddress); Repetition MyRepetition=new Repetition(); DateTime RepeatStart = new DateTime(); DateTime RepeatEnd= new DateTime(); bool RepetitionFlag = false; Color userColor= new Color(); if (RigidScheduleFlag) { DateTime FullStartTime = DateTime.Parse(StartDateEntry.ToShortDateString() + " " + StartTime); DateTime FullEndTime = DateTime.Parse(EndDateEntry.ToShortDateString() + " " + EndTime); EventDuration = (FullEndTime - FullStartTime).ToString(); } if (!string.IsNullOrEmpty(RepeatType)) { DateTime FullStartTime = DateTime.Parse(StartDateEntry.ToShortDateString() + " " + StartTime); DateTime FullEndTime = DateTime.Parse(EndDateEntry.ToShortDateString() + " " + EndTime); RepeatStart = StartDateEntry; RepeatEnd = new DateTime(Convert.ToInt32(RepeatEndYear),Convert.ToInt32(RepeatEndMonth),Convert.ToInt32(RepeatEndDay)); //RepeatEnd = (DateTime.Now).AddDays(7); RepetitionFlag = true; MyRepetition = new Repetition(RepetitionFlag, new TimeLine(RepeatStart, RepeatEnd), RepeatFrequency, new TimeLine(FullStartTime,FullEndTime)); EndDateEntry = RepeatEnd; } Schedule MySchedule = new Schedule(myUser,refNow); CalendarEvent newCalendarEvent = new CalendarEvent(Name, StartTime, StartDateEntry, EndTime, EndDateEntry, Count, "", EventDuration, MyRepetition, true, RigidScheduleFlag, "", true, EventLocation, true, new EventDisplay(true,userColor),new MiscData(),false); newCalendarEvent.Repeat.PopulateRepetitionParameters(newCalendarEvent); string BeforemyName = newCalendarEvent.ToString(); //BColor + " -- " + Count + " -- " + DurationDays + " -- " + DurationHours + " -- " + DurationMins + " -- " + EndDay + " -- " + EndHour + " -- " + EndMins + " -- " + EndMonth + " -- " + EndYear + " -- " + GColor + " -- " + LocationAddress + " -- " + LocationTag + " -- " + Name + " -- " + RColor + " -- " + RepeatData + " -- " + RepeatEndDay + " -- " + RepeatEndMonth + " -- " + RepeatEndYear + " -- " + RepeatStartDay + " -- " + RepeatStartMonth + " -- " + RepeatStartYear + " -- " + RepeatType + " -- " + RepeatWeeklyData + " -- " + Rigid + " -- " + StartDay + " -- " + StartHour + " -- " + StartMins + " -- " + StartMonth + " -- " + StartYear; string AftermyName = newCalendarEvent.ToString(); MySchedule.AddToSchedule(newCalendarEvent); PostBackData myPostData = new PostBackData("\"Success\"", 0); context.Response.Write(myPostData.getPostBackData); } break; case "2"://procrastinate { string EventID = context.Request.Form["EventID"]; string DurationDays = context.Request.Form["DurationDays"]; string DurationHours = context.Request.Form["DurationHours"]; string DurationMins = context.Request.Form["DurationMins"]; Schedule MySchedule = new Schedule(myUser, refNow); TimeSpan fullTimeSpan = new TimeSpan(Convert.ToInt32(DurationDays), Convert.ToInt32(DurationHours), Convert.ToInt32(DurationMins), 0); Tuple<CustomErrors, Dictionary<string, CalendarEvent>> ScheduleUpdateMessage = MySchedule.ProcrastinateJustAnEvent(EventID, fullTimeSpan); MySchedule.UpdateWithProcrastinateSchedule(ScheduleUpdateMessage.Item2); PostBackData myPostData = new PostBackData("\"Success\"", 0); context.Response.Write(myPostData.getPostBackData); } break; case "4"://SignInToUerAccount { string retValue; retValue = "{\"ID\":\"" + myUser.UserID + "\",\"User\":\"" + myUser.UserName + "\",\"Name\":\"" + myUser.Usersname + "\"}"; PostBackData myPostData = new PostBackData(retValue, 0); context.Response.Write(myPostData.getPostBackData); } break; case "5"://CreateLogFolder { string serverDirectoryOfFile = System.Web.HttpContext.Current.Server.MapPath("..\\18.xml"); { Directory.CreateDirectory(serverDirectoryOfCalLogs); File.Copy(serverDirectoryOfFile, serverDirectoryOfCalLogs + "18.xml",true); } context.Response.Write("Name of Dir: " + UserAccount.WagTapLogLocation + "\nRest Of File:" + serverDirectoryOfCalLogs); } break; case "6"://Delete an event and readjust { string EventID = context.Request.Form["EventID"]; Schedule MySchedule = new Schedule(myUser, refNow); MySchedule.deleteSubCalendarEvent(EventID); PostBackData myPostData = new PostBackData("\"Success\"", 0); context.Response.Write(myPostData.getPostBackData); } break; case "7"://Mark as Complete and readjust { string EventID = context.Request.Form["EventID"]; Schedule MySchedule = new Schedule(myUser, refNow); MySchedule.markSubEventAsCompleteCalendarEventAndReadjust(EventID); PostBackData myPostData = new PostBackData("\"Success\"", 0); context.Response.Write(myPostData.getPostBackData); } break; case "8"://Set as now { string EventID = context.Request.Form["EventID"]; Schedule MySchedule = new Schedule(myUser, refNow); Tuple<CustomErrors, Dictionary<string, CalendarEvent>> retValue = MySchedule.SetEventAsNow(EventID); MySchedule.UpdateWithProcrastinateSchedule(retValue.Item2); PostBackData myPostData = new PostBackData("\"Success\"", 0); context.Response.Write(myPostData.getPostBackData); } break; case "9"://Download Log { string serverDirectoryOfFile = System.Web.HttpContext.Current.Server.MapPath("..\\"+myUser.UserID+".xml"); byte[] FileData = File.ReadAllBytes(myUser.getFullLogDir); string SaveAsName = myUser.UserName + "Log.xml"; string SomeXLog= myUser.getFullLogDir; ResponseOpenFileBytes(FileData, null, SaveAsName, context.Response); context.Response.Write("sent: " + SaveAsName + "\nSomeXLog is:" + SomeXLog + "\nRest Of File:" + serverDirectoryOfCalLogs + "Current Time is: " + DateTime.Now.ToString()); context.Response.End(); } break; default: break; } } DateTime dt; }
private void LogInToWagtap() { UserAccount currentUser = new UserAccount(UserNameTextBox.Text, PasswordTextBox.Text); DateTime refNow=DateTime.Now; MySchedule = new Schedule(currentUser, refNow); if (MySchedule.isScheduleLoadSuccessful) { tabItem2.IsEnabled = true; datePicker1.SelectedDate = Schedule.Now.AddDays(0);// DateTime.Now.AddDays(0); //datePicker1.SelectedDate = DateTime.Now.AddDays(0); //datePicker1.SelectedDate = new DateTime(2013, 11, 20, 0, 0, 0); //datePicker2.SelectedDate = DateTime.Now.AddDays(2); datePicker2.SelectedDate = Schedule.Now.AddDays(0);//new DateTime(2014, 5, 15, 0, 0, 0); calendar4.SelectedDate = DateTime.Now.AddDays(0); Random myNumber = new Random(); int RandomHour = myNumber.Next(0, 24); int RandomMinute = myNumber.Next(0, 60); textBox4.Text = RandomHour + ":" + RandomMinute; textBox4.Text = 0 + ":" + "20";//total time textBox2.Text = 1.ToString();//number of splits int ProcrastinateStartDay = 0; int ProcrastinateEndDay = 365; int ProcrastinateStartHour = 0; int ProcrastinateEndHour = 24; int ProcrastinateStartMin = 0; int ProcrastinateEndMin = 60; comboBox4 = ProcrastinateComboBox.PopulateComboBox(ProcrastinateStartDay, ProcrastinateEndDay, 1, comboBox4); comboBox5 = ProcrastinateComboBox.PopulateComboBox(ProcrastinateStartHour, ProcrastinateEndHour, 1, comboBox5); comboBox6 = ProcrastinateComboBox.PopulateComboBox(ProcrastinateStartMin, ProcrastinateEndMin, 1, comboBox6); comboBox4.Text = 0.ToString(); comboBox5.Text = 0.ToString(); comboBox6.Text = 0.ToString(); #if enableDebugging #if enableMultithreading MessageBox.Show("Multithreading Enabled"); #else MessageBox.Show("Sequential run enabled"); var current = Process.GetCurrentProcess(); var affinity = current.ProcessorAffinity.ToInt32(); current.ProcessorAffinity = new IntPtr(affinity & 0x5555); #endif #endif //EventIDGenerator.Initialize((uint)(MySchedule.LastScheduleIDNumber)); } else { MessageBox.Show("Error loading Schedule please check user password"); } }
private void RunEvaluation(object sender, RoutedEventArgs e) { int NumberOfRetries = Convert.ToInt32(textBox10.Text); long[] AllData = new long[NumberOfRetries]; while(--NumberOfRetries>=0) { UserAccount currentUser = new UserAccount(UserNameTextBox.Text, PasswordTextBox.Text); MySchedule = new Schedule(currentUser,DateTime.Now); string eventName = textBox1.Text; string LocationString = textBox8.Text.Trim(); /*if (LocationString != "") { eventName += "," + LocationString; }*/ DateTime CurrentTimeOfExecution = DateTime.Now; string eventStartTime = textBox5.Text; string locationInformation = textBox8.Text; DateTime eventStartDate = (DateTime)datePicker1.SelectedDate.Value; string eventEndTime = textBox7.Text; DateTime eventEndDate = (DateTime)datePicker2.SelectedDate.Value; bool EventRepetitionflag = checkBox2.IsChecked.Value; bool DefaultPrepTimeflag = checkBox3.IsChecked.Value; string eventPrepTime = textBox3.Text; bool RigidScheduleFlag = checkBox5.IsChecked.Value; string RepeatFrequency = comboBox2.Text; string EventDuration = textBox4.Text; string eventSplit = textBox2.Text; bool DefaultPreDeadlineFlag = checkBox4.IsChecked.Value; string PreDeadlineTime = textBox6.Text; eventStartTime = eventStartTime.Trim(); eventStartTime = eventStartTime.Replace(" ", string.Empty); if (eventStartTime == "") { eventStartTime = CurrentTimeOfExecution.ToString(); string[] TempString = eventStartTime.Split(' '); eventStartTime = TempString[1] + TempString[2]; } //This attempts to detect invalid inputs for start time values string[] TimeElements = CalendarEvent.convertTimeToMilitary(eventStartTime).Split(':'); DateTime EnteredDateTime = new DateTime(eventStartDate.Year, eventStartDate.Month, eventStartDate.Day, Convert.ToInt32(TimeElements[0]), Convert.ToInt32(TimeElements[1]), 0); //if checks for StartDateTime if (EnteredDateTime < DateTime.Now) { //DateTime Now=DateTime.Now; //MessageBox.Show("Please Adjust Your Start Date, Its less than the current time:"); //return; } if (eventEndTime == "") { DateTime EventEndDateTime = new DateTime(eventEndDate.Year, eventEndDate.Month, eventEndDate.Day, EnteredDateTime.Hour, EnteredDateTime.Minute, EnteredDateTime.Second); eventEndTime = EventEndDateTime.ToString(); //eventEndDate //MessageBox.Show("Please Type EndTime in The Format: HH:MM A/PM"); //return; } TimeSpan TestTimeSpan = new TimeSpan(); bool RigidFlag = false; bool RepetitionFlag = false; Repetition MyRepetition = new Repetition(); if (checkBox5.IsChecked.Value) { RigidFlag = true; } DateTime CurrentNow = DateTime.Now; DateTime RepeatStart = CurrentNow; DateTime RepeatEnd = RepeatStart; if (checkBox2.IsChecked.Value) { DateTime FullStartTime = DateTime.Parse(eventStartDate.ToShortDateString() + " " + eventStartTime); DateTime FullEndTime = DateTime.Parse(eventEndDate.ToShortDateString() + " " + eventEndTime); //RepeatStart = (DateTime)calendar3.SelectedDate.Value; RepeatStart = DateTime.Parse(eventStartTime); RepeatEnd = (DateTime)calendar4.SelectedDate.Value; //RepeatEnd = (DateTime.Now).AddDays(7); RepetitionFlag = true; MyRepetition = new Repetition(RepetitionFlag, new TimeLine(RepeatStart, RepeatEnd), RepeatFrequency, new TimeLine((FullStartTime),(FullEndTime))); //eventStartDate = RepeatStart; eventEndDate = RepeatStart; } CustomErrors ErrorCheck = ValidateInputValues(EventDuration, eventStartTime, eventStartDate.ToString(), eventEndTime, eventEndDate.ToString(), RepeatStart.ToString(), RepeatEnd.ToString(), PreDeadlineTime, eventSplit, eventPrepTime, CurrentNow); if (!ErrorCheck.Status) { //MessageBox.Show(ErrorCheck.Message); return; // } //C6RXEZ Location var0 = new Location(textBox8.Text); EventDisplay UiData = new EventDisplay(); MiscData NoteData = new MiscData(); bool CompletedFlag = false; //CalendarEvent ScheduleUpdated = CreateSchedule(eventName, eventStartTime, eventStartDate, eventEndTime, eventEndDate, eventSplit, PreDeadlineTime, EventDuration, EventRepetitionflag, DefaultPreDeadlineFlag, RigidScheduleFlag, eventPrepTime, DefaultPreDeadlineFlag); CalendarEvent ScheduleUpdated = new CalendarEvent(eventName, eventStartTime, eventStartDate, eventEndTime, eventEndDate, eventSplit, PreDeadlineTime, EventDuration, MyRepetition, DefaultPreDeadlineFlag, RigidFlag, eventPrepTime, DefaultPreDeadlineFlag, var0, true, UiData, NoteData,CompletedFlag); ScheduleUpdated.Repeat.PopulateRepetitionParameters(ScheduleUpdated); Stopwatch snugarrayTester = new Stopwatch(); snugarrayTester.Start(); CustomErrors ScheduleUpdateMessage = MySchedule.AddToSchedule(ScheduleUpdated); snugarrayTester.Stop(); AllData[NumberOfRetries] = snugarrayTester.ElapsedMilliseconds; } int q= 0; double totalTIme = 0; for(q=0;q<AllData.Length;q++) { textBlock9.Text += AllData[q] + ","; totalTIme += AllData[q]; } totalTIme /= q; textBlock9.Text += "Average is " + totalTIme; }
public MainWindow() { InitializeComponent(); datePicker1.SelectedDate = DateTime.Now.AddDays(1); datePicker2.SelectedDate = DateTime.Now.AddDays(1); MySchedule = new Schedule(); LastID = (uint)(MySchedule.LastScheduleIDNumber); //EventIDGenerator(); EventIDGenerator.Initialize(); }