예제 #1
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);
        }
예제 #2
0
        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);
            }
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
0
        private JToken GetConnectionItem(string connectionString, string providerName)
        {
            JTokenWriter writer = new JTokenWriter();

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

            return(writer.Token);
        }
예제 #7
0
        public static JObject StoredProcXMLToJObject(string xml)
        {
            XDocument xmlContent;

            try
            {
                xmlContent = XDocument.Load(new System.IO.StringReader(xml));
            }
            catch (Exception)
            {
                return(new JObject());
            }

            if (xmlContent.ElementExists("NewDataSet"))
            {
                JTokenWriter jWriter = new JTokenWriter();
                jWriter.WriteStartObject();
                int    i         = 0;
                string tableName = "Table";
                while (xmlContent.Element("NewDataSet").ElementExists(tableName))
                {
                    //write a property for each table
                    jWriter.WritePropertyName(tableName);
                    //write an array for each collection of table entities
                    jWriter.WriteStartArray();

                    foreach (XElement item in xmlContent.Element("NewDataSet").Elements(tableName))
                    {
                        jWriter.WriteStartObject();
                        foreach (XElement prop in item.Elements())
                        {
                            jWriter.WritePropertyName(prop.Name.LocalName);
                            jWriter.WriteValue(prop.Value);
                        }
                        jWriter.WriteEndObject();
                    }
                    jWriter.WriteEndArray();

                    i++;
                    tableName = $"Table{i}";
                }

                jWriter.WriteEndObject();

                return((JObject)jWriter.Token);
            }

            return(new JObject());
        }
예제 #8
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());
        }
        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());
        }
        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);
            }
        }
예제 #11
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);
            }
        }
예제 #12
0
        private JToken CreateJObject(JsonReader reader)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");

//          throw new Exception("Expected current token of type {0}, got {1}.".FormatWith(CultureInfo.InvariantCulture, JsonToken.PropertyName, reader.TokenType));

            JToken token;

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

                if (reader.TokenType == JsonToken.PropertyName)
                {
                    writer.WriteToken(reader, reader.Depth - 1);
                }
                else
                {
                    writer.WriteEndObject();
                }

                token = writer.Token;
            }

            return(token);
        }
        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);
        }
예제 #14
0
        private JToken CreateJObject(JsonReader reader)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");

            // this is needed because we've already read inside the object, looking for special properties
            JToken token;

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

                if (reader.TokenType == JsonToken.PropertyName)
                {
                    writer.WriteToken(reader, reader.Depth - 1);
                }
                else
                {
                    writer.WriteEndObject();
                }

                token = writer.Token;
            }

            return(token);
        }
예제 #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);
        }
        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());
            }
        }
예제 #17
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);
            }
        }
예제 #18
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);
            }
        }
예제 #19
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);
            }
        }
예제 #20
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);
            }
        }
예제 #21
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);
        }
예제 #22
0
        public static string BuildJson(string Value, bool leaveOpen = true)
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();
            writer.WritePropertyName("Workflows");
            writer.WriteStartArray();
            writer.WriteStartObject();
            writer.WritePropertyName("FirmID");
            writer.WriteValue(470);
            writer.WritePropertyName("Procedure");
            writer.WriteValue("Accounts.New");
            writer.WritePropertyName("Description");
            writer.WriteValue(Value);
            writer.WritePropertyName("DueDate");
            writer.WriteValue(DateTime.Now.ToUniversalTime());
            writer.WritePropertyName("App");
            writer.WriteValue("Ingestion");
            writer.WritePropertyName("Type");
            writer.WriteValue("Info");
            writer.WritePropertyName("Remediation");
            writer.WriteValue("Feed.Acc.Insert");
            writer.WritePropertyName("ClosedDate");
            if (leaveOpen)
            {
                writer.WriteValue(DateTime.Now.ToUniversalTime());
            }
            else
            {
                writer.WriteValue(string.Empty);
            }
            writer.WritePropertyName("CreateEmail");
            writer.WriteValue("*****@*****.**");
            writer.WritePropertyName("Responsibility");
            writer.WriteValue("Internal.Ops");
            writer.WritePropertyName("Cause");
            writer.WriteValue("Feed.Acc.Created");
            writer.WritePropertyName("Group_UID");
            writer.WriteValue("2CBEF1AC-82C0-4452-B119-A6A18F1BCC41");
            writer.WriteEndObject();
            writer.WriteEndArray();
            writer.WriteEndObject();

            return(writer.Token.ToString());
        }
예제 #23
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));
        }
예제 #24
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}");
            }
        }
예제 #25
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);
            }
        }
예제 #26
0
        public void WriteDuplicatePropertyName()
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();

            writer.WritePropertyName("prop1");
            writer.WriteStartObject();
            writer.WriteEndObject();

            writer.WritePropertyName("prop1");
            writer.WriteStartArray();
            writer.WriteEndArray();

            writer.WriteEndObject();

            StringAssert.AreEqual(@"{
  ""prop1"": []
}", writer.Token.ToString());
        }
예제 #27
0
        private JToken GetDisableRedirectUrlItem(bool value)
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();
            writer.WritePropertyName("Umbraco");
            writer.WriteStartObject();
            writer.WritePropertyName("CMS");
            writer.WriteStartObject();
            writer.WritePropertyName("WebRouting");
            writer.WriteStartObject();
            writer.WritePropertyName("DisableRedirectUrlTracking");
            writer.WriteValue(value);
            writer.WriteEndObject();
            writer.WriteEndObject();
            writer.WriteEndObject();
            writer.WriteEndObject();

            return(writer.Token);
        }
예제 #28
0
        private object GetGlobalIdItem(string id)
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();
            writer.WritePropertyName("Umbraco");
            writer.WriteStartObject();
            writer.WritePropertyName("CMS");
            writer.WriteStartObject();
            writer.WritePropertyName("Global");
            writer.WriteStartObject();
            writer.WritePropertyName("Id");
            writer.WriteValue(id);
            writer.WriteEndObject();
            writer.WriteEndObject();
            writer.WriteEndObject();
            writer.WriteEndObject();

            return(writer.Token);
        }
        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());
        }
예제 #30
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);
        }
예제 #31
0
        private JToken CreateJObject(JsonReader reader)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");

            // this is needed because we've already read inside the object, looking for metadata properties
            using (JTokenWriter writer = new JTokenWriter())
            {
                writer.WriteStartObject();

                do
                {
                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        string propertyName = (string)reader.Value;
                        do
                        {
                            if (!reader.Read())
                                break;
                        } while (reader.TokenType == JsonToken.Comment);

                        if (CheckPropertyName(reader, propertyName))
                            continue;

                        writer.WritePropertyName(propertyName);
                        writer.WriteToken(reader, true, true);
                    }
                    else if (reader.TokenType == JsonToken.Comment)
                    {
                        // eat
                    }
                    else
                    {
                        writer.WriteEndObject();
                        return writer.Token;
                    }
                } while (reader.Read());

                throw JsonSerializationException.Create(reader, "Unexpected end when deserializing object.");
            }
        }