Esempio n. 1
0
        } // IEnumerable.GetEnumerator

        #endregion

        private void FillFromFolder(string recordTaskFolder)
        {
            foreach (var file in Directory.GetFiles(recordTaskFolder, "*.xml"))
            {
                TaskData task;

                task = null;
                try
                {
                    task = new TaskData
                    {
                        XmlFilePath = file,
                        Task        = RecordTaskSerialization.LoadFromXmlFile(file)
                    };
                    task.SchedulerName = task.Task.Description.TaskSchedulerName;
                    task.SchedulerPath = task.Task.AdvancedSettings.TaskSchedulerFolder;
                    task.Status        = TaskStatus.WindowsTaskMissing;
                }
                catch
                {
                    // ignore
                    if (task != null)
                    {
                        task.Status = TaskStatus.XmlError;
                    } // if
                }     // try-catch
                List.Add(task);
            }         // foreach file
        }             // FillFromFolder
Esempio n. 2
0
        } // Run

        private static RecordTask LoadRecordTask(Guid taskId, string dbFile)
        {
            RecordTask task;

            try
            {
                Logger.Log(Logger.Level.Info, Properties.Texts.LogInfoLoadingXml, taskId, dbFile);
                Console.Write(Properties.Texts.DisplayLoadingXml);

                task = RecordTaskSerialization.LoadFromDatabase(dbFile, taskId);

                Console.WriteLine(Properties.Texts.DisplayActionOk);
                Logger.Log(Logger.Level.Info, Properties.Texts.LogInfoLoadingXmlOk);

                return(task);
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine(Properties.Texts.DisplayErrorLoadTaskFile);
                Program.DisplayException(ex);
                Logger.Exception(ex, Properties.Texts.LogExceptionLoadTaskFile);
                return(null);
            } // try-catch
        }     // LoadXml
Esempio n. 3
0
        } // constructor

        public static bool IsRecordSchedulerTask(Task schedulerTask, out RecordTask recordTask)
        {
            recordTask = null;

            if (string.IsNullOrEmpty(schedulerTask.Definition.RegistrationInfo.Documentation))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(schedulerTask.Definition.Data))
            {
                return(false);
            }

            if (!schedulerTask.Definition.RegistrationInfo.Documentation.StartsWith(Resources.DefinitionRegistrationInfo_Documentation_Begins, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            } // if

            try
            {
                recordTask = RecordTaskSerialization.LoadFromXmlString(schedulerTask.Definition.Data);
                return(true);
            }
            catch
            {
                // ignore, but return a null RecordTask
                return(false);
            } // try-catch
        }     // IsRecordSchedulerTask
Esempio n. 4
0
        }     // IsRecordSchedulerTask

        public bool CreateTask(RecordTask record)
        {
            TaskService    taskScheduler;
            TaskDefinition definition;
            Task           task;
            bool           isOk;

            _taskFolder = null;
            _taskName   = null;

            taskScheduler = null;
            definition    = null;
            task          = null;
            isOk          = false;

            try
            {
                taskScheduler = new TaskService();
                definition    = taskScheduler.NewTask();

                // Get folder for new task
                _taskFolder = GetTaskSchedulerFolder(record.AdvancedSettings, taskScheduler);

                // "Duration"
                // Duration 'per-se' is handled by the recording process.
                // However, we need extract some information
                GetDuration(record);

                // "Schedule"
                SetSchedule(definition, record.Schedule);

                // "Description"
                SetDescription(definition, record);

                // "Save"
                // Save location is handled by the recording process

                // "Advanced"
                SetAdvancedSettings(definition.Settings, record.AdvancedSettings, record.Schedule.Kind == RecordScheduleKind.RightNow);

                // Save xml data
                SaveXmlData(record);

                // Aditional task data
                SetAdditionalData(definition, record, _dbFile);

                // Action
                SetAction(definition, record, _dbFile, _logFolder);

                // Register task
                task = _taskFolder.RegisterTaskDefinition(_taskName, definition);
                isOk = true;

                // Run task right now?
                if (record.Schedule.Kind != RecordScheduleKind.RightNow)
                {
                    return(true);
                }

                try
                {
                    task.Run();
                    return(true);
                }
                catch (Exception ex)
                {
                    _exceptionHandler(new ExceptionEventData(Texts.TaskRunException, ex));
                    return(false);
                } // try-catch
            }
            catch (Exception ex)
            {
                _exceptionHandler(new ExceptionEventData(Texts.TaskCreationException, ex));
                return(false);
            }
            finally
            {
                if (!isOk)
                {
                    RecordTaskSerialization.TryDeleteFromDatabase(record.TaskId, _dbFile);
                } // if
                if (task != null)
                {
                    task.Dispose();
                    task = null;
                } // if
                if (definition != null)
                {
                    definition.Dispose();
                    definition = null;
                } // if
                if (_taskFolder != null)
                {
                    _taskFolder.Dispose();
                    _taskFolder = null;
                } // if
                if (taskScheduler != null)
                {
                    taskScheduler.Dispose();
                    taskScheduler = null;
                } // if
                _taskName = null;
            }     // try-finally
        }         // CreateTask