Esempio n. 1
0
        /// <summary>
        /// Metoda pozwalająca na sterowanie widocznościa zakładki.
        /// </summary>
        /// <param name="context"></param>
        /// <returns>
        ///     true - widoczność zakładki,
        ///     false - zakładka niewidoczna
        /// </returns>
        public static bool IsVisible(Context context)
        {
            bool result;

            using (var session = context.Login.CreateSession(true, true)) {
                result = CfgWalutyNbpExtender.GetValue(session, "AktywneTowaryWlasne", false);
            }
            return(result);
        }
        private byte[] loadData(DateTime date, out string file)
        {
            var lastDay = date;

            switch (DateTime.Today.DayOfWeek)
            {
            case DayOfWeek.Thursday:
                lastDay = lastDay.AddDays(-1);
                break;

            case DayOfWeek.Saturday:
                lastDay = lastDay.AddDays(-1);
                break;

            case DayOfWeek.Sunday:
                lastDay = lastDay.AddDays(-2);
                break;
            }

            var nbpUrl = CfgWalutyNbpExtender.GetValue(Session, "UrlNbp", "http://www.nbp.pl/kursy/xml/a125z");

            nbpUrl += "{0}";
            file    = String.Format("{0}.xml", lastDay.ToString("yyMMdd"));
            var url = String.Format(nbpUrl, file);

            var request = (HttpWebRequest)WebRequest.Create(url);

            byte[] bytes;
            using (var webResponse = (HttpWebResponse)request.GetResponse()) {
                using (var sr = webResponse.GetResponseStream()) {
                    bytes = new byte[(int)webResponse.ContentLength];
                    var pos = 0;

                    while (pos < bytes.Length)
                    {
                        if (sr == null)
                        {
                            continue;
                        }

                        var bytesRead = sr.Read(bytes, pos, bytes.Length - pos);
                        if (bytesRead == 0)
                        {
                            throw new IOException("Premature end of data");
                        }
                        pos += bytesRead;
                    }
                    if (sr != null)
                    {
                        sr.Close();
                    }
                }
                webResponse.Close();
            }
            return(bytes);
        }