示例#1
0
        private IReadOnlyCollection <T> DownloadCatalog <T>(string postString)
        {
            const string contentType = "application/x-www-form-urlencoded";

            var request = (HttpWebRequest)HttpWebRequest.Create("https://www.bricklink.com/catalogDownload.asp?a=a");

            request.Method = "POST";

            request.ContentType = contentType;

            request.ContentLength = postString.Length;
            request.UserAgent     = Constants.UserAgent;
            request.Accept        = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            request.Referer       = "https://www.bricklink.com/catalogDownload.asp";

            using (var requestWriter = new StreamWriter(request.GetRequestStream()))
            {
                requestWriter.Write(postString);
                requestWriter.Close();
            }

            string xml = null;

            using (var response = request.GetResponse())
                using (var responseReader = new StreamReader(response.GetResponseStream()))
                {
                    xml = responseReader.ReadToEnd();
                }

            var serializer   = new TypedXmlSerializer <CatalogContainer <T> >();
            var deserialized = serializer.Deserialize(xml);

            return(deserialized.Items);
        }
示例#2
0
        private IDictionary <string, string> ReadProperties()
        {
            var appData = _appDataService.GetAppData(_appDataKey);

            if (string.IsNullOrWhiteSpace(appData))
            {
                return(new Dictionary <string, string>());
            }

            var serializer = new TypedXmlSerializer <List <SerializableKeyValuePair <string, string> > >();
            var list       = serializer.Deserialize(appData);

            return(list.ToDictionary(x => x.Key, x => x.Value));
        }
示例#3
0
        private List <T> GetItemsFromAppData()
        {
            var appData = _appDataService.GetAppData(AppDataKey);

            if (string.IsNullOrWhiteSpace(appData))
            {
                return(new List <T>());
            }

            var serializer = new TypedXmlSerializer <List <T> >();
            var items      = serializer.Deserialize(appData);

            return(items);
        }
示例#4
0
        public NetworkCredential GetCredential(ExternalSystem system)
        {
            var appData = _appDataService.GetAppData(GetAppDataKey(system));

            if (string.IsNullOrWhiteSpace(appData))
            {
                return(null);
            }

            var serializer = new TypedXmlSerializer <SerializableNetworkCredential>();
            var temp       = serializer.Deserialize(appData);
            var result     = new NetworkCredential(temp.UserName, temp.Password, temp.Domain);

            return(result);
        }
        private IReadOnlyCollection <T> DownloadCatalog <T>(string postString)
        {
            _sessionService.EnsureAuthenticated();
            MakeInitialRequest();

            const string contentType = "application/x-www-form-urlencoded";

            var request = (HttpWebRequest)HttpWebRequest.Create("https://www.bricklink.com/catalogDownload.asp?a=a");

            request.Method = "POST";

            request.ContentType = contentType;

            request.ContentLength   = postString.Length;
            request.UserAgent       = Constants.UserAgent;
            request.Accept          = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            request.Referer         = "https://www.bricklink.com/catalogDownload.asp?a=a";
            request.CookieContainer = _sessionService.GetCookieContainer();
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
            request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;

            using (var requestWriter = new StreamWriter(request.GetRequestStream()))
            {
                requestWriter.Write(postString);
                requestWriter.Close();
            }

            string xml = null;

            using (var response = request.GetResponse())
                using (var responseReader = new StreamReader(response.GetResponseStream()))
                {
                    xml = responseReader.ReadToEnd();
                }

            var serializer   = new TypedXmlSerializer <CatalogContainer <T> >();
            var deserialized = serializer.Deserialize(xml);

            return(deserialized.Items);
        }