Example #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);
        }
Example #2
0
        private void WriteProperties(IDictionary <string, string> properties)
        {
            var list       = properties.Select(x => new SerializableKeyValuePair <string, string>(x.Key, x.Value)).ToList();
            var serializer = new TypedXmlSerializer <List <SerializableKeyValuePair <string, string> > >();
            var data       = serializer.SerializeToString(list);

            _appDataService.WriteAppData(_appDataKey, data);
        }
Example #3
0
        public void Refresh()
        {
            var items = GetItemsFromSource();

            _items.Clear();
            _items.AddRange(items);

            var serializer = new TypedXmlSerializer <List <T> >();
            var serialized = serializer.SerializeToString(items);

            _appDataService.WriteAppData(AppDataKey, serialized);
        }
Example #4
0
        public void SetCredential(ExternalSystem system, NetworkCredential credential)
        {
            var serializer = new TypedXmlSerializer <SerializableNetworkCredential>();
            var temp       = new SerializableNetworkCredential
            {
                UserName = credential.UserName,
                Password = credential.Password,
                Domain   = credential.Domain
            };

            var data = serializer.SerializeToString(temp);

            _appDataService.WriteAppData(GetAppDataKey(system), data);
        }
Example #5
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));
        }
Example #6
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);
        }
Example #7
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);
        }
        public static QuestionData GetQuestionDataForQuestion(Question question)
        {
            switch (question.Type)
            {
            case QuestionType.DateQuestion:
                return(new TypedXmlSerializer <DateQuestionData>().DeserializeFromXmlString(question.XML));

            case QuestionType.DecimalQuestion:
                return(new TypedXmlSerializer <DecimalQuestionData>().DeserializeFromXmlString(question.XML));

            case QuestionType.DescriptiveQuestion:
                return(new TypedXmlSerializer <DescriptiveQuestionData>().DeserializeFromXmlString(question.XML));

            case QuestionType.ExclusiveChoiceQuestion:
                var exlusiveData = new TypedXmlSerializer <ExclusiveChocieQuestionData>().DeserializeFromXmlString(question.XML);
                exlusiveData.SetResult(exlusiveData.GetResult());
                return(exlusiveData);

            case QuestionType.ImageQuestion:
                return(new TypedXmlSerializer <ImageQuestionData>().DeserializeFromXmlString(question.XML));

            case QuestionType.IntegerQuestion:
                return(new TypedXmlSerializer <IntegerQuestionData>().DeserializeFromXmlString(question.XML));

            case QuestionType.MultipleChocieQuestion:
                var multipleData = new TypedXmlSerializer <MultipleChoiceQuestionData>().DeserializeFromXmlString(question.XML);
                multipleData.SetResult(multipleData.GetResult());
                return(multipleData);

            case QuestionType.TimeQuestion:
                return(new TypedXmlSerializer <TimeQuestionData>().DeserializeFromXmlString(question.XML));

            case QuestionType.GeopointQuestion:
                return(new TypedXmlSerializer <GeopointQuestionData>().DeserializeFromXmlString(question.XML));

            default:
                throw new ArgumentException("XML data for question is invalid!");
            }
        }