コード例 #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);
        }
        private InterfaceDefinitionJobData LoadJob(XElement root)
        {
            InterfaceDefinitionJobData data = new InterfaceDefinitionJobData();

            data.Id          = new Guid(GetRequiredAttributeValue(root, "id"));
            data.Name        = GetRequiredElementValue(root, "Name");
            data.Description = GetOptionalElementValue(root, "Description");
            data.EstimatedDurationRemarks = GetRequiredElementValue(root, "EstimatedDurationRemarks");
            data.IncludeFiles             = LoadIncludeFiles(root.Element("IncludeFiles"));

            return(data);
        }
コード例 #3
0
        /// <summary>
        /// Runs the Job with the given GUID.
        /// </summary>
        /// <param name="guid">The GUID of an existing Job from the current Interface Definition.</param>
        /// <returns></returns>
        public ExecutionResult RunJob(Guid guid)
        {
            if (IsInitialized == false)
            {
                throw new Exception(String.Format("{0} must be initialized before running a job", this.GetType().Name));
            }

            ExecutionResult result = PrepareRuntimeResult(false);

            InterfaceDefinitionJobData jobData = (from j in _InterfaceDefinitionData.Jobs
                                                  where j.Id == guid
                                                  select j).FirstOrDefault();

            if (jobData == null)
            {
                _Broadcaster.Error("The job with the Id '{0}' wasn't found.", guid.ToString());
                return(result);
            }

            result.IsSuccess = RunJob(jobData);

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Runs the Job with the given name.
        /// </summary>
        /// <param name="name">The full name (case insensitive) of an existing Job from the current Interface Definition.</param>
        /// <returns></returns>
        public ExecutionResult RunJob(string name)
        {
            if (IsInitialized == false)
            {
                throw new Exception(String.Format("{0} must be initialized before running a job", this.GetType().Name));
            }

            ExecutionResult result = PrepareRuntimeResult(false);

            InterfaceDefinitionJobData jobData = (from j in _InterfaceDefinitionData.Jobs
                                                  // compare case insensitive
                                                  where j.Name.ToLower() == name.ToLower()
                                                  select j).FirstOrDefault();

            if (jobData == null)
            {
                _Broadcaster.Error("The job with the name '{0}' wasn't found.", name);
                return(result);
            }

            result.IsSuccess = RunJob(jobData);

            return(result);
        }
        public void Setup()
        {
            // Prepare the paths of the temporary XML file and the expected XML file
            string solutionDirectoryPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())));

            _XmlFilePath         = Path.Combine(solutionDirectoryPath, @"_TestData\InterfaceBooster\InterfaceDefinition\saveInterfaceDefinition_TestFile.xml");
            _ExpectedXmlFilePath = Path.Combine(solutionDirectoryPath, @"_TestData\InterfaceBooster\InterfaceDefinition\saveInterfaceDefinition_ExpectedContent.xml");

            // Delete the XML file if it already exists
            if (File.Exists(_XmlFilePath))
            {
                File.Delete(_XmlFilePath);
            }

            _InterfaceDefinitionData = new InterfaceDefinitionData();

            // Details

            _InterfaceDefinitionData.Id                             = new Guid("f3b58f84-cbc0-4560-856d-f6c2b2feea5b");
            _InterfaceDefinitionData.Details.Name                   = "PROFFIX CSV Article Import";
            _InterfaceDefinitionData.Details.Description            = "Imports some articles from a comma separated value file to PROFFIX.";
            _InterfaceDefinitionData.Details.Author                 = "Roger Guillet";
            _InterfaceDefinitionData.Details.DateOfCreation         = new DateTime(2014, 2, 7);
            _InterfaceDefinitionData.Details.DateOfLastChange       = new DateTime(2014, 2, 26);
            _InterfaceDefinitionData.Details.Version                = new Version(1, 0, 0, 1);
            _InterfaceDefinitionData.Details.RequiredRuntimeVersion = new Version(1, 0, 0, 0);

            // Provider Plugins

            _InterfaceDefinitionData.RequiredPlugins.ProviderPluginInstances.Add(new ProviderPluginInstanceReference()
            {
                SyneryIdentifier   = "PROFFIX",
                IdPlugin           = new Guid("485eccb4-3920-4dc3-9ed4-27f65e8b3c91"),
                PluginName         = "PROFFIX Database",
                IdPluginInstance   = new Guid("b139306d-a688-43ae-a9dd-4e692fc2caea"),
                PluginInstanceName = "4.0.0000.0001",
            });

            _InterfaceDefinitionData.RequiredPlugins.ProviderPluginInstances.Add(new ProviderPluginInstanceReference()
            {
                SyneryIdentifier   = "CSV",
                IdPlugin           = new Guid("66CE1D53-14B3-420E-949F-EB94A3D69072"),
                PluginName         = "CSV Provider Plugin",
                IdPluginInstance   = new Guid("F897A501-60D9-4AE5-B214-920F450E9323"),
                PluginInstanceName = "CSV Version 1.0",
            });

            // Library Plugins

            _InterfaceDefinitionData.RequiredPlugins.LibraryPlugins.Add(new LibraryPluginReference()
            {
                SyneryIdentifier = "String",
                IdPlugin         = new Guid("74A8005D-C9F3-455F-94FC-04846493AB7B"),
                PluginName       = "String Helpers",
            });

            // Jobs

            var job1 = new InterfaceDefinitionJobData()
            {
                Id          = new Guid("79f8ca0f-c785-4f35-810e-835bc216f6b6"),
                Name        = "Run CSV Import",
                Description = "Executes the import of some articles to PROFFIX.",
                EstimatedDurationRemarks = "This import will only take a few seconds",
            };

            job1.IncludeFiles.Add(new IncludeFile()
            {
                Alias = "h", RelativePath = "helperFunctions.syn"
            });

            var job2 = new InterfaceDefinitionJobData()
            {
                Id          = new Guid("2D74CCFB-B1B3-4625-8763-99CFEB077207"),
                Name        = "Check for doublets",
                Description = "Executes a check for some doublets in PROFFIX.",
                EstimatedDurationRemarks = "This check will only take a few seconds",
            };

            job2.IncludeFiles.Add(new IncludeFile()
            {
                Alias = "h", RelativePath = "helperFunctions.syn"
            });
            job2.IncludeFiles.Add(new IncludeFile()
            {
                Alias = "px_con", RelativePath = "proffixConnection.syn"
            });

            _InterfaceDefinitionData.Jobs.Add(job1);
            _InterfaceDefinitionData.Jobs.Add(job2);
        }