Exemple #1
0
        /// <summary>uri to edit the entity</summary>
        /// <param name="baseUriResolver">retrieves the baseUri to use for a given entity set.</param>
        /// <param name="queryLink">whether to return the query link or edit link</param>
        /// <returns>absolute uri which can be used to edit the entity</returns>
        internal Uri GetResourceUri(UriResolver baseUriResolver, bool queryLink)
        {
            // If the entity was inserted using the AddRelatedObject API
            if (this.ParentEntityDescriptor != null)
            {
                // This is the batch scenario, where the entity might not have been saved yet, and there is another operation
                // (for e.g. PUT $1/links/BestFriend or something). Hence we need to generate a Uri with the changeorder number.
                if (this.ParentEntityDescriptor.Identity == null)
                {
                    Uri relativeReferenceUri = UriUtil.CreateUri("$" + this.ParentEntityDescriptor.ChangeOrder.ToString(CultureInfo.InvariantCulture), UriKind.Relative);
                    Uri absoluteReferenceUri = baseUriResolver.GetOrCreateAbsoluteUri(relativeReferenceUri);
                    Uri requestUri           = UriUtil.CreateUri(this.ParentProperty, UriKind.Relative);
                    return(UriUtil.CreateUri(absoluteReferenceUri, requestUri));
                }
                else
                {
                    Debug.Assert(this.ParentEntityDescriptor.ParentEntityDescriptor == null, "This code assumes that parentChild relationships will only ever be one level deep");
                    Debug.Assert(this.ParentProperty != null, "ParentProperty != null");
                    LinkInfo linkInfo;
                    if (this.ParentEntityDescriptor.TryGetLinkInfo(this.ParentProperty, out linkInfo))
                    {
                        if (linkInfo.NavigationLink != null)
                        {
                            return(linkInfo.NavigationLink);
                        }
                    }

                    return(UriUtil.CreateUri(this.ParentEntityDescriptor.GetLink(queryLink), this.GetLink(queryLink)));
                }
            }
            else
            {
                return(this.GetLink(queryLink));
            }
        }
        public async Task Invoke(IDictionary <string, object> environment)
        {
            var context   = new OwinContext(environment);
            var suContext = context.Request.GetServiceUnitContext();

            if (suContext == null || suContext.Request == null || !suContext.Request.ProcessType.Equals("page", StringComparison.InvariantCultureIgnoreCase))
            {
                await next.Invoke(environment);

                return;
            }

            var httpContext = context.Environment.Keys.Contains(HttpContextEnvironmentKey) ?
                              context.Environment[HttpContextEnvironmentKey] as HttpContextBase : null;

            if (httpContext == null && HttpContext.Current != null)
            {
                httpContext = new HttpContextWrapper(HttpContext.Current);
            }
            if (httpContext != null)
            {
                httpContext.SetServiceUnitContext(suContext);
            }

            var resolver = new UriResolver();
            var response = resolver.Execute(suContext, new WebFormProcessResolver());

            if (response != null)
            {
                return;
            }

            await next.Invoke(environment);
        }
Exemple #3
0
 public Main()
 {
     _storage     = new PluginJsonStorage <UriSettings>();
     _uriSettings = _storage.Load();
     _uriParser   = new ExtendedUriParser();
     _uriResolver = new UriResolver();
 }
Exemple #4
0
 public void GetUriFor_WithEntityWithSpaceInPath_EncodesUrlTheRightWay()
 {
     var typeMapper = new TypeMapper(new CritterPomonaConfiguration());
     var uriResolver = new UriResolver(typeMapper,
         new DummyBaseUriProvider() { BaseUri = new Uri("http://whateva/") });
     var galaxy = new Galaxy() { Name = "this is it" };
     var url = uriResolver.GetUriFor(galaxy);
     Assert.That(url, Is.EqualTo("http://whateva/galaxies/this%20is%20it"));
 }
            public Stream GetInputStreamByUrl(Uri url)
            {
                // The image with name 'imageToReplace.png' will be replaced by the default image.
                if (url.ToString().Contains("imageToReplace.png"))
                {
                    url = new UriResolver(this.baseUri).ResolveAgainstBaseUri("images/defaultImage.png");
                }

                return(new FileStream(url.LocalPath, FileMode.Open, FileAccess.Read));
            }
            protected void given_resource <T>(string template)
            {
                var resourceKey = TypeSystem.FromClr <T>();

                UriResolver.Add(new UriRegistration(template, resourceKey));
                Codecs.Add(new CodecRegistration(typeof(XmlCodec),
                                                 resourceKey,
                                                 false,
                                                 MediaType.Xml,
                                                 new[] { "xml" }, null, false));
            }
        /// <summary>
        /// Initializes a new instance of the <see cref="ConventionalODataEntityMetadataBuilder"/> class.
        /// </summary>
        /// <param name="resolver">The URI resolver to use.</param>
        /// <param name="entitySetName">Name of the entity set the entity belongs to.</param>
        /// <param name="entityInstance">The entity instance to build metadata for.</param>
        /// <param name="keyDelimiter">The user-specified conventions to use.</param>
        internal ConventionalODataEntityMetadataBuilder(UriResolver resolver, string entitySetName, IEdmStructuredValue entityInstance, DataServiceUrlKeyDelimiter keyDelimiter)
        {
            Util.CheckArgumentNullAndEmpty(entitySetName, "entitySetName");
            Util.CheckArgumentNull(entityInstance, "entityInstance");
            Util.CheckArgumentNull(keyDelimiter, "keyDelimiter");
            this.entitySetName  = entitySetName;
            this.entityInstance = entityInstance;

            this.uriBuilder = new ConventionalODataUriBuilder(resolver, keyDelimiter);
            this.baseUri    = resolver.BaseUriOrNull;
        }
        private PomonaJsonSerializer GetSerializer()
        {
            var serializerFactory = new PomonaJsonSerializerFactory();
            var nancyContext      = new NancyContext {
                Request = new Request("Get", "http://test")
            };
            var uriResolver     = new UriResolver(this.typeMapper, new BaseUriProvider(nancyContext, "/"));
            var contextProvider = new ServerSerializationContextProvider(this.typeMapper,
                                                                         uriResolver,
                                                                         Substitute.For <IResourceResolver>(), new NoContainer());
            var serializer = serializerFactory.GetSerializer(contextProvider);

            return(serializer);
        }
Exemple #9
0
        public IQueue GetQueue(string uri)
        {
            var queue =
                _queues.Find(
                    candidate => Find(candidate, uri));

            if (queue != null)
            {
                return(queue);
            }

            lock (_padlock)
            {
                queue =
                    _queues.Find(
                        candidate => Find(candidate, uri));

                if (queue != null)
                {
                    return(queue);
                }

                var queueUri = new Uri(uri);

                if (queueUri.Scheme.Equals("resolver"))
                {
                    if (UriResolver == null)
                    {
                        throw new InvalidOperationException(string.Format(ESBResources.NoUriResolverException, uri));
                    }

                    var resolvedQueueUri = UriResolver.Get(uri);

                    if (resolvedQueueUri == null)
                    {
                        throw new KeyNotFoundException(string.Format(ESBResources.UriNameNotFoundException, UriResolver.GetType().FullName, uri));
                    }

                    queue = new ResolvedQueue(GetQueueFactory(resolvedQueueUri).Create(resolvedQueueUri), queueUri);
                }
                else
                {
                    queue = GetQueueFactory(queueUri).Create(queueUri);
                }

                _queues.Add(queue);

                return(queue);
            }
        }
Exemple #10
0
        // open request code
        private void viewCodeButton_Click(object sender, RoutedEventArgs e)
        {
            string      stringUri   = this.pathTextBox.Text;
            UriResolver uriResolver = new UriResolver(stringUri);
            Uri         uri         = uriResolver.getUri();

            if (uri != null && uriResolver.getIPAddresses() != null)
            {
                this.codeFlyoutLabel.Content = this.formRequestString(uri);
                this.codeFlyout.IsOpen       = true;
            }
            else
            {
                this.codeFlyoutLabel.Content = "Bad request";
                this.codeFlyout.IsOpen       = true;
            }
        }
Exemple #11
0
        /// <summary>
        /// Try and get the navigation link. If the navigation link is not specified, then its used the self link of the entity and
        /// appends the property name.
        /// </summary>
        /// <param name="baseUriResolver">retrieves the appropriate baseUri for a given entitySet.</param>
        /// <param name="property">ClientProperty instance representing the navigation property.</param>
        /// <returns>returns the uri for the given link. If the link is not present, its uses the self link of the current entity and appends the navigation property name.</returns>
        internal Uri GetNestedResourceInfo(UriResolver baseUriResolver, ClientPropertyAnnotation property)
        {
            LinkInfo linkInfo = null;
            Uri      uri      = null;

            if (this.TryGetLinkInfo(property.PropertyName, out linkInfo))
            {
                uri = linkInfo.NavigationLink;
            }

            if (uri == null)
            {
                Uri relativeUri = UriUtil.CreateUri(property.PropertyName, UriKind.Relative);
                uri = UriUtil.CreateUri(this.GetResourceUri(baseUriResolver, true /*queryLink*/), relativeUri);
            }

            return(uri);
        }
 /// <summary>
 /// Creates a new
 /// <see cref="CssParserStateController"/>
 /// instance.
 /// </summary>
 /// <param name="baseUrl">the base URL</param>
 public CssParserStateController(String baseUrl)
 {
     if (baseUrl != null && baseUrl.Length > 0)
     {
         this.uriResolver = new UriResolver(baseUrl);
     }
     styleSheet    = new CssStyleSheet();
     nestedAtRules = new Stack <CssNestedAtRule>();
     storedPropertiesWithoutSelector = new Stack <IList <CssDeclaration> >();
     commentStartState = new CommentStartState(this);
     commendEndState   = new CommentEndState(this);
     commendInnerState = new CommentInnerState(this);
     unknownState      = new UnknownState(this);
     ruleState         = new RuleState(this);
     propertiesState   = new PropertiesState(this);
     atRuleBlockState  = new AtRuleBlockState(this);
     conditionalGroupAtRuleBlockState = new ConditionalGroupAtRuleBlockState(this);
     currentState = unknownState;
 }
        public async Task Invoke(IDictionary <string, object> environment)
        {
            var context   = new OwinContext(environment);
            var suContext = context.Request.GetServiceUnitContext();

            if (suContext == null || suContext.Request == null || !suContext.Request.ProcessType.Equals("resource", StringComparison.InvariantCultureIgnoreCase))
            {
                await next.Invoke(environment);

                return;
            }

            var resolver = new UriResolver();
            var response = resolver.Execute(suContext, new ResourceProcessResolver());

            if (response == null)
            {
                await next.Invoke(environment);

                return;
            }
            var data = response.Data as ResourceResponseData ?? new ResourceResponseData(null, null);

            if (data.Resources == null || data.Culture == null)
            {
                context.Response.StatusCode = 404;
                return;
            }
            var resultString = CreateJsonString(data.Resources, data.Culture);

            context.Response.StatusCode  = 200;
            context.Response.ContentType = "application/json";

            if (this.javaScriptFormatter != null)
            {
                var resourceName = suContext.Request.ProcessPath.Split('/')[1];
                resultString = this.javaScriptFormatter(resultString, data.Culture, resourceName);
                context.Response.ContentType = "application/javascript";
            }

            await context.Response.WriteAsync(resultString);
        }
Exemple #14
0
        // sending info to server and handling response
        private void sendInfo()
        {
            // hanle URI
            string      stringUri   = this.pathTextBox.Text;
            UriResolver uriResolver = new UriResolver(stringUri);
            Uri         uri         = uriResolver.getUri();

            // checking URI
            if (uri != null && uriResolver.getIPAddresses() != null)
            {
                string requestString = formRequestString(uri);
                this.showHeaders(uri);
                // create sending data thread
                Task.Factory.StartNew(() =>
                {
                    // send data to server
                    string response = ConnectionService.sendData(uri, uriResolver.getIPAddresses(), requestString);
                    Dispatcher.Invoke(() =>
                    {
                        if (response == "")
                        {
                            this.ShowMessageAsync("Error", "SocketException");
                        }
                        else
                        {
                            // pick body from response
                            this.responseBodyTextBlock.Text = MessageParser.getBodyFromMessage(response);
                            // pick headers from response
                            this.responseHeadersTextBlock.Text = MessageParser.getHeadersFromMessage(response);
                            MessageWriter.writeResponseIntoFile(
                                MessageParser.getHeadersFromMessage(response),
                                MessageParser.getBodyFromMessage(response));
                        }
                    });
                });
            }
            else
            {
                this.ShowMessageAsync("Error", "Name not resolved");
            }
        }
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.tags.DivTagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
         */
        public override void ProcessEnd(IElementNode element, ProcessorContext context)
        {
            base.ProcessEnd(element, context);
            String url = element.GetAttribute(AttributeConstants.HREF);

            if (url != null)
            {
                String @base = context.GetBaseUri();
                if (@base != null)
                {
                    UriResolver uriResolver = new UriResolver(@base);
                    if (!(url.StartsWith("#") && uriResolver.IsLocalBaseUri()))
                    {
                        try {
                            String resolvedUri = uriResolver.ResolveAgainstBaseUri(url).ToExternalForm();
                            if (!url.EndsWith("/") && resolvedUri.EndsWith("/"))
                            {
                                resolvedUri = resolvedUri.JSubstring(0, resolvedUri.Length - 1);
                            }
                            if (!resolvedUri.StartsWith("file:"))
                            {
                                url = resolvedUri;
                            }
                        }
                        catch (UriFormatException) {
                        }
                    }
                }
                ((Div)GetElementResult()).GetAccessibilityProperties().SetRole(StandardRoles.LINK);
                LinkHelper.ApplyLinkAnnotation(GetElementResult(), url);
            }
            if (GetElementResult() != null)
            {
                String name = element.GetAttribute(AttributeConstants.NAME);
                GetElementResult().SetProperty(Property.DESTINATION, name);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConventionalODataUriBuilder"/> class.
 /// </summary>
 /// <param name="resolver">The uri resolver to use.</param>
 /// <param name="urlKeyDelimiter">The key delimiter user specified.</param>
 internal ConventionalODataUriBuilder(UriResolver resolver, DataServiceUrlKeyDelimiter urlKeyDelimiter)
 {
     Debug.Assert(resolver != null, "resolver != null");
     this.resolver        = resolver;
     this.urlKeyDelimiter = urlKeyDelimiter;
 }
Exemple #17
0
 public void SetUp()
 {
     BaseUri = new Uri("http://whateva/");
     this.typeMapper = new TypeMapper(new CritterPomonaConfiguration());
     this.uriResolver = new UriResolver(this.typeMapper, this);
 }
Exemple #18
0
 private ReadContext(FileReaderCallback reader, UriResolver uriResolver = null)
 {
     _FileReader  = reader;
     _UriResolver = uriResolver;
 }
Exemple #19
0
        /// <summary>Initializes a new <see cref="AtomParser"/> instance.</summary>
        /// <param name="reader"><see cref="XmlReader"/> to parse content from.</param>
        /// <param name="entryCallback">
        /// Callback invoked each time an ATOM entry is found; see the comments
        /// on the entryCallback field.
        /// </param>
        /// <param name="typeScheme">
        /// Scheme used to find type information on ATOM category elements.
        /// </param>
        /// <param name="currentDataNamespace">The xml document's DataWeb Namespace</param>
        /// <param name="baseUriResolver">Interface to retrieve the baseUri to use for this EntitySetName - this will be used to convert relative uri's in the response payload to absolute uri's.</param>
        /// <param name="maxProtocolVersion">max protocol version that the client understands.</param>
        internal AtomParser(XmlReader reader, Func<XmlWrappingReader, KeyValuePair<XmlWrappingReader, AtomTag>> entryCallback, string typeScheme, string currentDataNamespace, UriResolver baseUriResolver, DataServiceProtocolVersion maxProtocolVersion)
        {
            Debug.Assert(reader != null, "reader != null");
            Debug.Assert(typeScheme != null, "typeScheme != null");
            Debug.Assert(entryCallback != null, "entryCallback != null");
            Debug.Assert(!String.IsNullOrEmpty(currentDataNamespace), "currentDataNamespace is empty or null");
            Debug.Assert(baseUriResolver != null, "baseUriResolver != null");

            if (reader.Settings.NameTable != null)
            {
                // NOTE: dataNamespace is used for reference equality, and while it looks like
                // a variable, it appears that it will only get set to XmlConstants.DataWebNamespace
                // at runtime. Therefore we remove string dataNamespace as a field here.
                // this.dataNamespace = reader != null ? reader.Settings.NameTable.Add(context.DataNamespace) : null;
                reader.Settings.NameTable.Add(currentDataNamespace);
            }

            this.reader = new Microsoft.OData.Service.Client.Xml.XmlAtomErrorReader(reader);
            this.readers = new Stack<XmlWrappingReader>();
            this.entryCallback = entryCallback;
            this.typeScheme = typeScheme;
            this.currentDataNamespace = currentDataNamespace;
            this.baseUriResolver = baseUriResolver;
            this.countValue = CountStateInitial;
            this.MaxProtocolVersion = maxProtocolVersion;
            Debug.Assert(this.kind == AtomDataKind.None, "this.kind == AtomDataKind.None -- otherwise not initialized correctly");
        }
Exemple #20
0
 public void SetUp()
 {
     BaseUri          = new Uri("http://whateva/");
     this.typeMapper  = new TypeMapper(new CritterPomonaConfiguration());
     this.uriResolver = new UriResolver(this.typeMapper, this);
 }
 public ServiceControllerService(UriResolver resolver)
 {
     this._client      = new HttpClient();
     this._uriResolver = resolver;
 }
Exemple #22
0
 public DefaultImageGetter()
 {
     _uriResolver = new DefaultUriResolver();
 }
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.tags.SpanTagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
         */
        public override void ProcessEnd(IElementNode element, ProcessorContext context)
        {
            base.ProcessEnd(element, context);
            String url = element.GetAttribute(AttributeConstants.HREF);

            if (url != null)
            {
                String @base = context.GetBaseUri();
                if (@base != null)
                {
                    UriResolver uriResolver = new UriResolver(@base);
                    if (!(url.StartsWith("#") && uriResolver.IsLocalBaseUri()))
                    {
                        try {
                            String resolvedUri = uriResolver.ResolveAgainstBaseUri(url).ToExternalForm();
                            if (!url.EndsWith("/") && resolvedUri.EndsWith("/"))
                            {
                                resolvedUri = resolvedUri.JSubstring(0, resolvedUri.Length - 1);
                            }
                            if (!resolvedUri.StartsWith("file:"))
                            {
                                url = resolvedUri;
                            }
                        }
                        catch (UriFormatException) {
                        }
                    }
                }
                for (int i = 0; i < GetAllElements().Count; i++)
                {
                    if (GetAllElements()[i] is RunningElement)
                    {
                        continue;
                    }
                    if (GetAllElements()[i] is IBlockElement)
                    {
                        Div simulatedDiv = new Div();
                        simulatedDiv.GetAccessibilityProperties().SetRole(StandardRoles.LINK);
                        Transform cssTransform = GetAllElements()[i].GetProperty <Transform>(Property.TRANSFORM);
                        if (cssTransform != null)
                        {
                            GetAllElements()[i].DeleteOwnProperty(Property.TRANSFORM);
                            simulatedDiv.SetProperty(Property.TRANSFORM, cssTransform);
                        }
                        FloatPropertyValue?floatPropVal = GetAllElements()[i].GetProperty <FloatPropertyValue?>(Property.FLOAT);
                        if (floatPropVal != null)
                        {
                            GetAllElements()[i].DeleteOwnProperty(Property.FLOAT);
                            simulatedDiv.SetProperty(Property.FLOAT, floatPropVal);
                        }
                        simulatedDiv.Add((IBlockElement)GetAllElements()[i]);
                        String display = childrenDisplayMap.JRemove(GetAllElements()[i]);
                        if (display != null)
                        {
                            childrenDisplayMap.Put(simulatedDiv, display);
                        }
                        GetAllElements()[i] = simulatedDiv;
                    }
                    LinkHelper.ApplyLinkAnnotation(GetAllElements()[i], url);
                }
            }
            if (!GetAllElements().IsEmpty())
            {
                String             name         = element.GetAttribute(AttributeConstants.NAME);
                IPropertyContainer firstElement = GetAllElements()[0];
                firstElement.SetProperty(Property.DESTINATION, name);
            }
        }
Exemple #24
0
 private ReadContext(FileReaderCallback reader, UriResolver uriResolver = null, bool checkExtensions = true)
 {
     _FileReader  = reader;
     _UriResolver = uriResolver;
     _CheckSupportedExtensions = checkExtensions;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConventionalODataEntityMetadataBuilder"/> class.
 /// </summary>
 /// <param name="baseUri">The base URI of the service.</param>
 /// <param name="entitySetName">Name of the entity set the entity belongs to.</param>
 /// <param name="entityInstance">The entity instance to build metadata for.</param>
 /// <param name="keyDelimiter">The user-specified delimiter to use.</param>
 internal ConventionalODataEntityMetadataBuilder(Uri baseUri, string entitySetName, IEdmStructuredValue entityInstance, DataServiceUrlKeyDelimiter keyDelimiter)
     : this(UriResolver.CreateFromBaseUri(baseUri, "baseUri"), entitySetName, entityInstance, keyDelimiter)
 {
 }