Exemple #1
0
 public TextFindForm(GetContentMethod method, FindCallback findCall, bool openReplace = false)
 {
     InitializeComponent();
     SkinUtil.SetFormSkin(this);
     this.openReplace = openReplace;
     this.getContent  = method;
     this.findCall    = findCall;
 }
Exemple #2
0
        /// <summary>
        /// Returns the value of the first element in the array where predicate is true, and undefined otherwise.
        /// </summary>
        /// <param name="predicate">find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns null.</param>
        /// <returns></returns>
        public T Find(FindCallback predicate)
        {
            for (int index = 0; index < this.Length; index++)
            {
                if (predicate(this[index], index, this))
                {
                    return(this[index]);
                }
            }

            return(default(T));
        }
Exemple #3
0
        /// <summary>
        /// Search documents
        /// </summary>

        public Response Search(Document[] docs, string sourceFolder, string query)
        {
            if (docs == null)
            {
                return(PasswordProtectedResponse);
            }
            if (docs.Length == 0 || docs.Length > MaximumUploadFiles)
            {
                return(MaximumFileLimitsResponse);
            }

            SetDefaultOptions(docs, "");
            Opts.AppName        = "Search";
            Opts.MethodName     = "Search";
            Opts.FolderName     = sourceFolder;
            Opts.OutputType     = ".docx";
            Opts.ResultFileName = "Search Results";
            Opts.CreateZip      = false;

            var statusValue             = "OK";
            var statusCodeValue         = 200;
            var fileProcessingErrorCode = FileProcessingErrorCode.OK;

            if (IsValidRegex(query))
            {
                try
                {
                    var findings = new FindCallback();
                    var options  = new FindReplaceOptions()
                    {
                        ReplacingCallback = findings,
                        Direction         = FindReplaceDirection.Forward,
                        MatchCase         = false
                    };
                    foreach (var doc in docs)
                    {
                        doc.Range.Replace(new Regex(query, RegexOptions.IgnoreCase), "", options);
                    }

                    if (findings.MatchesFound > 0)
                    {
                        return(Process((inFilePath, outPath, zipOutFolder) => findings.Save(outPath)));
                    }

                    fileProcessingErrorCode = FileProcessingErrorCode.NoSearchResults;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    statusCodeValue = 500;
                    statusValue     = "500 " + ex.Message;
                }
            }
            else
            {
                fileProcessingErrorCode = FileProcessingErrorCode.WrongRegExp;
            }

            return(new Response
            {
                Status = statusValue,
                StatusCode = statusCodeValue,
                FileProcessingErrorCode = fileProcessingErrorCode
            });
        }
Exemple #4
0
 public TextFindForm(GetContentMethod method, FindCallback findCall, ReplaceCallback replaceCall)
     : this(method, findCall, true)
 {
     this.replaceCall = replaceCall;
 }
 public static extern int Find(FileSystem *file_system, string path, [MarshalAs(UnmanagedType.FunctionPtr)] FindCallback callback);