Esempio n. 1
0
 Generic.IEnumerator<Dom.Node> LoadAll(Uri.Path path)
 {
     string platformPath = System.IO.Path.GetFullPath(path.FolderPath.PlatformPath);
     if (System.IO.Directory.Exists(platformPath))
         foreach (string file in System.IO.Directory.GetFiles(platformPath, path.Last.Head).Sort())
         {
             Dom.Document document = Dom.Document.Open(Uri.Locator.FromPlatformPath(file));
             if (document.NotNull() && document.Root.NotNull())
                 yield return document.Root;
         }
 }
Esempio n. 2
0
		bool Start(Uri.Endpoint endPoint, Action<Action> run)
		{
			bool result;
			if (result = (this.tcpListener = this.Connect(endPoint)).NotNull())
			{
				this.Endpoint = endPoint;
				this.tcpListener.Start();
				run(() => 
				{
					try
					{
						this.OnConnect(Connection.Connect(this.tcpListener.AcceptTcpClient()));
					}
					catch (System.Net.Sockets.SocketException)
					{
						if (this.listener.NotNull())
							this.listener.Abort();
					}
				});
			}
			return result;
		}
Esempio n. 3
0
 Generic.IEnumerator<Dom.Node> LoadAll(Uri.Locator locator)
 {
     return (locator.Scheme == "file" && locator.Authority == null) ? this.LoadAll(locator.Path) : this.Load(locator);
 }
Esempio n. 4
0
 Generic.IEnumerator<Dom.Node> Load(Uri.Locator locator)
 {
     Dom.Document document = Dom.Document.Open(locator);
     if (document.NotNull() && document.Root.NotNull())
         yield return document.Root;
 }
Esempio n. 5
0
		public bool Save(Uri.Locator resource)
		{
			using (IO.ICharacterWriter writer = IO.CharacterWriter.Create(resource))
				return this.Save(writer);
		}
Esempio n. 6
0
		public Link(Uri.Locator locator) :
			this()
		{
			this.Locator = locator;
		}
Esempio n. 7
0
		public static IByteDevice Open(System.Reflection.Assembly assembly, Uri.Path resource)
		{
			return new ByteDevice(assembly.GetManifestResourceStream(assembly.GetName().Name + ((string)resource).Replace('/', '.'))) {
				Resource = new Uri.Locator("assembly", assembly.GetName().Name, resource),
				FixedLength = true
			};
		}
Esempio n. 8
0
		public static IByteDevice Open(Uri.Locator input, Uri.Locator output)
		{
			return ByteDeviceCombiner.Open(ByteDevice.Open(input), ByteDevice.Create(output));
		}
Esempio n. 9
0
		public static ICharacterDevice Create(Uri.Locator resource)
		{
			return CharacterDevice.Open(ByteDevice.Create(resource));
		}
Esempio n. 10
0
		public static bool Run(Action<Connection> connected, Uri.Endpoint endPoint)
		{
			bool result;
			using (Server server = new Server(connected))
				result = server.Run(endPoint);
			return result;
		}
Esempio n. 11
0
		public bool Start(Uri.Endpoint endPoint)
		{
			return this.Start(endPoint, action => this.listener = Parallel.RepeatThread.Start("TcpServer", action));
		}
Esempio n. 12
0
		public static Server Start(Action<Connection> connected, Uri.Endpoint endPoint)
		{
			Server result = new Server(connected);
			if (!result.Start(endPoint))
			{
				result.Dispose();
				result = null;
			}
			return result;
		}
Esempio n. 13
0
		System.Net.Sockets.TcpListener Connect(Uri.Endpoint endPoint)
		{
			System.Net.Sockets.TcpListener result = null;
			if (endPoint.Port.HasValue)
			{
				string host = endPoint.Host;
				if (host.NotEmpty())
				{
					System.Net.IPAddress address;
					if (System.Net.IPAddress.TryParse(host, out address))
						result = new System.Net.Sockets.TcpListener(address, (int)endPoint.Port.Value);
				}
				else
					result = new System.Net.Sockets.TcpListener(IPAddress.Any, (int)endPoint.Port.Value);
			}
			return result;
		}
Esempio n. 14
0
		public bool Run(Uri.Endpoint endPoint)
		{
			return this.Start(endPoint, action => this.listener = Parallel.RepeatThread.Run(action));
		}
Esempio n. 15
0
		protected Device(System.IO.Stream stream, Uri.Locator resource)
		{
			this.stream = stream;
			this.Resource = resource;
			this.Encoding = System.Text.Encoding.UTF8;
		}
Esempio n. 16
0
		public static Parser Open(System.Reflection.Assembly assembly, Uri.Path path)
		{
			return Parser.Open(IO.ByteDevice.Open(assembly, path));
		}
Esempio n. 17
0
		public static IByteDevice Open(Uri.Locator resource)
		{
			return ByteDevice.Open(resource, System.IO.FileMode.Open);
		}
Esempio n. 18
0
		public static Parser Open(Uri.Locator resource)
		{
			return Parser.Open(IO.ByteDevice.Open(resource));
		}
Esempio n. 19
0
		static IByteDevice Open(Uri.Locator resource, System.IO.FileMode mode)
		{
			IByteDevice result = null;
			if (resource.NotNull())
				switch (resource.Scheme)
				{
					case "assembly":
						result = resource.Authority == "" ? ByteDevice.Open(System.Reflection.Assembly.GetEntryAssembly(), resource.Path) : ByteDevice.Open(System.Reflection.Assembly.Load(new System.Reflection.AssemblyName(resource.Authority)), resource.Path);
						break;
					case "file":
						try
						{
							System.IO.FileStream stream = System.IO.File.Open(System.IO.Path.GetFullPath(resource.PlatformPath), mode, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
							if (stream.NotNull())
								result = new ByteDevice(stream) { Resource = resource, FixedLength = true }; 
						}
						catch (System.IO.DirectoryNotFoundException)
						{
							result = null;
						}
						catch (System.IO.FileNotFoundException)
						{
							result = null;
						}
						break;
					case "http":
					case "https":
						if (mode == System.IO.FileMode.Open)
						{
							try
							{
								using (System.Net.WebClient client = new System.Net.WebClient())
									result = new ByteDevice(new System.IO.MemoryStream(client.DownloadData(resource))) {
										Resource = resource,
										FixedLength = true
									};
							}
							catch (System.Net.WebException)
							{
								result = null;
							}
						}
						break;
				}
			return result;
		}
Esempio n. 20
0
 public static IDisposable Listen(object root, Uri.Locator resource)
 {
     IDisposable result = null;
     switch (resource.Scheme)
     {
         case "file":
             result = Parser.Read(root, resource);
             break;
         case "telnet":
             result = IO.Net.Tcp.ThreadedServer.Start(connection => new Parser(root, true, new Cli.VT100(new IO.Net.Telnet.Server(connection.ByteDevice))).Read(), resource.Authority.Endpoint);
             break;
         case "tcp":
             result = IO.Net.Tcp.ThreadedServer.Start(connection =>
             {
                 Cli.Terminal terminal = Cli.Terminal.Open(connection.ByteDevice);
                 if (terminal.NotNull())
                 {
                     terminal.NewLine = new char[] { '\r', '\n' };
                     new Parser(root, false, terminal).Read();
                 }
             }, resource.Authority.Endpoint);
             break;
         case "console":
             result = Parallel.Thread.Start("console", () => new Parser(root, true, new Cli.ConsoleTerminal()).Read());
             break;
         case "stdio":
             result = Parallel.Thread.Start("stdio", () => new Parser(root, false, Cli.Terminal.Open(IO.ByteDeviceCombiner.Open(Console.OpenStandardInput(), Console.OpenStandardOutput()))).Read());
             break;
     }
     return result;
 }
Esempio n. 21
0
		public static IByteDevice Create(Uri.Locator resource)
		{
			IByteDevice result = ByteDevice.Open(resource, System.IO.FileMode.Create);
			if (result.IsNull() && resource.NotNull())
			{
				System.IO.Directory.CreateDirectory(resource.Path.FolderPath.PlatformPath);
				result = ByteDevice.Open(resource, System.IO.FileMode.Create);
			}
			return result;
		}
Esempio n. 22
0
 public static Parser Read(object root, Uri.Locator resource)
 {
     return Parser.Read(root, IO.CharacterDevice.Open(IO.ByteDevice.Open(resource, null)));
 }
Esempio n. 23
0
		public static Response MovedPermanently(Uri.Locator location)
		{
			return new Response() { Status = Status.MovedPermanently, Location = location };
		}
Esempio n. 24
0
		public static Client Open(Uri.Locator url)
		{
			Client result = null;
			System.Net.HttpWebRequest backendRequest = System.Net.WebRequest.Create(url) as System.Net.HttpWebRequest;
			if (backendRequest.NotNull())
			{
				backendRequest.Credentials = url.Authority.User.NotNull() && url.Authority.User.Name.NotEmpty() && url.Authority.User.Password.NotEmpty() ? new System.Net.NetworkCredential(url.Authority.User.Name, url.Authority.User.Password) : null;
				System.Net.HttpWebResponse backendResponse = null;
				try
				{
					backendResponse = backendRequest.GetResponse() as System.Net.HttpWebResponse;
				}
				catch (System.Net.WebException ex)
				{
					backendResponse = ex.Response as System.Net.HttpWebResponse;
				}
				if (backendResponse.NotNull())
					result = new Client(backendRequest, backendResponse);
			}
			return result;
		}