protected override void ProcessRecord()
        {
            var missedWebResourcesCount = 0;
            var resourceFiles           = new HashSet <string>();
            var patterns = (string.IsNullOrWhiteSpace(SearchPattern)) ? new string[1] {
                "*"
            } :
            SearchPattern.Split(',');

            foreach (var pattern in patterns)
            {
                WriteVerbose($"Processing pattern {pattern}...");

                Directory.GetFiles(Path, pattern.Trim(), SearchOption.AllDirectories).ToList()
                .ForEach((item) => resourceFiles.Add(item));
            }

            if (resourceFiles.Count == 0)
            {
                WriteVerbose($"There are no files in folder '{Path}' matching patterns {SearchPattern}");
                return;
            }
            else
            {
                WriteVerbose($"Found {resourceFiles.Count} resource files.");
            }

            using (var context = new CIContext(OrganizationService))
            {
                WriteVerbose($"Retrieving web resources from CRM...");
                var query = from resource in context.WebResourceSet
                            select resource;
                var solutionId = GetSolutionId(context, SolutionName);
                if (!solutionId.Equals(Guid.Empty))
                {
                    query = from resource in context.WebResourceSet
                            join sol in context.SolutionComponentSet on resource.Id equals sol.ObjectId
                            where sol.SolutionId.Equals(solutionId)
                            select resource;
                }

                var allWebResources = query.ToList();
                WriteVerbose($"Found {allWebResources.Count}");

                var importexportxml = new StringBuilder();
                var webResource     = default(WebResource);
                foreach (var resourceFile in resourceFiles)
                {
                    WriteVerbose($"Processing file: {System.IO.Path.GetFileName(resourceFile)}");
                    try
                    {
                        webResource = allWebResources.Single(CompareCondition(resourceFile));
                        WriteVerbose($"Found web resource: {webResource.Name}");
                    }
                    catch (Exception ex)
                    {
                        missedWebResourcesCount++;
                        WriteWarning($"Cannot process {resourceFile}: {ex.Message}");
                        continue;
                    }

                    // update in context
                    var fileContent = Convert.ToBase64String(File.ReadAllBytes(resourceFile));
                    if (webResource.Content?.GetHashCode() != fileContent.GetHashCode())
                    {
                        webResource.Content = fileContent;
                        //context.UpdateObject(webResource);

                        // update web resource then add to a solution.
                        UpdateRequest update = new UpdateRequest
                        {
                            Target = webResource
                        };
                        update.Parameters.Add("SolutionUniqueName", SolutionName);

                        context.Execute(update);

                        // add id to publish xml
                        if (Publish)
                        {
                            importexportxml.Append($"<webresource>{webResource.Id}</webresource>");
                        }
                    }
                }

                // Update
                WriteVerbose("Saving changes...");
                context.SaveChanges();

                // Publish
                if (Publish)
                {
                    WriteVerbose("Publishing web resources...");
                    PublishXmlRequest req = new PublishXmlRequest()
                    {
                        ParameterXml = $"<importexportxml><webresources>{importexportxml.ToString()}</webresources></importexportxml>"
                    };
                    OrganizationService.Execute(req);
                }

                WriteObject($"{resourceFiles.Count - missedWebResourcesCount} out of {resourceFiles.Count} web resources were processed");

                if (FailIfWebResourceNotFound && missedWebResourcesCount > 0)
                {
                    ThrowTerminatingError(new ErrorRecord(
                                              new RuntimeException($"{missedWebResourcesCount} web resources were not found"),
                                              "", ErrorCategory.ObjectNotFound, null));
                }
            }
        }