Ejemplo n.º 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.");
            }
        }
Ejemplo n.º 2
0
        public override void Run()
        {
            // Лучше всего пользоваться сервисным объектом (реальным субъектом) через прокси. С тем условием, что объект создаётся внутри.
            System.Console.WriteLine("Создание сервера внутри прокси");
            var serverProxy = new ServerProxy();

            //serverProxy.GetFast(); // NullReferenceException

            System.Console.WriteLine(serverProxy.Get());
            serverProxy.Post("Тестовые параметры");

            // Но ничего не мешает нам его создать заранее
            System.Console.WriteLine("--- --- ---");
            System.Console.WriteLine("Создание сервера заранее");
            var server       = new Server();
            var serverProxy2 = new ServerProxy(server);

            System.Console.WriteLine(serverProxy2.GetFast());
            serverProxy2.Post("Тестовые параметры");
        }