Exemplo n.º 1
0
        /// <summary>
        /// Loads all previous results from a given directory.
        /// </summary>
        /// <param name="jobID">The identifier of the job represented by
        /// the directory</param>
        /// <param name="dir">The directory to load from</param>
        /// <returns>An enumerable set of previous results.</returns>
        private ICollection <PersistedResult> _loadFromDir(Guid jobID, string dir)
        {
            ICollection <PersistedResult> results = new List <PersistedResult>();
            var files = Directory.EnumerateFiles(dir, "*.png");

            foreach (string fileName in files)
            {
                PersistedResult result = _createResult(jobID, fileName);
                if (result != null)
                {
                    results.Add(result);
                }
            }

            return(results);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the result to the provided job.
        /// </summary>
        /// <param name="job">The job associated with the result.</param>
        /// <param name="result">The result to save</param>
        private void _storeResult(Guid job, PersistedResult result)
        {
            ICollection <PersistedResult> results = null;

            _resultsMap.TryGetValue(job, out results);
            if (results != null)
            {
                results.Add(result);
            }
            else
            {
                results = new List <PersistedResult>();
                results.Add(result);
                _resultsMap.Add(job, results);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Persits the output of a job.
        /// </summary>
        /// <param name="jobID">The unique identifier of the job to save
        /// the image against.</param>
        /// <param name="output">The <see cref="Image"/> generated from a
        /// complete job.</param>
        /// <param name="identifier">The identifier for the input provided
        /// by the client.</param>
        public void Persist(Guid jobID, Image output, object identifier)
        {
            PersistedResult r = null;

            if (identifier is string)
            {
                r = new PersistedResult(output, (string)identifier);
            }
            else
            {
                r = new PersistedResult(output, _sequence);
            }

            _sequence++;
            _storeResult(jobID, r);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Deletes a result from a particular job with the associated identifier
        /// from the storage.
        /// </summary>
        /// <param name="jobID">The unique identifier of the job to delete
        /// the results for.</param>
        /// <param name="identifier">The identifier given to the input to be
        /// deleted.</param>
        /// <returns><c>true</c> if the result from the job was deleted
        /// successfully; <c>false</c> otherwise.</returns>
        public bool Delete(Guid jobID, object identifier)
        {
            if (_resultsMap.ContainsKey(jobID) == false)
            {
                return(false);
            }

            ICollection <PersistedResult> results = _resultsMap[jobID];
            PersistedResult result = results.Where(x => x.Identifier == identifier).FirstOrDefault();

            if (result != null)
            {
                results.Remove(result);
                return(true);
            }
            else
            {
                return(false);
            }
        }