PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/IntelWebProc/IntelWebService.cs

https://github.com/sirivedula/IntelWebPro
C# | 138 lines | 122 code | 14 blank | 2 comment | 4 complexity | ec8f6cf3f5ba1e127454aaa77ad9c2f4 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Linq;
  7. using System.ServiceProcess;
  8. using System.Text;
  9. using System.Threading;
  10. using IntelWeb;
  11. namespace IntelWebProc
  12. {
  13. public partial class IntelWebService : ServiceBase
  14. {
  15. public IntelWebService()
  16. {
  17. InitializeComponent();
  18. }
  19. public void StartUp()
  20. {
  21. cuser.userName = "Balaji";
  22. cuser.Load();
  23. /* Start After a Min and every 5 min check queue */
  24. myTimer = new Timer(CheckJobQ, this, 60, 10*1000);
  25. }
  26. public void ShutDown()
  27. {
  28. myTimer.Dispose();
  29. }
  30. protected override void OnStart(string[] args)
  31. {
  32. this.StartUp();
  33. }
  34. protected override void OnStop()
  35. {
  36. this.ShutDown();
  37. }
  38. private Timer myTimer;
  39. private CurrentUser cuser = new CurrentUser();
  40. private void CheckJobQ(object state)
  41. {
  42. JobQ tempJob = new JobQ(cuser);
  43. tempJob.jobStatus = "active";
  44. tempJob.LoadSingle();
  45. Console.Write("{1} Checking Job Queue...{0} Jobs Found.\n", (tempJob.isNew ? 0 : 1), DateTime.Now);
  46. if (!tempJob.isNew)
  47. {
  48. tempJob.jobStatus = "running";
  49. tempJob.starttime = DateTime.Now;
  50. tempJob.save();
  51. Importer objImp = new Importer();
  52. objImp.CJobQ = tempJob;
  53. Thread oThread = new Thread(new ThreadStart(objImp.doImport));
  54. oThread.Start();
  55. }
  56. }
  57. }
  58. public class Importer
  59. {
  60. public JobQ CJobQ { get; set; }
  61. public string lastError = "";
  62. public void doImport()
  63. {
  64. if (CJobQ.filename.Length > 0)
  65. {
  66. string localPath = "D:\\Balaji";
  67. string sourceFile = localPath + "\\" + CJobQ.filename;
  68. DownloadFile objDownload = new DownloadFile();
  69. objDownload.ftpServerIP = "iweb.vasbal.com";
  70. objDownload.ftpUserId = "gsquote";
  71. objDownload.ftpPassword = "gs@quote";
  72. objDownload.localDestnDir = localPath;
  73. objDownload.remoteDir = "httpdocs/data";
  74. if (objDownload.Download(CJobQ.filename))
  75. {
  76. string filext = System.IO.Path.GetExtension(sourceFile);
  77. string destFilename = localPath + "\\" + System.IO.Path.GetFileName(sourceFile.Replace(".xls", ".txt"));
  78. if (filext.Equals(".xls", StringComparison.InvariantCultureIgnoreCase))
  79. {
  80. //Make Text File From Excel
  81. FileConverter fileConv = new FileConverter();
  82. fileConv.SrcFile = sourceFile;
  83. fileConv.DestFile = destFilename;
  84. if (System.IO.File.Exists(sourceFile))
  85. {
  86. fileConv.ConvertXLSToText();
  87. }
  88. }
  89. IntelWebImporter.ImportRun imp = new IntelWebImporter.ImportRun();
  90. imp.fullFileName = destFilename;
  91. imp.UserName = "Balaji";
  92. imp.tierCode = CJobQ.tiername;
  93. imp.tierCode = CJobQ.tiername;
  94. try
  95. {
  96. imp.doImport(true);
  97. CJobQ.jobResults = imp.toHTML();
  98. CJobQ.jobStatus = "Done";
  99. }
  100. catch (Exception ex)
  101. {
  102. CJobQ.jobResults = ex.Message;
  103. CJobQ.jobStatus = "error";
  104. }
  105. }
  106. else
  107. {
  108. CJobQ.jobStatus = "error";
  109. CJobQ.jobResults = "Download File Error";
  110. }
  111. CJobQ.endtime = DateTime.Now;
  112. CJobQ.save();
  113. }
  114. else
  115. {
  116. CJobQ.endtime = DateTime.Now;
  117. CJobQ.jobStatus = "error";
  118. CJobQ.save();
  119. lastError = "File does not exists.";
  120. }
  121. }
  122. }
  123. }