Exemple #1
0
        private RecordExtractToDocumentResponse ExtractRecordToDocument(RecordExtractToDocumentRequest request)
        {
            var             container              = new RecordExtractContainer(request);
            var             recordToExtract        = ExtractMainRecord(container);
            var             hasRelatedRecordOutput = false;
            ContentBookmark bookmark = null;

            try
            {
                var relatedTypes = GetRelatedTypes(container);

                foreach (var relatedType in relatedTypes.OrderBy(r => Service.GetDisplayName(r)))
                {
                    var recordType = relatedType;
                    try
                    {
                        var recordsToOutput = new Dictionary <string, IRecord>();
                        GetOneToManyRelated(container, relatedType, recordsToOutput);
                        GetManyToManyRelated(container, relatedType, recordsToOutput);
                        GetActivityPartyRelated(container, relatedType, recordsToOutput);
                        hasRelatedRecordOutput = AppendRelatedToDocument(recordsToOutput, hasRelatedRecordOutput,
                                                                         container, recordType, ref bookmark, request);
                    }
                    catch (Exception ex)
                    {
                        container.Response.AddResponseItem(new RecordExtractResponseItem(
                                                               "Error Loading Related Records",
                                                               recordType, ex));
                    }
                }
            }
            catch (Exception ex)
            {
                container.Response.AddResponseItem(new RecordExtractResponseItem("Error Loading Relationships",
                                                                                 recordToExtract.Type, ex));
            }
            return(container.Response);
        }
        private void AppendFieldMatchesToDocument(TextSearchContainer container,
                                                  Dictionary <string, IRecord> recordsToOutput, string recordType,
                                                  ContentBookmark bookmark)
        {
            Table2Column fieldCountTable  = null;
            var          fieldsDictionary = new Dictionary <string, int>();

            if (recordsToOutput.Any())
            {
                var recordOutput = false;
                var todoDone     = 0;
                var todoCount    = recordsToOutput.Count;
                var primaryField = Service.GetPrimaryField(recordType);

                var fieldsToExclude = GetFieldsToExlcude(container, recordType);

                //some lookup names dont get loaded into the record so will load them all now so i don't have to field by field
                recordsToOutput.Values.PopulateEmptyLookups(Service, ExtractUtility.GetSystemRecordTypesToExclude());

                var primaryFieldLabel         = Service.GetFieldLabel(primaryField, recordType);
                var recordTypeCollectionLabel = Service.GetCollectionName(recordType);
                foreach (var match in recordsToOutput.Values)
                {
                    container.Controller.UpdateLevel2Progress(todoDone++, todoCount,
                                                              string.Format("Appending {0} To Document", recordTypeCollectionLabel));

                    var fieldsToDisplay = new List <string>();
                    foreach (var field in match.GetFieldsInEntity().Where(f => !fieldsToExclude.Contains(f)))
                    {
                        if (Service.IsString(field, recordType))
                        {
                            var value = Service.GetFieldAsDisplayString(match, field);
                            if (container.Request.StripHtmlTagsPriorToSearch &&
                                IsHtmlField(recordType, field, container))
                            {
                                value = value.StripHtml();
                            }
                            if (value != null)
                            {
                                if (IsSearchMatch(value, container))
                                {
                                    fieldsToDisplay.Add(field);
                                    if (!fieldsDictionary.ContainsKey(field))
                                    {
                                        fieldsDictionary.Add(field, 0);
                                    }
                                    fieldsDictionary[field]++;
                                }
                            }
                        }
                    }

                    if (fieldsToDisplay.Any())
                    {
                        if (!recordOutput)
                        {
                            var thisBookmark =
                                container.Section.AddHeading2WithBookmark(string.Format("{0} ({1})", Service.GetCollectionName(recordType), recordsToOutput.Count()));
                            bookmark.AddChildBookmark(thisBookmark);
                            recordOutput    = true;
                            fieldCountTable = container.Section.Add2ColumnTable();
                        }
                        var table = container.Section.Add2ColumnTable();
                        table.AddFieldToTable(primaryFieldLabel, match.GetStringField(primaryField));
                        foreach (var field in fieldsToDisplay)
                        {
                            var value = Service.GetFieldAsDisplayString(match, field);
                            if (container.Request.StripHtmlTagsPriorToSearch &&
                                IsHtmlField(recordType, field, container))
                            {
                                value = value.StripHtml();
                            }
                            if (value != null)
                            {
                                if (IsSearchMatch(value, container))
                                {
                                    table.AddFieldToTable(Service.GetFieldLabel(field, recordType),
                                                          value);
                                }
                            }
                        }
                    }
                }
                //insert field count summary
                if (fieldsDictionary.Any())
                {
                    foreach (var field in fieldsDictionary
                             .OrderBy(f => Service.GetFieldLabel(f.Key, recordType)))
                    {
                        fieldCountTable.AddFieldToTable(Service.GetFieldLabel(field.Key, recordType), field.Value.ToString());
                    }
                }
            }
        }
        private void AppendFieldMatchesToDocument(TextSearchContainer container,
                                                  Dictionary <string, IRecord> recordsToOutput, string recordType,
                                                  ContentBookmark bookmark)
        {
            if (recordsToOutput.Any())
            {
                var recordOutput = false;
                var todoDone     = 0;
                var todoCount    = recordsToOutput.Count;
                var primaryField = Service.GetPrimaryField(recordType);

                var fieldsToExclude = new List <string>();
                fieldsToExclude.AddRange(Settings.GetFieldsToExclude());

                foreach (var field in Service.GetFields(recordType))
                {
                    var fieldType = Service.GetFieldType(field, recordType);
                    if (fieldType == RecordFieldType.Uniqueidentifier)
                    {
                        fieldsToExclude.Add(field);
                    }
                    else if (Service.GetFieldType(field, recordType) == RecordFieldType.String &&
                             Service.GetFieldMetadata(field, recordType).TextFormat == TextFormat.PhoneticGuide)
                    {
                        fieldsToExclude.Add(field);
                    }
                    if (field.EndsWith("_base") && fieldType == RecordFieldType.Money)
                    {
                        fieldsToExclude.Add(field);
                    }
                }

                //some lookup names don;t get loaded into the record so will load them all now so i don't have to field by field
                recordsToOutput.Values.PopulateEmptyLookups(Service, Settings.GetRecordTypesToExclude());

                var primaryFieldLabel         = Service.GetFieldLabel(primaryField, recordType);
                var recordTypeCollectionLabel = Service.GetCollectionName(recordType);
                foreach (var match in recordsToOutput.Values)
                {
                    container.Controller.UpdateLevel2Progress(todoDone++, todoCount,
                                                              string.Format("Appending {0} To Document", recordTypeCollectionLabel));

                    var fieldsToDisplay = new List <string>();
                    foreach (
                        var field in
                        match.GetFieldsInEntity().Where(f => f != primaryField && !fieldsToExclude.Contains(f)))
                    {
                        var value = Service.GetFieldAsDisplayString(match, field);
                        if (value != null)
                        {
                            var stringValue = value.CheckStripHtml(field);
                            if (IsSearchMatch(stringValue, container))
                            {
                                fieldsToDisplay.Add(field);
                            }
                        }
                    }

                    if (fieldsToDisplay.Any())
                    {
                        if (!recordOutput)
                        {
                            var thisBookmark =
                                container.Section.AddHeading2WithBookmark(string.Format("{0} ({1})", Service.GetCollectionName(recordType), recordsToOutput.Count()));
                            bookmark.AddChildBookmark(thisBookmark);
                            recordOutput = true;
                        }
                        var table = container.Section.Add2ColumnTable();
                        table.AddFieldToTable(primaryFieldLabel, match.GetStringField(primaryField));
                        foreach (var field in fieldsToDisplay)
                        {
                            var value = Service.GetFieldAsDisplayString(match, field);
                            if (value != null)
                            {
                                var stringValue = value.CheckStripHtml(field);
                                if (IsSearchMatch(stringValue, container))
                                {
                                    table.AddFieldToTable(Service.GetFieldLabel(field, recordType),
                                                          stringValue);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #4
0
 public void AddBookmark(ContentBookmark bookmark)
 {
     _bookmarks.Add(bookmark);
 }
Exemple #5
0
        private bool AppendRelatedToDocument(Dictionary <string, IRecord> recordsToOutput, bool hasRelatedRecordOutput,
                                             RecordExtractContainer container, string recordType, ref ContentBookmark bookmark, RecordExtractToDocumentRequest request)
        {
            if (recordsToOutput.Any())
            {
                var outputNumbers = recordsToOutput.Count > 1 && container.Request.RelatedDetail == DetailLevel.AllFields;
                recordsToOutput.Values.PopulateEmptyLookups(Service, GetRecordTypesToExclude());
                var recordTypeCollectionLabel = Service.GetCollectionName(recordType);
                var recordTypeLabel           = Service.GetDisplayName(recordType);
                if (!hasRelatedRecordOutput)
                {
                    hasRelatedRecordOutput = true;
                    bookmark = container.Section.AddHeading2WithBookmark("Related Records");
                    container.AddBookmark(bookmark);
                }
                var todoDone  = 0;
                var todoCount = recordsToOutput.Count;

                var thisBookmark =
                    container.Section.AddHeading3WithBookmark(string.Format("{0} ({1})", recordTypeCollectionLabel, recordsToOutput.Count));
                bookmark.AddChildBookmark(thisBookmark);

                var i = 1;
                foreach (var match in recordsToOutput.Values)
                {
                    if (outputNumbers)
                    {
                        container.Section.AddParagraph(string.Format("{0} {1}", recordTypeLabel, i++), true);
                    }
                    container.Controller.UpdateProgress(todoDone++, todoCount,
                                                        string.Format("Appending Related {0} To Document", recordTypeCollectionLabel));
                    WriteRecordToSection(match, container.Section, container.Request.RelatedDetail, request);
                }
            }
            return(hasRelatedRecordOutput);
        }
Exemple #6
0
 public void AddBookmark(ContentBookmark bookmark)
 {
     Response.AddBookmark(bookmark);
 }