Esempio n. 1
0
        public static FileFilteringServiceInvokerRequest CreateInstance(string fileName, Stream fileStream, int textScanLimit, string organizationId)
        {
            ArgumentValidator.ThrowIfNullOrEmpty("fileName", fileName);
            ArgumentValidator.ThrowIfInvalidValue <Stream>("fileStream", fileStream, (Stream stream) => stream != null || stream.Length > 0L);
            ArgumentValidator.ThrowIfNullOrEmpty("organizationId", organizationId);
            TimeSpan       scanTimeout    = FileFilteringServiceInvokerRequest.GetScanTimeout(fileStream);
            ContentManager contentManager = new ContentManager(Path.GetTempPath());
            FileFipsDataStreamFilteringRequest fileFipsDataStreamFilteringRequest = FileFipsDataStreamFilteringRequest.CreateInstance(fileName, fileStream, contentManager);

            return(new FileFilteringServiceInvokerRequest(organizationId, scanTimeout, textScanLimit, fileFipsDataStreamFilteringRequest));
        }
Esempio n. 2
0
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            if (this.FileData == null || !this.FileData.Any <byte>())
            {
                throw new ErrorFileIsTooSmallForFingerprintException();
            }
            if (this.FileData.Length > 15728640)
            {
                throw new ErrorFileIsTooLargeForFingerprintException(this.FileData.Length, 15728640);
            }
            int textScanLimit = this.GetTextScanLimit();

            try
            {
                using (MemoryStream memoryStream = new MemoryStream(this.FileData))
                {
                    string fileName = "Default";
                    using (FileFilteringServiceInvokerRequest fileFilteringServiceInvokerRequest = FileFilteringServiceInvokerRequest.CreateInstance(fileName, memoryStream, textScanLimit, base.CurrentOrgContainerId.ObjectGuid.ToString()))
                    {
                        base.WriteVerbose(Strings.VerboseBeginTextExtraction(this.FileData.Length, textScanLimit));
                        FilteringResults unifiedContentResults = UnifiedContentServiceInvoker.GetUnifiedContentResults(fileFilteringServiceInvokerRequest);
                        base.WriteVerbose(Strings.VerboseEndTextExtraction(unifiedContentResults.Streams.Count));
                        List <StreamIdentity> list = (from streamId in unifiedContentResults.Streams
                                                      where NewFingerprint.IsTextAvailableStream(streamId)
                                                      select streamId).ToList <StreamIdentity>();
                        string streamNames = string.Join(";", from streamId in list
                                                         select string.Format("{0}: {1}", streamId.Name, string.Join <StreamType>(",", streamId.Types ?? new StreamType[0])));
                        base.WriteVerbose(Strings.VerboseExtractedTextStreams(list.Count, streamNames));
                        StreamIdentity streamIdentity = unifiedContentResults.Streams.FirstOrDefault((StreamIdentity streamId) => streamId.ParentId == 0);
                        if (!NewFingerprint.IsSupportedFileType(streamIdentity))
                        {
                            throw new ErrorFileTypeIsUnsupportedException();
                        }
                        StreamIdentity streamIdentity2 = null;
                        if (NewFingerprint.IsTextAvailableStream(streamIdentity))
                        {
                            streamIdentity2 = streamIdentity;
                        }
                        else if (list.Count > 0)
                        {
                            streamIdentity2 = list[0];
                        }
                        if (streamIdentity2 == null)
                        {
                            throw new ErrorFileHasNoTextContentException();
                        }
                        if (RuleAgentResultUtils.HasExceededProcessingLimit(streamIdentity2))
                        {
                            throw new ErrorExceededTextScanLimitException(textScanLimit);
                        }
                        if (list.Count > 1 && (streamIdentity.Types == null || streamIdentity.Types.Length != 1 || streamIdentity.Types[0] != 3))
                        {
                            this.WriteWarning(Strings.WarningMultipleStreamForFingerprint(list.Count, streamIdentity2.Name));
                        }
                        this.extractedText = streamIdentity2.Content.TextReader.ReadToEnd();
                        base.WriteVerbose(Strings.VerboseSelectedTextStream(this.extractedText.Length, this.extractedText));
                    }
                }
            }
            catch (FilteringServiceFailureException innerException)
            {
                throw new ErrorFailedExtractTextForFingerprintException(innerException);
            }
            TaskLogger.LogExit();
        }