如何更新ObservableCollection时,我调用相同的URL

本文关键字:调用 URL 何更新 更新 ObservableCollection | 更新日期: 2023-09-27 18:02:43

我有问题,我不知道如何更新ObservableCollection当我调用相同的URL在windows phone

问题是:-我第一次调用URL,然后我将其添加到我的列表框中,然后一分钟后我调用相同的URL,结果有新数据(添加的新数据或删除的旧数据),我不如何搜索旧数据来检查是否存在所有新数据,如果不存在,如何添加没有重复接收的新行。

请告诉我:(

这是我如何调用URL和如何添加数据:-

 private void GetOpentPos (Object sender, EventArgs e)
    {

        var request = HttpWebRequest.Create(new Uri("http://74.54.46.178/vertexweb10/webservice.svc/GetOpenPositions?AccountId=1122336675")) as HttpWebRequest;
        request.Method = "GET";
        if (request.Headers == null)
        {
            request.Headers = new WebHeaderCollection();
        }
        request.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString();
        request.CookieContainer = cookieJar2;
        request.BeginGetResponse(ar =>
        {
            HttpWebRequest req2 = (HttpWebRequest)ar.AsyncState;
            using (var response = (HttpWebResponse)req2.EndGetResponse(ar))
            {
                using (Stream stream = response.GetResponseStream())
                {
                    using (var reader = new StreamReader(stream))
                    {
                        var outerRoot4 = JsonConvert.DeserializeObject<OuterRootObject4>(reader.ReadToEnd());
                        JArray jsonArray = JArray.Parse(outerRoot4.d);
                        JToken jsonArray_Item = jsonArray.First;
                        DispatchInvoke(() =>
                        {

                            while (jsonArray_Item != null)
                            {

                                string SymbolNameTra = jsonArray_Item.Value<string>("SymbolName");
                                string TypeTra = jsonArray_Item.Value<string>("BuySell");
                                double AmountTra = jsonArray_Item.Value<double>("Amount");
                                double ProfitLossTra = jsonArray_Item.Value<double>("ProfitLoss");
                                int PosID = jsonArray_Item.Value<int>("ID");

                                DataReceivedCollectionTr.Add(new DataTr() { SymbolNameTr = SymbolNameTra, TypeTr = TypeTra, AmountTr = AmountTra, ProfitLossTr = ProfitLossTra,PosID = PosID });
                                jsonArray_Item = jsonArray_Item.Next;
                            }
                        }
);

                    }
                }
            }
        }, request);

    }

如何更新ObservableCollection时,我调用相同的URL

根据某个唯一字段进行检查,如果列表中不包含该项,则添加

if (DataReceivedCollectionTr.FirstOrDefault(i => i.SymbolNameTr == SymbolNameTra) == null)
{
    DataReceivedCollectionTr.Add(new DataTr() { SymbolNameTr = SymbolNameTra, TypeTr = TypeTra, AmountTr = AmountTra, ProfitLossTr = ProfitLossTra,PosID = PosID });
}