Пример #1
0
        protected override void OnStart(string[] args)
        {
            Log.EventLog = this.EventLog;
            Log.Info("SendVideo service starting ...");

            try
            {
                var configuration = ConfigurationManager.GetSection("sendVideo") as SendVideoSection;
                if (configuration == null)
                {
                    throw new ApplicationException("Section 'sendVideo' not found in application configuration file!");
                }

                var encoder = new Encoder(configuration.Handbrake);
                var sender = new MailSender(configuration.SmptServer);

                foreach (var folder in configuration.ObservedFolders.Cast<ObservedFolder>())
                {
                    new FolderObserver(folder, encoder, sender, configuration.Recipients.Cast<Recipient>());
                }
            }
            catch (Exception e)
            {
                Log.Error($"Could not start service with {e.GetType().Name}: {e.Message}");
                return;
            }
        }
Пример #2
0
 public FolderObserver(ObservedFolder folder, Encoder encoder, MailSender sender, IEnumerable<Recipient> allRecipients)
 {
     this.folder = folder;
     this.encoder = encoder;
     this.sender = sender;
     var names = folder.Recipients.Split(',');
     this.recipients = allRecipients.Where(r => names.Contains(r.Name)).ToList();
     this.watcher = new FileSystemWatcher(this.folder.Path);
     this.watcher.Created += OnFileCreated;
     this.watcher.EnableRaisingEvents = true;
 }