file360

Log | Files | Refs

UriMapper.cs (2740B)


      1 using System;
      2 using System.Collections.Generic;
      3 using System.IO;
      4 using System.Linq;
      5 using System.Text;
      6 using System.Threading.Tasks;
      7 using System.Windows;
      8 using System.Windows.Navigation;
      9 using Windows.Phone.Storage.SharedAccess;
     10 
     11 namespace WindowsPhoneFileandURIAssociationDemo
     12 {
     13     class UriMapper : UriMapperBase
     14     {
     15         public override Uri MapUri(Uri uri)
     16         {
     17             string uriToLaunch = uri.ToString();
     18 
     19             // File association launch
     20             if (uriToLaunch.Contains("/FileTypeAssociation"))
     21             {
     22                 
     23                 int fileIDIndex = uriToLaunch.IndexOf("fileToken=") + "fileToken=".Length;
     24                 string fileID = uriToLaunch.Substring(fileIDIndex);
     25 
     26                 // Get the file name.
     27                 string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
     28 
     29                 // Get the file extension.
     30                 string incomingFileType = Path.GetExtension(incomingFileName);
     31 
     32                 // Map the file extension to different pages.
     33                 switch (incomingFileType)
     34                 {
     35                     case ".pdf":
     36                         return new Uri("/EBookReader.xaml?fileToken=" + fileID, UriKind.Relative);
     37                     case ".svg":
     38                         return new Uri("/VideoPlayer.xaml?fileToken=" + fileID, UriKind.Relative);
     39                     case ".mkv":
     40                         return new Uri("/VideoPlayer.xaml?fileToken=" + fileID, UriKind.Relative);
     41                     case ".rar":
     42                         return new Uri("/VideoPlayer.xaml?fileToken=" + fileID, UriKind.Relative);
     43                     case ".csv":
     44                         return new Uri("/EBookReader.xaml?fileToken=" + fileID, UriKind.Relative);
     45                     case ".avi":
     46                         return new Uri("/EBookReader.xaml?fileToken=" + fileID, UriKind.Relative);
     47                     case ".7z":
     48                         return new Uri("/EBookReader.xaml?fileToken=" + fileID, UriKind.Relative);
     49                     default:
     50                         return new Uri("/MainPage.xaml", UriKind.Relative);
     51                 }
     52             }
     53             else if (System.Net.HttpUtility.UrlDecode(uriToLaunch).Contains("f360:ShowURIPage?UniqueID="))
     54             {
     55                 string uniqueId = uriToLaunch.Substring(System.Net.HttpUtility.UrlDecode(uriToLaunch).IndexOf("UniqueID=") + "UniqueID=".Length);
     56 
     57                 // Map the request to URIScheme Landing page URISchemeFooBarLandingPage.xaml
     58                 return new Uri("/URISchemeExtensionsLandingPage.xaml?UniqueID=" + uniqueId, UriKind.Relative);
     59 
     60             }
     61             // Otherwise perform normal launch.
     62             return uri;
     63         }
     64 
     65     }
     66 }