Ejemplo n.º 1
0
        public void TestLocalUrl_CheckValid()
        {
            VideoInfo[] vInfos = new VideoInfo[]
            {
                new VideoInfo("CCTV1_50BAD15900010301", 1, "Name1"),
                new VideoInfo("CCTV1_50BAD15900010302", 1),
            };
            LocalUrl url = new LocalUrl(@"", vInfos);

            ExceptionManager.CheckInvalidOperationException(url.CheckValid);
            Assert.AreNotEqual("", url.ToString());
        }
Ejemplo n.º 2
0
        public void TestLocalUrl()
        {
            VideoInfo[] vInfos = new VideoInfo[]
            {
                new VideoInfo("video1", 2, "Name1"),
                new VideoInfo("video2", 2),
            };
            IUrl   url       = new LocalUrl(@"d:\path", vInfos);
            string urlString = url.ToString();

            Console.WriteLine(urlString);
            var urlNew = LocalUrl.Parse(urlString);

            Assert.AreEqual(url.LocalPath, urlNew.LocalPath);
            Assert.AreEqual(url.VideoInfos.Length, urlNew.VideoInfos.Length);
        }
Ejemplo n.º 3
0
        internal static async Task <Uri> Ping(Uri urlToPing)
        {
            Uri localUriPing = new Uri(urlToPing, "/command/ping");

            using (HttpClient client = new HttpClient())
                using (HttpRequestMessage request = new HttpRequestMessage())
                {
                    request.Method     = HttpMethod.Post;
                    request.RequestUri = localUriPing;
                    HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);

                    string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    LocalUrl localUrl = new LocalUrl().FromJson(responseBody);
                    return(new Uri(localUrl.Url));
                }
        }
            private void HandleRequest(StreamReader r, StreamWriter w)
            {
                var request = r.ReadLine();

                if (request == null)
                {
                    return;
                }
                var tokens = request.Split(' ');

                Verb        = tokens[0].ToUpper();
                LocalUrl    = tokens[1];
                HttpVersion = tokens[2];
                ReadHeader(r);
                var file = Path.Combine(Path.GetFullPath(_localPath), LocalUrl.TrimStart('/'));
                var text = File.ReadAllText(file);

                Success(w, Path.GetExtension(LocalUrl).TrimStart('.'));
                w.Write(text);
            }
Ejemplo n.º 5
0
 private void initSettings(string[] args)
 {
     if (args.Length > 0)
     {
         string url = args[0];
         try
         {
             IUrl ui = null;
             try
             {
                 ui = LocalUrl.Parse(url);
             }
             catch { }
             if (ui == null)
             {
                 try
                 {
                     ui = RemoteUrl.Parse(url);
                 }
                 catch { }
             }
             if (ui != null)
             {
                 return;
             }
             if (!tryToRemote(url))
             {
                 throw new ErrorMessageException("URL未能正确解析!");
             }
         }
         catch (ErrorMessageException ae)
         {
             Common.Log.Logger.Default.Error(ae);
             Util.DialogUtil.ShowError(ae.Message);
         }
     }
 }