Пример #1
0
 private void ProcessForRelationships(CustomisationExporterRequest request,
                                      CustomisationExporterResponse response,
                                      LogController controller)
 {
     if (request.Relationships)
     {
         var allRelationship = new List <RelationshipExport>();
         var types           = GetRecordTypesToExport(request).OrderBy(t => Service.GetDisplayName(t)).ToArray();
         var count           = types.Count();
         var manyToManyDone  = new List <string>();
         for (var i = 0; i < count; i++)
         {
             var thisType      = types.ElementAt(i);
             var thisTypeLabel = Service.GetDisplayName(thisType);
             controller.UpdateProgress(i, count, "Exporting Relationships For " + thisTypeLabel);
             try
             {
                 var relationships = Service.GetManyToManyRelationships(thisType);
                 for (var j = 0; j < relationships.Count(); j++)
                 {
                     var relationship = relationships.ElementAt(j);
                     try
                     {
                         if (relationship.RecordType1 == thisType
                             ||
                             (!request.DuplicateManyToManyRelationshipSides &&
                              !manyToManyDone.Contains(relationship.SchemaName))
                             )
                         {
                             allRelationship.Add(new RelationshipExport(relationship.SchemaName,
                                                                        relationship.RecordType1, relationship.RecordType2,
                                                                        relationship.IsCustomRelationship, relationship.RecordType1DisplayRelated,
                                                                        relationship.RecordType2DisplayRelated
                                                                        , relationship.Entity1IntersectAttribute, relationship.Entity2IntersectAttribute,
                                                                        RelationshipExport.RelationshipType.ManyToMany,
                                                                        relationship.RecordType1UseCustomLabel, relationship.RecordType2UseCustomLabel,
                                                                        relationship.RecordType1CustomLabel, relationship.RecordType2CustomLabel
                                                                        , relationship.RecordType1DisplayOrder, relationship.RecordType2DisplayOrder, relationship.MetadataId
                                                                        , null));
                             manyToManyDone.Add(relationship.SchemaName);
                         }
                         if (relationship.RecordType2 == thisType &&
                             (request.DuplicateManyToManyRelationshipSides ||
                              (!manyToManyDone.Contains(relationship.SchemaName))))
                         {
                             allRelationship.Add(new RelationshipExport(relationship.SchemaName,
                                                                        relationship.RecordType2, relationship.RecordType1,
                                                                        relationship.IsCustomRelationship, relationship.RecordType2DisplayRelated,
                                                                        relationship.RecordType1DisplayRelated
                                                                        , relationship.Entity2IntersectAttribute, relationship.Entity1IntersectAttribute,
                                                                        RelationshipExport.RelationshipType.ManyToMany,
                                                                        relationship.RecordType2UseCustomLabel, relationship.RecordType1UseCustomLabel,
                                                                        relationship.RecordType2CustomLabel, relationship.RecordType1CustomLabel
                                                                        , relationship.RecordType2DisplayOrder, relationship.RecordType1DisplayOrder
                                                                        , relationship.MetadataId, null));
                             manyToManyDone.Add(relationship.SchemaName);
                         }
                     }
                     catch (Exception ex)
                     {
                         response.AddResponseItem(
                             new CustomisationExporterResponseItem("Error Exporting Relationship",
                                                                   relationship.SchemaName, ex));
                     }
                 }
                 if (request.IncludeOneToManyRelationships)
                 {
                     var oneTorelationships = Service.GetOneToManyRelationships(thisType);
                     for (var j = 0; j < oneTorelationships.Count(); j++)
                     {
                         var relationship = oneTorelationships.ElementAt(j);
                         try
                         {
                             var isCustomRelationship = Service.FieldExists(relationship.ReferencingAttribute, relationship.ReferencingEntity) &&
                                                        Service.GetFieldMetadata(relationship.ReferencingAttribute, relationship.ReferencingEntity).IsCustomField;
                             allRelationship.Add(new RelationshipExport(relationship.SchemaName,
                                                                        relationship.ReferencedEntity, relationship.ReferencingEntity,
                                                                        isCustomRelationship, false,
                                                                        relationship.DisplayRelated
                                                                        , null, relationship.ReferencingAttribute,
                                                                        RelationshipExport.RelationshipType.OneToMany, false, relationship.IsCustomLabel,
                                                                        null, relationship.GetRelationshipLabel
                                                                        , 0, relationship.DisplayOrder, relationship.MetadataId, relationship.DeleteCascadeConfiguration));
                         }
                         catch (Exception ex)
                         {
                             response.AddResponseItem(
                                 new CustomisationExporterResponseItem("Error Exporting Relationship",
                                                                       relationship.SchemaName, ex));
                         }
                     }
                 }
             }
             catch (Exception ex)
             {
                 response.AddResponseItem(new CustomisationExporterResponseItem("Error Exporting Relationships",
                                                                                thisType, ex));
             }
         }
         response.AddListToOutput("Relationships", allRelationship);
     }
 }