Пример #1
0
        private void WriteBigFile(EnglishFeedFile reviewList)
        {
            byte[] fileBuffer = new byte[1024];//每次读取1024字节大小的数据
            if (reviewList != null)
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    GC.Collect();
                    Thread.Sleep(1000);
                    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(ReviewListingsType));
                    serializer.Serialize(stream, reviewList.GetReviewList());

                    long totalLength = stream.Length;
                    stream.Seek(0, SeekOrigin.Begin);
                    while (totalLength > 0 && Response.IsClientConnected)           //持续传输文件
                    {
                        int length = stream.Read(fileBuffer, 0, fileBuffer.Length); //每次读取1024个字节长度的内容
                        Response.OutputStream.Write(fileBuffer, 0, length);         //写入到响应的输出流
                        totalLength = totalLength - length;
                    }
                }
            }
        }
Пример #2
0
        public EnglishFeedFile DealReviewFeed(HttpFileCollectionBase files)
        {
            //byte[] result = null;
            string host = Request.Params["Host"];
            string lang = Request.Params["Lang"];

            var englishFile = new EnglishFeedFile();

            if (files != null && files.Count > 0)
            {
                for (var i = 0; i < files.Count; i++)
                {
                    HttpPostedFileBase file = files[i];
                    if (file != null && file.FileName.Contains("english"))
                    {
                        using (ExcelTemplateHelper <HotelFeedModel> exHelper = new ExcelTemplateHelper <HotelFeedModel>(file, englishFile.FeedXmlProcess))
                        {
                            exHelper.Run();
                        }

                        file.InputStream.Dispose();
                    }
                }

                englishFile.GetReviewList().ListModel =
                    englishFile.GetReviewList().ListModel.OrderBy(l => l.Ctriphotelid).ToList();
                englishFile.SortHotelList = englishFile.GetReviewList().ListModel.Select(l => l.Ctriphotelid).ToArray();

                for (var i = 0; i < files.Count; i++)
                {
                    HttpPostedFileBase file = files[i];

                    if (file != null && file.FileName.Contains("pic"))
                    {
                        var imageFile = new ImageDeco(englishFile, host, lang);
                        using (var imageDeco = new ExcelTemplateHelper <ImageModel>(file, imageFile.FeedXmlProcess))
                        {
                            imageDeco.Run();
                        }
                    }

                    if (file != null && file.FileName.Contains("review"))
                    {
                        var reviewFile = new ReviewDeco(englishFile, host, lang);
                        using (var reviewDeco = new ExcelTemplateHelper <ReviewModel>(file, reviewFile.FeedXmlProcess))
                        {
                            reviewDeco.Run();
                        }
                    }

                    if (file != null && file.FileName.Contains("name"))
                    {
                        var nameFile = new NameDeco(englishFile, host, lang);
                        using (var nameDeco = new ExcelTemplateHelper <NameModel>(file, nameFile.FeedXmlProcess))
                        {
                            nameDeco.Run();
                        }
                    }

                    if (file != null && file.FileName.Contains("DESC"))
                    {
                        var descFile = new DescTxtDeco(englishFile, host, lang);
                        using (var descDeco = new TxtTemplateHelper(file, descFile.FeedXmlProcess))
                        {
                            descDeco.Run();
                        }
                    }

                    file?.InputStream.Dispose();
                }

                englishFile.GetReviewList().ListModel = englishFile.GetReviewList().ListModel.Where(l => l.HasName || l.HasReview).ToList();
                //result = Serializer.SerializeToBytes(englishFile.GetReviewList());
                //result = XmlHelper.XmlSerialize(englishFile.GetReviewList(), Encoding.UTF8);
            }

            return(englishFile);
        }