1 //==========================================================================
4 // Summary: Implements Helper internal class for transmission over HTTP.
6 // Classes: internal HttpHelper
9 // Ahmad Tantawy popsito82@hotmail.com
10 // Ahmad Kadry kadrianoz@hotmail.com
11 // Hussein Mehanna hussein_mehanna@hotmail.com
13 //==========================================================================
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 using System.Text.RegularExpressions;
42 namespace System.Runtime.Remoting.Channels.Http
44 internal class HttpHelper
46 public static string Parse(string URL , out string ObjectURI)
51 string ChannelURI = null;
54 if(StartsWithHttp(URL))
56 Pos = URL.IndexOf("/",7);
59 ObjectURI = URL.Substring(Pos);
60 ChannelURI = URL.Substring(0, Pos);
62 else ChannelURI = URL;
68 public static bool StartsWithHttp(string URL)
70 if(URL.StartsWith("http://"))
76 public static void CopyStream (Stream inStream, Stream outStream)
78 byte[] buffer = new byte [1024];
81 while ((nr = inStream.Read (buffer, 0, buffer.Length)) > 0)
82 outStream.Write (buffer, 0, nr);
86 if (outStream.CanSeek)
87 outStream.Seek (0,SeekOrigin.Begin);
90 public static String GetHostName()
92 string hostName = Dns.GetHostName();
96 throw new ArgumentNullException("hostName");
102 public static String GetMachineName()
105 String machineName = GetHostName();
106 if (machineName != null)
107 machineName= Dns.GetHostByName(machineName).HostName;
109 if (machineName== null)
111 throw new ArgumentNullException("machine");