gajda-ltd

pipeStreamExample

Mar 10th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.05 KB | None | 0 0
  1. //public void Upload(GoogleProductFeedAccount account, IEnumerable<GoogleProductFeedRecord> records)
  2. //{
  3. // switch (account)
  4. // {
  5. // case GoogleProductFeedAccount.Au:
  6. // this.txtFileName = "Feed_Live_AU.txt";
  7. // this.zipFileName = "Feed_Live_AU.zip";
  8. // break;
  9. // case GoogleProductFeedAccount.Us:
  10. // this.txtFileName = "Feed_Live_US.txt";
  11. // this.zipFileName = "Feed_Live_US.zip";
  12. // break;
  13. // default:
  14. // this.txtFileName = "Feed_Live_UK.txt";
  15. // this.zipFileName = "Feed_Live_UK.zip";
  16. // break;
  17. // }
  18.  
  19. // try
  20. // {
  21. // Task.Factory.StartNew(
  22. // () =>
  23. // {
  24. // this.dataService.SendMessage("Preparing text file");
  25.  
  26. // var headerColumns = new List<string>();
  27.  
  28. // if (account == GoogleProductFeedAccount.Uk)
  29. // {
  30. // headerColumns.AddRange(
  31. // (new[]
  32. // {
  33. // "id", "title", "description", "google_product_category", "product type",
  34. // "link", "image link", "condition", "availability", "price", "brand", "mpn",
  35. // "gtin", "shipping_weight", "shipping_label"
  36. // }).Select(
  37. // column => column.Quotations()).ToArray());
  38. // }
  39. // else
  40. // {
  41. // headerColumns.AddRange(
  42. // (new[]
  43. // {
  44. // "id", "title", "description", "google_product_category", "product type",
  45. // "link", "image link", "condition", "availability", "price", "brand", "mpn",
  46. // "gtin", "shipping_weight"
  47. // }).Select(column => column.Quotations()).ToArray());
  48. // }
  49.  
  50. // var header = string.Format("{0}\n", string.Join("|", headerColumns));
  51.  
  52. // this.log.Info(header);
  53.  
  54. // this.pipeStream.Write(header.ToBytes(), 0, header.ToBytes().Length);
  55.  
  56. // var format = account == GoogleProductFeedAccount.Uk
  57. // ? "\"{0}\"|\"{1}\"|\"{2}\"|\"{3}\"|\"{4}\"|\"{5}\"|\"{6}\"|\"{7}\"|\"{8}\"|\"{9}\"|\"{10}\"|\"{11}\"|\"{12}\"|\"{13}\"|\"{14}\"\n"
  58. // : "\"{0}\"|\"{1}\"|\"{2}\"|\"{3}\"|\"{4}\"|\"{5}\"|\"{6}\"|\"{7}\"|\"{8}\"|\"{9}\"|\"{10}\"|\"{11}\"|\"{12}\"|\"{13}\"\n";
  59.  
  60. // foreach (var record in records)
  61. // {
  62. // var message = string.Format(
  63. // format,
  64. // record.Id,
  65. // record.Title.GoogleTruncate(96),
  66. // record.Description.GoogleTruncate(256),
  67. // record.GoogleProductCategory,
  68. // record.ProductType,
  69. // record.Link,
  70. // record.ImageLink,
  71. // record.Condition,
  72. // record.Availability,
  73. // record.Price,
  74. // record.Brand,
  75. // record.Mpn,
  76. // record.Gtin,
  77. // record.ShippingWeight,
  78. // record.ShippingLabel);
  79.  
  80. // //this.log.Info(message);
  81.  
  82. // var buffer = Encoding.ASCII.GetBytes(message);
  83.  
  84. // this.pipeStream.Write(buffer, 0, buffer.Length);
  85. // this.isNotReady = false;
  86. // }
  87.  
  88. // this.pipeStream.Flush();
  89. // this.pipeStream.Close();
  90. // });
  91.  
  92. // using (var memoryStream = new MemoryStream())
  93. // {
  94. // Thread.Sleep(10000);
  95.  
  96. // using (var zip = new ZipFile())
  97. // {
  98. // zip.CompressionLevel = CompressionLevel.BestCompression;
  99. // //zip.AddProgress += this.ZipOnAddProgress;
  100. // //zip.SaveProgress += this.ZipOnSaveProgress;
  101.  
  102. // while (this.isNotReady)
  103. // {
  104. // Thread.Sleep(100);
  105. // }
  106.  
  107. // this.log.Info("Start compressing text file");
  108. // this.dataService.SendMessage("Compressing text file");
  109.  
  110. // zip.AddEntry(this.txtFileName, this.pipeStream);
  111.  
  112. // zip.Save(memoryStream);
  113. // }
  114.  
  115. // memoryStream.Position = 0;
  116.  
  117. // using (
  118. // var ftp = new FTP("Michal Gajda/Aphrohead Ltd 201198", "2;640DE373013E3E0060B75EB0971AADE0")
  119. // {
  120. // HostAddress = this.hostAddress,
  121. // UserName = this.userName,
  122. // Password = this.password,
  123. // UseBinary = true,
  124. // UsePassive = true
  125. // })
  126. // {
  127. // ftp.FileProgressEvent += this.FtpOnFileProgressEvent;
  128. // ftp.FileTransferCompleteEvent += this.FtpOnFileTransferCompleteEvent;
  129.  
  130. // ftp.Connect();
  131.  
  132. // if (ftp.IsConnected)
  133. // {
  134. // this.dataService.SendMessage("Uploading compressed file");
  135.  
  136. // if (ftp.FileExists(this.zipFileName))
  137. // {
  138. // ftp.DeleteFile(this.zipFileName);
  139. // }
  140.  
  141. // ftp.UploadStream(memoryStream, this.zipFileName);
  142. // }
  143. // }
  144. // }
  145. // }
  146. // catch (Exception exception)
  147. // {
  148. // this.log.Error(exception.Message, exception);
  149. // }
  150.  
  151. // GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
  152. // GC.WaitForPendingFinalizers();
  153. //}
Add Comment
Please, Sign In to add comment