コード例 #1
0
        protected virtual string ProcessCss(string url)
        {
            RRTracer.Trace("Beginning Processing {0}", url);
            var urlParts = url.Split(new[] { '^' }, 2);

            url = urlParts[0];
            RRTracer.Trace("Beginning to Download {0}", url);
            var cssContent = WebClientWrapper.DownloadString <CssResource>(url);

            RRTracer.Trace("Finished Downloading {0}", url);
            RRTracer.Trace("Beginning to absolutize urls in {0}", url);
            cssContent = MakeRelativeUrlsAbsoluteAndRemoveComments(cssContent, url);
            RRTracer.Trace("finished absolutizing urls in {0}", url);
            RRTracer.Trace("Beginning to expand imports in {0}", url);
            cssContent = ExpandImports(cssContent, url);
            RRTracer.Trace("Finished expanding imports in {0}", url);
            if (!configuration.ImageSpritingDisabled)
            {
                RRTracer.Trace("Beginning to process sprites in {0}", url);
                ProcessSprites(cssContent);
                RRTracer.Trace("Finished processing sprites in {0}", url);
            }
            if (urlParts.Length > 1)
            {
                RRTracer.Trace("Beginning to wrap media in {0}", url);
                cssContent = WrapMedia(cssContent, urlParts[1]);
                RRTracer.Trace("finished wraping media in {0}", url);
            }
            return(cssContent);
        }
コード例 #2
0
        private string ExpandImports(string cssContent, string parentUrl)
        {
            var imports = Regex.CssImportPattern.Matches(cssContent);
            var filter  = RRContainer.Current.GetAllInstances <IFilter>().FirstOrDefault(x => (x is CssFilter));

            foreach (Match match in imports)
            {
                var url = match.Groups["url"].Value;
                if (filter != null && filter.IgnoreTarget(new CssJsFilterContext(null, url, match.ToString())))
                {
                    continue;
                }
                var absoluteUrl   = RelativeToAbsoluteUtility.ToAbsolute(parentUrl, url);
                var importContent = WebClientWrapper.DownloadString <CssResource>(absoluteUrl);
                importContent = MakeRelativeUrlsAbsoluteAndRemoveComments(importContent, absoluteUrl);
                importContent = ExpandImports(importContent, absoluteUrl);
                var media = match.Groups["media"];
                if (media.Success)
                {
                    importContent = WrapMedia(importContent, media.Value);
                }
                cssContent = cssContent.Replace(match.ToString(), importContent);
            }
            return(cssContent);
        }
コード例 #3
0
        /// <summary>
        ///     Downloads the update configurations from the server.
        /// </summary>
        /// <param name="configFileUri">The url of the configuration file.</param>
        /// <param name="credentials">The HTTP authentication credentials.</param>
        /// <param name="proxy">The optional proxy to use.</param>
        /// <param name="timeout">The timeout for the download request. In milliseconds. Default 10000.</param>
        /// <returns>Returns an <see cref="IEnumerable{UpdateConfiguration}" /> containing the package configurations.</returns>
        public static IEnumerable <UpdateConfiguration> Download(Uri configFileUri, NetworkCredential credentials,
                                                                 WebProxy proxy, int timeout = 10000)
        {
            using (var wc = new WebClientWrapper(timeout))
            {
                wc.Encoding = Encoding.UTF8;
                if (credentials != null)
                {
                    wc.Credentials = credentials;
                }

                if (proxy != null)
                {
                    wc.Proxy = proxy;
                }

                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol  = (SecurityProtocolType)3072;

                var source = wc.DownloadString(configFileUri);
                if (!string.IsNullOrEmpty(source))
                {
                    return(Serializer.Deserialize <IEnumerable <UpdateConfiguration> >(source));
                }
            }

            return(Enumerable.Empty <UpdateConfiguration>());
        }
コード例 #4
0
        /// <summary>
        ///     Downloads the update configurations from the server.
        /// </summary>
        /// <param name="configFileUri">The url of the configuration file.</param>
        /// <param name="credentials">The HTTP authentication credentials.</param>
        /// <param name="proxy">The optional proxy to use.</param>
        /// <returns>
        /// Returns an <see cref="IEnumerable" /> of type <see cref="UpdateConfiguration" /> containing the package
        /// configurations.
        /// </returns>
        public static IEnumerable <UpdateConfiguration> Download(Uri configFileUri, NetworkCredential credentials, WebProxy proxy)
        {
            using (var wc = new WebClientWrapper(10000))
            {
                wc.Encoding = Encoding.UTF8;
                if (credentials != null)
                {
                    wc.Credentials = credentials;
                }

                if (proxy != null)
                {
                    wc.Proxy = proxy;
                }

                // Check for SSL and ignore it
                ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); };
                var source = wc.DownloadString(configFileUri);
                if (!string.IsNullOrEmpty(source))
                {
                    return(Serializer.Deserialize <IEnumerable <UpdateConfiguration> >(source));
                }
            }

            return(Enumerable.Empty <UpdateConfiguration>());
        }
コード例 #5
0
        public void Class_Handles_Error_Response()
        {
            var client = new WebClientWrapper(this.baseUrl);

            PageResponse <string> response = client.DownloadString("/invalid-url");

            response.ResponseCode.ShouldBe(HttpStatusCode.InternalServerError);
            response.Content.ShouldBeNull();
        }
コード例 #6
0
        public void Class_Handles_404_Response()
        {
            var client = new WebClientWrapper(this.baseUrl);

            PageResponse <string> response = client.DownloadString("/nonexistent-url");

            response.ResponseCode.ShouldBe(HttpStatusCode.NotFound);
            response.Content.ShouldBeNull();
        }
コード例 #7
0
        public void DownloadString_Handles_Valid_Response()
        {
            var client = new WebClientWrapper(this.baseUrl);

            PageResponse <string> response = client.DownloadString("/valid-url");

            response.ResponseCode.ShouldBe(HttpStatusCode.OK);
            response.Content.ShouldContain("valid url");
        }
コード例 #8
0
            public void WillNotIncludeUtf8PreambleInstring()
            {
                if (ConfigurationManager.AppSettings["Environment"] == "Test")
                {
                    return;
                }

                var wrapper = new WebClientWrapper();

                var result = wrapper.DownloadString("http://localhost:8877/styles/style1.css");

                Assert.NotEqual(Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble())[0], result[0]);
            }
コード例 #9
0
        private void sendButton_Click(object sender, EventArgs e)
        {
            if (!ValidationManager.Validate(this))
            {
                Popup.ShowPopup(this, SystemIcons.Error, "Missing information", "All fields need to have a value.",
                                PopupButtons.Ok);
                return;
            }

            if (!IsValidMailAdress(emailTextBox.Text))
            {
                Popup.ShowPopup(SystemIcons.Error, "Invalid e-mail address", "Please enter a valid e-mail address.",
                                PopupButtons.Ok);
                return;
            }

            try
            {
                string responseString;
                using (var client = new WebClientWrapper())
                {
                    responseString =
                        client.DownloadString(
                            String.Format(
                                "http://www.nupdate.net/mail.php?name={0}&sender={1}&content={2}",
                                nameTextBox.Text, emailTextBox.Text, contentTextBox.Text));
                }

                if (!String.IsNullOrEmpty(responseString) && responseString != "\n")
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Error while sending feedback.",
                                    String.Format("Please report this message: {0}", responseString), PopupButtons.Ok);
                    return;
                }

                Popup.ShowPopup(this, SystemIcons.Information, "Delivering successful.",
                                "The feedback was sent. Thank you!", PopupButtons.Ok);
                Close();
            }
            catch (Exception ex)
            {
                Popup.ShowPopup(this, SystemIcons.Error, "Error while sending feedback.", ex, PopupButtons.Ok);
            }
        }
コード例 #10
0
ファイル: FeedbackDialog.cs プロジェクト: chantsunman/nUpdate
        private void sendButton_Click(object sender, EventArgs e)
        {
            if (!ValidationManager.Validate(this))
            {
                Popup.ShowPopup(this, SystemIcons.Error, "Missing information", "All fields need to have a value.",
                    PopupButtons.Ok);
                return;
            }

            if (!IsValidMailAdress(emailTextBox.Text))
            {
                Popup.ShowPopup(SystemIcons.Error, "Invalid e-mail address", "Please enter a valid e-mail address.",
                    PopupButtons.Ok);
                return;
            }

            try
            {
                string responseString;
                using (var client = new WebClientWrapper())
                {
                    responseString =
                        client.DownloadString(
                            String.Format(
                                "http://www.nupdate.net/mail.php?name={0}&sender={1}&content={2}",
                                nameTextBox.Text, emailTextBox.Text, contentTextBox.Text));
                }

                if (!String.IsNullOrEmpty(responseString) && responseString != "\n")
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Error while sending feedback.",
                        String.Format("Please report this message: {0}", responseString), PopupButtons.Ok);
                    return;
                }

                Popup.ShowPopup(this, SystemIcons.Information, "Delivering successful.",
                    "The feedback was sent. Thank you!", PopupButtons.Ok);
                Close();
            }
            catch (Exception ex)
            {
                Popup.ShowPopup(this, SystemIcons.Error, "Error while sending feedback.", ex, PopupButtons.Ok);
            }
        }
コード例 #11
0
ファイル: WebClientWrapperTests.cs プロジェクト: mhoyer/KLO
 private void because_of_execution()
 {
     _result = _sut.DownloadString(_address, _optionalHeaders);
 }