Beispiel #1
0
 public void Start()
 {
     try
     {
         Initialize();
         _monitorTimer.Enabled = true;
     }
     catch (Exception ex)
     {
         ServiceLog.Log(ex.Message);
     }
 }
Beispiel #2
0
        public void Upload(string ftpServer)//for eg. Upload("ftp://ftpserver.com/matsfiles/clientId")
        {
            try
            {
                var client = new WebClient
                {
                    Credentials = new NetworkCredential("username", "password")
                };

                if (!Directory.Exists(ftpServer))
                {
                    Directory.CreateDirectory(ftpServer);
                }

                var source = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments) + "\\MATS_Files" + "\\";

                var backupSource = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments) + "\\MATS_Files_Backup" + "\\";
                if (!Directory.Exists(backupSource))
                {
                    Directory.CreateDirectory(backupSource);
                }

                IEnumerable <FileInfo> fileList = new DirectoryInfo(source).GetFiles();

                foreach (FileInfo fi in fileList)
                {
                    try
                    {
                        client.UploadFile(ftpServer + "/" + fi.Name, "STOR", fi.FullName);
                        //move the file after upload
                        fi.MoveTo(Path.Combine(backupSource, fi.Name));
                        var attachment = _dbContext.Attachments.FirstOrDefault(a =>
                                                                               a.AttachmentName == fi.Name.Substring(fi.Name.LastIndexOf("_" + 1)) &&
                                                                               a.Ticket.ROWGUID == fi.Name.Substring(0, fi.Name.LastIndexOf("_" + 1)));
                        if (attachment != null)
                        {
                            attachment.AttachmentStatus = (int)AttachmentStatus.Completed;
                            _dbContext.Add(attachment);
                            _dbContext.SaveChanges();
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                ServiceLog.Log(ex.Message);
            }
        }
Beispiel #3
0
 public void StartUploadFiles()
 {
     try
     {
         ServiceLog.Log(" - upload started");
         Upload("");
         ServiceLog.Log(" - upload completed");
     }
     catch
     {
         ServiceLog.Log(" - upload failed");
     }
 }
Beispiel #4
0
 private void ObserverTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     ObserverTimer.Enabled = false;
     try
     {
         var post = new UploadFiles();
         post.Start();
     }
     catch (Exception ex)
     {
         Stop();
         ServiceLog.Log(ex.Message);
     }
 }
Beispiel #5
0
        private void OnMonitorTimerElapsed(object source, System.Timers.ElapsedEventArgs e)
        {
            _monitorTimer.Enabled = false;

            try
            {
                StartUploadFiles();
            }
            catch (Exception ex)
            {
                ServiceLog.Log(ex.Message);
            }

            _monitorTimer.Enabled = true;
        }