protected void action_Click(object sender, EventArgs e)
        {
            string url = input.Text;
            if (string.IsNullOrEmpty(url))
            {
                return;
            }

            // Execute methods on the UrlShortener service based upon the type of the URL provided.
            try
            {
                string resultURL;
                if (IsShortUrl(url))
                {
                    // Expand the URL by using a Url.Get(..) request.
                    Url result = service.Url.Get(url).Execute();
                    resultURL = result.LongUrl;
                }
                else
                {
                    // Shorten the URL by inserting a new Url.
                    Url toInsert = new Url { LongUrl = url };
                    toInsert = service.Url.Insert(toInsert).Execute();
                    resultURL = toInsert.Id;
                }
                output.Text = string.Format("<a href=\"{0}\">{0}</a>", resultURL);
            }
            catch (GoogleApiException ex)
            {
                var str = ex.ToString();
                str = str.Replace(Environment.NewLine, Environment.NewLine + "<br/>");
                str = str.Replace("  ", " &nbsp;");
                output.Text = string.Format("<font color=\"red\">{0}</font>", str);
            }
        }
Ejemplo n.º 2
0
        public VirtualFileStore(string virtualPathProviderName)
        {
            if (string.IsNullOrEmpty(virtualPathProviderName))
            {
                throw new ArgumentNullException("virtualPathProviderName");
            }

            var vppRegistrationHandler = ServiceLocator.Current.GetInstance<VirtualPathRegistrationHandler>();
            var storeVirtualPathProviderSettings = vppRegistrationHandler.RegisteredVirtualPathProviders.Values.FirstOrDefault(ps => ps.Name == virtualPathProviderName);

            if (storeVirtualPathProviderSettings == null)
            {
                throw new ArgumentException(string.Format("Virtual path provider with name \"{0}\" has not been registered, please check EPiServerFramwork.config file.", virtualPathProviderName), "virtualPathProviderName");
            }

            string storePath = storeVirtualPathProviderSettings.Parameters["physicalPath"];
            string storeUrl = storeVirtualPathProviderSettings.Parameters["virtualPath"];

            if (string.IsNullOrEmpty(storePath) || string.IsNullOrEmpty(storeUrl))
            {
                throw new ConfigurationErrorsException(@"Target virtual path provider is not well configured, ""physicalPath"" and ""virtualPath"" parameters are required.");
            }

            _storePath = VirtualPathUtilityEx.RebasePhysicalPath(storePath);
            _storeUrl = Url.Parse(storeUrl);

            if (!Directory.Exists(_storePath))
            {
                Directory.CreateDirectory(_storePath);
            }
        }
Ejemplo n.º 3
0
 private static void RegisterEntryPointControllerDescriptionBuilder(this IComponentProvider container, Url entryPoint)
 {
     container.Register<IHttpControllerDescriptionBuilder, EntryPointControllerDescriptionBuilder>(
         entryPoint.ToString().Substring(1),
         () => new EntryPointControllerDescriptionBuilder(entryPoint, container.Resolve<IDefaultValueRelationSelector>()),
         Lifestyles.Singleton);
 }
 public Response(String message, Url address)
 {
     var buffer = Encoding.UTF8.GetBytes(message);
     _content = new MemoryStream(buffer);
     _headers = new Dictionary<String, String>();
     _address = address;
 }
Ejemplo n.º 5
0
        internal Account(Newtonsoft.Json.Linq.JToken json) : this()
        {
            IsDeactivated             = (bool)json["deactivated"];
            IsWithdrawalHalted        = (bool)json["withdrawal_halted"];
            IsSweepEnabled            = (bool)json["sweep_enabled"];
            OnlyPositionClosingTrades = (bool)json["only_position_closing_trades"];

            UpdatedAt = (DateTime)json["updated_at"];

            AccountUrl    = new Url<Account>((string)json["url"]);
            PortfolioUrl  = new  Url<AccountPortfolio>((string)json["portfolio"]);
            UserUrl       = new Url<User>((string)json["user"]);
            PositionsUrl  = new  Url<AccountPositions>((string)json["positions"]);

            AccountNumber = (string)json["account_number"];
            AccountType   = (string)json["type"];

            Sma = json["sma"];
            SmaHeldForOrders = json["sma_held_for_orders"];

            MarginBalances = json["margin_balances"];

            MaxAchEarlyAccessAmount = (decimal)json["max_ach_early_access_amount"];

            CashBalance = new Balance(json["cash_balances"]);
        }
        public string RewriteUrl(string url)
        {
            if(url.Contains("productid"))
            {
                // Give it a thorough look - see if we can redirect it
                Url uri = new Url(url);
                string[] productIds = uri.QueryCollection.GetValues("productid");
                if(productIds != null && productIds.Any())
                {
                    string productId = productIds.FirstOrDefault();

                    if (productId != null && string.IsNullOrEmpty(productId) == false)
                    {
                        SearchResults<FindProduct> results = SearchClient.Instance.Search<FindProduct>()
                            .Filter(p => p.Code.MatchCaseInsensitive(productId))
                            .GetResult();
                        if (results.Hits.Any())
                        {
                            // Pick the first one
                            SearchHit<FindProduct> product = results.Hits.FirstOrDefault();
                            return product.Document.ProductUrl;
                        }
                    }

                }
            }
            return null;
        }
Ejemplo n.º 7
0
        protected void action_Click(object sender, EventArgs e)
        {
            string url = input.Text;
            if (string.IsNullOrEmpty(url))
            {
                return;
            }

            // Execute methods on the UrlShortener service based upon the type of the URL provided.
            try
            {
                string resultURL;
                if (IsShortUrl(url))
                {
                    // Expand the URL by using a Url.Get(..) request.
                    Url result = _service.Url.Get(url).Fetch();
                    resultURL = result.LongUrl;
                }
                else
                {
                    // Shorten the URL by inserting a new Url.
                    Url toInsert = new Url { LongUrl = url};
                    toInsert = _service.Url.Insert(toInsert).Fetch();
                    resultURL = toInsert.Id;
                }
                output.Text = string.Format("<a href=\"{0}\">{0}</a>", resultURL);
            }
            catch (GoogleApiException ex)
            {
                output.Text = ex.ToHtmlString();
            }
        }
        public string ResolveUrl(Url url)
        {
            if (url == null) return string.Empty;

            var parsedUrl = ResolveUrl(PageReference.ParseUrl(url.OriginalString));
            return string.IsNullOrWhiteSpace(parsedUrl) ? url.OriginalString : parsedUrl;
        }
Ejemplo n.º 9
0
 public Download(Task<IResponse> task, CancellationTokenSource cts, Url target, INode originator)
 {
     _task = task;
     _cts = cts;
     _target = target;
     _originator = originator;
 }
Ejemplo n.º 10
0
 internal Position(Newtonsoft.Json.Linq.JToken json)
     : this()
 {
     InstrumentUrl = new Url<Account>((string)json["instrument"]);
       AverageBuyPrice = (decimal)json["average_buy_price"];
       Quantity = (decimal)json["quantity"];
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RawPage" /> class.
        /// </summary>
        /// <param name="uri">The uri to the page on the site</param>
        /// <param name="textData">Raw text of the page.</param>
        /// <param name="links">Links recovered from this page.</param>
        /// <param name="alternativePaths">The path the request was redirected to.</param>
        public RawPage(Uri uri, string textData, string reference, IEnumerable<Uri> links, params string[] alternativePaths)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            
            if (string.IsNullOrWhiteSpace(textData))
            {
                throw new ArgumentNullException("textData");
            }

            if (links == null)
            {
                throw new ArgumentNullException("links");
            }

            this.path = uri.PathAndQuery;
            this.url = new Url(uri);
            this.textData = textData;
            this.links = links.ToList();
            var alternative = (alternativePaths ?? Enumerable.Empty<string>())
                .Where(p => p != path);
            this.alternativePaths.AddRange(alternative);
            this.reference = reference;
        }
Ejemplo n.º 12
0
		public FlurlClient(Url url, bool autoDispose) {
			this.Url = url;
			this.AutoDispose = autoDispose;
			this.AllowedHttpStatusRanges = new List<string>();
			if (FlurlHttp.Configuration.AllowedHttpStatusRange != null)
				this.AllowedHttpStatusRanges.Add(FlurlHttp.Configuration.AllowedHttpStatusRange);
		}
Ejemplo n.º 13
0
        public SitemapData GetSitemapData(string requestUrl)
        {
            var url = new Url(requestUrl); 
            
            var host = url.Path.TrimStart('/').ToLowerInvariant();

            return GetAllSitemapData().FirstOrDefault(x => GetHostWithLanguage(x) == host && (x.SiteUrl == null || x.SiteUrl.Contains(url.Host)));
        }
Ejemplo n.º 14
0
 private VirtualResponse()
 {
     _address = Url.Create("http://localhost/");
     _status = HttpStatusCode.OK;
     _headers = new Dictionary<String, String>();
     _content = MemoryStream.Null;
     _dispose = false;
 }
Ejemplo n.º 15
0
 public void UrlWithHttpAsResourceIsARelativeUrl()
 {
     var address = "http";
     var result = new Url(address);
     Assert.That(result.IsInvalid, Is.False);
     Assert.That(result.Href, Is.EqualTo("http"));
     Assert.That(result.IsRelative, Is.True);
 }
Ejemplo n.º 16
0
 // constructors
 /// <summary>
 /// Creates a new member of EdgeMart.
 /// </summary>
 /// <param name="url">Server and EdgeMart settings in the form of a Url.</param>
 protected EdgeMart(Url url)
 {
     if (url == null) throw new ArgumentNullException("url");
     if (String.IsNullOrEmpty(url.EdgeMartName))
     {
         throw new ArgumentException("The name of the EdgeMart is required.");
     }
     _url = url;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Creates a GET request for the given target from the optional source
 /// node and optional referer string.
 /// </summary>
 /// <param name="target">The target to use.</param>
 /// <param name="source">The optional source of the request.</param>
 /// <param name="referer">The optional referrer string.</param>
 /// <returns>The new document request.</returns>
 public static DocumentRequest Get(Url target, INode source = null, String referer = null)
 {
     return new DocumentRequest(target)
     {
         Method = HttpMethod.Get,
         Referer = referer,
         Source = source
     };
 }
Ejemplo n.º 18
0
 public void UrlWithSchemeOnlyIsAnInvalidUrl()
 {
     var address = "http://";
     var result = new Url(address);
     Assert.That(result.IsInvalid, Is.True);
     Assert.That(result.Href, Is.EqualTo("http:///"));
     Assert.That(String.IsNullOrEmpty(result.Path), Is.True);
     Assert.That(String.IsNullOrEmpty(result.Query), Is.True);
 }
Ejemplo n.º 19
0
 public void UrlWithHttpAndColonIsAValidUrl()
 {
     var address = "http:";
     var result = new Url(address);
     Assert.That(result.IsInvalid, Is.False);
     Assert.That(result.Href, Is.EqualTo("http:///"));
     Assert.That(String.IsNullOrEmpty(result.Path), Is.True);
     Assert.That(String.IsNullOrEmpty(result.Query), Is.True);
 }
Ejemplo n.º 20
0
 public void ChangeImageSourceWithAbsoluteUrlResultsInUpdatedAbsoluteUrl()
 {
     var document = CreateEmpty("http://localhost");
     var img = document.CreateElement<IHtmlImageElement>();
     img.Source = "http://www.test.com/test.png";
     Assert.AreEqual("http://www.test.com/test.png", img.Source);
     var url = new Url(img.Source);
     Assert.AreEqual("test.png", url.Path);
 }
Ejemplo n.º 21
0
 public void ChangeVideoPosterResultsInUpdatedAbsoluteUrl()
 {
     var document = CreateEmpty("http://localhost");
     var video = document.CreateElement<IHtmlVideoElement>();
     video.Poster = "test.jpg";
     Assert.AreEqual("http://localhost/test.jpg", video.Poster);
     var url = new Url(video.Poster);
     Assert.AreEqual("test.jpg", url.Path);
 }
Ejemplo n.º 22
0
 public async Task<Instrument> GetInstrument (Url<Instrument> instrumentUrl)
 {
     Instrument instrument = null;
     if (!_instrumentKeyToIntrument.TryGetValue(instrumentUrl.ToString(), out instrument))
     {
         instrument = await _client.DownloadInstrument(instrumentUrl);
         addInstrument(instrument);
     }
     return instrument;
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Creates a new document request for the given url.
        /// </summary>
        /// <param name="target">The resource's url.</param>
        public DocumentRequest(Url target)
        {
            if (target == null)
                throw new ArgumentNullException(nameof(target));

            Headers = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
            Target = target;
            Method = HttpMethod.Get;
            Body = MemoryStream.Null;
        }
Ejemplo n.º 24
0
        static Boolean IsInvalidUrl(String value)
        {
            if (!String.IsNullOrEmpty(value))
            {
                var url = new Url(value);
                return url.IsInvalid || url.IsRelative;
            }

            return false;
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Creates a new resource request for the given url.
 /// </summary>
 /// <param name="source">The request's source.</param>
 /// <param name="target">The resource's url.</param>
 public ResourceRequest(IElement source, Url target)
 {
     Source = source;
     Target = target;
     Origin = source.Owner.Origin;
     IsManualRedirectDesired = false;
     IsSameOriginForced = false;
     IsCookieBlocked = false;
     IsCredentialOmitted = false;
 }
Ejemplo n.º 26
0
        public async Task Should_Return_Response_From_Full_Url()
        {
            //Given
            var url = new Url {Path = "/", Scheme = "http", HostName = "mydomain.com"};

            //When
            var result = await browser.Get(url);

            //Then
            Assert.Equal("hi", result.Body.AsString());
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Creates a new document request for the given url.
        /// </summary>
        /// <param name="target">The resource's url.</param>
        public DocumentRequest(Url target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            Target = target;
            Referer = null;
            Method = HttpMethod.Get;
            Body = MemoryStream.Null;
            MimeType = null;
        }
Ejemplo n.º 28
0
        public async Task Should_Return_QueryString_Values_From_Full_Url()
        {
            //Given
            var url = new Url { Path = "/querystring", Scheme = "http", HostName = "mydomain.com", Query = "?myKey=myvalue" };

            //When
            var result = await browser.Get(url);

            //Then
            Assert.Equal("myvalue", result.Body.AsString());
        }
Ejemplo n.º 29
0
        public void it_can_return_the_server_url()
        {
            // Arrange
            var esUrl = new Url(String.Format("http://{0}:{1}/remote?edgemart={2}", SERVER_NAME, DEFAULT_PORT.ToString(), EDGEMART_NAME));

            // Act
            var em = new EdgeMart<Object>(esUrl);

            // Assert
            Assert.AreEqual(String.Format("http://{0}:{1}/remote", SERVER_NAME, DEFAULT_PORT.ToString()), em.AbsoluteUri.ToString());
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Creates a POST request for the given target with the fields being
        /// used to generate the body and encoding type plaintext.
        /// </summary>
        /// <param name="target">The target to use.</param>
        /// <param name="fields">The fields to send.</param>
        /// <returns>The new document request.</returns>
        public static DocumentRequest PostAsPlaintext(Url target, IDictionary<String, String> fields)
        {
            if (fields == null)
                throw new ArgumentNullException("fields");

            var fds = new FormDataSet();

            foreach (var field in fields)
                fds.Append(field.Key, field.Value, InputTypeNames.Text);

            return Post(target, fds.AsPlaintext(), MimeTypes.Plain);
        }