Ejemplo n.º 1
0
        private void DirectoryExistsFailure(string oFile)
        {
            IReporter             reporter  = ReporterManager.GetReporter();
            ActionReportContainer container = new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed,
                                                                        "The source directory " + Path.GetDirectoryName(oFile) + " does not exist.  It cannot be watched.");

            reporter.AddReport(container);
            this.reporter.AddReport(container);
        }
Ejemplo n.º 2
0
        private void Timer_Tick(object sender, System.Timers.ElapsedEventArgs args)
        {
            JobContainer jContainer  = this.wcontainer.Container;
            string       destination = SharedBO.CalculateDestination(
                jContainer.SourceDirectory, fullpath, jContainer.DestinationDirectory);                // Path.Combine(jContainer.DestinationDirectory, Path.GetFileName(this.fullpath));

            try {
                if (DoneTrying())
                {
                    IReporter reporter = ReporterManager.GetReporter();
                    reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, "Attempted to copy file " + this.RetryCount + " times.", this.fullpath, destination));
                    this.QTimer.Stop();
                    this.OnFinished(EventArgs.Empty);
                }
                else
                {
                    if (!File.Exists(this.fullpath))
                    {
                        if (wcontainer.ChangeType == WatcherChangeTypes.Renamed)
                        {
                            string relativeOldDir = SharedBO.CalculateDestination(
                                wcontainer.OldFullPath,
                                jContainer.SourceDirectory,
                                jContainer.DestinationDirectory);
                            Directory.Move(relativeOldDir, destination);
                        }
                        else
                        {
                            if (!Directory.Exists(destination))
                            {
                                Directory.CreateDirectory(destination);
                            }
                        }

                        this.QTimer.Stop();
                        this.OnFinished(EventArgs.Empty);
                    }
                    else
                    {
                        this.Copier.Copy(this.fullpath, destination, true);
                        this.QTimer.Stop();
                        this.OnFinished(EventArgs.Empty);
                    }
                }
            }
            catch (System.IO.FileNotFoundException) {
                IReporter reporter = ReporterManager.GetReporter();
                reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, "File Not Found", this.fullpath, destination));
                this.QTimer.Stop();
                this.OnFinished(EventArgs.Empty);
            }
            catch (System.Exception ex) {
                IReporter reporter = ReporterManager.GetReporter();
                reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, ex.ToString(), this.fullpath, destination));
                this.RetryCount++;
            }
        }
Ejemplo n.º 3
0
        public void Copy(string original, string copy, bool overwrite)
        {
            FileInfo fiOriginal = new FileInfo(original);

            fiOriginal.CopyTo(copy, overwrite);

            IReporter reporter = ReporterManager.GetReporter();

            reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Succeeded,
                                                         "Copy succeeded", original, copy));
        }
Ejemplo n.º 4
0
 private void Copy(string oFile, string cFile)
 {
     try {
         this.copier.Copy(oFile, cFile, true);
         this.reporter.AddReport(
             new ActionReportContainer(ActionType.Copy, ActionReportResult.Succeeded, "Copy succeeded", oFile, cFile));
     }
     catch (Exception ex) {
         IReporter             reporter  = ReporterManager.GetReporter();
         ActionReportContainer container = new ActionReportContainer(
             ActionType.Copy, ActionReportResult.Failed, ex.ToString(), oFile, cFile);
         reporter.AddReport(container);
         this.reporter.AddReport(container);
     }
 }
Ejemplo n.º 5
0
        private void Watcher_Event(object sender, FileSystemEventArgs args)
        {
            string         dir        = Path.GetDirectoryName(args.FullPath);
            JobContainer   container  = AcquireJobContainerByDirectory(dir);         // (JobContainer)this.WatcherContainers[dir];
            WriteContainer wcontainer = new WriteContainer(container.SourceDirectory, container);

            try {
                if (WatcherChangeTypes.Deleted != args.ChangeType)
                {
                    this.ProcessFile(args.FullPath, wcontainer);
                }
                //TODO: Give users the option to copy a "delete" action
            }
            catch (Exception ex) {
                IReporter reporter = ReporterManager.GetReporter();
                reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted, ex.ToString()));
            }
        }
Ejemplo n.º 6
0
        public void StartListeners()
        {
            if (this.Started)
            {
                return;
            }

            JobsBO jbo = (JobsBO)SingletonManager.GetSingleton(typeof(JobsBO));

            foreach (JobContainer container in jbo.JContainer.Jobs)
            {
                if (container.SourceDirectory.Length > 0 && container.DestinationDirectory.Length > 0)
                {
                    if (Directory.Exists(container.SourceDirectory) && Directory.Exists(container.DestinationDirectory))
                    {
                        try {
                            FileSystemWatcher watcher = new FileSystemWatcher(container.SourceDirectory);
                            watcher.NotifyFilter          = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.DirectoryName | NotifyFilters.CreationTime;
                            watcher.IncludeSubdirectories = container.WatchSubDirectories;
                            watcher.Created += new FileSystemEventHandler(Watcher_Event);
                            //watcher.Deleted += new FileSystemEventHandler(Watcher_Event);
                            watcher.Renamed            += new RenamedEventHandler(Watcher_Renamed);
                            watcher.Changed            += new FileSystemEventHandler(Watcher_Event);
                            watcher.EnableRaisingEvents = true;
                            lock (this.Watchers) { Watchers.Add(container, watcher); }
                            lock (this.WatcherContainers) { this.WatcherContainers.Add(container.SourceDirectory, container); }
                        }
                        catch (Exception ex) {
                            IReporter reporter = ReporterManager.GetReporter();
                            reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted, ex.ToString()));
                        }
                    }
                    else
                    {
                        IReporter reporter = ReporterManager.GetReporter();
                        reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted,
                                                                     "There was an error finding one or more of the two following directories:\n" +
                                                                     container.SourceDirectory + "\n" + container.DestinationDirectory));
                    }
                }
            }
            this.Started = true;
            OnStatusChanged(EventArgs.Empty);
        }
Ejemplo n.º 7
0
        private void Watcher_Renamed(object sender, RenamedEventArgs args)
        {
            string dir = Path.GetDirectoryName(args.FullPath);

            if (WatcherChangeTypes.Renamed == args.ChangeType)
            {
                //at this point the renamed item could be a directory
                try {
                    JobContainer   container  = AcquireJobContainerByDirectory(dir);                  //(JobContainer)this.WatcherContainers[dir];
                    WriteContainer wcontainer = new WriteContainer(container.SourceDirectory, container);
                    wcontainer.ChangeType  = args.ChangeType;
                    wcontainer.OldFullPath = args.OldFullPath;
                    this.ProcessFile(args.FullPath, wcontainer);
                }
                catch (Exception ex) {
                    IReporter reporter = ReporterManager.GetReporter();
                    reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted, ex.ToString()));
                }
            }
        }
Ejemplo n.º 8
0
        public static void SendEmail(FolderMapContainer container)
        {
            string From = System.Configuration.ConfigurationSettings.AppSettings["EmailFrom"];
            string Body = "";

            if (container.BODY.Length > 0)
            {
                Body = container.BODY;
            }
            else
            {
                Body = System.Configuration.ConfigurationSettings.AppSettings["EmailBody"];
            }
            string Subject = "";

            if (container.SUBJECT.Length > 0)
            {
                Subject = container.SUBJECT;
            }
            else
            {
                Subject = System.Configuration.ConfigurationSettings.AppSettings["EmailSubject"];
            }

            string SMTPServerName = System.Configuration.ConfigurationSettings.AppSettings["SMTPServerName"];
            string Username       = System.Configuration.ConfigurationSettings.AppSettings["Username"];
            string Password       = System.Configuration.ConfigurationSettings.AppSettings["Password"];

            string[] emails = new string[5];
            emails[0] = container.EMAIL1;
            emails[1] = container.EMAIL2;
            emails[2] = container.EMAIL3;
            emails[3] = container.EMAIL4;
            emails[4] = container.EMAIL5;

            foreach (string email in emails)
            {
                try
                {
                    if (email.Length > 0)
                    {
                        System.Web.Mail.MailMessage mmsg = new System.Web.Mail.MailMessage();
                        mmsg.From    = From;
                        mmsg.To      = email;
                        mmsg.Body    = Body;
                        mmsg.Subject = Subject;
                        System.Web.Mail.SmtpMail.SmtpServer = SMTPServerName;                                     //"smtp.1and1.com";
                        mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");  //basic authentication
                        mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Username); //set your username here
                        mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password); //set your password here
                        System.Web.Mail.SmtpMail.Send(mmsg);
                    }
                }
                catch (Exception)
                {
                    IReporter reporter = ReporterManager.GetReporter();
                    reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Failed, "Email notification to " +
                                                                 email + " failed"));
                }
            }
        }