Skip to content

Commit

Permalink
Make compatible with OpenRiaServices 5.0 rc1 (#15)
Browse files Browse the repository at this point in the history
* Updated to use OpenRiaServices 5
* Rename OpenRiaSerices.M2M.Silverlight -> OpenRiaSerices.M2M.Client
* Update gitversion in pipleine
* Remove silverlight from pipeline
  • Loading branch information
niklas-holma authored Nov 18, 2020
1 parent e56addd commit 19fd41d
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 119 deletions.
1 change: 1 addition & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ branches:
master: {}
ignore:
sha: []

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using OpenRiaServices.DomainServices.Client;
using OpenRiaServices.Client;

namespace OpenRiaServices.M2M
{
Expand Down
15 changes: 15 additions & 0 deletions OpenRiaServices.M2M.Client/IExtendedEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using OpenRiaServices.Client;

namespace OpenRiaServices.M2M
{
/// <summary>
/// An interface for M2M relation entities
/// </summary>
public interface IExtendedEntity
{
/// <summary>
/// The EntitySet this entity belongs to.
/// </summary>
EntitySet EntitySet { get; }
}
}
25 changes: 25 additions & 0 deletions OpenRiaServices.M2M.Client/OpenRiaServices.M2M.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net472;netstandard2.0</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RootNamespace>OpenRiaServices.M2M</RootNamespace>
<PackageId>OpenRiaServices.M2M.Client</PackageId>
<Description>Client part of OpenServices.M2M providing the M2M view on link table entities.</Description>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="WindowsBase" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="OpenRiaServices.Client.Core" Version="5.0.0-rc0001" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion OpenRiaServices.M2M.Demo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRiaServices.M2M.Demo",
{E878F804-5CD7-46C4-98A6-9B801000FB2B} = {E878F804-5CD7-46C4-98A6-9B801000FB2B}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRiaServices.M2M.Silverlight", "OpenRiaServices.M2M.Silverlight\OpenRiaServices.M2M.Silverlight.csproj", "{F6E5D0B7-FE90-4498-A5F5-3FFA505762A0}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRiaServices.M2M.Client", "OpenRiaServices.M2M.Client\OpenRiaServices.M2M.Client.csproj", "{F6E5D0B7-FE90-4498-A5F5-3FFA505762A0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRiaServices.M2M", "OpenRiaServices.M2M\OpenRiaServices.M2M.csproj", "{88EFBF58-E42A-4314-BAAF-746FC34CB5EC}"
EndProject
Expand Down
62 changes: 37 additions & 25 deletions OpenRiaServices.M2M.LinkTable/LinkTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

namespace OpenRiaServices.M2M
{
/// <summary>
/// Generic link table class that is used by M2M4RIA.
/// </summary>
/// <typeparam name="TObject1"> </typeparam>
/// <typeparam name="TObject2"> </typeparam>
public abstract class LinkTable<TObject1, TObject2>

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: Properties not browsable in editor.
/// <summary>
/// Generic link table class that is used by M2M4RIA.
/// </summary>
/// <typeparam name="TObject1"> </typeparam>
/// <typeparam name="TObject2"> </typeparam>
public abstract class LinkTable<TObject1, TObject2>
where TObject1 : class where TObject2 : class
{
#region Constants and Fields
Expand Down Expand Up @@ -336,24 +338,27 @@ private static PropertyInfo GetMember<T>(Expression<Func<LinkTable<TObject1, TOb
return (PropertyInfo)expression.Member;
}

private static AssociationAttribute GetAssociationAttribute(PropertyDescriptor propDescriptor)
{
return (AssociationAttribute)propDescriptor.Attributes[typeof(AssociationAttribute)];
}

/// <summary>
/// The foreign key values of a link table entity are not automatically set/updated when the corresponding entities
/// are new and have server-generated keys. Once these entities have been saved to the database they get id's generated
/// by the database, which should be populated to the link table entities as well, such that the correct values are sent
/// to the RiaRIA services client. The trick is that when a foreign key property of a link table entity is accessed, we try
/// to obtain its value from the associated entity. Amongst others, the foreign key properties are accessed when serializing
/// a link table entity. Therefore, with this trick, we're sure that always the correct values are transmitted to the
/// Ria services client.
/// </summary>
/// <typeparam name="T"> </typeparam>
/// <param name="propertySelector"> </param>
/// <returns> </returns>
private T GetKey<T>(Expression<Func<LinkTable<TObject1, TObject2>, T>> propertySelector)
#pragma warning disable CS0618 // 'AssociationAttribute' is obsolete but still used by M2M
private static AssociationAttribute GetAssociationAttribute(PropertyDescriptor propDescriptor)
{
return (AssociationAttribute)propDescriptor.Attributes[typeof(AssociationAttribute)];
}
#pragma warning restore CS0618

/// <summary>
/// The foreign key values of a link table entity are not automatically set/updated when the corresponding entities
/// are new and have server-generated keys. Once these entities have been saved to the database they get id's generated
/// by the database, which should be populated to the link table entities as well, such that the correct values are sent
/// to the RiaRIA services client. The trick is that when a foreign key property of a link table entity is accessed, we try
/// to obtain its value from the associated entity. Amongst others, the foreign key properties are accessed when serializing
/// a link table entity. Therefore, with this trick, we're sure that always the correct values are transmitted to the
/// Ria services client.
/// </summary>
/// <typeparam name="T"> </typeparam>
/// <param name="propertySelector"> </param>
/// <returns> </returns>
private T GetKey<T>(Expression<Func<LinkTable<TObject1, TObject2>, T>> propertySelector)
{
var foreignKeyName = ((MemberExpression)propertySelector.Body).Member.Name;
var foreignKeyValue = default(T);
Expand Down Expand Up @@ -392,7 +397,9 @@ private PropertyDescriptor GetNavigationProperty(string foreignKeyName)
var thisType = GetType();
var propertyDescriptor =
from property in TypeDescriptor.GetProperties(thisType).OfType<PropertyDescriptor>()
#pragma warning disable CS0618 // 'AssociationAttribute' is obsolete but still used by M2M
let association = (AssociationAttribute) property.Attributes[typeof(AssociationAttribute)]
#pragma warning restore CS0618
where association != null
where association.ThisKeyMembers.Contains(foreignKeyName)
select property;
Expand Down Expand Up @@ -444,8 +451,11 @@ private void SetKeyValuesForEntity<T>(Expression<Func<LinkTable<TObject1, TObjec
var entity = property.GetValue(this, null);

var propertyDescriptor = TypeDescriptor.GetProperties(thisType)[propertyName];
var association = (AssociationAttribute) propertyDescriptor.Attributes[typeof(AssociationAttribute)];
var thisKeys = association.ThisKeyMembers.ToArray();
#pragma warning disable CS0618 // 'AssociationAttribute' is obsolete but still used by M2M
var association = (AssociationAttribute) propertyDescriptor.Attributes[typeof(AssociationAttribute)];
#pragma warning restore CS0618

var thisKeys = association.ThisKeyMembers.ToArray();
var otherKeys = association.OtherKeyMembers.ToArray();

for(var i = 0; i < thisKeys.Count(); i++)
Expand All @@ -459,4 +469,6 @@ private void SetKeyValuesForEntity<T>(Expression<Func<LinkTable<TObject1, TObjec

#endregion
}

#pragma warning restore CS1591
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net472;netstandard2.0</TargetFrameworks>
<RootNamespace>OpenRiaServices.M2M</RootNamespace>
<AssemblyName>OpenRiaServices.M2M.LinkTable</AssemblyName>

Expand All @@ -12,10 +12,10 @@
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
Expand Down
9 changes: 0 additions & 9 deletions OpenRiaServices.M2M.Silverlight/IExtendedEntity.cs

This file was deleted.

37 changes: 0 additions & 37 deletions OpenRiaServices.M2M.Silverlight/OpenRiaServices.M2M.Client.csproj

This file was deleted.

2 changes: 1 addition & 1 deletion OpenRiaServices.M2M.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28902.138
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenRiaServices.M2M.Client", "OpenRiaServices.M2M.Silverlight\OpenRiaServices.M2M.Client.csproj", "{F6E5D0B7-FE90-4498-A5F5-3FFA505762A0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenRiaServices.M2M.Client", "OpenRiaServices.M2M.Client\OpenRiaServices.M2M.Client.csproj", "{F6E5D0B7-FE90-4498-A5F5-3FFA505762A0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenRiaServices.M2M.Server", "OpenRiaServices.M2M\OpenRiaServices.M2M.Server.csproj", "{88EFBF58-E42A-4314-BAAF-746FC34CB5EC}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace OpenRiaServices.M2M.Configuration
{
/// <summary>
/// Static Extension class for M2M Configuration expressions.
/// </summary>
public static class FluentConfigurationExpressions
{
#region Public Methods and Operators
Expand Down
8 changes: 7 additions & 1 deletion OpenRiaServices.M2M/Configuration/M2M4RIAExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using OpenRiaServices.DomainServices.Server;
using OpenRiaServices.Server;
using OpenRiaServices.FluentMetadata;
using OpenRiaServices.M2M.Utilities;

namespace OpenRiaServices.M2M.Configuration
{
/// <summary>
/// An M2M Configuration expression.
/// </summary>
/// <typeparam name="TObject1">One entity type that partakes in the M2M relation</typeparam>
/// <typeparam name="TObject2">Other entity type that partakes in the M2M relation</typeparam>
/// <typeparam name="TLinkTable">The type of the link table</typeparam>
public class M2M4RiaExpression<TObject1, TObject2, TLinkTable>
where TObject1 : class where TObject2 : class where TLinkTable : LinkTable<TObject1, TObject2>
{
Expand Down
2 changes: 1 addition & 1 deletion OpenRiaServices.M2M/DbContext/LinkTableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using OpenRiaServices.DomainServices.Server;
using OpenRiaServices.Server;

namespace OpenRiaServices.M2M.DbContext
{
Expand Down
6 changes: 3 additions & 3 deletions OpenRiaServices.M2M/EntityGenerator/M2M4RiaCodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using OpenRiaServices.DomainServices.Tools;
using OpenRiaServices.DomainServices.Tools.TextTemplate.CSharpGenerators;
using OpenRiaServices.Tools;
using OpenRiaServices.Tools.TextTemplate.CSharpGenerators;

namespace OpenRiaServices.M2M.EntityGenerator
{
Expand All @@ -8,7 +8,7 @@ public class M2M4RiaCodeGenerator : CSharpClientCodeGenerator
{
#region Properties

protected override DomainServices.Tools.TextTemplate.EntityGenerator EntityGenerator
protected override Tools.TextTemplate.EntityGenerator EntityGenerator
{
get { return new M2M4RiaEntityGenerator(); }
}
Expand Down
4 changes: 2 additions & 2 deletions OpenRiaServices.M2M/EntityGenerator/M2M4RiaEntityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using OpenRiaServices.DomainServices.Tools.TextTemplate.CSharpGenerators;
using OpenRiaServices.Tools.TextTemplate.CSharpGenerators;

namespace OpenRiaServices.M2M.EntityGenerator
{
Expand Down Expand Up @@ -161,7 +161,7 @@ public void AddIExtendedEntityImplementation(Type type)
WriteLine(@"/// Gets the EntitySet the link table entity is contained in.");
WriteLine(@"/// </summary>");
WriteLine(
@"OpenRiaServices.DomainServices.Client.EntitySet OpenRiaServices.M2M.IExtendedEntity.EntitySet");
@"OpenRiaServices.Client.EntitySet OpenRiaServices.M2M.IExtendedEntity.EntitySet");
WriteLine(@"{");
WriteLine(@" get");
WriteLine(@" {");
Expand Down
10 changes: 5 additions & 5 deletions OpenRiaServices.M2M/OpenRiaServices.M2M.Server.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45</TargetFrameworks>
<TargetFrameworks>net472</TargetFrameworks>
<Description>Server part of M2M support for OpenRiaServices. It includes Code generator and Fluent configuration extensions for OpenServices.M2M.</Description>
<PackageId>OpenRiaServices.M2M</PackageId>
</PropertyGroup>
Expand All @@ -10,7 +10,7 @@
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand All @@ -20,9 +20,9 @@

<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.2.0" />
<PackageReference Include="OpenRiaServices.FluentMetadata" Version="3.0.0" />
<PackageReference Include="OpenRiaServices.Server" Version="4.6.0" />
<PackageReference Include="OpenRiaServices.T4" Version="4.6.0" />
<PackageReference Include="OpenRiaServices.FluentMetadata" Version="5.0.0-rc.1" />
<PackageReference Include="OpenRiaServices.Server" Version="5.0.0-rc0001" />
<PackageReference Include="OpenRiaServices.T4" Version="5.0.0-rc0001" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ M2M4RIA is an extension for [OpenRIAServices](https://github.com/OpenRIAServices
M2M4RIA is distributed as a collection of NuGet packages:
* [OpenRIAServices.M2M](https://nuget.org/packages/OpenRiaServices.M2M) This is the server-side part of M2M4RIA. It contains an entity code generator and an extension to the fluent metadata configuration for OpenRIAServices.
* [OpenRIAServices.M2M.LinkTable](https://nuget.org/packages/OpenRIAServices.M2M.LinkTable) This is a generic link table implementation that is used for creating "link table" views for your M2M relations (see [GeneralOverview](../GeneralOverview)).
* [OpenRIAServices.M2M.Silverlight](https://nuget.org/packages/OpenRIAServices.M2M.Silverlight) This is the client-side part of M2M4RIA. It contains classes for creating M2M views (see [GeneralOverview](../GeneralOverview)).
* [OpenRiaServices.M2M.Client](https://nuget.org/packages/OpenRiaServices.M2M.Client) This is the client-side part of M2M4RIA. It contains classes for creating M2M views (see [GeneralOverview](../GeneralOverview)).

## Usage

Expand Down
30 changes: 1 addition & 29 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,7 @@ steps:
versionSpec: '5.x'

- task: gitversion/execute@0
displayName: Execute GitVersion

- powershell: |
[string]$RepositoryRoot = "$(Build.SourcesDirectory)"
$url = "https://download.microsoft.com/download/3/A/3/3A35179D-5C87-4D0A-91EB-BF5FEDC601A4/sdk/silverlight_sdk.exe"
$fileName = "silverlight_5_sdk.exe"
$fullPath = (join-path $RepositoryRoot $fileName)
if (Test-Path $fullPath)
{
echo "'$fileName' already downloading, reusing it"
}
else
{
echo "Downloading Silverlight sdk"
Measure-Command { (New-Object System.Net.WebClient).DownloadFile($url, $fullPath) }
echo "Downloaded Silverlight sdk"
}
dir $fullPath
echo "Installing Silverlight 5 SDK"
"executing $fullPath /q /norestart"
& $fullPath "/q" "/norestart"
echo "Success = '$?'"
displayName: 'Download and install Silverlight 5 SDK'
displayName: Use GitVersion

- task: NuGetCommand@2
inputs:
Expand Down

0 comments on commit 19fd41d

Please sign in to comment.