Beispiel #1
0
        private bool RunJob(InterfaceDefinitionJobData jobData)
        {
            // display some information about the job
            _Broadcaster.Info("Found the job with the name '{0}'.", jobData.Name);
            //_Broadcaster.Info("Description: '{0}'", jobData.Description);
            //_Broadcaster.Info("Estimated Duration: '{0}'", jobData.EstimatedDurationRemarks);

            string codeFileName = String.Format("{0}.sny", jobData.Id.ToString());
            string codeFilePath = Path.Combine(EnvironmentVariables.InterfaceDefinitionCodeDirectoryPath, codeFileName);

            if (File.Exists(codeFilePath) == false)
            {
                _Broadcaster.Error("Code file of job '{0}' not found at '{1}'.", jobData.Name, codeFilePath);
                return(false);
            }

            try
            {
                string code = File.ReadAllText(codeFilePath);
                Dictionary <string, string> listOfIncludeCode = null;

                if (jobData.IncludeFiles != null && jobData.IncludeFiles.Count != 0)
                {
                    listOfIncludeCode = new Dictionary <string, string>();

                    foreach (var includeFileData in jobData.IncludeFiles)
                    {
                        string includeFilePath = Path.Combine(EnvironmentVariables.FilesystemDirectoryPath, includeFileData.RelativePath);

                        if (File.Exists(includeFilePath))
                        {
                            string includeFileCode = File.ReadAllText(includeFilePath);
                            listOfIncludeCode.Add(includeFileData.Alias, includeFileCode);
                        }
                        else
                        {
                            _Broadcaster.Warning("Include file of job '{0}' not found at '{1}'.", jobData.Name, includeFilePath);
                        }
                    }
                }

                _Broadcaster.Info("Start running the file at '{0}'.", codeFilePath);

                RunFile(code, listOfIncludeCode);

                _Broadcaster.Info("Finished executing the job '{0}'.", jobData.Name);
            }
            catch (SyneryException ex)
            {
                _Broadcaster.Error(ex, "Synery");
                return(false);
            }
            catch (Exception ex)
            {
                _Broadcaster.Error("An unknown error occurred while running the job '{0}'. Message: '{1}'.", jobData.Name, ex.Message);
                return(false);
            }

            return(true);
        }