public static void getFechAndLayouXml(ExcelMatrix dataMatrix, ViewExcelSheetsInfo sheetView, out string fetchXml, out string viewXml) { List <ViewFeo> viewFeoList = new List <ViewFeo>(); for (int i = 0; i < dataMatrix.numberofElements; i++) { string[] row = dataMatrix.getRow(i); string[] values = getEntityRelation(row[ExcelColumsDefinition.VIEWATTRIBUTEENTITY]); string attributeName = row[ExcelColumsDefinition.VIEWATTRIBUTENAME]; if (attributeName.LastIndexOf("-") >= 0) { attributeName = attributeName.Substring(attributeName.LastIndexOf("-") + 1, attributeName.Length - attributeName.LastIndexOf("-") - 1); attributeName = attributeName.Trim(); } string attributeEntity = string.Empty; string attributeRelationAttribute = string.Empty; if (values != null && values.Count() == 2) { attributeEntity = values[0]; attributeRelationAttribute = values[1]; } string attributewidth = row[ExcelColumsDefinition.VIEWATTRIBUTEWIDTH]; ViewsRelationsObj obj = null; if (!string.IsNullOrEmpty(attributeEntity)) { obj = sheetView.relationsList.Where(x => x.relationAlias != null && x.entity.Equals(attributeEntity, StringComparison.InvariantCultureIgnoreCase) && x.relationTo.Equals(attributeRelationAttribute, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); } else { obj = sheetView.relationsList.Where(x => x.relationAlias == null).FirstOrDefault(); attributeEntity = obj.entity; } ViewFeo viewFeo = new ViewFeo() { AttributeName = attributeName, AttributeEntity = attributeEntity, AttributeWidth = attributewidth, AttributeObj = obj, }; if (obj == null) { setAttributesObj(viewFeo, sheetView.relationsList); } viewFeoList.Add(viewFeo); } viewXml = getViewXmlString(viewFeoList, sheetView.viewObj); removeUnnecessaryLinksAttributes(sheetView.viewObj, sheetView); fetchXml = getFecthXmlString(viewFeoList, sheetView.fetchObj); }
private static void setAttributesObj(ViewFeo viewFeo, List <ViewsRelationsObj> relObj) { ViewsRelationsObj mainobj = relObj.Where(x => x.relationAlias == null).FirstOrDefault(); OneToManyRelationshipMetadata rel = mainobj.entityMetadata.ManyToOneRelationships.Where(x => x.ReferencedEntity.Equals(viewFeo.AttributeEntity, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (rel != null) { viewFeo.AttributeObj = new ViewsRelationsObj() { entity = viewFeo.AttributeEntity.ToLower(), entityMetadata = GlobalOperations.Instance.CRMOpHelper.RetriveEntityAtrribute(viewFeo.AttributeEntity), relationAlias = string.Concat("a_", Guid.NewGuid().ToString().Replace("-", "")).ToLower(), relationFrom = rel.ReferencedAttribute.ToLower(), relationTo = rel.ReferencingAttribute.ToLower() }; relObj.Add(viewFeo.AttributeObj); } }