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 LogInButton_Copy_Click(object sender, RoutedEventArgs e)
 {
     //Register(string FirstName, string LastName, string NickName, string UserName, string PassWord)
     UserAccount newUser = new UserAccount();
     if (!newUser.Register(FirstNameRegisterTextBox.Text, LastNameRegisterTextBox.Text, NickNameRegisterTextBox.Text, UserNameRegisterTextBox.Text, PasswordRegisterTextBox.Text).Status)
     {
         UserNameTextBox.Text = UserNameRegisterTextBox.Text;
         PasswordTextBox.Text = PasswordRegisterTextBox.Text;
         LogInToWagtap();
     }
 }