예제 #1
0
        public void ParseSerializedCurrentDateAsEpochSeconds()
        {
            var writer = new JSonWriter();
            var now    = DateTime.Now;

            using (writer.WriteObject())
                writer.WriteMember("date", now, JSonWriterDateFormat.UnixEpochSeconds);

            // remove below seconds:
            now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, 0, now.Kind);

            var reader = new JSonReader(writer.ToString());
            var item   = reader.ReadAsJSonObject();
            var date   = item["date"].ToDateTimeValue(JSonDateTimeKind.UnixEpochSeconds);

            Assert.AreNotEqual(0, item["date"].Int64Value);
            Assert.AreEqual(now, date);
        }
예제 #2
0
        /// <summary>
        /// Makes a Re-Rayz Request
        /// </summary>
        /// <param name="rayzId"> Rayz ID </param>
        /// <param name="latitude"> Latitude Coordinate </param>
        /// <param name="longitude"> Longitude Coordinate </param>
        /// <param name="accuracy"> Accuracy of the user's position in meters </param>
        /// <param name="maxDistance"> Max Rayz Distance - NOT USED </param>
        public async Task <IJSonObject> ReRayz(String rayzId, String latitude, String longitude, String accuracy, String maxDistance)
        {
            try
            {
                var writer = new JSonWriter(true);
                var reader = new JSonReader();

                // Make sure that lat and long are dot separated
                latitude  = latitude.Replace(@",", @".");
                longitude = longitude.Replace(@",", @".");

                writer.WriteObjectBegin();
                writer.WriteMember("userId", _deviceId);
                writer.WriteMember("rayzId", rayzId);
                writer.WriteMember("latitude", latitude);
                writer.WriteMember("longitude", longitude);
                writer.WriteMember("accuracy", accuracy);
                writer.WriteMember("maxDistance", maxDistance);
                writer.WriteObjectEnd();

                var json = new StringContent(writer.ToString());
                json.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

                var response = await _client.PostAsync(new Uri(ServerBaseUri, "/rayz/rerayz"), json);

                var cr = CheckResponse(response);
                if (cr != null)
                {
                    var creply = reader.ReadAsJSonObject(cr);
                    return(creply);
                }

                var r = await response.Content.ReadAsStringAsync();

                var reply = reader.ReadAsJSonObject(r);
                return(reply);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #3
0
 public void WriteInvalidMember()
 {
     writer.WriteMember("name", "value");
 }
예제 #4
0
        /// <summary>
        /// Creates a new Rayz
        /// </summary>
        /// <param name="latitude"> Latitude Coordinate </param>
        /// <param name="longitude"> Longitude Coordinate </param>
        /// <param name="accuracy"> Accuracy of the user's position in meters </param>
        /// <param name="maxDistance"> Max Rayz Distance - NOT USED </param>
        /// <param name="rayzMessage"> The Rayz message </param>
        /// <param name="attachments"> The Rayz Attachments </param>
        public async Task <IJSonObject> CreateNewRayz(String latitude, String longitude, String accuracy, String maxDistance, String rayzMessage, ObservableCollection <RayzItAttachment> attachments)
        {
            try
            {
                var content = new MultipartFormDataContent();
                var writer  = new JSonWriter(true);
                var reader  = new JSonReader();

                // PLAY PROBLEM
                foreach (var param in content.Headers.ContentType.Parameters.Where(param => param.Name.Equals("boundary")))
                {
                    param.Value = param.Value.Replace("\"", String.Empty);
                }

                // Make sure that lat and long are dot separated
                latitude  = latitude.Replace(@",", @".");
                longitude = longitude.Replace(@",", @".");

                writer.WriteObjectBegin();
                writer.WriteMember("userId", _deviceId);
                writer.WriteMember("latitude", latitude);
                writer.WriteMember("longitude", longitude);
                writer.WriteMember("accuracy", accuracy);
                writer.WriteMember("maxDistance", maxDistance);
                writer.WriteMember("rayzMessage", rayzMessage);
                writer.WriteObjectEnd();

                var json = new StringContent(writer.ToString());
                content.Add(json, "\"json\"");

                foreach (var a in attachments)
                {
                    var fileContent = new StreamContent(new MemoryStream(a.FileBody));
                    fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                    {
                        Name     = "\"attachment\"",
                        FileName = "\"attachment.file\""
                    };
                    fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse(a.ContType);
                    content.Add(fileContent);
                }

                var response = await _client.PostAsync(new Uri(ServerBaseUri, "/rayz/create"), content);

                var cr = CheckResponse(response);
                if (cr != null)
                {
                    var creply = reader.ReadAsJSonObject(cr);
                    return(creply);
                }

                var r = await response.Content.ReadAsStringAsync();

                var reply = reader.ReadAsJSonObject(r);
                return(reply);
            }
            catch (Exception)
            {
                return(null);
            }
        }