Пример #1
0
        public JSONObject toJSONObject()
        {
            JSONObject obj = new JSONObject(JSONObject.Type.OBJECT);

            obj.AddField(JSONConsts.SOOM_CLASSNAME, SoomlaUtils.GetClassName(this));
            obj.AddField(JSONConsts.SOOM_SCHE_REC, (int)RequiredRecurrence);
            obj.AddField(JSONConsts.SOOM_SCHE_APPROVALS, ActivationLimit);

            JSONObject rangesObj = new JSONObject(JSONObject.Type.ARRAY);

            if (TimeRanges != null)
            {
                foreach (DateTimeRange dtr in TimeRanges)
                {
                    long       startMillis = dtr.Start.Ticks / TimeSpan.TicksPerMillisecond;
                    long       endMillis   = dtr.End.Ticks / TimeSpan.TicksPerMillisecond;
                    JSONObject singleRange = new JSONObject(JSONObject.Type.OBJECT);
                    singleRange.AddField(JSONConsts.SOOM_CLASSNAME, SoomlaUtils.GetClassName(dtr));
                    singleRange.AddField(JSONConsts.SOOM_SCHE_RANGE_START, startMillis);
                    singleRange.AddField(JSONConsts.SOOM_SCHE_RANGE_END, endMillis);

                    rangesObj.Add(singleRange);
                }
            }

            obj.AddField(JSONConsts.SOOM_SCHE_RANGES, rangesObj);

            return(obj);
        }
Пример #2
0
        /// <summary>
        /// Converts the current <c>SoomlaEntity</c> to a JSONObject.
        /// </summary>
        /// <returns>A <c>JSONObject</c> representation of the current <c>SoomlaEntity</c>.</returns>
        public virtual JSONObject toJSONObject()
        {
            if (string.IsNullOrEmpty(this._id))
            {
                SoomlaUtils.LogError(TAG, "This is BAD! We don't have ID in the this SoomlaEntity. Stopping here.");
                return(null);
            }

            JSONObject obj = new JSONObject(JSONObject.Type.OBJECT);

            obj.AddField(JSONConsts.SOOM_ENTITY_NAME, this.Name);
            obj.AddField(JSONConsts.SOOM_ENTITY_DESCRIPTION, this.Description);
            obj.AddField(JSONConsts.SOOM_ENTITY_ID, this._id);
            obj.AddField(JSONConsts.SOOM_CLASSNAME, SoomlaUtils.GetClassName(this));

            return(obj);
        }