Ejemplo n.º 1
0
        /// <summary>
        /// Gets sub item of the specified EntityContainer instance by the name
        /// </summary>
        /// <param name="container">The EntityContainer instance</param>
        /// <param name="name">The name of sub item</param>
        /// <returns>sub item object if one is found; null otherwise</returns>
        private static ODataUriItem GetItem(EntityContainer container, string name)
        {
            ODataUriItem result = null;

            EntitySet entitySet;
            bool      isEntitySet = container.TryGetEntitySetByName(name, false, out entitySet);

            if (isEntitySet)
            {
                return(new ODataUriItem(entitySet, UriType.URI1));
            }
            else
            {
                var fs = container.FunctionImports.Where(x => x.Name.Equals(name, StringComparison.Ordinal));
                if (fs.Any())
                {
                    EdmFunction func       = fs.First();
                    var         retVal     = func.ReturnParameter;
                    var         retType    = retVal.TypeUsage.EdmType;
                    UriType     retUriType = GetUriTypeOfFuncReturn(retType);
                    if (retUriType == UriType.URI11 || retUriType == UriType.URI13 || retUriType == UriType.URI_CollEt)
                    {
                        result = new ODataUriItem(((CollectionType)retType).TypeUsage.EdmType, retUriType);
                    }
                    else
                    {
                        result = new ODataUriItem(retType, retUriType);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
 private async Task MakeFeed(UriType type, HttpMultipartFormDataContent content)
 {
     try
     {
         if (type == UriType.CreateFeed)
         {
             if (await DataHelper.PostDataAsync(UriProvider.GetUri(type), content) != null)
             {
                 SendSuccessful();
             }
         }
         else
         {
             if (await DataHelper.PostDataAsync(UriProvider.GetUri(type, FeedId), content) != null)
             {
                 SendSuccessful();
             }
         }
     }
     catch (CoolapkMessageException cex)
     {
         UIHelper.ShowMessage(cex.Message);
         if (cex.MessageStatus == CoolapkMessageException.RequestCaptcha)
         {
             var dialog = new CaptchaDialog();
             await dialog.ShowAsync();
         }
     }
 }
Ejemplo n.º 3
0
 private string CreateUri(UriType uriType, QueryParameters parameters)
 {
     return(uriType switch
     {
         UriType.PreviousPage => Url.Link("GetBands",
                                          new
         {
             PageNumber = parameters.PageNumber - 1,
             parameters.PageSize,
             parameters.BandName,
             parameters.MainGenre
         }),
         UriType.NextPage => Url.Link("GetBands",
                                      new
         {
             PageNumber = parameters.PageNumber + 1,
             parameters.PageSize,
             parameters.BandName,
             parameters.MainGenre
         }),
         _ => Url.Link("GetBands",
                       new
         {
             parameters.PageNumber,
             parameters.PageSize,
             parameters.BandName,
             parameters.MainGenre
         })
     });
Ejemplo n.º 4
0
        private string CreatePostsUri(PostResourceParameters postResourceParameters, UriType uriType, string routeName)
        {
            switch (uriType)
            {
            case UriType.PreviousPage:
                return(Url.Link(routeName, new
                {
                    pageNumber = postResourceParameters.PageNumber - 1,
                    postResourceParameters.PageSize,
                    postResourceParameters.SearchQuery,
                    postResourceParameters.OrderBy,
                    postResourceParameters.Fields
                }));

            case UriType.NextPage:
                return(Url.Link(routeName, new
                {
                    pageNumber = postResourceParameters.PageNumber + 1,
                    postResourceParameters.PageSize,
                    searchQuery = postResourceParameters.SearchQuery,
                    postResourceParameters.OrderBy,
                    postResourceParameters.Fields
                }));

            default:
                return(Url.Link(routeName, new
                {
                    postResourceParameters.PageNumber,
                    postResourceParameters.PageSize,
                    postResourceParameters.SearchQuery,
                    postResourceParameters.OrderBy,
                    postResourceParameters.Fields
                }));
            }
        }
Ejemplo n.º 5
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked
     {
         return(((UriType != null ? UriType.GetHashCode() : 0) * 397) ^ EqualityComparer <T> .Default.GetHashCode(Meta));
     }
 }
Ejemplo n.º 6
0
        public void UriTypeTest(string u, UriType type)
        {
            var uri = SpotifyUri.Make(u);

            Assert.Equal(u, uri.FullUri);
            Assert.Equal(type, uri.Type);
        }
Ejemplo n.º 7
0
        public UriResourceInfo(Options options, string originalUrl
                               , Uri uri, Uri baseUri, UriType linkType)
        {
            _options     = options;
            _originalUrl = originalUrl;
            _baseUri     = baseUri;

            uri = new Uri(CleanupUrl(uri.OriginalString), UriKind.Relative);

            if (Uri.IsWellFormedUriString(uri.OriginalString, UriKind.Absolute))
            {
                _absoluteUri = uri;
                _relativeUri = null;
            }
            else if (Uri.IsWellFormedUriString(uri.OriginalString, UriKind.Relative))
            {
                _absoluteUri = MakeAbsoluteUri(baseUri, uri);
                _relativeUri = uri;
            }
            else
            {
                if (originalUrl.StartsWith(@"#"))
                {
                    _absoluteUri = null;
                    _relativeUri = new Uri(originalUrl, UriKind.Relative);
                }
                else
                {
                    _absoluteUri = MakeAbsoluteUri(baseUri, uri);
                    _relativeUri = uri;
                }
                _linkType = linkType;
            }
        }
Ejemplo n.º 8
0
 private static bool DoIsProcessableUri(
     Uri absoluteUri, UriType linkType)
 {
     return
         (absoluteUri != null &&
          (DoWantFollowUri(absoluteUri, linkType) || DoIsResourceUri(absoluteUri)));
 }
Ejemplo n.º 9
0
        public static Uri GetUri(UriType type, params object[] args)
        {
            var s = "https://api.coolapk.com/v6" + GetTemplate(type);
            var u = string.Format(s, args);

            return(new Uri(u, UriKind.Absolute));
        }
Ejemplo n.º 10
0
 public Uri(string path, UriType type)
     : this()
 {
     FileName        = path;
     Type            = type;
     Extension       = AnaysisExtension(path);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a <see cref="SpotifyUri"/> from the given id and type.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="type">The <see cref="UriType"/>.
        /// Note this can not be <see cref="UriType.Playlist"/>, if you want to create a playlist uri use
        /// <see cref="Make(string)"/> or <see cref="Make(string, string)"/></param>
        /// <returns>A new instance of <see cref="SpotifyUri"/>.</returns>
        public static SpotifyUri Make(string id, UriType type)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("id is null or empty.");
            }

            switch (type)
            {
            case UriType.User:
                return(new SpotifyUri($"spotify:user:{id}"));

            case UriType.Track:
                return(new SpotifyUri($"spotify:track:{id}"));

            case UriType.Artist:
                return(new SpotifyUri($"spotify:artist:{id}"));

            case UriType.Album:
                return(new SpotifyUri($"spotify:album:{id}"));

            case UriType.Playlist:
                throw new NotSupportedException("UriType Playlist is not supported.");

            case UriType.Local:
                throw new NotSupportedException("UriType Local is not supported.");

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Ejemplo n.º 12
0
        public static SpotifyUri Parse(string uri)
        {
            if (string.IsNullOrEmpty(uri))
            {
                throw new ArgumentNullException("Uri");
            }

            UriType uriType = UriType.none;

            string[] props = uri.Split(':');
            if (props.Length < 3 || !Enum.TryParse(props[1], out uriType))
            {
                throw new ArgumentException("Unexpected Uri");
            }

            Dictionary <UriType, string> properties = new Dictionary <UriType, string> {
                { uriType, props[2] }
            };

            for (int index = 3; index < props.Length; index += 2)
            {
                UriType type = UriType.none;
                if (Enum.TryParse(props[index], out type))
                {
                    properties.Add(type, props[index + 1]);
                }
            }

            return(new SpotifyUri(props[0], properties));
        }
Ejemplo n.º 13
0
        private async Task MakeFeed(UriType type, HttpContent content)
        {
            try
            {
                object[] arg = Array.Empty <object>();
                if (type != UriType.CreateFeed)
                {
                    arg = new object[] { FeedId };
                }
                var(r, _) = await DataHelper.PostDataAsync(UriHelper.GetUri(type, arg), content);

                if (r)
                {
                    SendSuccessful();
                }
            }
            catch (Core.Exceptions.CoolapkMessageException cex)
            {
                UIHelper.ShowMessage(cex.Message);
                if (cex.MessageStatus == Core.Exceptions.CoolapkMessageException.RequestCaptcha)
                {
                    var dialog = new CaptchaDialog();
                    await dialog.ShowAsync();
                }
            }
        }
Ejemplo n.º 14
0
 public string GetUriPropValue(UriType type)
 {
     if (!_properties.ContainsKey(type))
     {
         return(null);
     }
     return(_properties[type]);
 }
Ejemplo n.º 15
0
        public NavigationUrl(UriType uriType, string url, Formular form)
        {
            Contract.Requires(uriType != UriType.None, "uriType must NOT be None");

            UrlType   = uriType;
            UrlString = url;
            Formular  = form;
        }
Ejemplo n.º 16
0
        public NavigatorUrl( UriType uriType, string url, Formular form )
        {
            uriType.Require( x => uriType != UriType.None );

            UrlType = uriType;
            UrlString = url;
            Formular = form;
        }
Ejemplo n.º 17
0
        public NavigatorUrl(UriType uriType, string url, Formular form)
        {
            uriType.Require(x => uriType != UriType.None);

            UrlType   = uriType;
            UrlString = url;
            Formular  = form;
        }
Ejemplo n.º 18
0
        // ------------------------------------------------------------------

        /// <summary>
        /// Constructor.
        /// </summary>
        private LinkElement(
            UriType linkType,
            string name,
            params string[] attributes)
        {
            LinkType   = linkType;
            Name       = name;
            Attributes = attributes;
        }
Ejemplo n.º 19
0
 public UriResourceInfo(UriResourceInfo copyFrom)
 {
     _options     = copyFrom._options;
     _originalUrl = copyFrom._originalUrl;
     _relativeUri = copyFrom._relativeUri;
     _baseUri     = copyFrom._baseUri;
     _absoluteUri = copyFrom._absoluteUri;
     _linkType    = copyFrom._linkType;
 }
Ejemplo n.º 20
0
		// ------------------------------------------------------------------

		/// <summary>
		/// Constructor.
		/// </summary>
		private LinkElement(
			UriType linkType,
			string name,
			params string[] attributes )
		{
			LinkType = linkType;
			Name = name;
			Attributes = attributes;
		}
Ejemplo n.º 21
0
 /// <summary>
 /// Takes a type of URI and a bunch of key/value pairs to replace within the string
 /// </summary>
 /// <param name="baseUrl">The current path without trailing slash</param>
 /// <param name="type">the type to return</param>
 /// <param name="replacements">the key value replacements to use within the URI</param>
 /// <returns>The new URI</returns>
 public static string GetUriWithReplacments(string baseUrl, UriType type, Dictionary<string, string> replacements)
 {
     string uri = UriTypeMapping[type];
     if (uri.IndexOf("http:") != 0)
     {
         uri  = baseUrl + "/" + uri;
     }
     return GetUriWithReplacments(baseUrl, uri, replacements);
 }
Ejemplo n.º 22
0
        private void ExtractAll()
        {
            if (!IsUriRecord(this) || Payload is not object)
            {
                throw new ArgumentException($"Record type must be {TypeNameFormat.NfcWellKnowType} and payload type 'U' (0x55)");
            }

            _uriType = (UriType)Payload[0];
            _uri     = Encoding.UTF8.GetString(Payload, 1, Payload.Length - 1);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Sets the URI of the sticker data.
        /// </summary>
        /// <remarks><paramref name="uri"/> must be a path inside the app package directory like 'res/smile.png' when the type of URI is local path.</remarks>
        /// <since_tizen> 10 </since_tizen>
        /// <feature>http://tizen.org/feature/ui_service.sticker</feature>
        /// <param name="uriType">The URI type to be saved.</param>
        /// <param name="uri">The URI to be saved.</param>
        /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
        /// <exception cref="ArgumentException">This exception can be due to an invalid parameter.</exception>
        public void SetUri(UriType uriType, string uri)
        {
            ErrorCode error = StickerDataSetUri(_handle, uriType, uri);

            if (error != ErrorCode.None)
            {
                Log.Error(LogTag, "SetUri Failed with error " + error);
                throw ExceptionFactory.CreateException(error);
            }
        }
Ejemplo n.º 24
0
        public Image(Guid imageId, UriType uriPath, Item item)
        {
            if (uriPath == null) throw new ArgumentNullException("uriPath");
            if (item == null) throw new ArgumentNullException("item");
            if (imageId == null) throw new ArgumentNullException("imageId");

            ImageId = imageId;
            UriPath = uriPath;
            Item = item;
            ItemId = item.ItemId;
        }
        // ------------------------------------------------------------------
        #endregion

        #region Private methods.
        // ------------------------------------------------------------------

        /// <summary>
        /// Makes the name of the local file.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="baseUri">The base URI.</param>
        /// <param name="linkType">Type of the link.</param>
        /// <returns></returns>
        public static string MakeLocalFileName(
            Uri uri,
            Uri baseUri,
            UriType linkType)
        {
            Debug.Assert(
                uri.IsAbsoluteUri,
                @"URI must be absolute but is not.");

            // Each URI is unique, use this fact.
            string unique =
                uri.AbsoluteUri.GetHashCode().ToString(@"X8");

            string result;

            if (linkType == UriType.Content)
            {
                if (string.Compare(
                        uri.AbsoluteUri.TrimEnd('/'),
                        baseUri.AbsoluteUri.TrimEnd('/'),
                        true) == 0)
                {
                    result = @"index.html";
                }
                else
                {
                    result = unique +
                             CorrectFileExtension(
                        TryExtractFileExtension(uri));
                }
            }
            else
            {
                Debug.Assert(linkType == UriType.Resource);

                result =
                    unique +
                    CorrectFileExtension(
                        TryExtractFileExtension(uri));
            }

            if (!result.EndsWith(".html"))
            {
                result = @"Resources\" + result;
            }

            Trace.WriteLine(
                string.Format(
                    @"Making local file path '{0}' for URI '{1}'.",
                    result,
                    uri.AbsoluteUri));

            return(result);
        }
Ejemplo n.º 26
0
        public static NavigatorUrl Parse(string str)
        {
            int pos = str.IndexOf(':');

            if (pos < 0)
            {
                throw new ArgumentException("Invalid string syntax: " + str);
            }

            UriType type = str.Substring(0, pos).Trim().ToEnum <UriType>();

            return(new NavigatorUrl(type, str.Substring(pos + 1).Trim()));
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <param name="originalUrl">The original URL.</param>
 /// <param name="uri">The URI.</param>
 /// <param name="baseUri">The base URI.</param>
 /// <param name="folderPath">The folder path.</param>
 /// <param name="baseFolderPath">The base folder path.</param>
 /// <param name="linkType">Type of the link.</param>
 public DownloadedResourceInformation(
     WebSiteDownloaderOptions options,
     string originalUrl,
     Uri uri,
     Uri baseUri,
     DirectoryInfo folderPath,
     DirectoryInfo baseFolderPath,
     UriType linkType)
     :
     base(options, originalUrl, uri, baseUri, linkType)
 {
     _localFolderPath     = folderPath;
     _localBaseFolderPath = baseFolderPath;
 }
Ejemplo n.º 28
0
        public void Add(string url, UriType uriType, UriStatus status)
        {
            if (Contains(url))
            {
                return;
            }
            var item = new UriItem()
            {
                Source = url, Type = uriType, Status = status
            };

            Items.Add(item);
            UrlChanged?.Invoke(item, true);
        }
Ejemplo n.º 29
0
        // ------------------------------------------------------------------
        #endregion

        #region Private methods.
        // ------------------------------------------------------------------

        /// <summary>
        /// Checks the type of the verify link.
        /// </summary>
        /// <param name="absoluteUri">The absolute URI.</param>
        /// <param name="linkType">Type of the link.</param>
        /// <returns></returns>
        private UriType CheckVerifyLinkType(
            Uri absoluteUri,
            UriType linkType)
        {
            if (linkType == UriType.Resource)
            {
                // The original.
                return(linkType);
            }
            else
            {
                if (DoIsProcessableUri(absoluteUri, linkType))
                {
                    // Ensure PDFs don't get parsed.
                    string head = ResourceDownloader.DownloadHead(
                        absoluteUri,
                        _options);

                    if (string.IsNullOrEmpty(head))
                    {
                        return(UriType.Resource);
                    }
                    else
                    {
                        head = head.ToLowerInvariant();

                        if (head.Contains(@"pdf") ||
                            head.Contains(@"application") ||
                            head.Contains(@"image"))
                        {
                            return(UriType.Resource);
                        }
                        else
                        {
                            Debug.Assert(
                                head.Contains(@"text"),
                                @"no text document type but marked as content.");

                            // The original.
                            return(linkType);
                        }
                    }
                }
                else
                {
                    return(UriType.Resource);
                }
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Create a Uri Record from a Uri Type and a Uri
        /// </summary>
        /// <param name="uriType">The Uri type</param>
        /// <param name="uri">A Uri</param>
        public UriRecord(UriType uriType, string uri)
        {
            Header = new RecordHeader()
            {
                TypeNameFormat    = TypeNameFormat.NfcWellKnowType,
                PayloadTypeLength = 1,
                PayloadType       = new byte[1] {
                    0x55
                },
                IdLength = 0,
            };

            _uriType = uriType;
            _uri     = uri;
            SetPayload();
        }
Ejemplo n.º 31
0
        public static string GetUri(UriType type, IParameters parameters)
        {
            string uri;

            switch (type)
            {
            case UriType.MalListQuery:
                uri = "http://myanimelist.net/malappinfo.php?";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
            uri += parameters.GetParamChain();
            return(uri);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Gets collection of RelationshipEndMember as navigation targets along the navigation path from the EntityType object
        /// </summary>
        /// <param name="entityType">The EntityType instance to start with</param>
        /// <param name="navigation">The navigation path</param>
        /// <returns>Collection of navigation targets</returns>
        public static IEnumerable <RelationshipEndMember> GetNavigationStack(EntityType entityType, IEnumerable <string> navigation)
        {
            var result = new List <RelationshipEndMember>();

            EntityType currEntityType = entityType;
            UriType    uriType        = UriType.URI2;

            foreach (var nav in navigation)
            {
                ODataUriItem          curr    = new ODataUriItem(currEntityType, uriType);
                var                   next    = curr.GetItem(nav);
                RelationshipEndMember navRole = (RelationshipEndMember)next.Item;
                result.Add(navRole);
                currEntityType = navRole.GetEntityType();
            }

            return(result);
        }
Ejemplo n.º 33
0
 private static bool DoWantFollowUri(Uri absoluteUri, UriType linkType)
 {
     if (absoluteUri == null || linkType == UriType.Resource)
     {
         return(false);
     }
     else
     {
         if (absoluteUri.Scheme == Uri.UriSchemeHttp || absoluteUri.Scheme == Uri.UriSchemeHttps || absoluteUri.Scheme == Uri.UriSchemeFile)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 34
0
        public static Uri GetBaseUri(UriType uriType, string url = null)
        {
            Uri baseUri;

            switch (uriType)
            {
            case UriType.Api:
                baseUri = new Uri(Configuration.Instance.Settings["appSettings:Nexmo.Url.Api"]);
                break;

            case UriType.Rest:
                baseUri = new Uri(Configuration.Instance.Settings["appSettings:Nexmo.Url.Rest"]);
                break;

            default:
                throw new Exception("Unknown Uri Type Detected");
            }
            return(string.IsNullOrEmpty(url) ? baseUri : new Uri(baseUri, url));
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Checks whether the given name is a HTML element (=tag) with
        /// a contained link. If true, linkAttributeNames contains a list
        /// of all attributes that are links.
        /// </summary>
        /// <returns>Returns true, if it is a link element,
        /// false otherwise.</returns>
        private static bool IsLinkElement(
            string name,
            out string[] linkAttributeNames,
            out UriType linkType)
        {
            foreach (LinkElement e in LinkElement.LinkElements)
            {
                if (string.Compare(name, e.Name, true) == 0)
                {
                    linkAttributeNames = e.Attributes;
                    linkType           = e.LinkType;
                    return(true);
                }
            }

            linkAttributeNames = null;
            linkType           = UriType.Resource;
            return(false);
        }
Ejemplo n.º 36
0
        // ------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the 
        /// <see cref="UriResourceInformation"/> class.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <param name="originalUrl">The original URL.</param>
        /// <param name="uri">The URI.</param>
        /// <param name="baseUri">The base URI.</param>
        /// <param name="linkType">Type of the link.</param>
        public UriResourceInformation(
            WebSiteDownloaderOptions options,
            string originalUrl,
            Uri uri,
            Uri baseUri,
            UriType linkType,
            Uri parentUri,
            Int32 index)
        {
            _options = options;
            _originalUrl = originalUrl;
            _baseUri = baseUri;
            _parentUri = parentUri;
            _index = index;

            uri = new Uri(CleanupUrl(uri.OriginalString), UriKind.RelativeOrAbsolute);

            if (Uri.IsWellFormedUriString(uri.OriginalString, UriKind.Absolute))
            {
                _absoluteUri = uri;
                _relativeUri = null;
            }
            else if (Uri.IsWellFormedUriString(uri.OriginalString, UriKind.Relative))
            {
                _absoluteUri = MakeAbsoluteUri(baseUri, uri);
                _relativeUri = uri;
            }
            else
            {
                if (originalUrl.StartsWith(@"#"))
                {
                    _absoluteUri = null;
                    _relativeUri = new Uri(originalUrl, UriKind.RelativeOrAbsolute);
                }
                else
                {
                    _absoluteUri = MakeAbsoluteUri(baseUri, uri);
                    _relativeUri = uri;
                }
            }

            _linkType = linkType;
        }
Ejemplo n.º 37
0
 public ODataUriItem(MetadataItem item_, UriType uriType_)
 {
     this.Item = item_;
     this.uriType = uriType_;
 }
Ejemplo n.º 38
0
 internal static bool UriTypeHasFacet(UriType type, UriTypeFacets facet)
 {
     return ((uint)type & (uint)facet) != 0;
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Initializes a new instance of the 
 /// <see cref="UriResourceInformation"/> class.
 /// </summary>
 /// <param name="copyFrom">The copy from.</param>
 public UriResourceInformation(
     UriResourceInformation copyFrom)
 {
     _options = copyFrom._options;
     _originalUrl = copyFrom._originalUrl;
     _relativeUri = copyFrom._relativeUri;
     _baseUri = copyFrom._baseUri;
     _absoluteUri = copyFrom._absoluteUri;
     _linkType = copyFrom._linkType;
 }
Ejemplo n.º 40
0
 public NavigatorUrl( UriType type, string url )
     : this(type, url, null)
 {
 }
Ejemplo n.º 41
0
 public NavigatorUrl( UriType type, Uri url )
     : this(type, url.ToString())
 {
     myUrl = url;
 }
Ejemplo n.º 42
0
        /// <summary>
        /// Gets MetadataItem object for URI relative path under the specified EntityContainer instance 
        /// </summary>
        /// <param name="container">The EntityContainer instance</param>
        /// <param name="pathSegment">The URI relative path</param>
        /// <param name="uriType">Output parameter of UriType value</param>
        /// <returns>The MetadataItem instance if one is found; null otherwise</returns>
        private static MetadataItem GetTargetType(EntityContainer container, IEnumerable<string> pathSegment, ref UriType uriType)
        {
            ODataUriItem curr = new ODataUriItem(container, UriType.URI_Container);
            foreach (var segment in pathSegment)
            {
                // to normalize first segment
                string segmentKey;
                string segmentCore = ResourcePathHelper.ParseSegment(segment, out segmentKey);
                ODataUriItem subItem = curr.GetItem(segmentCore);
                if (subItem == null)
                {
                    uriType = UriType.URIUNKNOWN;
                    return null;
                }

                if (subItem.uriType == UriType.URI1 && !string.IsNullOrEmpty(segmentKey))
                {
                    subItem = new ODataUriItem(((EntitySet)subItem.Item).ElementType, UriType.URI2);
                }

                curr = subItem;
            }

            uriType = curr.uriType;
            return curr.Item;
        }
Ejemplo n.º 43
0
        /// <summary>
        /// Gets the target MetadataItem for sequence of uri path segments
        /// </summary>
        /// <param name="edmxHelper">The EdmxHelper class object</param>
        /// <param name="pathSegment">The sequence of uri path segment</param>
        /// <param name="uriType">Output parameter of UriType</param>
        /// <returns>The target MetadataItem for the uri path segments; or null if a meaningful one cannot be derived</returns>
        public static MetadataItem GetTargetType(this EdmxHelper edmxHelper, IEnumerable<string> pathSegment, out UriType uriType)
        {
            EntityContainer currContainer;
            string leadSegment = pathSegment.First();
            var containers = from c in edmxHelper.containers where c.Name.Equals(leadSegment, System.StringComparison.Ordinal) select c;
            if (!containers.Any())
            {
                // get the default container
                currContainer = edmxHelper.containerDefault;
            }
            else
            {
                currContainer = containers.First();
                pathSegment = pathSegment.Skip(1);
            }

            UriType uType = UriType.URIUNKNOWN;
            var result = GetTargetType(currContainer, pathSegment, ref uType);
            uriType = uType;
            return result;
        }
Ejemplo n.º 44
0
		/// <summary>
		/// Checks whether the given name is a HTML element (=tag) with
		/// a contained link. If true, linkAttributeNames contains a list
		/// of all attributes that are links.
		/// </summary>
		/// <returns>Returns true, if it is a link element,
		/// false otherwise.</returns>
		private static bool IsLinkElement(
			string name,
			out string[] linkAttributeNames,
			out UriType linkType )
		{
			foreach ( LinkElement e in LinkElement.LinkElements )
			{
				if ( string.Compare( name, e.Name, true ) == 0 )
				{
					linkAttributeNames = e.Attributes;
					linkType = e.LinkType;
					return true;
				}
			}

			linkAttributeNames = null;
			linkType = UriType.Resource;
			return false;
		}
Ejemplo n.º 45
0
		// ------------------------------------------------------------------
		#endregion

		#region Private methods.
		// ------------------------------------------------------------------

		/// <summary>
		/// Checks the type of the verify link.
		/// </summary>
		/// <param name="absoluteUri">The absolute URI.</param>
		/// <param name="linkType">Type of the link.</param>
		/// <returns></returns>
		private UriType CheckVerifyLinkType(
			Uri absoluteUri,
			UriType linkType )
		{
			if ( linkType == UriType.Resource )
			{
				// The original.
				return linkType;
			}
			else
			{
				if ( DoIsProcessableUri( absoluteUri, linkType ) )
				{
					// Ensure PDFs don't get parsed.
					string head = ResourceDownloader.DownloadHead(
						absoluteUri,
						_options );

					if ( string.IsNullOrEmpty( head ) )
					{
						return UriType.Resource;
					}
					else
					{
						head = head.ToLowerInvariant();

						if ( head.Contains( @"pdf" ) ||
							head.Contains( @"application" ) ||
							head.Contains( @"image" ) )
						{
							return UriType.Resource;
						}
						else
						{
							Debug.Assert(
								head.Contains( @"text" ),
								@"no text document type but marked as content." );

							// The original.
							return linkType;
						}
					}
				}
				else
				{
					return UriType.Resource;
				}
			}
		}
Ejemplo n.º 46
0
 /// <summary>
 /// 获取位图
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="uriType"></param>
 /// <returns></returns>
 public static BitmapImage GetImage(string uri, UriType uriType)
 {
     switch (uriType) {
         case UriType.Default:
             return new BitmapImage(new Uri(uri, UriKind.Relative)) { CreateOptions = BitmapCreateOptions.None };
         case UriType.Project:
             return new BitmapImage(new Uri(ProjectPath(uri), UriKind.Relative)) { CreateOptions = BitmapCreateOptions.None };
         case UriType.Web:
             return new BitmapImage(new Uri(WebPath(uri), UriKind.Relative)) { CreateOptions = BitmapCreateOptions.None };
         default:
             return null;
     }
 }
Ejemplo n.º 47
0
		/// <summary>
		/// Decides whether to follow an URI.
		/// </summary>
		/// <param name="absoluteUri">The absolute URI.</param>
		/// <param name="linkType">Type of the link.</param>
		/// <returns></returns>
		private static bool DoWantFollowUri(
			Uri absoluteUri,
			UriType linkType )
		{
			if ( absoluteUri == null ||
				linkType == UriType.Resource )
			{
				return false;
			}
			else
			{
				if ( absoluteUri.Scheme == Uri.UriSchemeHttp ||
					absoluteUri.Scheme == Uri.UriSchemeHttps ||
					absoluteUri.Scheme == Uri.UriSchemeFile )
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		}
Ejemplo n.º 48
0
		/// <summary>
		/// Does the is processable URI.
		/// </summary>
		/// <param name="absoluteUri">The absolute URI.</param>
		/// <param name="linkType">Type of the link.</param>
		/// <returns></returns>
		private static bool DoIsProcessableUri(
			Uri absoluteUri,
			UriType linkType )
		{
			return
				absoluteUri != null &&
				(DoWantFollowUri( absoluteUri, linkType ) ||
				DoIsResourceUri( absoluteUri ));
		}