예제 #1
0
        public void populatePauseData(PausedEvent PausedEvent, DateTimeOffset currentTime)
        {
            DateTimeOffset           CurrentTime = currentTime;
            long                     RangeStart  = (long)(CurrentTime - TilerElementExtension.JSStartTime).TotalMilliseconds;
            long                     RangeEnd    = RangeStart + (long)TimeSpan.FromDays(1).TotalMilliseconds;
            Func <SubCalEvent, bool> predicate   = (subEvent =>
            {
                if ((RangeStart <= subEvent.SubCalEndDate) && (RangeEnd >= subEvent.SubCalStartDate))
                {
                    return(true);
                }
                return(false);
            });
            List <SubCalEvent> allSubEvents = this.SubCalendarEvents == null?this.RepeatCalendarEvent.SelectMany(obj => obj.RepeatCalendarEvents.SelectMany(CalEvent => CalEvent.AllSubCalEvents)).Concat(NonRepeatCalendarEvent.SelectMany(obj => obj.AllSubCalEvents)).ToList() : this.SubCalendarEvents.ToList();

            SubCalEvent pausedSubEVent = allSubEvents.FirstOrDefault(obj => obj.isPaused);

            //creates paused event from the list of events derived
            if ((pausedSubEVent != null) && (PausedEvent == null))
            {
                PausedEvent = new PausedEvent()
                {
                    EventId        = pausedSubEVent.ID,
                    isPauseDeleted = pausedSubEVent.isEnabled
                };
            }

            PausedEvent PausedEventDuplicate = null;

            if (PausedEvent != null)// doing this to avoid modifying Entity framework attached copy of the object
            {
                PausedEventDuplicate = new PausedEvent()
                {
                    EventId        = PausedEvent.EventId,
                    isPauseDeleted = PausedEvent.isPauseDeleted,
                    PauseTime      = PausedEvent.PauseTime
                };
            }


            allSubEvents = allSubEvents.Take(10).ToList();
            dynamic RetValue = new JObject();

            RetValue.pausedEvent = PausedEvent == null? null : JObject.FromObject(PausedEventDuplicate);
            RetValue.subEvents   = JArray.FromObject(allSubEvents);
            this.PauseData       = RetValue as JObject;
        }
예제 #2
0
        public static SubCalEvent ToSubCal(this Event googleEvent, EventID AuthenticationID, uint CurrentCount)
        {
            SubCalEvent retValue = new SubCalEvent();

            retValue.ThirdPartyEventID = googleEvent.Id;
            retValue.ThirdPartyType    = ThirdPartyControl.CalendarTool.google.ToString();
            retValue.ThirdPartyUserID  = googleEvent.Organizer?.Email;


            retValue.ID                       = AuthenticationID.getIDUpToRepeatDayCalendarEvent() + "_" + CurrentCount + "_1";
            retValue.CalendarID               = AuthenticationID.getIDUpToRepeatDayCalendarEvent() + "_" + CurrentCount + "_0";
            retValue.isThirdParty             = true;
            retValue.SubCalAddressDescription = googleEvent.Location;


            retValue.SubCalStartDate = (long)(new DateTimeOffset(googleEvent.Start.DateTime.Value) - TilerElementExtension.JSStartTime).TotalMilliseconds;
            retValue.SubCalEndDate   = (long)(new DateTimeOffset(googleEvent.End.DateTime.Value) - TilerElementExtension.JSStartTime).TotalMilliseconds;

            retValue.SubCalTotalDuration      = (googleEvent.End.DateTime.Value - googleEvent.Start.DateTime.Value);
            retValue.SubCalRigid              = true;
            retValue.SubCalAddressDescription = googleEvent.Location;// SubCalendarEventEntry.Location.Description;
            retValue.SubCalAddress            = googleEvent.Location;
            retValue.SubCalCalendarName       = googleEvent.Summary;
            retValue.isReadOnly = false;
            if (googleEvent.ExtendedProperties != null && googleEvent.ExtendedProperties.Private__ != null && googleEvent.ExtendedProperties.Private__.ContainsKey(GoogleTilerEventControl.tilerReadonlyKey))
            {
                retValue.isReadOnly = Convert.ToBoolean(googleEvent.ExtendedProperties.Private__[GoogleTilerEventControl.tilerReadonlyKey]);
            }
            if (retValue.ThirdPartyUserID == null || retValue.SubCalCalendarName == null)
            {
                retValue.SubCalCalendarName = "busy";
            }

            retValue.SubCalCalEventStart = retValue.SubCalStartDate;
            retValue.SubCalCalEventEnd   = retValue.SubCalEndDate;

            retValue.isComplete     = false;
            retValue.isEnabled      = true;
            retValue.Duration       = (long)retValue.SubCalTotalDuration.TotalMilliseconds;
            retValue.Priority       = 0;
            retValue.ColorSelection = 0;
            return(retValue);
        }
예제 #3
0
        public static SubCalEvent ToRepeatInstance(this Event googleEvent, EventID CalendarID, uint CurrentCount)
        {
            SubCalEvent retValue = new SubCalEvent();

            retValue.ThirdPartyEventID = googleEvent.Id;
            retValue.ThirdPartyType    = ThirdPartyControl.CalendarTool.google.ToString();
            retValue.ThirdPartyUserID  = googleEvent.Organizer.Email;
            EventID SubEVentID = EventID.generateRepeatGoogleSubCalendarEventID(CalendarID, CurrentCount);

            retValue.ID         = SubEVentID.ToString();
            retValue.CalendarID = SubEVentID.getRepeatCalendarEventID();


            retValue.SubCalStartDate = (long)(new DateTimeOffset(googleEvent.Start.DateTime.Value) - TilerElementExtension.JSStartTime).TotalMilliseconds;
            retValue.SubCalEndDate   = (long)(new DateTimeOffset(googleEvent.End.DateTime.Value) - TilerElementExtension.JSStartTime).TotalMilliseconds;

            retValue.SubCalTotalDuration      = (googleEvent.End.DateTime.Value - googleEvent.Start.DateTime.Value);
            retValue.SubCalRigid              = true;
            retValue.SubCalAddressDescription = googleEvent.Location;// SubCalendarEventEntry.Location.Description;
            retValue.SubCalAddress            = googleEvent.Location;
            retValue.SubCalCalendarName       = googleEvent.Summary;

            retValue.SubCalCalEventStart = retValue.SubCalStartDate;
            retValue.SubCalCalEventEnd   = retValue.SubCalEndDate;
            retValue.isThirdParty        = true;
            retValue.isReadOnly          = false;
            if (googleEvent.ExtendedProperties != null && googleEvent.ExtendedProperties.Private__ != null && googleEvent.ExtendedProperties.Private__.ContainsKey(GoogleTilerEventControl.tilerReadonlyKey))
            {
                retValue.isReadOnly = Convert.ToBoolean(googleEvent.ExtendedProperties.Private__[GoogleTilerEventControl.tilerReadonlyKey]);
            }



            retValue.isComplete = false;
            retValue.isEnabled  = true;
            retValue.Duration   = (long)retValue.SubCalTotalDuration.TotalMilliseconds;
            //retValue.EventPreDeadline = (long)SubCalendarEventEntry.PreDeadline.TotalMilliseconds;
            retValue.Priority = 0;
            //retValue.Conflict = String.Join(",", SubCalendarEventEntry.Conflicts.getConflictingEventIDs());
            retValue.ColorSelection = 0;
            return(retValue);
        }
예제 #4
0
        public static SubCalEvent ToSubCalEvent(this TilerElements.PausedTimeLineEntry pausedTimeline, TilerElements.CalendarEvent CalendarEventEntry, bool includeCalendarEvent = true)
        {
            SubCalendarEvent pausedSubEvent = CalendarEventEntry.getSubEvent(pausedTimeline.getSubEventId());
            DateTimeOffset   CurrentTime    = DateTimeOffset.UtcNow;
            SubCalEvent      retValue       = new SubCalEvent();

            retValue.ThirdPartyUserID  = CalendarEventEntry.getCreator.Id;
            retValue.ThirdPartyType    = CalendarEventEntry.ThirdpartyType.ToString();
            retValue.ThirdPartyEventID = CalendarEventEntry.ThirdPartyID;
            retValue.ID         = pausedTimeline.Id;
            retValue.CalendarID = CalendarEventEntry.Calendar_EventID.getRepeatCalendarEventID();

            retValue.SubCalStartDate          = (long)(pausedTimeline.Start - JSStartTime).TotalMilliseconds;
            retValue.SubCalEndDate            = (long)(pausedTimeline.End - JSStartTime).TotalMilliseconds;
            retValue.SubCalTotalDuration      = pausedTimeline.TimelineSpan;
            retValue.SubCalRigid              = CalendarEventEntry.isRigid;
            retValue.SubCalAddressDescription = pausedSubEvent.Location.Description;
            retValue.SubCalAddress            = pausedSubEvent.Location.Address;
            retValue.ThirdPartyEventID        = pausedSubEvent.ThirdPartyID;
            retValue.SubCalCalendarName       = pausedSubEvent.Name?.NameValue;
            retValue.Notes = pausedSubEvent?.Notes?.UserNote;

            if (CalendarEventEntry != null)
            {
                retValue.CalRigid               = CalendarEventEntry.isRigid;
                retValue.SubCalCalEventStart    = (long)(CalendarEventEntry.Start - JSStartTime).TotalMilliseconds;
                retValue.SubCalCalEventEnd      = (long)(CalendarEventEntry.End - JSStartTime).TotalMilliseconds;
                retValue.SuggestedDeadline      = CalendarEventEntry.DeadlineSuggestion.ToUnixTimeMilliseconds();
                retValue.SleepSuggestedDeadline = CalendarEventEntry.SleepDeadlineSuggestion.ToUnixTimeMilliseconds();
                if (string.IsNullOrEmpty(CalendarEventEntry.ThirdPartyID))
                {
                }
                else
                {
                    retValue.ID = retValue.ThirdPartyEventID;
                }
            }

            retValue.SubCalEventLong    = pausedSubEvent.Location.Longitude;
            retValue.SubCalEventLat     = pausedSubEvent.Location.Latitude;
            retValue.SubCalCalendarName = pausedSubEvent.getName?.NameValue;
            TilerColor uiColor = TilerColor.pausedUIColor();

            if (uiColor != null)
            {
                retValue.RColor         = uiColor.R;
                retValue.GColor         = uiColor.G;
                retValue.BColor         = uiColor.B;
                retValue.OColor         = uiColor.O;
                retValue.ColorSelection = uiColor.User;
            }
            retValue.isComplete         = false;
            retValue.isEnabled          = true;
            retValue.Duration           = (long)pausedTimeline.TimelineSpan.TotalMilliseconds;
            retValue.ThirdPartyEventID  = pausedSubEvent.ThirdPartyID;
            retValue.EventPreDeadline   = (long)pausedSubEvent.getPreDeadline.TotalMilliseconds;
            retValue.Priority           = pausedSubEvent.getEventPriority;
            retValue.Conflict           = String.Join(",", pausedSubEvent.Conflicts.getConflictingEventIDs());
            retValue.isPaused           = false;
            retValue.isPauseAble        = false;
            retValue.PauseStart         = (long)(pausedTimeline.Start - JSStartTime).TotalMilliseconds;
            retValue.PauseEnd           = (long)(pausedTimeline.End - JSStartTime).TotalMilliseconds;
            retValue.IsLocked           = true;
            retValue.UserLocked         = false;
            retValue.isThirdParty       = pausedSubEvent.isThirdParty;
            retValue.isReadOnly         = true;
            retValue.isTardy            = false;
            retValue.isProcrastinateAll = false;
            retValue.isAllDay           = pausedSubEvent.getActiveDuration >= Utility.LeastAllDaySubeventDuration;

            if (CalendarEventEntry != null && includeCalendarEvent)
            {
                retValue.CalEvent = CalendarEventEntry.ToCalEvent(includeSubevents: false);
            }

            return(retValue);
        }
예제 #5
0
        public async Task <IHttpActionResult> pushedEvent([FromBody] WhatIfModel UserData)
        {
            AuthorizedUser myAuthorizedUser = UserData.User;
            UserAccount    retrievedUser    = await UserData.getUserAccount(db);

            await retrievedUser.Login();

            retrievedUser.getTilerUser().updateTimeZoneTimeSpan(UserData.getTimeSpan);
            PostBackData returnPostBack;

            if (retrievedUser.Status)
            {
                Task <Tuple <ThirdPartyControl.CalendarTool, IEnumerable <CalendarEvent> > > thirdPartyDataTask = ScheduleController.updatemyScheduleWithGoogleThirdpartyCalendar(retrievedUser.UserID, db);
                DB_Schedule schedule       = new DB_Schedule(retrievedUser, myAuthorizedUser.getRefNow(), UserData.getCurrentLocation());
                var         thirdPartyData = await thirdPartyDataTask.ConfigureAwait(false);

                schedule.updateDataSetWithThirdPartyData(thirdPartyData);
                schedule.CurrentLocation = myAuthorizedUser.getCurrentLocation();
                Tuple <Health, Health> evaluation;

                SubCalendarEvent subEvent = null;
                try
                {
                    if (String.IsNullOrEmpty(UserData.EventId))
                    {
                        var calEventAndSubEvent = schedule.getNearestEventToNow();
                        subEvent = calEventAndSubEvent.Item2;
                        EventID eventId = new EventID(calEventAndSubEvent.Item2.getId);
                        evaluation = await schedule.TimeStone.PushSingleEvent(UserData.Duration, eventId, null);
                    }
                    else
                    {
                        evaluation = await schedule.TimeStone.PushSingleEvent(UserData.Duration, new EventID(UserData.EventId), null);
                    }

                    JObject before     = evaluation.Item1.ToJson();
                    JObject after      = evaluation.Item2.ToJson();
                    JObject resultData = new JObject();
                    if (subEvent != null)
                    {
                        SubCalEvent subcalevent = subEvent.ToSubCalEvent();
                        JObject     jsonSubcal  = JObject.FromObject(subcalevent);
                        resultData.Add("subEvent", jsonSubcal);
                    }

                    resultData.Add("before", before);
                    resultData.Add("after", after);
                    returnPostBack = new PostBackData(resultData, 0);
                    return(Ok(returnPostBack.getPostBack));
                }
                catch (CustomErrors error)
                {
                    returnPostBack = new PostBackData(error);
                    return(Ok(returnPostBack.getPostBack));
                }
            }
            else
            {
                returnPostBack = new PostBackData("", 1);
            }

            return(Ok(returnPostBack.getPostBack));
        }