Пример #1
0
 public override void Close()
 {
     if (!leaveOpen)
     {
         try
         {
             WriteStream.Close();
         }
         finally
         {
             ReadStream.Close();
         }
     }
 }
Пример #2
0
        public virtual void Close()
        {
            if (ReadStream != null)
            {
                ReadStream.Flush();
                ReadStream.Close();
            }
            if (WriteStream != null)
            {
                WriteStream.Flush();
                WriteStream.Close();
            }

            if (Socket != null)
            {
                Socket.Close();
            }
        }
Пример #3
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         closedCancelSource.Cancel();
         if (!leaveOpen)
         {
             if (WriteStream != null)
             {
                 WriteStream.Close();
             }
             if (ReadStream != null)
             {
                 ReadStream.Close();
             }
         }
     }
     base.Dispose(disposing);
 }
Пример #4
0
 public async Task CloseAsync(CancellationToken cancel_token)
 {
     if (!closedCancelSource.IsCancellationRequested)
     {
         writeBuffer.CloseWrite();
         readBuffer.CloseRead();
         try {
             await Task.WhenAll(writeTask, readTask).ConfigureAwait(false);
         }
         catch (Exception) {
         }
         closedCancelSource.Cancel();
         if (WriteStream != null)
         {
             WriteStream.Close();
         }
         if (ReadStream != null)
         {
             ReadStream.Close();
         }
     }
     Close();
 }
Пример #5
0
 protected override void Dispose(bool disposing)
 {
     if (disposing && !closedCancelSource.IsCancellationRequested)
     {
         writeBuffer.CloseWrite();
         readBuffer.CloseRead();
         try {
             Task.WhenAll(writeTask, readTask).Wait();
         }
         catch (AggregateException) {
         }
         closedCancelSource.Cancel();
         if (WriteStream != null)
         {
             WriteStream.Close();
         }
         if (ReadStream != null)
         {
             ReadStream.Close();
         }
         closedCancelSource.Dispose();
     }
     base.Dispose(disposing);
 }
Пример #6
0
        public void Html_Original()
        {
            //string[] DATA = new string[5000];
            // int count = 0;

            HttpWebRequest  Request  = (HttpWebRequest)WebRequest.Create(Url);
            HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();

            if (Response.StatusCode == HttpStatusCode.OK)
            {
                Stream       ReceiveStream = Response.GetResponseStream();
                StreamReader ReadStream    = null;
                if (Response.CharacterSet == null)
                {
                    ReadStream = new StreamReader(ReceiveStream);
                }
                else
                {
                    ReadStream = new StreamReader(ReceiveStream, Encoding.GetEncoding(Response.CharacterSet));
                }

                string Data = ReadStream.ReadToEnd().Replace(",", Environment.NewLine);

                HtmlDocument Doc = new HtmlDocument();
                Doc.LoadHtml(Data);



                //  if (SW == true)
                // {


                DateTime d       = DateTime.Now;
                string   Sameday = d.GetDateTimeFormats('D')[1].ToString();
                string   dirPath = $@"{AppDomain.CurrentDomain.BaseDirectory}\{Area}";
                if (Directory.Exists(dirPath))
                {
                    Console.WriteLine("success");
                }
                else
                {
                    Directory.CreateDirectory(dirPath);
                    Console.WriteLine("The directory {0} was created.", dirPath);
                }

                StreamWriter str = new StreamWriter($@"{AppDomain.CurrentDomain.BaseDirectory}\{Area}\{Sameday}-{Area}.txt");
                // str.WriteLine(data);
                if (Doc.DocumentNode.SelectNodes("//table") != null)
                {
                    foreach (HtmlNode table in Doc.DocumentNode.SelectNodes("//table"))
                    {
                        str.WriteLine($"\n({Area})日期:" + table.Id + "\n");
                        //DATA[count] = $"\n({Area})日期:" + table.Id + "\n";
                        //count++;
                        //Console.WriteLine("Date:" + table.Id);
                        foreach (HtmlNode row in table.SelectNodes("tr"))
                        {
                            str.WriteLine();
                            //DATA[count] = $"\n";
                            //count++;
                            //Console.WriteLine("row");
                            foreach (HtmlNode cell in row.SelectNodes("th|td"))
                            {
                                str.WriteLine(cell.InnerText);
                                //DATA[count] = $"\n" + cell.InnerText + "\n";
                                //count++;
                                // Console.WriteLine("cell:" + cell.InnerText);
                            }
                        }
                    }

                    str.Close();

                    //}
                }
                ReadStream.Close();
            }

            Response.Close();
        }