Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into ExtendBulkDeleteRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
iggsn committed Jan 4, 2019
2 parents e4b8bc9 + f7a5b5f commit 33ddd03
Show file tree
Hide file tree
Showing 115 changed files with 6,204 additions and 4,852 deletions.
4 changes: 2 additions & 2 deletions DevToolkitSamples/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.44.0.0")]
[assembly: AssemblyVersion("1.49.0.0")]
[assembly: AssemblyFileVersion("1.49.0.0")]
[assembly: AssemblyVersion("1.50.1.0")]
[assembly: AssemblyFileVersion("1.50.1.0")]
4 changes: 2 additions & 2 deletions FakeXrmEasy.2013/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.44.0.0")]
[assembly: AssemblyVersion("1.49.0.0")]
[assembly: AssemblyFileVersion("1.49.0.0")]
[assembly: AssemblyVersion("1.50.1.0")]
[assembly: AssemblyFileVersion("1.50.1.0")]
4 changes: 2 additions & 2 deletions FakeXrmEasy.2015/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.44.0.0")]
[assembly: AssemblyVersion("1.49.0.0")]
[assembly: AssemblyFileVersion("1.49.0.0")]
[assembly: AssemblyVersion("1.50.1.0")]
[assembly: AssemblyFileVersion("1.50.1.0")]
4 changes: 2 additions & 2 deletions FakeXrmEasy.2016/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.44.0.0")]
[assembly: AssemblyVersion("1.49.0.0")]
[assembly: AssemblyFileVersion("1.49.0.0")]
[assembly: AssemblyVersion("1.50.1.0")]
[assembly: AssemblyFileVersion("1.50.1.0")]
4 changes: 2 additions & 2 deletions FakeXrmEasy.365/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.44.0.0")]
[assembly: AssemblyVersion("1.49.0.0")]
[assembly: AssemblyFileVersion("1.49.0.0")]
[assembly: AssemblyVersion("1.50.1.0")]
[assembly: AssemblyFileVersion("1.50.1.0")]
4 changes: 2 additions & 2 deletions FakeXrmEasy.9/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.44.0.0")]
[assembly: AssemblyVersion("1.49.0.0")]
[assembly: AssemblyFileVersion("1.49.0.0")]
[assembly: AssemblyVersion("1.50.1.0")]
[assembly: AssemblyFileVersion("1.50.1.0")]
45 changes: 41 additions & 4 deletions FakeXrmEasy.Shared/Extensions/EntityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,15 @@ public static object CloneAttribute(object attributeValue)
var original = (attributeValue as EntityReference);
var clone = new EntityReference(original.LogicalName, original.Id);
clone.Name = CloneAttribute(original.Name) as string;
return clone;

#if !FAKE_XRM_EASY && !FAKE_XRM_EASY_2013 && !FAKE_XRM_EASY_2015
if (original.KeyAttributes != null)
{
clone.KeyAttributes = new KeyAttributeCollection();
clone.KeyAttributes.AddRange(original.KeyAttributes.Select(kvp => new KeyValuePair<string, object>(CloneAttribute(kvp.Key) as string, kvp.Value)).ToArray());
}
#endif
return clone;
}
else if (type == typeof(BooleanManagedProperty))
{
Expand All @@ -225,13 +233,13 @@ public static object CloneAttribute(object attributeValue)
var collection = attributeValue as EntityCollection;
return new EntityCollection(collection.Entities.Select(e => e.Clone(e.GetType())).ToList());
}
else if(attributeValue is IEnumerable<Entity>)
else if (attributeValue is IEnumerable<Entity>)
{
var enumerable = attributeValue as IEnumerable<Entity>;
return enumerable.Select(e => e.Clone(e.GetType())).ToArray();
}
#if !FAKE_XRM_EASY
else if(type == typeof(byte[]))
else if (type == typeof(byte[]))
{
var original = (attributeValue as byte[]);
var copy = new byte[original.Length];
Expand All @@ -240,7 +248,7 @@ public static object CloneAttribute(object attributeValue)
}
#endif
#if FAKE_XRM_EASY_9
else if(attributeValue is OptionSetValueCollection)
else if (attributeValue is OptionSetValueCollection)
{
var original = (attributeValue as OptionSetValueCollection);
var copy = new OptionSetValueCollection(original.ToArray());
Expand Down Expand Up @@ -290,6 +298,12 @@ public static Entity Clone(this Entity e)
{
cloned[attKey] = e[attKey] != null ? CloneAttribute(e[attKey]) : null;
}
#if !FAKE_XRM_EASY && !FAKE_XRM_EASY_2013 && !FAKE_XRM_EASY_2015
foreach (var attKey in e.KeyAttributes.Keys)
{
cloned.KeyAttributes[attKey] = e.KeyAttributes[attKey] != null ? CloneAttribute(e.KeyAttributes[attKey]) : null;
}
#endif
return cloned;
}

Expand Down Expand Up @@ -323,6 +337,13 @@ public static Entity Clone(this Entity e, Type t)
cloned[attKey] = CloneAttribute(e[attKey]);
}
}

#if !FAKE_XRM_EASY && !FAKE_XRM_EASY_2013 && !FAKE_XRM_EASY_2015
foreach (var attKey in e.KeyAttributes.Keys)
{
cloned.KeyAttributes[attKey] = e.KeyAttributes[attKey] != null ? CloneAttribute(e.KeyAttributes[attKey]) : null;
}
#endif
return cloned;
}

Expand Down Expand Up @@ -493,5 +514,21 @@ public static void SetValueIfEmpty(this Entity e, string property, object value)
e[property] = value;
}
}

/// <summary>
/// ToEntityReference implementation which converts an entity into an entity reference with key attribute info as well
/// </summary>
/// <param name="e">Entity to convert to an Entity Reference</param>
/// <returns></returns>
public static EntityReference ToEntityReferenceWithKeyAttributes(this Entity e)
{
var result = e.ToEntityReference();
#if !FAKE_XRM_EASY && !FAKE_XRM_EASY_2013 && !FAKE_XRM_EASY_2015
result.KeyAttributes = e.KeyAttributes;
#endif
return result;
}


}
}
24 changes: 24 additions & 0 deletions FakeXrmEasy.Shared/Extensions/EntityReferenceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Text;

namespace FakeXrmEasy.Extensions
{
public static class EntityReferenceExtensions
{
public static bool HasKeyAttributes(this EntityReference er)
{
if(er == null)
{
return false;
}

#if !FAKE_XRM_EASY && !FAKE_XRM_EASY_2013 && !FAKE_XRM_EASY_2015
return er.KeyAttributes.Count > 0;
#else
return false;
#endif
}
}
}
38 changes: 38 additions & 0 deletions FakeXrmEasy.Shared/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,44 @@ public static bool IsPrimitive(this Type type)
return (type.IsValueType & type.IsPrimitive);
}

private static FieldInfo GetFieldInfo(Type type, string fieldName)
{
FieldInfo fieldInfo;
do
{
fieldInfo = type.GetField(fieldName,
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
type = type.BaseType;
}
while (fieldInfo == null && type != null);
return fieldInfo;
}

public static object GetFieldValue(this object obj, string fieldName)
{
if (obj == null)
throw new ArgumentNullException("obj");
Type objType = obj.GetType();
FieldInfo fieldInfo = GetFieldInfo(objType, fieldName);
if (fieldInfo == null)
throw new ArgumentOutOfRangeException("fieldName",
string.Format("Couldn't find field {0} in type {1}", fieldName, objType.FullName));
return fieldInfo.GetValue(obj);
}

public static void SetFieldValue(this object obj, string fieldName, object val)
{
if (obj == null)
throw new ArgumentNullException("obj");
Type objType = obj.GetType();
FieldInfo fieldInfo = GetFieldInfo(objType, fieldName);
if (fieldInfo == null)
throw new ArgumentOutOfRangeException("fieldName",
string.Format("Couldn't find field {0} in type {1}", fieldName, objType.FullName));
fieldInfo.SetValue(obj, val);
}


public static Object Copy(this Object originalObject)
{
return InternalCopy(originalObject, new Dictionary<Object, Object>(new ReferenceEqualityComparer()));
Expand Down
18 changes: 18 additions & 0 deletions FakeXrmEasy.Shared/Extensions/XmlExtensionsForFetchXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,24 @@ public static ConditionExpression ToConditionExpression(this XElement elem, XrmF
case "next-x-weeks":
op = ConditionOperator.NextXWeeks;
break;
case "this-year":
op = ConditionOperator.ThisYear;
break;
case "last-year":
op = ConditionOperator.LastYear;
break;
case "next-year":
op = ConditionOperator.NextYear;
break;
case "this-month":
op = ConditionOperator.ThisMonth;
break;
case "last-month":
op = ConditionOperator.LastMonth;
break;
case "next-month":
op = ConditionOperator.NextMonth;
break;
#if FAKE_XRM_EASY_9
case "contain-values":
op = ConditionOperator.ContainValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext
throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not delete without target");
}

var service = ctx.GetFakedOrganizationService();
service.Delete(target.LogicalName, target.Id);
var targetId = ctx.GetRecordUniqueId(target);

var service = ctx.GetOrganizationService();
service.Delete(target.LogicalName, targetId);

return new DeleteResponse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public OrganizationResponse Execute(OrganizationRequest req, XrmFakedContext ctx
qe.Criteria.AddCondition(new ConditionExpression(query.Attributes[i], ConditionOperator.Equal, query.Values[i]));
}

qe.PageInfo = query.PageInfo;

// QueryExpression now done... execute it!
var linqQuery = XrmFakedContext.TranslateQueryExpressionToLinq(ctx, qe);
list = linqQuery.ToList();
Expand All @@ -82,6 +84,13 @@ public OrganizationResponse Execute(OrganizationRequest req, XrmFakedContext ctx
list = list.Take(qe.TopCount.Value).ToList();
}

// Handle TotalRecordCount here?
int totalRecordCount = -1;
if (qe?.PageInfo?.ReturnTotalRecordCount == true)
{
totalRecordCount = list.Count;
}

// Handle paging
var pageSize = ctx.MaxRetrieveCount;
pageInfo = qe.PageInfo;
Expand Down Expand Up @@ -124,6 +133,7 @@ public OrganizationResponse Execute(OrganizationRequest req, XrmFakedContext ctx
};
response.EntityCollection.EntityName = entityName;
response.EntityCollection.MoreRecords = (list.Count - pageSize * pageNumber) > 0;
response.EntityCollection.TotalRecordCount = totalRecordCount;

if (response.EntityCollection.MoreRecords)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public bool CanExecute(OrganizationRequest request)
return request.GetType().Equals(GetResponsibleRequestType());
}



public OrganizationResponse Execute(OrganizationRequest req, XrmFakedContext context)
{
var request = req as RetrieveRequest;
Expand All @@ -23,7 +25,8 @@ public OrganizationResponse Execute(OrganizationRequest req, XrmFakedContext con
}

var service = context.GetOrganizationService();
var resultEntity = service.Retrieve(request.Target.LogicalName, request.Target.Id, request.ColumnSet);
var targetId = context.GetRecordUniqueId(request.Target);
var resultEntity = service.Retrieve(request.Target.LogicalName, targetId, request.ColumnSet);
resultEntity.ApplyDateBehaviour(context);

if (request.RelatedEntitiesQuery != null && request.RelatedEntitiesQuery.Count > 0)
Expand Down Expand Up @@ -75,9 +78,11 @@ public OrganizationResponse Execute(OrganizationRequest req, XrmFakedContext con
retrieveRelatedEntitiesQuery.Criteria
.AddFilter(LogicalOperator.And)
.AddCondition(linkEntity.LinkFromAttributeName, ConditionOperator.Equal, resultEntity.Id);
} else {
}
else
{
var link = retrieveRelatedEntitiesQuery.AddLink(fakeRelationship.Entity1LogicalName, fakeRelationship.Entity2Attribute, fakeRelationship.Entity1Attribute);
link.LinkCriteria.AddCondition(resultEntity.LogicalName+"id", ConditionOperator.Equal, resultEntity.Id);
link.LinkCriteria.AddCondition(resultEntity.LogicalName + "id", ConditionOperator.Equal, resultEntity.Id);
}
}
else
Expand Down
1 change: 1 addition & 0 deletions FakeXrmEasy.Shared/FakeXrmEasy.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Enums\ProcessingStepStage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\EntityExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\EntityMetadataExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\EntityReferenceExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ObjectExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\QueryExpressionExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\TypeExtensions.cs" />
Expand Down
Loading

0 comments on commit 33ddd03

Please sign in to comment.