Exemplo n.º 1
0
        private void Calendar_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                var    date1 = calendar.SelectedDates.FirstOrDefault();
                var    date2 = calendar.SelectedDates.LastOrDefault();
                string dateInFormatFirst;
                string dateInFormatSecond;
                if (date1 > date2)
                {
                    dateInFormatFirst  = date2.ToString("yyyy-MM-dd");
                    dateInFormatSecond = date1.ToString("yyyy-MM-dd");
                }
                else
                {
                    dateInFormatFirst  = date1.ToString("yyyy-MM-dd");
                    dateInFormatSecond = date2.ToString("yyyy-MM-dd");
                }
                var             request = WebRequest.Create("https://iss.moex.com/iss/analyticalproducts/futoi/securities/" + (list.SelectedItem as ListBoxItem).Content.ToString() + ".json?from=" + dateInFormatFirst + "&till=" + dateInFormatSecond) as HttpWebRequest;
                HttpStatusCode  last_status;
                string          last_status_text = null;
                CookieContainer cookiejar        = new CookieContainer();
                var             AuthReq          = WebRequest.Create("https://passport.moex.com/authenticate") as HttpWebRequest;
                AuthReq.CookieContainer = new CookieContainer();
                HttpWebResponse AuthResponse;
                // use the Basic authorization mechanism
                byte[] binData;
                binData = System.Text.Encoding.UTF8.GetBytes("*****@*****.**" + ":" + "871117");
                string sAuth64 = Convert.ToBase64String(binData, System.Base64FormattingOptions.None);
                AuthReq.Headers.Add(HttpRequestHeader.Authorization, "Basic " + sAuth64);

                AuthResponse = (HttpWebResponse)AuthReq.GetResponse();
                AuthResponse.Close();
                last_status = AuthResponse.StatusCode;

                cookiejar = new CookieContainer();
                cookiejar.Add(AuthResponse.Cookies);
                request.CookieContainer = cookiejar;
                var          response                  = request.GetResponse();
                Stream       receiveStream             = response.GetResponseStream();
                StreamReader readStream                = new StreamReader(receiveStream, Encoding.UTF8);
                var          result                    = readStream.ReadToEnd();
                Temperatures deserializedProduct       = JsonConvert.DeserializeObject <Temperatures>(result);
                ObservableCollection <GridModel> users = new ObservableCollection <GridModel>();
                foreach (var obj in deserializedProduct.futoi.Data)
                {
                    users.Add(new GridModel
                    {
                        sess_id       = obj[0].ToString(),
                        seqnum        = obj[1].ToString(),
                        tradedate     = obj[2].ToString(),
                        tradetime     = obj[3].ToString(),
                        ticker        = obj[4].ToString(),
                        clgroup       = obj[5].ToString(),
                        pos           = obj[6].ToString(),
                        pos_long      = obj[7].ToString(),
                        pos_short     = obj[8].ToString(),
                        pos_long_num  = obj[9].ToString(),
                        pos_short_num = obj[10].ToString(),
                        systime       = obj[11].ToString()
                    });
                    grid1.ItemsSource = null;
                    grid1.ItemsSource = users;
                }
            }
            catch (Exception ex)
            {
            }
        }