Esempio n. 1
0
        public void State()
        {
            using (JsonWriter jsonWriter = new JTokenWriter())
            {
                Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);

                jsonWriter.WriteStartObject();
                Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);

                jsonWriter.WritePropertyName("CPU");
                Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);

                jsonWriter.WriteValue("Intel");
                Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);

                jsonWriter.WritePropertyName("Drives");
                Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);

                jsonWriter.WriteStartArray();
                Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);

                jsonWriter.WriteValue("DVD read/writer");
                Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);

                jsonWriter.WriteValue(new byte[0]);
                Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);

                jsonWriter.WriteEnd();
                Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);

                jsonWriter.WriteEndObject();
                Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
            }
        }
Esempio n. 2
0
        public static JArray GetPortsGroupedJson(string langCode = "en", byte portType = 0)
        {
            var          portsGrouped  = GetPortsGrouped(langCode, portType);
            JTokenWriter pJTokenWriter = new JTokenWriter();
            JArray       ordersJson    = new JArray();

            pJTokenWriter.WriteStartArray();
            foreach (var item in portsGrouped)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("text");
                pJTokenWriter.WriteValue(item.CountryName);
                pJTokenWriter.WritePropertyName("children");
                pJTokenWriter.WriteStartArray();
                foreach (var item1 in item.PortList)
                {
                    pJTokenWriter.WriteStartObject();
                    pJTokenWriter.WritePropertyName("id");
                    pJTokenWriter.WriteValue(item1.Key.ToString());
                    pJTokenWriter.WritePropertyName("text");
                    pJTokenWriter.WriteValue(item1.Value);
                    pJTokenWriter.WriteEndObject();
                }
                pJTokenWriter.WriteEndArray();

                pJTokenWriter.WriteEndObject();
            }
            pJTokenWriter.WriteEndArray();


            ordersJson = (JArray)pJTokenWriter.Token;
            return(ordersJson);
        }
        private static JToken WriteToJToken(List <Dictionary <string, dynamic> > data, CultureInfo culture)
        {
            using (var writer = new JTokenWriter())
            {
                writer.Formatting = Newtonsoft.Json.Formatting.Indented;
                writer.Culture    = culture;

                writer.WriteStartArray(); // root start

                foreach (var row in data)
                {
                    writer.WriteStartObject(); // start row object
                    foreach (var key in row.Keys)
                    {
                        writer.WritePropertyName(key);
                        // null check
                        if (row[key] != null)
                        {
                            writer.WriteValue(row[key]);
                        }
                        else //write empty string value for null fields
                        {
                            writer.WriteValue("");
                        }
                    }

                    writer.WriteEndObject(); // end row
                }

                writer.WriteEndArray(); // root array end

                return(writer.Token);
            }
        }
Esempio n. 4
0
        // send a message to iot central, topic is the key
        public static async Task SendMessageFromDeviceToCloud(string topic, string messageText)
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();
            writer.WritePropertyName("time");
            writer.WriteValue(DateTime.Now.ToString(CultureInfo.InvariantCulture));
            writer.WritePropertyName("deviceId");
            writer.WriteValue(CentralDeviceId);
            writer.WritePropertyName(topic);
            writer.WriteValue(messageText);
            writer.WriteEndObject();

            JObject o = (JObject)writer.Token;

            // serialise message to a JSON string
            string messageString = o.ToString();

            // format JSON string into IoT Hub message
            Message message = new Message(Encoding.ASCII.GetBytes(messageString));

            // push message to IoT Hub
            try
            {
                await _deviceClient.SendEventAsync(message).ConfigureAwait(false);

                ShowEventMessage?.Invoke($"Success Send to azure topic {topic} message {messageText}");
            }
            catch (Exception e)
            {
                ShowEventMessage?.Invoke($"Error Send to azure topic {topic} message {messageText}");
                ShowEventMessage?.Invoke(e.Message);
            }
        }
Esempio n. 5
0
        public void Example()
        {
            #region Usage
            JTokenWriter writer = new JTokenWriter();
            writer.WriteStartObject();
            writer.WritePropertyName("name1");
            writer.WriteValue("value1");
            writer.WritePropertyName("name2");
            writer.WriteStartArray();
            writer.WriteValue(1);
            writer.WriteValue(2);
            writer.WriteEndArray();
            writer.WriteEndObject();

            JObject o = (JObject)writer.Token;

            Console.WriteLine(o.ToString());
            // {
            //   "name1": "value1",
            //   "name2": [
            //     1,
            //     2
            //   ]
            // }
            #endregion

            Assert.AreEqual(@"{
  ""name1"": ""value1"",
  ""name2"": [
    1,
    2
  ]
}", o.ToString());
        }
Esempio n. 6
0
        public static JToken CreateJTokenObject(BerkeleyDbError error, Byte[] key, Byte[] value, int keySize, int valueSize)
        {
            using (var jsonWriter = new JTokenWriter())
            {
                jsonWriter.WriteStartObject();

                if (error != 0)
                {
                    jsonWriter.WritePropertyName("ErrorCode");
                    jsonWriter.WriteValue((int)error);
                }

                if (key != null)
                {
                    jsonWriter.WritePropertyName("Key");
                    String base64 = Convert.ToBase64String(key, 0, keySize);
                    jsonWriter.WriteValue(base64);
                }

                if (value != null)
                {
                    jsonWriter.WritePropertyName("Value");
                    String base64 = Convert.ToBase64String(value, 0, valueSize);
                    jsonWriter.WriteValue(base64);
                }

                jsonWriter.WriteEndObject();
                return(jsonWriter.Token);
            }
        }
        public static JToken CreateJTokenDtoPartialPut(Byte[] key, Byte[] value, int valueLength, int valueOffset)
        {
            using (var jsonWriter = new JTokenWriter())
            {
                jsonWriter.WriteStartObject();

                if (key != null)
                {
                    jsonWriter.WritePropertyName("Key");
                    String base64 = Convert.ToBase64String(key, 0, key.Length);
                    jsonWriter.WriteValue(base64);
                }

                jsonWriter.WritePropertyName("Value");
                {
                    jsonWriter.WriteStartObject();

                    jsonWriter.WritePropertyName("Data");
                    String base64 = Convert.ToBase64String(value, valueOffset, valueLength);
                    jsonWriter.WriteValue(base64);

                    jsonWriter.WritePropertyName("Offset");
                    jsonWriter.WriteValue(valueOffset);

                    jsonWriter.WriteEndObject();
                }

                jsonWriter.WriteEndObject();
                return(jsonWriter.Token);
            }
        }
Esempio n. 8
0
        // send senor data to iot central, for all sensors of beacon
        public static async Task SendSensorDataToIotCentral(Beacon beacon, DateTime timeStampReceived)
        {
            // TODO V1
            // create new telemetry message
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();

            // Timestamp values received
            writer.WritePropertyName("timestamp");
            writer.WriteValue(timeStampReceived.ToUniversalTime());

            // Azuire Iot Central device id
            writer.WritePropertyName("deviceid");
            writer.WriteValue(CentralDeviceId);

            // Iterate sensor data
            foreach (var sensorData in beacon.SensorDatas)
            {
                // Only active sensors
                if (sensorData.Enabled == false)
                {
                    continue;
                }

                // Key => value
                writer.WritePropertyName($"Bt{beacon.BluetoothAddress:X}_{(int)sensorData.SensorType}");
                writer.WriteValue(sensorData.Value);
                writer.WritePropertyName($"Bt{beacon.BluetoothAddress:X}_{(int)sensorData.SensorType}_meta");
                writer.WriteValue(beacon.Description);
            }
            writer.WriteEndObject();

            JObject o = (JObject)writer.Token;

            // serialise message to a JSON string
            string messageString = o.ToString();

            Debug.WriteLine(messageString);

            // format JSON string into IoT Hub message
            Message message = new Message(Encoding.ASCII.GetBytes(messageString));

            // push message to IoT Hub
            try
            {
                await _deviceClient.SendEventAsync(message).ConfigureAwait(false);

                ShowTelemetryMessage?.Invoke($"Success SendSensorDataToIotCentral BLE {beacon.Name}");
            }
            catch (Exception e)
            {
                ShowEventMessage?.Invoke($"Exception SendSensorDataToIotCentral {e.Message}");
            }
        }
Esempio n. 9
0
        public void CurrentToken()
        {
            using (JTokenWriter jsonWriter = new JTokenWriter())
            {
                Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
                Assert.AreEqual(null, jsonWriter.CurrentToken);

                jsonWriter.WriteStartObject();
                Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
                Assert.AreEqual(jsonWriter.Token, jsonWriter.CurrentToken);

                JObject o = (JObject)jsonWriter.Token;

                jsonWriter.WritePropertyName("CPU");
                Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);
                Assert.AreEqual(o.Property("CPU"), jsonWriter.CurrentToken);

                jsonWriter.WriteValue("Intel");
                Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
                Assert.AreEqual(o["CPU"], jsonWriter.CurrentToken);

                jsonWriter.WritePropertyName("Drives");
                Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);
                Assert.AreEqual(o.Property("Drives"), jsonWriter.CurrentToken);

                jsonWriter.WriteStartArray();
                Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
                Assert.AreEqual(o["Drives"], jsonWriter.CurrentToken);

                JArray a = (JArray)jsonWriter.CurrentToken;

                jsonWriter.WriteValue("DVD read/writer");
                Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
                Assert.AreEqual(a[a.Count - 1], jsonWriter.CurrentToken);

#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
                jsonWriter.WriteValue(new BigInteger(123));
                Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
                Assert.AreEqual(a[a.Count - 1], jsonWriter.CurrentToken);
#endif

                jsonWriter.WriteValue(new byte[0]);
                Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
                Assert.AreEqual(a[a.Count - 1], jsonWriter.CurrentToken);

                jsonWriter.WriteEnd();
                Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
                Assert.AreEqual(a, jsonWriter.CurrentToken);

                jsonWriter.WriteEndObject();
                Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
                Assert.AreEqual(o, jsonWriter.CurrentToken);
            }
        }
        public void SendJoinToGame(string token)
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();
            writer.WritePropertyName("game_token");
            writer.WriteValue(token);
            writer.WritePropertyName("user_name");
            writer.WriteValue(context.gameCtrl.UserName);
            writer.WriteEndObject();
            SendJsonData("POST", "/join_game", null, writer.Token.ToString());
        }
Esempio n. 11
0
        internal static JObject GetCashReceiptsJson()
        {
            AccountingEntities db = new AccountingEntities();

            var receiptList = db.ArCashDepositViews.OrderByDescending(x => x.CreateDate).ToList();


            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();

            foreach (var item in receiptList)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("ReceiptId");
                pJTokenWriter.WriteValue(item.ReceiptId);

                pJTokenWriter.WritePropertyName("ReceiptCode");
                pJTokenWriter.WriteValue(item.ReceiptCode);

                pJTokenWriter.WritePropertyName("ReceiptDate");
                pJTokenWriter.WriteValue(item.ReceiptDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("ReceiptAmount");
                pJTokenWriter.WriteValue(item.ReceiptAmount.ToString() + " " + item.CurrencySign);

                pJTokenWriter.WritePropertyName("Notes");
                pJTokenWriter.WriteValue(item.Notes ?? "");

                pJTokenWriter.WritePropertyName("Client");
                pJTokenWriter.WriteValue(string.IsNullOrEmpty(item.ShipperNameEn) ? item.ConsigneeNameEn : item.ShipperNameEn);

                pJTokenWriter.WritePropertyName("CreateDate");
                pJTokenWriter.WriteValue(item.CreateDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("UserName");
                pJTokenWriter.WriteValue(item.UserName);

                pJTokenWriter.WritePropertyName("PaymentTermEn");
                pJTokenWriter.WriteValue(item.PaymentTermEn);

                pJTokenWriter.WriteEndObject();
            }


            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
        private List <byte> CreateBrowserStateJsonString(string bookmarkUrl, [Optional] string oldBrowserState)
        {
            JObject browserState   = new JObject();
            JArray  bookmarksArray = new JArray();

            if (!string.IsNullOrEmpty(oldBrowserState))
            {
                browserState   = JObject.Parse(oldBrowserState);
                bookmarksArray = (JArray)browserState["bookmarks"];
                browserState.Remove("bookmarks");
            }

            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();
            writer.WritePropertyName("url");
            writer.WriteValue(bookmarkUrl);
            writer.WriteEndObject();

            JObject newBookmarksJObject = (JObject)writer.Token;

            bookmarksArray.Add(newBookmarksJObject);
            browserState.Add("bookmarks", bookmarksArray);
            var newbrowserState = JsonConvert.SerializeObject(browserState);

            return(newbrowserState.ToUtfBytes());
        }
Esempio n. 13
0
        private JToken GetConnectionItem(string connectionString, string providerName)
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();
            writer.WritePropertyName("ConnectionStrings");
            writer.WriteStartObject();
            writer.WritePropertyName(Constants.System.UmbracoConnectionName);
            writer.WriteValue(connectionString);
            writer.WritePropertyName($"{Constants.System.UmbracoConnectionName}{ConnectionStrings.ProviderNamePostfix}");
            writer.WriteValue(providerName);
            writer.WriteEndObject();
            writer.WriteEndObject();

            return(writer.Token);
        }
Esempio n. 14
0
        public void Coercion_Coerce_JToken()
        {
            ICoercion coercion = new Coercion();
            var       writer   = new JTokenWriter();

            writer.WriteStartObject();
            writer.WritePropertyName("type");
            writer.WriteValue("request");
            writer.WritePropertyName("command");
            writer.WriteValue("launch");
            writer.WriteEndObject();

            var result = coercion.Coerce(writer.Token, typeof(JToken));

            Assert.Equal(writer.Token, result);
        }
Esempio n. 15
0
        public async Task <List <ContasReceber> > GetContasReceberResultSet(NpgsqlCommand command)
        {
            List <ContasReceber> list = new List <ContasReceber>();

            command.ExecuteNonQuery();

            using var reader = await command.ExecuteReaderAsync();

            while (await reader.ReadAsync())
            {
                DataTable schemaTable = reader.GetSchemaTable();

                JTokenWriter writer = new JTokenWriter();
                writer.WriteStartObject();

                foreach (DataRow row in schemaTable.Rows)
                {
                    writer.WritePropertyName(row[0].ToString());
                    writer.WriteValue(reader[row[0].ToString()]);
                }
                writer.WriteEndObject();
                JObject       o          = (JObject)writer.Token;
                var           stringJson = o.ToString();
                ContasReceber p          = JsonConvert.DeserializeObject <ContasReceber>(stringJson);
                list.Add(p);
            }
            return(list);
        }
Esempio n. 16
0
 private void SetKeyValue(string KeyName, object TheValue, RegistryValueKind type)
 {
     if (this.readJson())
     {
         JToken token;
         bool   write = true;
         if (AIDASettings.TryGetValue(KeyName, out token))
         {
             string asdd = (token.Value <object>()).ToString();
             if (type == RegistryValueKind.String || type == RegistryValueKind.DWord || type == RegistryValueKind.ExpandString || type == RegistryValueKind.MultiString || type == RegistryValueKind.QWord)
             {
                 write = (!string.IsNullOrEmpty(asdd) && asdd.ToLower() != TheValue.ToString().ToLower());
             }
         }
         if (write)
         {
             using (JTokenWriter asd = new JTokenWriter())
             {
                 asd.WriteValue(TheValue);
                 asd.Flush();
                 AIDASettings[KeyName] = asd.Token;
                 using (StreamWriter sr = new StreamWriter(AIDASettingsLocation, false))
                     using (Newtonsoft.Json.JsonTextWriter jr = new Newtonsoft.Json.JsonTextWriter(sr))
                     {
                         AIDASettings.WriteTo(jr);
                         jr.Flush();
                     }
                 this.jsonLastWrite = DateTime.Now;
                 File.SetLastWriteTime(AIDASettingsLocation, this.jsonLastWrite);
             }
         }
     }
     this.theReg.SetValue(KeyName, TheValue, type);
     this.theReg.Flush();
 }
        public static string ToJson(this OracleDataReader reader, string cultureInfo)
        {
            var culture = String.IsNullOrWhiteSpace(cultureInfo) ? CultureInfo.InvariantCulture : new CultureInfo(cultureInfo);

            // create json result
            using (var writer = new JTokenWriter())
            {
                writer.Formatting = Newtonsoft.Json.Formatting.Indented;
                writer.Culture    = culture;

                // start array
                writer.WriteStartArray();

                while (reader.Read())
                {
                    // start row object
                    writer.WriteStartObject();
                    for (var i = 0; i < reader.FieldCount; i++)
                    {
                        // add row element name
                        writer.WritePropertyName(reader.GetName(i));
                        // add row element value
                        writer.WriteValue(reader.GetValue(i) ?? string.Empty);
                    }
                    writer.WriteEndObject(); // end row object
                }
                // end array
                writer.WriteEndArray();

                return(writer.Token.ToString());
            }
        }
Esempio n. 18
0
        private List <dynamic> Execute(ConfigurationEntry config, string sql)
        {
            using (var ds = _dataRetriever.RetrieveData(_dataCreator, config.ConnectionString, config.DatabaseType, sql, config.CommandTimeout))
            {
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    return(new List <dynamic>());
                }

                var rows = new List <dynamic>();
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    var writer = new JTokenWriter();
                    writer.WriteStartObject();

                    foreach (DataColumn col in ds.Tables[0].Columns)
                    {
                        writer.WritePropertyName(col.ColumnName);
                        writer.WriteValue(row[col.ColumnName]);
                    }

                    writer.WriteEndObject();

                    rows.Add(writer.Token);
                }

                return(rows);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Use this to get json format for Pie chat used in charts.js
        /// </summary>
        /// <param name="chartData">Dictionary string "For Label Name", int "For Label count"</param>
        /// <returns>Json</returns>
        public static JObject GetPieChartData(Dictionary <string, int> chartData)
        {
            if (chartData == null || chartData.Count == 0)
            {
                return(null);
            }

            Random       randomGen     = new Random();
            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("labels");
            pJTokenWriter.WriteStartArray();
            foreach (var item in chartData)
            {
                pJTokenWriter.WriteValue(item.Key);
            }
            pJTokenWriter.WriteEndArray();

            pJTokenWriter.WritePropertyName("datasets");
            pJTokenWriter.WriteStartArray();  //datasets array
            pJTokenWriter.WriteStartObject(); //datasets Object
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();  //data array
            foreach (var item in chartData)
            {
                pJTokenWriter.WriteValue(item.Value);
            }
            pJTokenWriter.WriteEndArray();//data array

            pJTokenWriter.WritePropertyName("backgroundColor");
            pJTokenWriter.WriteStartArray(); //backgroundColor array
            foreach (var item in chartData)
            {
                pJTokenWriter.WriteValue("rgb(" + randomGen.Next(256) + "," + randomGen.Next(256) + "," + randomGen.Next(256) + ")");
            }
            pJTokenWriter.WriteEndArray();  //backgroundColor array

            pJTokenWriter.WriteEndObject(); //datasets Object
            pJTokenWriter.WriteEndArray();  //datasets array

            pJTokenWriter.WriteEndObject();

            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Esempio n. 20
0
        public static JObject GetAccTransByAccId(string accId, string fromDate = null, string toDate = null)
        {
            List <AccountSummary>     accSummary = new List <AccountSummary>();
            ReportsAccountingEntities db         = new ReportsAccountingEntities();
            var spResult = db.GetAccountDetailsByAccId(accId, fromDate == "" ? null : fromDate, toDate == "" ? null : toDate).ToList();

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();
            foreach (var item in spResult)
            {
                pJTokenWriter.WriteStartObject();
                pJTokenWriter.WritePropertyName("AccountId");
                pJTokenWriter.WriteValue(item.AccountId);

                pJTokenWriter.WritePropertyName("CreateDate");
                pJTokenWriter.WriteValue(item.CreateDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("CreateBy");
                pJTokenWriter.WriteValue(item.UserName);

                pJTokenWriter.WritePropertyName("DebitAmount");
                pJTokenWriter.WriteValue(item.DebitAmount);

                pJTokenWriter.WritePropertyName("CreditAmount");
                pJTokenWriter.WriteValue(item.CreditAmount);

                pJTokenWriter.WritePropertyName("CurrencySign");
                pJTokenWriter.WriteValue(item.CurrencySign);

                pJTokenWriter.WritePropertyName("TransactionName");
                pJTokenWriter.WriteValue(item.TransactionName);

                pJTokenWriter.WritePropertyName("TransactionNameAr");
                pJTokenWriter.WriteValue(item.TransactionNameAr);

                pJTokenWriter.WritePropertyName("ReceiptNotes");
                //pJTokenWriter.WriteValue(item.ReceiptNotes);
                pJTokenWriter.WriteValue("");

                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Esempio n. 21
0
        internal static JObject GetCarrierRates(System.Web.Mvc.FormCollection form)
        {
            List <CarrierRateVm> carrRateList = CarrierRateHelper.GetCarrierRatesInquiry(form);

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();

            foreach (var item in carrRateList)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("CarrierRateId");
                pJTokenWriter.WriteValue(item.CarrierRateId);

                pJTokenWriter.WritePropertyName("CarrierName");
                pJTokenWriter.WriteValue(item.CarrierName);

                pJTokenWriter.WritePropertyName("ContainerTypeName");
                pJTokenWriter.WriteValue(item.ContainerTypeName);

                pJTokenWriter.WritePropertyName("FromPort");
                pJTokenWriter.WriteValue(item.FromCountryName + " / " + item.FromPortName);

                pJTokenWriter.WritePropertyName("ToPort");
                pJTokenWriter.WriteValue(item.ToCountryName + " / " + item.ToPortName);

                pJTokenWriter.WritePropertyName("FreightCost");
                pJTokenWriter.WriteValue(item.FreightCostAmount + "  " + item.FreighCurrencySign);

                pJTokenWriter.WritePropertyName("ThcCost");
                pJTokenWriter.WriteValue(item.ThcCostAmount + "  " + item.ThcCurrencySign);

                pJTokenWriter.WritePropertyName("ValidToDate");
                pJTokenWriter.WriteValue(item.ValidToDate == null ? "" : item.ValidToDate.Value.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("CarrierId");
                pJTokenWriter.WriteValue(item.CarrierId);

                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Esempio n. 22
0
        private string AssembleChickenNugetProject(IProjectFile[] packageConfigs, IProjectFile[] nuspecs)
        {
            var writer = new JTokenWriter();

            // main obj
            writer.WriteStartObject();

            // files obj
            writer.WritePropertyName("files");
            writer.WriteStartObject();

            if (packageConfigs.Length > 0)
            {
                // packages-config array
                writer.WritePropertyName("packages-config");
                writer.WriteStartArray();
                foreach (var packageConfig in packageConfigs)
                {
                    writer.WriteValue(packageConfig.FilePath());
                }

                writer.WriteEndArray();
            }

            if (nuspecs.Length > 0)
            {
                // packages-config array
                writer.WritePropertyName("package-nuspec");
                writer.WriteStartArray();
                foreach (var projectFile in nuspecs)
                {
                    writer.WriteValue(projectFile.FilePath());
                }

                writer.WriteEndArray();
            }

            // files obj
            writer.WriteEndObject();

            // main obj
            writer.WriteEndObject();

            return(writer.Token.ToString(Formatting.Indented));
        }
Esempio n. 23
0
        public static JToken GetFileInfoFromResponseXml(string applicationResponseXml)
        {
            string resp = applicationResponseXml;

            // Select only the nodes that may be of interest
            using (var writer = new JTokenWriter())
            {
                writer.Formatting = Newtonsoft.Json.Formatting.Indented;
                writer.Culture    = CultureInfo.InvariantCulture;

                writer.WriteStartObject();
                writer.WritePropertyName("CustomerId");
                writer.WriteValue(FindElement(resp, "CustomerId")?.Value);
                writer.WritePropertyName("Timestamp");
                writer.WriteValue(FindElement(resp, "Timestamp")?.Value);
                writer.WritePropertyName("ResponseCode");
                writer.WriteValue(FindElement(resp, "ResponseCode")?.Value);
                writer.WritePropertyName("Encrypted");
                writer.WriteValue(FindElement(resp, "Encrypted")?.Value);
                writer.WritePropertyName("Compressed");
                writer.WriteValue(FindElement(resp, "Compressed")?.Value);
                writer.WritePropertyName("AmountTotal");
                writer.WriteValue(FindElement(resp, "AmountTotal")?.Value);
                writer.WritePropertyName("TransactionCount");
                writer.WriteValue(FindElement(resp, "TransactionCount")?.Value);
                writer.WriteEndObject();

                return(writer.Token);
            }
        }
Esempio n. 24
0
        private JToken?GetConnectionItem(string connectionString, string?providerName)
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();
            writer.WritePropertyName("ConnectionStrings");
            writer.WriteStartObject();
            writer.WritePropertyName(Constants.System.UmbracoConnectionName);
            writer.WriteValue(connectionString);

            if (!string.IsNullOrEmpty(providerName))
            {
                writer.WritePropertyName(Constants.System.UmbracoConnectionName + ConnectionStrings.ProviderNamePostfix);
                writer.WriteValue(providerName);
            }

            writer.WriteEndObject();
            writer.WriteEndObject();

            return(writer.Token);
        }
Esempio n. 25
0
        public void State()
        {
            using (JsonWriter jsonWriter = new JTokenWriter())
            {
                Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);

                jsonWriter.WriteStartObject();
                Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);

                jsonWriter.WritePropertyName("CPU");
                Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);

                jsonWriter.WriteValue("Intel");
                Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);

                jsonWriter.WritePropertyName("Drives");
                Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);

                jsonWriter.WriteStartArray();
                Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);

                jsonWriter.WriteValue("DVD read/writer");
                Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);

#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
                jsonWriter.WriteValue(new BigInteger(123));
                Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
#endif

                jsonWriter.WriteValue(new byte[0]);
                Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);

                jsonWriter.WriteEnd();
                Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);

                jsonWriter.WriteEndObject();
                Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
            }
        }
        private void SetPostedTransaction(HttpClient http, List <string> lstParameter)
        {
            string metodo         = "api/v1/jobs/Transactions/SetPosted";
            int    page           = 1;
            int    totalPages     = (int)Decimal.Ceiling(lstParameter.Count / 100);
            int    posicaoLista   = 0;
            int    registrosLidos = 1;

            do
            {
                JTokenWriter writerJson = new JTokenWriter();

                writerJson.WriteStartObject();
                writerJson.WritePropertyName("Assignments");
                writerJson.WriteStartArray();

                for (int index = posicaoLista; index < lstParameter.Count; index++)
                {
                    writerJson.WriteStartObject();
                    writerJson.WritePropertyName("TransactionId");
                    writerJson.WriteValue(lstParameter[index]);
                    writerJson.WritePropertyName("PostedDate");
                    writerJson.WriteValue(DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:sszzz"));
                    writerJson.WriteEndObject();
                    registrosLidos++;
                    if (registrosLidos > 100)
                    {
                        posicaoLista += (registrosLidos - 1);
                        break;
                    }
                }
                writerJson.WriteEndArray();
                writerJson.WriteEndObject();

                JObject json = (JObject)writerJson.Token;
                PostSyncApi(metodo, http, json);
                page++;
            } while (page <= totalPages);
        }
Esempio n. 27
0
        public static JToken readerToJson(SQLiteDataReader reader)
        {
            JTokenWriter jwrite = new JTokenWriter();

            jwrite.WriteStartObject();
            for (int i = 0; i < reader.FieldCount; ++i)
            {
                jwrite.WritePropertyName(reader.GetName(i));
                jwrite.WriteValue(reader.GetValue(i));
            }
            jwrite.WriteEndObject();
            return(jwrite.Token);
        }
Esempio n. 28
0
        public void ValueFormatting()
        {
            JToken root;

            using (JTokenWriter jsonWriter = new JTokenWriter())
            {
                jsonWriter.WriteStartArray();
                jsonWriter.WriteValue('@');
                jsonWriter.WriteValue("\r\n\t\f\b?{\\r\\n\"\'");
                jsonWriter.WriteValue(true);
                jsonWriter.WriteValue(10);
                jsonWriter.WriteValue(10.99);
                jsonWriter.WriteValue(0.99);
                jsonWriter.WriteValue(0.000000000000000001d);
                jsonWriter.WriteValue(0.000000000000000001m);
                jsonWriter.WriteValue((string)null);
                jsonWriter.WriteValue("This is a string.");
                jsonWriter.WriteNull();
                jsonWriter.WriteUndefined();
                jsonWriter.WriteEndArray();

                root = jsonWriter.Token;
            }

            Assert.IsInstanceOfType(typeof(JArray), root);
            Assert.AreEqual(12, root.Children().Count());
            Assert.AreEqual("@", (string)root[0]);
            Assert.AreEqual("\r\n\t\f\b?{\\r\\n\"\'", (string)root[1]);
            Assert.AreEqual(true, (bool)root[2]);
            Assert.AreEqual(10, (int)root[3]);
            Assert.AreEqual(10.99, (double)root[4]);
            Assert.AreEqual(0.99, (double)root[5]);
            Assert.AreEqual(0.000000000000000001d, (double)root[6]);
            Assert.AreEqual(0.000000000000000001m, (decimal)root[7]);
            Assert.AreEqual(string.Empty, (string)root[8]);
            Assert.AreEqual("This is a string.", (string)root[9]);
            Assert.AreEqual(null, ((JValue)root[10]).Value);
        }
Esempio n. 29
0
        public void DateTimeZoneHandling()
        {
            JTokenWriter writer = new JTokenWriter
            {
                DateTimeZoneHandling = Json.DateTimeZoneHandling.Utc
            };

            writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Unspecified));

            JValue   value = (JValue)writer.Token;
            DateTime dt    = (DateTime)value.Value;

            Assert.AreEqual(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc), dt);
        }
Esempio n. 30
0
        public string ToJson()
        {
            var writer = new JTokenWriter();

            writer.WriteStartObject();

            writer.WritePropertyName("result");
            writer.WriteValue(Result);

            if (Result == JsonValues.Authenticated)
            {
                writer.WritePropertyName("jwt");
                writer.WriteValue(Jwt);
            }
            else if (Result == JsonValues.Error)
            {
                writer.WritePropertyName("errordetails");
                writer.WriteValue(ErrorDetails);
            }

            writer.WriteEndObject();
            return(writer.Token.ToString(Formatting.None));
        }