当前位置: 首页>>代码示例>>C#>>正文


C# JArray.Any方法代码示例

本文整理汇总了C#中Newtonsoft.Json.Linq.JArray.Any方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.Any方法的具体用法?C# JArray.Any怎么用?C# JArray.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.Linq.JArray的用法示例。


在下文中一共展示了JArray.Any方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetGcmData

        private static byte[] GetGcmData(string userNameFromComment, IEnumerable<User> users, string message, Feeling feeling)
        {
            var jsonObject = new JObject();
            var arr = new JArray();
            users.Where(u => !string.IsNullOrWhiteSpace(u.Key)).ForEach(u => arr.Add(u.Key));
            if (!arr.Any())
                return null;

            jsonObject.Add("registration_ids", arr);
            var jsonSerializerSettings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var data = new JObject
            {
                {"message", message},
                {"user", userNameFromComment},
                {"feeling", JsonConvert.SerializeObject(feeling.Id, Formatting.Indented, jsonSerializerSettings)}
            };

            jsonObject.Add("data", data);
            var postData = JsonConvert.SerializeObject(jsonObject);
            var byteArray = Encoding.UTF8.GetBytes(postData);
            return byteArray;
        }
开发者ID:neoms21,项目名称:FeelKnit.Service,代码行数:25,代码来源:PushNotificationService.cs

示例2: MergeJArrays

 /// <summary>
 /// Merges the donor array values into the receiver array
 /// </summary>
 /// <param name="receiver"></param>
 /// <param name="donor"></param>
 internal static void MergeJArrays(JArray receiver, JArray donor)
 {
     foreach (var item in donor)
     {
         if (!receiver.Any(x => x.Equals(item)))
         {
             receiver.Add(item);   
         }
     }
 }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:15,代码来源:ManifestParser.cs

示例3: StoreData

        public Task StoreData(string tableName, JArray data, bool overwrite = true)
        {
            Debug.WriteLine("Storing data for table {0}", tableName);

            if (!data.Any())
            {
                return completed;
            }

            EnsureDatabaseThread();

            // the actual columns for the item
            IDictionary<string, Column> columns = this.GetColumnsFromItems(data);
            this.EnsureSchemaForTable(tableName, db, columns);

            try
            {
                Debug.WriteLine("Inserting...");

                foreach (JObject item in data)
                {
                    db.InsertIntoTable(tableName, columns, item, overwrite);
                }
                return completed;
            }
            catch (SQLiteException ex)
            {
                throw new Exception(string.Format("Error occurred during interaction with the local database: {0}", ex.Message));
            }
        }
开发者ID:jlaanstra,项目名称:azure-mobile-services,代码行数:30,代码来源:SQLiteStructuredStorage.cs

示例4: GetMaxEntityKey

        /// <summary>
        /// Get the max value of the key property.
        /// </summary>
        /// <param name="entries">The feed. (The collection/set of the entities.)</param>
        /// <param name="keyPropertyName">The name of the key property.</param>
        /// <returns>Returns the max value of the key property.</returns>
        private object GetMaxEntityKey(JArray entries, string keyPropertyName)
        {
            object value = null;

            if (null != entries && entries.Any())
            {
                value = entries.First[keyPropertyName];

                foreach (var entry in entries)
                {
                    if (Convert.ToInt64(value) < (Int64)entry[keyPropertyName])
                    {
                        value = entry[keyPropertyName];
                    }
                }
            }

            return value;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:25,代码来源:DataFactory.cs

示例5: TestIncrementalSync

        private async Task TestIncrementalSync(MobileServiceTableQueryDescription query, JArray result, DateTime maxUpdatedAt, bool savesMax, string firstQuery, string secondQuery)
        {
            var action = new PullAction(this.table.Object, MobileServiceTableKind.Table, this.context.Object, "latestItems", query, null, null, this.opQueue.Object, this.settings.Object, this.store.Object, MobileServiceRemoteTableOptions.All, null, CancellationToken.None);

            this.opQueue.Setup(q => q.LockTableAsync(It.IsAny<string>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult<IDisposable>(null));
            this.opQueue.Setup(q => q.CountPending(It.IsAny<string>())).Returns(Task.FromResult(0L));
            this.table.Setup(t => t.ReadAsync(firstQuery, It.IsAny<IDictionary<string, string>>(), It.IsAny<MobileServiceFeatures>()))
                      .Returns(Task.FromResult(QueryResult.Parse(result, null, false)));

            if (result.Any())
            {
                this.table.Setup(t => t.ReadAsync(secondQuery, It.IsAny<IDictionary<string, string>>(), It.IsAny<MobileServiceFeatures>()))
                          .Returns(Task.FromResult(QueryResult.Parse(new JArray(), null, false)));
            }

            if (result.Any())
            {
                this.store.Setup(s => s.UpsertAsync("test", It.IsAny<IEnumerable<JObject>>(), true)).Returns(Task.FromResult(0));
            }

            this.settings.Setup(s => s.GetDeltaTokenAsync("test", "latestItems")).Returns(Task.FromResult(new DateTimeOffset(2013, 1, 1, 0, 0, 0, TimeSpan.Zero)));
            if (savesMax)
            {
                this.settings.Setup(s => s.SetDeltaTokenAsync("test", "latestItems", maxUpdatedAt)).Returns(Task.FromResult(0));
            }

            await action.ExecuteAsync();

            this.store.VerifyAll();
            this.opQueue.VerifyAll();
            this.table.VerifyAll();
            this.settings.VerifyAll();

            store.Verify(s => s.DeleteAsync("test", It.IsAny<IEnumerable<string>>()), Times.Never(), "There shouldn't be any call to delete");
        }
开发者ID:angusbreno,项目名称:azure-mobile-services,代码行数:35,代码来源:PullActionTests.cs

示例6: PutSale_Sale_CollectionNavigationProperty

        public void PutSale_Sale_CollectionNavigationProperty()
        {
            var location = default(string);

            var token = new JObject();
            token["SalesPersonName"] = "sale person post";
            token["CustomerName"] = "customer post";
            var contact1 = new JObject();
            contact1["Method"] = "Phone";
            contact1["Value"] = "phone 1";
            var contact2 = new JObject();
            contact2["Method"] = "Phone";
            contact2["Value"] = "phone 2";
            var contacts = new JArray();
            contacts.Add(contact1);
            contacts.Add(contact2);
            token["CustomerContacts"] = contacts;
            var transaction1 = new JObject();
            transaction1["ProductName"] = "product 1";
            transaction1["ProductDescription"] = "description 1";
            transaction1["Quantity"] = 1;
            transaction1["UnitPrice"] = 100000;
            var transaction2 = new JObject();
            transaction2["ProductName"] = "product 2";
            transaction2["ProductDescription"] = "description 2";
            transaction2["Quantity"] = 2;
            transaction2["UnitPrice"] = 200000;
            var transactions = new JArray();
            transactions.Add(transaction1);
            transactions.Add(transaction2);
            token["Items"] = transactions;
            ODataClientHelper.InvokePost(string.Format("{0}Sales", SalesServiceRootUrl),
                token.ToString(Formatting.None),
                null,
                response =>
                {
                    location = response.Headers.Location.ToString();
                    return true;
                });

            token = (JObject)ODataClientHelper.InvokeGet(location + "?$expand=CustomerContacts,Items");

            token.Remove("@odata.context");
            token.Remove("[email protected]");
            token.Remove("[email protected]");
            token["SalesPersonName"] = "new sale person";
            contacts = (JArray)token["CustomerContacts"];
            contacts[0]["Method"] = "QQ";
            transactions = (JArray)token["Items"];
            transactions[0]["ProductName"] = "new product";
            ODataClientHelper.InvokePut(
                location,
                token.ToString(Formatting.None), client =>
                {
                    client.DefaultRequestHeaders.IfMatch.Add(EntityTagHeaderValue.Any);
                });

            token = (JObject)ODataClientHelper.InvokeGet(location + "?$expand=CustomerContacts,Items");
            Assert.AreEqual("new sale person", token["SalesPersonName"]);
            contacts = (JArray)token["CustomerContacts"];
            Assert.AreEqual(2, contacts.Count);
            Assert.IsTrue(contacts.Any(t => (string)t["Method"] == "QQ"));
            transactions = (JArray)token["Items"];
            Assert.AreEqual(2, transactions.Count);
            Assert.IsTrue(transactions.Any(t => (string)t["ProductName"] == "new product"));
        }
开发者ID:wei-zhou,项目名称:diamond,代码行数:66,代码来源:SalesServiceE2ETest.cs

示例7: PostSale_Sale_CollectionNavigationProperty

        public void PostSale_Sale_CollectionNavigationProperty()
        {
            var location = default(string);

            var token = new JObject();
            token["SalesPersonName"] = "sale person post";
            token["CustomerName"] = "customer post";
            var contact1 = new JObject();
            contact1["Method"] = "Phone";
            contact1["Value"] = "phone 1";
            var contact2 = new JObject();
            contact2["Method"] = "Phone";
            contact2["Value"] = "phone 2";
            var contacts = new JArray();
            contacts.Add(contact1);
            contacts.Add(contact2);
            token["CustomerContacts"] = contacts;
            var transaction1 = new JObject();
            transaction1["ProductName"] = "product 1";
            transaction1["ProductDescription"] = "description 1";
            transaction1["Quantity"] = 1;
            transaction1["UnitPrice"] = 100000;
            var transaction2 = new JObject();
            transaction2["ProductName"] = "product 2";
            transaction2["ProductDescription"] = "description 2";
            transaction2["Quantity"] = 2;
            transaction2["UnitPrice"] = 200000;
            var transactions = new JArray();
            transactions.Add(transaction1);
            transactions.Add(transaction2);
            token["Items"] = transactions;
            ODataClientHelper.InvokePost(string.Format("{0}Sales", SalesServiceRootUrl),
                token.ToString(Formatting.None),
                null,
                response =>
                {
                    location = response.Headers.Location.ToString();
                    return true;
                });

            token = (JObject)ODataClientHelper.InvokeGet(location + "?$expand=CustomerContacts,Items");
            Assert.AreEqual("sale person post", token["SalesPersonName"]);
            Assert.AreEqual("customer post", token["CustomerName"]);
            contacts = (JArray)token["CustomerContacts"];
            Assert.IsTrue(contacts.Any(t => (string)t["Method"] == "Phone" && (string)t["Value"] == "phone 1"));
            Assert.IsTrue(contacts.Any(t => (string)t["Method"] == "Phone" && (string)t["Value"] == "phone 2"));
            transactions = (JArray)token["Items"];
            Assert.IsTrue(transactions.Any(t => (string)t["ProductName"] == "product 1" && (string)t["ProductDescription"] == "description 1" && (int)t["Quantity"] == 1 && (int)t["UnitPrice"] == 100000));
            Assert.IsTrue(transactions.Any(t => (string)t["ProductName"] == "product 2" && (string)t["ProductDescription"] == "description 2" && (int)t["Quantity"] == 2 && (int)t["UnitPrice"] == 200000));
        }
开发者ID:wei-zhou,项目名称:diamond,代码行数:50,代码来源:SalesServiceE2ETest.cs

示例8: LoadProfiles

 private void LoadProfiles()
 {
     if (profiles == null || profiles.Count == 0)
     {
         string data = MyGetWebData(homeUrl, true);
         Regex rgx = new Regex(@"nf\.constants\.page\.contextData =(.*); }\(netflix\)\);");
         Match m = rgx.Match(data);
         if (m.Success)
         {
             string jsonData = m.Groups[1].Value;
             JObject json = (JObject)JsonConvert.DeserializeObject(jsonData);
             profiles = json["profiles"]["data"]["allProfiles"].Value<JArray>();
             if (string.IsNullOrEmpty(ProfileName) || !profiles.Any(p => p["profileName"].Value<string>() == ProfileName))
             {
                 if (!string.IsNullOrWhiteSpace(startupUserProfile) && profiles.Any(p => p["profileName"].Value<string>() == startupUserProfile))
                 {
                     currentProfile = (JObject)profiles.FirstOrDefault(p => p["profileName"].Value<string>() == startupUserProfile);
                 }
                 else
                 {
                     currentProfile = (JObject)profiles.FirstOrDefault(p => p["isAccountOwner"].Value<bool>());
                 }
             }
             else
             {
                 currentProfile = (JObject)profiles.FirstOrDefault(p => p["profileName"].Value<string>() == ProfileName);
             }
             MyGetWebData(string.Format(switchProfileUrl, apiRoot, ProfileToken), true);
         }
         else
         {
             cc = null;
             Settings.DynamicCategoriesDiscovered = false;
             Settings.Categories.Clear();
             profiles = null;
             throw new OnlineVideosException("Error loading profiles. Please try again");
         }
     }
 }
开发者ID:leesanghyun2,项目名称:mp-onlinevideos2,代码行数:39,代码来源:NetfilxWebUtil.cs


注:本文中的Newtonsoft.Json.Linq.JArray.Any方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。