Пример #1
0
        /// <summary>

        /// Add a candidate for resolving.

        /// If the candidates are currently being resolved, they will

        /// also be resolved in the the 'next batch' of _nextProcessing

        /// </summary>

        /// <param name="path">Path to process</param>

        /// <param name="depth">Current depth</param>

        /// <param name="parent">Parent candidate if any </param>
        public SubmissionCandidate Add(string path, int depth = 0, SubmissionCandidate parent = null)
        {
            if (depth > 20)
            {
                // @TODO
                // Make this more user friendly.
                // YUp. ...
                throw new Exception("Hit maximum folder depth");
            }

            SubmissionCandidate candidate = new SubmissionCandidate(path, depth, parent);

            if (_isProcessing)
            {
                lock (_nextProcessingObject)
                {
                    _nextProcessing.Add(candidate);
                }
            }
            else
            {
                _processing.Add(candidate);
            }

            return(candidate);
        }
Пример #2
0
        /// <summary>

        /// Submission constructor

        /// </summary>

        /// <param name="session">Current session</param>

        /// <param name="candidate">Candidate to work with</param>
        internal Submission(HunterSession session, SubmissionCandidate candidate)
        {
            // Assign references
            _session   = session;
            _candidate = candidate;

            // Assign Defaults
            FirstName           = string.Empty;
            LastName            = string.Empty;
            StudentID           = string.Empty;
            ContentLength       = 0;
            ContentHash         = string.Empty;
            Content             = string.Empty;
            MetaLastModifiedBy  = string.Empty;
            MetaCreator         = string.Empty;
            MetaUsername        = string.Empty;
            MetaDateLastPrinted = DateTime.MinValue;
            MetaDateModified    = DateTime.MinValue;
            MetaDateCreated     = DateTime.MinValue;

            // Create our relative path based on the working directory (just remove it and add a directory character)
            _relativePath = AbsolutePath.Replace(session.WorkingDirectory, string.Empty);

            DetectName();

            // Figure out the processor
            _processor = candidate.FileType.CreateProcessor(this);

            // Do a quick check of the meta data filling out some of our details
            if (Processor != null)
            {
                Processor.Process();
            }

            // Check Processor
            if (!Processor.IsProcessed())
            {
                _session.Log.Add("- " + Markdown.Emphasis("Unable to process this submission. Please confirm that it is a supported file type."));
            }

            // Create Checks
            _checks = CheckFactory.CreateChecks(this, Processor.GetCheckTypes());



            // Create simple ID

            _guidHash = Core.Compare.Hash(_candidate.Guid.ToString()).Substring(0, 6);
        }
Пример #3
0
        /// <summary>

        /// Search a directory or archive and add any files or sub-directories

        /// to the list of candidates currently being resolved

        /// </summary>

        /// <param name="candidates">Candidates currently being resolved</param>
        public void Explode(SubmissionCandidates candidates, string workingDirectory)
        {
            if (IsArchive)
            {
                // Archives in Archives!!
                if (IsArchivedFile)
                {
                    string exportPath = Path.Combine(workingDirectory, HunterConfig.GalileoDefaultDataFolder + Path.DirectorySeparatorChar + "galileo_" + Guid.ToString() + FileExtension);

                    ArchiveInfo.Extract(ReadPath, exportPath);
                    _resolvePath = exportPath;
                }

                if (_fileType == FileTypes.Types.Zip)
                {
                    _archiveInfo     = new ZipArchiveInfo(ReadPath);
                    _archiveChildren = new List <SubmissionCandidate>(10);

                    if (_archiveInfo.IsOpen == false)
                    {
                        // Probably best to do something better than this?
                        throw new Exception("Could not open archive???");
                    }

                    foreach (var fileName in _archiveInfo)
                    {
                        SubmissionCandidate candidate = candidates.Add(fileName, _depth + 1, this);
                        _archiveChildren.Add(candidate);
                    }

                    // We leave _archiveInfo open, because later the files
                    // will want to be inspected and possibly extracted.
                }
            }
            else if (IsDirectory)
            {
                System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(ReadPath);
                foreach (var file in info.EnumerateFiles())
                {
                    candidates.Add(file.FullName, _depth + 1, this);
                }
                foreach (var directory in info.EnumerateDirectories())
                {
                    candidates.Add(directory.FullName, _depth + 1, this);
                }
            }
        }
Пример #4
0
        /// <summary>

        /// Run all the filters through a Candidate and return if it was

        /// filtered or not.

        /// </summary>

        /// <param name="candidate">The candidate to filter against</param>

        /// <returns></returns>
        public bool ApplyFilter(SubmissionCandidate candidate)
        {
            if (_filters == null || _filters.Count == 0)
            {
                return(false);
            }

            foreach (var filter in _filters)
            {
                if (filter.Filter(candidate))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #5
0
        /// <summary>

        /// Constructor for Submission Candidate

        /// </summary>

        /// <param name="path">Path to the candidate</param>

        /// <param name="depth">Current filesystem depth</param>

        /// <param name="parent">Any parent submission</param>
        public SubmissionCandidate(string path, int depth, SubmissionCandidate parent)
        {
            _guid          = Guid.NewGuid();
            _guidShorthand = _guid.ToString("N").Substring(0, 6);
            _resolution    = SubmissionCandidateResolution.None;
            _depth         = depth;
            _path          = path;
            _parent        = parent;
            _fileType      = FileTypes.Types.None;
            _resolvePath   = string.Empty;

            // Initial set of naming information, before processing or exploding, useful
            // for any sort of filtering that gets done prior to exploding
            _fileName = Path.GetFileName(path);
            _fileNameWithoutExtension = Path.GetFileNameWithoutExtension(_fileName);
            _fileExtension            = Path.GetExtension(_fileName);
        }