src/Foundation/Net/Gimela.Net.Http/Resources/EmbeddedResourceLoader.cs
/// <summary>
/// Tries to load file by using previously added paths.
/// </summary>
/// <param name="uriPath">Uri path including file name</param>
/// <returns></returns>
Tries to load file by using previously added paths.
Tries to load file by using previously added paths .
private bool LoadMappingFromPath(string uriPath)
    {
      uriPath = uriPath.ToLower();
      foreach (var pathMapping in _pathMappings)
      {
        if (!uriPath.StartsWith(pathMapping.UriPath))
          continue;
        int pos = uriPath.LastIndexOf('/');
        string fileName = uriPath.Substring(pos + 1);
        string ns = pathMapping.RootNameSpace + '.' +
                    uriPath.Remove(0, pathMapping.UriPath.Length).Replace('/', '.');
        foreach (var resourceName in pathMapping.Resources)
        {
          if (!resourceName.Equals(ns, StringComparison.OrdinalIgnoreCase))
            continue;
          ns = resourceName;
          pathMapping.Resources.Remove(resourceName);
          break;
        }
        Stream stream = pathMapping.Assembly.GetManifestResourceStream(ns);
        if (stream == null)
          continue;
        var mapping = new Mapping
                          {
                            Assembly = pathMapping.Assembly,
                            FileName = fileName,
                            FullResourceName = ns,
                            TypeExtension = Path.GetExtension(ns),
                            UriPath = uriPath.ToLower()
                          };
        lock (_mappings)
        {
          if (!_mappings.ContainsKey(uriPath))
            _mappings[uriPath] = mapping;
        }
        return true;
      }
      return false;
    }
private bool LoadMappingFromPath ( string uriPath ) { uriPath = uriPath . ToLower ( ) ; foreach ( var pathMapping in _pathMappings ) { if ( ! uriPath . StartsWith ( pathMapping . UriPath ) ) continue ; int pos = uriPath . LastIndexOf ( ' ' ) ; string fileName = uriPath . Substring ( pos + 1 ) ; string ns = pathMapping . RootNameSpace + ' ' + uriPath . Remove ( 0 , pathMapping . UriPath . Length ) . Replace ( ' ' , ' ' ) ; foreach ( var resourceName in pathMapping . Resources ) { if ( ! resourceName . Equals ( ns , StringComparison . OrdinalIgnoreCase ) ) continue ; ns = resourceName ; pathMapping . Resources . Remove ( resourceName ) ; break ; } Stream stream = pathMapping . Assembly . GetManifestResourceStream ( ns ) ; if ( stream == null ) continue ; var mapping = new Mapping { Assembly = pathMapping . Assembly , FileName = fileName , FullResourceName = ns , TypeExtension = Path . GetExtension ( ns ) , UriPath = uriPath . ToLower ( ) } ; lock ( _mappings ) { if ( ! _mappings . ContainsKey ( uriPath ) ) _mappings [ uriPath ] = mapping ; } return true ; } return false ; }
Tries to load file by using previously added paths.
Tries to load file by using previously added paths .
// create namespace  // try to find the resource using our small index // no need for it in the index, since a correct // mapping is created below. // try to load it.
None
uriPath
string
Uri path including file name
Uri path including file name