Ejemplo n.º 1
0
        public MonitorTaskForm(MCEBuddyConf mceOptions, string SourceName)
        {
            InitializeComponent();

            _mceOptions = mceOptions;
            _mjo = mceOptions.GetMonitorTaskByName(SourceName);
        }
Ejemplo n.º 2
0
        public CredentialsForm(MonitorJobOptions mjo)
        {
            InitializeComponent();
            options = mjo;

            domainNameTxt.Text = mjo.domainName;
            userNameTxt.Text = mjo.userName;
            passwordTxt.Text = confirmPasswordTxt.Text = mjo.password;

            fallbackToSourceChk.Visible = fallbackToSourceChk.Enabled = false; // This option is not valid for Monitor Jobs
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes the settings to the mjo object
        /// </summary>
        /// <param name="save">True if you want to save the settings to the Global MCE object</param>
        private void WriteSettings(MonitorJobOptions mjo, bool save)
        {
            _mjo.taskName = sourceNameTxt.Text.Trim();
            _mjo.searchPath = searchPathTxt.Text;
            _mjo.monitorSubdirectories = monitorSubdirChk.Checked;

            if (searchPatternTxt.Text == "")
                _mjo.searchPattern = GlobalDefs.DEFAULT_VIDEO_STRING;
            else
                _mjo.searchPattern = searchPatternTxt.Text;

            if (save) // Are we asked to save them
                _mceOptions.AddOrUpdateMonitorTask(mjo, false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads the settings from the montior job options and populates the form
        /// </summary>
        /// <param name="mjo">Refernce to a mjo object, will create a new object if it is null</param>
        private void ReadSettings(ref MonitorJobOptions mjo)
        {
            if (mjo != null)
            {
                sourceNameTxt.Text = mjo.taskName;
                if (!_newTask)
                    sourceNameTxt.ReadOnly = true;
                searchPathTxt.Text = mjo.searchPath;
                searchPatternTxt.Text = mjo.searchPattern;
                monitorSubdirChk.Checked = mjo.monitorSubdirectories;
            }
            else
            {
                mjo = new MonitorJobOptions();
                _newTask = true; // this is a new task and will remain until we hit OK

                searchPatternTxt.Text = GlobalDefs.DEFAULT_VIDEO_STRING;
            }

            CheckNetDrive(false); // No pop up while reading
        }
Ejemplo n.º 5
0
        private void ReadMonitorSettings(Ini configIni)
        {
            // Read the Monitor Tasks
            string[] searchRecords = configIni.ReadString("Engine", "SearchRecords", "").Split(',');
            foreach (string searchRecord in searchRecords)
            {
                if (String.IsNullOrEmpty(searchRecord))
                    continue;

                MonitorJobOptions mjo = new MonitorJobOptions();

                mjo.taskName = searchRecord;
                mjo.searchPath = configIni.ReadString(searchRecord, "SearchPath", "");
                CheckPathEnding(ref mjo.searchPath);
                mjo.searchPattern = configIni.ReadString(searchRecord, "SearchPattern", GlobalDefs.DEFAULT_VIDEO_STRING);
                mjo.searchPattern = mjo.searchPattern.Replace(GlobalDefs.DEFAULT_VIDEO_STRING, GlobalDefs.DEFAULT_VIDEO_FILE_TYPES);
                mjo.monitorSubdirectories = configIni.ReadBoolean(searchRecord, "MonitorSubdirectories", true);
                mjo.monitorConvertedFiles = configIni.ReadBoolean(searchRecord, "MonitorConvertedFiles", false);
                mjo.reMonitorRecordedFiles = configIni.ReadBoolean(searchRecord, "ReMonitorRecordedFiles", false);

                mjo.domainName = configIni.ReadString(searchRecord, "DomainName", "");
                mjo.userName = configIni.ReadString(searchRecord, "UserName", "Guest");
                mjo.password = configIni.ReadString(searchRecord, "Password", "");
                if (!String.IsNullOrEmpty(mjo.password))
                    mjo.password = Crypto.Decrypt(mjo.password); // Password is kept as encrypted

                mceBuddyConfSettings.monitorTasks.Add(mjo); // Add the Monitor Task object
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Update a Monitor Task or Add to the list if not found (by Name), optionally write to file
        /// </summary>
        /// <param name="mjo">Monitor job options</param>
        /// <param name="write">Write to configuration file immediately</param>
        public void AddOrUpdateMonitorTask(MonitorJobOptions mjo, bool write)
        {
            int index = mceBuddyConfSettings.monitorTasks.FindIndex(item => item.taskName == mjo.taskName);

            // Clone it, to avoid conflict
            if (index < 0) // new task, cannot find it
                mceBuddyConfSettings.monitorTasks.Add(mjo.Clone());
            else
                mceBuddyConfSettings.monitorTasks[index] = mjo.Clone();

            if (write)
                WriteMonitorSettings(configIni);
        }
 /// <summary>
 /// Validates and Writes the settings from the form to the Monitor Job Options
 /// </summary>
 private void WriteSettings(MonitorJobOptions mjo)
 {
     mjo.monitorConvertedFiles = monitorConvertedChk.Checked;
     mjo.reMonitorRecordedFiles = reMonitorRecordedChk.Checked;
 }
 /// <summary>
 /// Reads the settings from the monitor job options and populates the form
 /// </summary>
 private void ReadSettings(MonitorJobOptions mjo)
 {
     monitorConvertedChk.Checked = mjo.monitorConvertedFiles;
     reMonitorRecordedChk.Checked = mjo.reMonitorRecordedFiles;
 }
        public MonitorTaskExpertSettingsForm(MonitorJobOptions mjo)
        {
            InitializeComponent();

            _mjo = mjo;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Check if a file is in the queue, if not add it to the queue.
        /// This function does NOT take a lock on the queue before modifying it. This function is not thread safe
        /// </summary>
        /// <param name="filePath">Filename to check and add</param>
        /// <param name="monitorTask">Name of the monitor task adding the file, blank if manually added</param>
        /// <param name="manualFile">True is it's added manually to the queue</param>
        private void CheckAndAddFile(string filePath, MonitorJobOptions monitorTask, bool manualFile)
        {
            Ini iniHistory = new Ini(GlobalDefs.HistoryFile);
            if (!QueueContains(filePath))
            {
                if (!Util.FileIO.FileLocked(filePath))
                {
                    string historyRec = iniHistory.ReadString(filePath, "Status", "");

                    // If it's an output file (you can skip output file reconversion by setting SkipReconversion in Conversion Task Settings)
                    if ((monitorTask != null) && monitorTask.monitorConvertedFiles)
                        if (Core.ConvertedFileStatuses.Any(x => x.Equals(historyRec)))
                            historyRec = ""; // This is a converted file and we have been asked to process converted files also

                    // Are we asked to reconvert recorded files
                    if ((monitorTask != null) && monitorTask.reMonitorRecordedFiles)
                        if (Core.SourceFileStatuses.Any(x => x.Equals(historyRec))) // Check if the status matches any of the source file status
                            historyRec = "";

                    if (historyRec == "" || manualFile) // Either the file has not been processed (Status is missing) or readded manually (Status is blank)
                    {
                        if (File.Exists(filePath))
                        {
                            if (manualFile)
                            {
                                AddJobs(filePath, monitorTask, true); //add manual jobs for conversion at the head of queue (after the last currently active job)
                            }
                            else
                            {
                                // Check to see if the age of the file is old enough
                                DateTime timeStamp = Util.FileIO.GetFileModifiedTime(filePath);
                                if (timeStamp.AddHours(_minimumAge) < DateTime.Now)
                                {
                                    AddJobs(filePath, monitorTask, false); // Added by a monitor task
                                }
                            }
                        }
                        else if (manualFile) //delete only if a manual entry is made
                        {
                            Log.AppLog.WriteEntry(this, "Unable to queue file for conversion - file not found " + filePath + "\r\n", Log.LogEntryType.Warning);
                            Ini iniManualQueue = new Ini(GlobalDefs.ManualQueueFile);
                            iniManualQueue.DeleteKey("ManualQueue", filePath);
                        }
                    }
                    else
                    {
                        if (!_processedFiles.Contains(filePath)) // Keep a track of processed file so we don't overload the mcebuddy.log file
                        {
                            _processedFiles.Add(filePath); // to the list of processed file so we don't end up doing it again
                            Log.AppLog.WriteEntry(this, "File " + filePath + " already converted with status " + historyRec + "\r\n", Log.LogEntryType.Debug);
                        }

                        // Manual file entry may have been readded multiple times, each time we log it and remove it from the ini file
                        if (manualFile) // Delete the manual entry
                        {
                            Log.AppLog.WriteEntry(this, "Manual file " + filePath + " already converted with status " + historyRec + "\r\n", Log.LogEntryType.Debug);
                            Ini iniManualQueue = new Ini(GlobalDefs.ManualQueueFile);
                            iniManualQueue.DeleteKey("ManualQueue", filePath);
                        }
                    }
                }
                else
                {
                    if (!_processedFiles.Contains(filePath)) // Keep a track of processed file so we don't overload the mcebuddy.log file
                    {
                        _processedFiles.Add(filePath); // to the list of processed file so we don't end up doing it again
                        Log.AppLog.WriteEntry(this, "Unable to queue file for conversion - file inaccessible/locked by another process " + filePath + "\r\n", Log.LogEntryType.Debug);
                    }

                    // Manual file entry may have been readded multiple times, each time we log it and remove it from the ini file
                    if (manualFile) // Delete the manual entry
                    {
                        Ini iniManualQueue = new Ini(GlobalDefs.ManualQueueFile);
                        iniManualQueue.DeleteKey("ManualQueue", filePath);
                        Log.AppLog.WriteEntry(this, "Unable to queue manual file for conversion - file inaccessible/locked by another process " + filePath + "\r\n", Log.LogEntryType.Debug);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds a conversion job to the queue
        /// This function does NOT take a lock on the queue before modifying it. This function is not thread safe
        /// </summary>
        /// <param name="filePath">File to add</param>
        /// <param name="monitorTask">Monitor task name which found the file</param>
        /// <param name="manual">True if this is a manuall added entry, false if it's added by a monitor task</param>
        private void AddJobs(string filePath, MonitorJobOptions monitorTask, bool manual)
        {
            bool filterMatchSuccessful = false;

            // Check if the file has already been processed in the past if so skip
            if (_conversionTaskFilterMismatchFiles.Contains(filePath))
                return; //

            foreach (ConversionJobOptions conversionTask in MCEBuddyConf.GlobalMCEConfig.AllConversionTasks)
            {
                // Check if the task is disabled, which case skip
                if (!conversionTask.enabled)
                {
                    Log.AppLog.WriteEntry(this, Localise.GetPhrase("Conversion Task") + " " + conversionTask.taskName + " " + Localise.GetPhrase("disabled, skipping file") + " " + filePath, Log.LogEntryType.Debug, true);
                    continue;
                }

                conversionTask.sourceVideo = filePath;

                // Monitor Task name matching if not empty
                if ((monitorTask != null) && !String.IsNullOrWhiteSpace(monitorTask.taskName) && (conversionTask.monitorTaskNames != null))
                {
                    bool foundMatch = false;
                    foreach (string matchMonitorTaskName in conversionTask.monitorTaskNames)
                    {
                        if (monitorTask.taskName.ToLower().Trim() != matchMonitorTaskName.ToLower().Trim()) // match the list of a name
                            continue; // move onto next monitor task name
                        else
                        {
                            foundMatch = true;
                            break;
                        }
                    }

                    if (!foundMatch)
                    {
                        Log.AppLog.WriteEntry(this, "Skipping Conversion task " + conversionTask.taskName + " for file " + filePath + " since Monitor task " + monitorTask.taskName + " does not match the list of monitor tasks in the conversion task.", Log.LogEntryType.Debug, true);
                        continue; // move into next conversion task
                    }
                }

                // Metadata extract and pattern match from conversion task
                VideoMetaData metaData = MetadataMatchFilters(conversionTask);
                if (metaData != null) // We got a match - process the file
                {
                    // Calculate where to add the job in the queue
                    int idx;
                    if (manual || conversionTask.insertQueueTop) // Manual jobs to the head of the queue, just after the current active job, or check if the conversion task is asking to add the job at the head of the queue
                    {
                        for (idx = 0; idx < _jobQueue.Count; idx++)
                        {
                            if (!_jobQueue[idx].Active)
                                break;
                        }
                    }
                    else
                        idx = _jobQueue.Count; // Add the job to the end of the active queue

                    // If it's a manual entry then we need to convert, reset the skip reconverting flag if it's set
                    if (manual && conversionTask.skipReprocessing)
                    {
                        conversionTask.skipReprocessing = conversionTask.checkReprocessingHistory = false; // We can make a direct change since this is a copy object
                        Log.AppLog.WriteEntry(this, "Manually added file, resetting the skip reprocessing option, the file will converted even if it has been processed before", Log.LogEntryType.Debug, true);
                    }

                    Log.AppLog.WriteEntry(this, Localise.GetPhrase("Added new job to queue for") + " " + filePath, Log.LogEntryType.Information, true);
                    ConversionJob job = new ConversionJob(conversionTask, metaData);
                    _jobQueue.Insert(idx, job);
                    filterMatchSuccessful = true; // we cleared filters and processed the file

                    // Send an eMail if required
                    GeneralOptions go = MCEBuddyConf.GlobalMCEConfig.GeneralOptions;
                    bool sendEMail = go.sendEmail; // do we need to send an eMail after adding a job to the queue
                    bool sendQueue = go.eMailSettings.queueEvent;
                    string sendQueueSubject = go.eMailSettings.queueSubject;
                    bool skipBody = go.eMailSettings.skipBody;
                    if (sendEMail && sendQueue)
                    {
                        string subject = Localise.GetPhrase("MCEBuddy added a video conversion to the queue");
                        string message = Localise.GetPhrase("Source Video") + " -> " + job.OriginalFileName + "\r\n";
                        message += Localise.GetPhrase("Profile") + " -> " + job.Profile + "\r\n";
                        message += Localise.GetPhrase("Conversion Task") + " -> " + job.TaskName + "\r\n";

                        // Check for custom subject and process
                        if (!String.IsNullOrWhiteSpace(sendQueueSubject))
                            subject = UserCustomParams.CustomParamsReplace(sendQueueSubject, job.WorkingPath, "", "", job.OriginalFileName, "", "", "", job.Profile, job.TaskName, metaData.MetaData, Log.AppLog);

                        eMailSendEngine.AddEmailToSendQueue(subject, (skipBody ? "" : message)); // Send the eMail through the eMail engine
                    }
                }
                else if (manual) // Delete manual file entry if we didn't create a conversion job, otherwise the engine will clear it on completion
                {
                    // Manual files may be added multiple times and the filter may already have it from the last time, so be safe and delete it
                    Ini iniManualQueue = new Ini(GlobalDefs.ManualQueueFile); // Delete the entry from the manual queue
                    iniManualQueue.DeleteKey("ManualQueue", filePath);
                }
            }

            // If we have been through all the conversion tasks and not a single task has processed this file, hence we add it to the filter mismatch list so it won't be processed in future (MetadataExtract is very intensive and also prevent overburdening the log file)
            if (!filterMatchSuccessful)
                _conversionTaskFilterMismatchFiles.Add(filePath);
        }