Beispiel #1
0
        private IRecord ExtractMainRecord(RecordExtractContainer container)
        {
            container.Controller.UpdateProgress(1, 3, "Loading Record");
            var recordToExtract = Service.Get(container.Request.RecordLookup.RecordType,
                                              container.Request.RecordLookup.Id);

            container.RecordToExtract = recordToExtract;
            var primaryField = Service.GetPrimaryField(recordToExtract.Type);
            var recordName   = recordToExtract.GetStringField(primaryField);

            container.AddBookmark(ExtractUtility.CheckStripFormatting(recordName, container.RecordToExtractType,
                                                                      primaryField));
            container.Response.Record = recordToExtract;
            container.Controller.UpdateProgress(2, 3, "Loading Record");
            WriteRecordToSection(recordToExtract, container.Section, DetailLevel.AllFields, container.Request);
            return(recordToExtract);
        }
        void ProcessRecordsContainedInName(TextSearchContainer container)
        {
            var bookmark    = container.AddHeadingWithBookmark("Records With Matching Name");
            var recordTypes = GetSearchRecordTypes().ToArray();
            var count       = recordTypes.Count();
            var done        = 0;

            foreach (var recordType in recordTypes)
            {
                try
                {
                    var progressTextPrefix = string.Format("Searching Record Names In {0}",
                                                           Service.GetCollectionName(recordType));
                    container.Controller.UpdateProgress(done++, count, progressTextPrefix);
                    var primaryField = Service.GetPrimaryField(recordType);
                    if (!primaryField.IsNullOrWhiteSpace())
                    {
                        var conditions = new[]
                        {
                            new Condition(primaryField, ConditionType.Like,
                                          string.Format("%{0}%", container.Request.SearchText))
                        };
                        var matches =
                            Service.RetrieveAllAndClauses(recordType, conditions, new[] { primaryField }).ToArray();
                        if (matches.Any())
                        {
                            try
                            {
                                var thisBookmark =
                                    container.Section.AddHeading2WithBookmark(string.Format("{0} ({1})", Service.GetCollectionName(recordType), matches.Count()));
                                bookmark.AddChildBookmark(thisBookmark);
                                var table          = container.Section.Add1ColumnTable();
                                var matchCount     = matches.Count();
                                var matchCountDone = 0;
                                foreach (var match in matches)
                                {
                                    container.Controller.UpdateProgress(done, count,
                                                                        string.Format("{0} (Adding {1} Of {2})", progressTextPrefix, ++matchCountDone,
                                                                                      matchCount));
                                    container.AddNameMatch(match);
                                    var outputText = match.GetStringField(primaryField);
                                    outputText = ExtractUtility.CheckStripFormatting(outputText, recordType,
                                                                                     primaryField);
                                    table.AddRow(outputText);
                                }
                            }
                            catch (Exception ex)
                            {
                                container.Response.AddResponseItem(
                                    new TextSearchResponseItem("Error Adding Matched Record",
                                                               recordType, ex));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    container.Response.AddResponseItem(new TextSearchResponseItem("Error Adding Match Records",
                                                                                  recordType, ex));
                }
            }
        }
Beispiel #3
0
        private void WriteRecordToSection(IRecord record, Section section, DetailLevel detailLevel, RecordExtractToDocumentRequest request)
        {
            if (detailLevel == DetailLevel.CountsOnly)
            {
                return;
            }

            var primaryField = Service.GetPrimaryField(record.Type);
            var recordName   = Service.GetFieldAsDisplayString(record, primaryField);
            var table        = section.Add2ColumnTable();

            table.AddFieldToTable(Service.GetFieldLabel(primaryField, record.Type),
                                  ExtractUtility.CheckStripFormatting(recordName, record.Type, primaryField));

            if (detailLevel == DetailLevel.Names || request.OnlyDisplayName(record.Type))
            {
                return;
            }

            var fields = Service.GetFields(record.Type).Intersect(record.GetFieldsInEntity()).ToArray();

            if (fields.Any())
            {
                var primaryKey            = Service.GetPrimaryKey(record.Type);
                var actualFieldsToExclude = new List <string> {
                    primaryField, primaryKey
                };

                actualFieldsToExclude.AddRange(request.GetAllFieldsToExclude(record.Type));

                foreach (var field in fields)
                {
                    var fieldType = Service.GetFieldType(field, record.Type);
                    if (fieldType == RecordFieldType.Uniqueidentifier)
                    {
                        actualFieldsToExclude.Add(field);
                    }
                    else if (Service.GetFieldType(field, record.Type) == RecordFieldType.String &&
                             new[] { TextFormat.PhoneticGuide, TextFormat.VersionNumber }.Contains(
                                 Service.GetFieldMetadata(field, record.Type).TextFormat))
                    {
                        actualFieldsToExclude.Add(field);
                    }
                    if (field.EndsWith("_base") && fields.Contains(field.Left(field.Length - 5)))
                    {
                        actualFieldsToExclude.Add(field);
                    }
                }

                var orderedFieldsToDisplay = fields
                                             .Where(f => !actualFieldsToExclude.Contains(f))
                                             .OrderBy(f => Service.GetFieldLabel(f, record.Type));


                foreach (var field in orderedFieldsToDisplay)
                {
                    var label   = Service.GetFieldLabel(field, record.Type);
                    var display = Service.GetFieldAsDisplayString(record, field);
                    if (request.StripHtmlTags && IsHtmlField(record.Type, field, request))
                    {
                        display = display.StripHtml();
                    }
                    if (!label.IsNullOrWhiteSpace() && !display.IsNullOrWhiteSpace() &&
                        !GetStringValuesToExclude().Contains(display))
                    {
                        table.AddFieldToTable(label, display);
                    }
                }
            }
        }