public virtual JSONObject toJSONObject()
        {
            if (mID == null)
            {
                SoomlaUtils.LogError(TAG, "This is BAD! We don't have ID in the this SoomlaEntity. Stopping here.");
                return(null);
            }
            JSONObject jsonObject = new JSONObject();

            /*jsonObject[JSONConsts.SOOM_ENTITY_NAME] = mName;
             * jsonObject[JSONConsts.SOOM_ENTITY_DESCRIPTION] = mDescription;
             * jsonObject[JSONConsts.SOOM_ENTITY_ID] = mID;*/

            return(jsonObject);
        }
Beispiel #2
0
        public bool Approve(int activationTimes)
        {
            DateTime now = DateTime.Now;

            if (ActivationLimit < 1 && (TimeRanges == null || TimeRanges.Count == 0))
            {
                SoomlaUtils.LogDebug(TAG, "There's no activation limit and no TimeRanges. APPROVED!");
                return(true);
            }

            if (ActivationLimit > 0 && activationTimes >= ActivationLimit)
            {
                SoomlaUtils.LogDebug(TAG, "Activation limit exceeded.");
                return(false);
            }

            if ((TimeRanges == null || TimeRanges.Count == 0))
            {
                SoomlaUtils.LogDebug(TAG, "We have an activation limit that was not reached. Also, we don't have any time ranges. APPROVED!");
                return(true);
            }


            // NOTE: From this point on ... we know that we didn't reach the activation limit AND we have TimeRanges.
            //		 We'll just make sure the time ranges and the Recurrence copmlies.


            foreach (DateTimeRange dtr in TimeRanges)
            {
                if (now >= dtr.Start && now <= dtr.End)
                {
                    SoomlaUtils.LogDebug(TAG, "We are just in one of the time spans, it can't get any better then that. APPROVED!");
                    return(true);
                }
            }

            // we don't need to continue if RequiredRecurrence is NONE
            if (RequiredRecurrence == Recurrence.NONE)
            {
                return(false);
            }

            foreach (DateTimeRange dtr in TimeRanges)
            {
                if (now.Minute >= dtr.Start.Minute && now.Minute <= dtr.End.Minute)
                {
                    SoomlaUtils.LogDebug(TAG, "Now is in one of the time ranges' minutes span.");

                    if (RequiredRecurrence == Recurrence.EVERY_HOUR)
                    {
                        SoomlaUtils.LogDebug(TAG, "It's a EVERY_HOUR recurrence. APPROVED!");
                        return(true);
                    }

                    if (now.Hour >= dtr.Start.Hour && now.Hour <= dtr.End.Hour)
                    {
                        SoomlaUtils.LogDebug(TAG, "Now is in one of the time ranges' hours span.");

                        if (RequiredRecurrence == Recurrence.EVERY_DAY)
                        {
                            SoomlaUtils.LogDebug(TAG, "It's a EVERY_DAY recurrence. APPROVED!");
                            return(true);
                        }

                        if (now.DayOfWeek >= dtr.Start.DayOfWeek && now.DayOfWeek <= dtr.End.DayOfWeek)
                        {
                            SoomlaUtils.LogDebug(TAG, "Now is in one of the time ranges' day-of-week span.");

                            if (RequiredRecurrence == Recurrence.EVERY_WEEK)
                            {
                                SoomlaUtils.LogDebug(TAG, "It's a EVERY_WEEK recurrence. APPROVED!");
                                return(true);
                            }

                            if (now.Day >= dtr.Start.Day && now.Day <= dtr.End.Day)
                            {
                                SoomlaUtils.LogDebug(TAG, "Now is in one of the time ranges' days span.");

                                if (RequiredRecurrence == Recurrence.EVERY_MONTH)
                                {
                                    SoomlaUtils.LogDebug(TAG, "It's a EVERY_MONTH recurrence. APPROVED!");
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }