gajda-ltd icon

pipeStreamExample

gajda-ltd | PRO | 03/10/16 10:08:32 AM UTC | 0 ⭐ | 225 👁️ | Never ⏰ | []
text |

7.05 KB

|

None

|

0 👍

/

0 👎

        //public void Upload(GoogleProductFeedAccount account, IEnumerable<GoogleProductFeedRecord> records)
        //{
        //    switch (account)
        //    {
        //        case GoogleProductFeedAccount.Au:
        //            this.txtFileName = "Feed_Live_AU.txt";
        //            this.zipFileName = "Feed_Live_AU.zip";
        //            break;
        //        case GoogleProductFeedAccount.Us:
        //            this.txtFileName = "Feed_Live_US.txt";
        //            this.zipFileName = "Feed_Live_US.zip";
        //            break;
        //        default:
        //            this.txtFileName = "Feed_Live_UK.txt";
        //            this.zipFileName = "Feed_Live_UK.zip";
        //            break;
        //    }
         //    try
        //    {
        //        Task.Factory.StartNew(
        //            () =>
        //            {
        //                this.dataService.SendMessage("Preparing text file");
         //                var headerColumns = new List<string>();
         //                if (account == GoogleProductFeedAccount.Uk)
        //                {
        //                    headerColumns.AddRange(
        //                        (new[]
        //                                 {
        //                                     "id", "title", "description", "google_product_category", "product type",
        //                                     "link", "image link", "condition", "availability", "price", "brand", "mpn",
        //                                     "gtin", "shipping_weight", "shipping_label"
        //                                 }).Select(
        //                                 column => column.Quotations()).ToArray());
        //                }
        //                else
        //                {
        //                    headerColumns.AddRange(
        //                        (new[]
        //                                 {
        //                                     "id", "title", "description", "google_product_category", "product type",
        //                                     "link", "image link", "condition", "availability", "price", "brand", "mpn",
        //                                     "gtin", "shipping_weight"
        //                                 }).Select(column => column.Quotations()).ToArray());
        //                }
         //                var header = string.Format("{0}\n", string.Join("|", headerColumns));
         //                this.log.Info(header);
         //                this.pipeStream.Write(header.ToBytes(), 0, header.ToBytes().Length);
         //                var format = account == GoogleProductFeedAccount.Uk
        //                                 ? "\"{0}\"|\"{1}\"|\"{2}\"|\"{3}\"|\"{4}\"|\"{5}\"|\"{6}\"|\"{7}\"|\"{8}\"|\"{9}\"|\"{10}\"|\"{11}\"|\"{12}\"|\"{13}\"|\"{14}\"\n"
        //                                 : "\"{0}\"|\"{1}\"|\"{2}\"|\"{3}\"|\"{4}\"|\"{5}\"|\"{6}\"|\"{7}\"|\"{8}\"|\"{9}\"|\"{10}\"|\"{11}\"|\"{12}\"|\"{13}\"\n";
         //                foreach (var record in records)
        //                {
        //                    var message = string.Format(
        //                        format,
        //                        record.Id,
        //                        record.Title.GoogleTruncate(96),
        //                        record.Description.GoogleTruncate(256),
        //                        record.GoogleProductCategory,
        //                        record.ProductType,
        //                        record.Link,
        //                        record.ImageLink,
        //                        record.Condition,
        //                        record.Availability,
        //                        record.Price,
        //                        record.Brand,
        //                        record.Mpn,
        //                        record.Gtin,
        //                        record.ShippingWeight,
        //                        record.ShippingLabel);
         //                    //this.log.Info(message);
         //                    var buffer = Encoding.ASCII.GetBytes(message);
         //                    this.pipeStream.Write(buffer, 0, buffer.Length);
        //                    this.isNotReady = false;
        //                }
         //                this.pipeStream.Flush();
        //                this.pipeStream.Close();
        //            });
         //        using (var memoryStream = new MemoryStream())
        //        {
        //            Thread.Sleep(10000);
         //            using (var zip = new ZipFile())
        //            {
        //                zip.CompressionLevel = CompressionLevel.BestCompression;
        //                //zip.AddProgress += this.ZipOnAddProgress;
        //                //zip.SaveProgress += this.ZipOnSaveProgress;
         //                while (this.isNotReady)
        //                {
        //                    Thread.Sleep(100);
        //                }
         //                this.log.Info("Start compressing text file");
        //                this.dataService.SendMessage("Compressing text file");
         //                zip.AddEntry(this.txtFileName, this.pipeStream);
         //                zip.Save(memoryStream);
        //            }
         //            memoryStream.Position = 0;
         //            using (
        //                var ftp = new FTP("Michal Gajda/Aphrohead Ltd 201198", "2;640DE373013E3E0060B75EB0971AADE0")
        //                              {
        //                                  HostAddress = this.hostAddress,
        //                                  UserName = this.userName,
        //                                  Password = this.password,
        //                                  UseBinary = true,
        //                                  UsePassive = true
        //                              })
        //            {
        //                ftp.FileProgressEvent += this.FtpOnFileProgressEvent;
        //                ftp.FileTransferCompleteEvent += this.FtpOnFileTransferCompleteEvent;
         //                ftp.Connect();
         //                if (ftp.IsConnected)
        //                {
        //                    this.dataService.SendMessage("Uploading compressed file");
         //                    if (ftp.FileExists(this.zipFileName))
        //                    {
        //                        ftp.DeleteFile(this.zipFileName);
        //                    }
         //                    ftp.UploadStream(memoryStream, this.zipFileName);
        //                }
        //            }
        //        }
        //    }
        //    catch (Exception exception)
        //    {
        //        this.log.Error(exception.Message, exception);
        //    }
         //    GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
        //    GC.WaitForPendingFinalizers();
        //}

Comments