Пример #1
0
 /// <summary>
 /// Copies the file at the given path to the server, which could be anywhere from
 /// the local machine to a remote one.
 /// </summary>
 /// <param name="virtualPath">The virtual path.</param>
 public void CopyToServer(VirtualPath virtualPath)
 {
     var fromFullPath = _pathFactory.CreateShadwoFullPath4Write(virtualPath);
       byte[] infoBytes = _serverProxy.Get(new Uri("/BitTorrent/Info"));
       var infoObj = XmlUtil.FromXml<BitTorrentServiceInfo>(
     Encoding.UTF8.GetString(infoBytes));
       if (infoObj.ServerCacheUri.IsLoopback) {
     // Server on the same machine, we copy from file system.
     var relativePath = virtualPath.PathString.Substring(
       virtualPath.PathString.IndexOf(Path.DirectorySeparatorChar, 1));
     var toFullPath = UriUtil.CombinePaths(infoObj.ServerCacheUri.LocalPath,
       new Uri(relativePath, UriKind.Relative));
     IOUtil.PrepareParentDirForPath(toFullPath);
     if (SysEnvironment.OSVersion == OS.Unix) {
       // In case of Unix, we actually use symbolic link instead of copying.
       var symlink = new UnixSymbolicLinkInfo(toFullPath);
       Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format(
     "Creating Symlink: {0} -> {1}", toFullPath, fromFullPath.PathString));
       // Linking toPath to fromPath == Copy fromPath to toPath.
       symlink.CreateSymbolicLinkTo(fromFullPath.PathString);
     } else {
       throw new NotImplementedException("Only Unix hosts are currently supported.");
     }
       } else {
     throw new NotImplementedException("Only local machine is currently supported.");
       }
 }
Пример #2
0
 public OpenFileInfo(IntPtr fileHandle, VirtualPath virtualPath, 
     VirtualFile virtualFile, FileAccess fileAccess)
 {
     _fileHandle = fileHandle;
       _virtualPath = virtualPath;
       _virtualFile = virtualFile;
       _fileAccess = fileAccess;
 }
Пример #3
0
 public ShadowFullPath CreateShadowFullPath(VirtualPath vp, FilesysOp op)
 {
     if (op == FilesysOp.Read) {
     return new ShadowMetaFullPath(_shadowDirPath, vp);
       } else {
     return new ShadowFullPath(_shadowDirPath, vp);
       }
 }
Пример #4
0
 /// <summary>
 /// Gets the length of the physical file which is read from the virtual file.
 /// </summary>
 /// <param name="virtualPath">The virtual path to the virtual file.</param>
 /// <returns>The file size.</returns>
 public long GetFileLength(VirtualPath virtualPath)
 {
     var shadowPath = _pathFactory.CreateShadowFullPath4Read(virtualPath);
       if (File.Exists(shadowPath.PathString)) {
     var vf = XmlUtil.ReadXml<VirtualFile>(shadowPath.PathString);
     return vf.FileSize;
       } else {
     throw new ArgumentException("Virtual file not exists.");
       }
 }
Пример #5
0
 internal ShadowMetaFullPath(string shadowDirPath, VirtualPath vp)
     : base(Path.Combine(shadowDirPath, MetaDirName), vp)
 {
 }
Пример #6
0
   internal ShadowFullPath(string shadowDirPath, VirtualPath vp)
       : base(Path.Combine(shadowDirPath, vp.PathString.TrimStart(
 Path.DirectorySeparatorChar)))
   {
   }
Пример #7
0
 /// <summary>
 /// Updates the file size in virtual file.
 /// </summary>
 void UpdateFileSizeInVirtualFile(VirtualPath vp)
 {
     ShadowFullPath readPath = _pathFactory.CreateShadowFullPath4Read(vp);
       ShadowFullPath writePath = _pathFactory.CreateShadwoFullPath4Write(vp);
       var virtualFile = XmlUtil.ReadXml<VirtualFile>(readPath.PathString);
       // Get the size from the real file.
       long fileSize = new FileInfo(writePath.PathString).Length;
       virtualFile.FileSize = fileSize;
       XmlUtil.WriteXml<VirtualFile>(virtualFile, readPath.PathString);
 }
Пример #8
0
        /// <summary>
        /// Creates a virtual file with the Physical location information in it.
        /// </summary>
        /// <param name="vp">The vp.</param>
        VirtualFile CreateAndWriteVirtualFile(VirtualPath vp)
        {
            ShadowFullPath readPath = _pathFactory.CreateShadowFullPath4Read(vp);
              ShadowFullPath writePath = _pathFactory.CreateShadwoFullPath4Write(vp);
              var virtualFile = new VirtualFile() {
            PhysicalUri = new Uri(writePath.PathString)
              };
              IOUtil.PrepareParentDirForPath(readPath.PathString);
              XmlUtil.WriteXml<VirtualFile>(virtualFile, readPath.PathString);

              Logger.WriteLineIf(LogLevel.Verbose, _log_props,
            string.Format("A virtual file is created at {0}", readPath.PathString));
              return virtualFile;
        }
Пример #9
0
 /// <summary>
 /// Reads the virtual file  from the specified path.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <returns></returns>
 public VirtualFile ReadVirtualFile(VirtualPath path)
 {
     var shadowPath = _pathFactory.CreateShadowFullPath4Read(path);
       if (File.Exists(shadowPath.PathString)) {
     var vf = XmlUtil.ReadXml<VirtualFile>(shadowPath.PathString);
     return vf;
       } else {
     // This is an erroneous situation where you think the file exists but no virtual file
     // presents.
     throw new Exception();
       }
 }
Пример #10
0
 public ShadowFullPath CreateShadwoFullPath4Write(VirtualPath vp)
 {
     return CreateShadowFullPath(vp, FilesysOp.Write);
 }
Пример #11
0
 public ShadowFullPath CreateShadowFullPath4Read(VirtualPath vp)
 {
     return CreateShadowFullPath(vp, FilesysOp.Read);
 }
Пример #12
0
 internal ShadowMetaFullPath(string shadowDirPath, VirtualPath vp)
     : base(Path.Combine(shadowDirPath, MetaDirName), vp)
 {
 }
Пример #13
0
 internal ShadowFullPath(string shadowDirPath, VirtualPath vp)
     : base(
         Path.Combine(shadowDirPath, vp.PathString.TrimStart(
                          Path.DirectorySeparatorChar)))
 {
 }