private CintDynEntityCollection GetMatchingRecords(CintDynEntity cdEntity, List <string> matchattributes, List <string> updateattributes, bool preretrieveall, ref CintDynEntityCollection cAllRecordsToMatch) { log.StartSection(MethodBase.GetCurrentMethod().Name); CintDynEntityCollection matches = null; var allattributes = new List <string>(); allattributes.Add(cdEntity.PrimaryIdAttribute); if (cdEntity.Contains("ownerid")) { allattributes.Add("ownerid"); } if (cdEntity.Contains("statecode") || cdEntity.Contains("statuscode")) { allattributes.Add("statecode"); allattributes.Add("statuscode"); } allattributes = allattributes.Union(matchattributes.Union(updateattributes)).ToList(); if (preretrieveall) { if (cAllRecordsToMatch == null) { cAllRecordsToMatch = GetAllRecordsForMatching(allattributes, cdEntity); } matches = GetMatchingRecordsFromPreRetrieved(matchattributes, cdEntity, cAllRecordsToMatch); } else { QueryExpression qMatch = new QueryExpression(cdEntity.Name); // We need to be able to see if any attributes have changed, so lets make sure matching records have all the attributes that will be updated qMatch.ColumnSet = new ColumnSet(allattributes.ToArray()); foreach (var matchattr in matchattributes) { object value = null; if (cdEntity.Entity.Contains(matchattr)) { value = CintEntity.AttributeToBaseType(cdEntity.Entity[matchattr]); } else if (matchattr == cdEntity.PrimaryIdAttribute) { value = cdEntity.Id; } if (value != null) { CintQryExp.AppendCondition(qMatch.Criteria, LogicalOperator.And, matchattr, Microsoft.Xrm.Sdk.Query.ConditionOperator.Equal, value); } else { CintQryExp.AppendCondition(qMatch.Criteria, LogicalOperator.And, matchattr, Microsoft.Xrm.Sdk.Query.ConditionOperator.Null, null); } } #if DEBUG log.Log("Finding matches for {0}:\n{1}", cdEntity, CintQryExp.ConvertToFetchXml(qMatch, crmsvc)); #endif matches = CintDynEntity.RetrieveMultiple(crmsvc, qMatch, log); } log.EndSection(); return(matches); }
private void AddFilter(QueryExpression qExport, DataBlockExportFilter filter) { var valuestring = filter.Value; if (valuestring.Contains("{0}")) { throw new ArgumentOutOfRangeException("Name", "Filter", "Parameterized Filters not supported in embedded Shuffle Utils"); } var operstr = filter.Operator.ToString(); if (string.IsNullOrEmpty(operstr)) { operstr = "Equal"; } var oper = (Microsoft.Xrm.Sdk.Query.ConditionOperator)Enum.Parse(typeof(Microsoft.Xrm.Sdk.Query.ConditionOperator), operstr, true); object value = null; if (oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.EqualBusinessId && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.EqualUserId && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.EqualUserLanguage && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.NotEqualBusinessId && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.NotEqualUserId && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.NotNull && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.Null && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.ThisMonth && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.ThisWeek && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.ThisYear && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.Today && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.Tomorrow && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.Yesterday) { if (filter.TypeSpecified) { switch (filter.Type) { case FilterTypes.@string: value = valuestring; break; case FilterTypes.@int: value = int.Parse(valuestring); break; case FilterTypes.@bool: value = bool.Parse(valuestring); break; case FilterTypes.datetime: value = DateTime.Parse(valuestring); break; case FilterTypes.guid: value = new Guid(valuestring); break; default: throw new ArgumentOutOfRangeException("Type", filter.Type, "Invalid filter attribute type"); } } } var attribute = filter.Attribute; log.Log("Adding filter: {0} {1} {2}", attribute, oper, value); CintQryExp.AppendCondition(qExport.Criteria, LogicalOperator.And, attribute, oper, value); }
private void AddFilter(QueryExpression qExport, XmlNode xExpProp) { string valuestring = CintXML.GetAttribute(xExpProp, "Value"); if (valuestring.Contains("{0}")) { throw new ArgumentOutOfRangeException("Name", "Filter", "Parameterized Filters not supported in embedded Shuffle Utils"); } string operstr = CintXML.GetAttribute(xExpProp, "Operator"); if (string.IsNullOrEmpty(operstr)) { operstr = "Equal"; } Microsoft.Xrm.Sdk.Query.ConditionOperator oper = (Microsoft.Xrm.Sdk.Query.ConditionOperator)Enum.Parse(typeof(Microsoft.Xrm.Sdk.Query.ConditionOperator), operstr, true); object value = null; if (oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.EqualBusinessId && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.EqualUserId && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.EqualUserLanguage && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.NotEqualBusinessId && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.NotEqualUserId && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.NotNull && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.Null && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.ThisMonth && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.ThisWeek && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.ThisYear && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.Today && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.Tomorrow && oper != Microsoft.Xrm.Sdk.Query.ConditionOperator.Yesterday) { switch (CintXML.GetAttribute(xExpProp, "Type").ToUpperInvariant()) { case "STRING": value = valuestring; break; case "INT": value = int.Parse(valuestring); break; case "BOOL": value = bool.Parse(valuestring); break; case "DATETIME": value = DateTime.Parse(valuestring); break; case "GUID": value = new Guid(valuestring); break; default: throw new ArgumentOutOfRangeException("Type", CintXML.GetAttribute(xExpProp, "Type"), "Invalid filter attribute type"); } } string attribute = CintXML.GetAttribute(xExpProp, "Attribute"); log.Log("Adding filter: {0} {1} {2}", attribute, oper, value); CintQryExp.AppendCondition(qExport.Criteria, LogicalOperator.And, attribute, oper, value); }