Skip to content

Commit

Permalink
Remove OperationContract and similar methods from generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Svensson committed Nov 14, 2024
1 parent 9d0ef1c commit 5c4561d
Show file tree
Hide file tree
Showing 104 changed files with 598 additions and 2,226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
<group targetFramework="net472">
<dependency id="OpenRiaServices.Client.Core" version="$version$"/>
</group>
<group targetFramework="net8.0" />
<group targetFramework="net8.0">
<dependency id="OpenRiaServices.Client.Core" version="$version$"/>
<!-- Generated code uses some of these attributes -->
<dependency id="System.ServiceModel.Primitives" version="8.1.0" />
</group>
</dependencies>
</metadata>
Expand Down
2 changes: 0 additions & 2 deletions NuGet/OpenRiaServices.Client.Core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
<frameworkAssembly assemblyName="System.ComponentModel.DataAnnotations" targetFramework="net472" />
<frameworkAssembly assemblyName="System.Net.Http" targetFramework="net472" />
<frameworkAssembly assemblyName="System.Runtime.Serialization" targetFramework="net472" />
<frameworkAssembly assemblyName="System.ServiceModel" targetFramework="net472" />
<frameworkAssembly assemblyName="System.ServiceModel.Web" targetFramework="net472" />
</frameworkAssemblies>
</metadata>
<files>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.ServiceModel.Http" Version="4.10.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net472' and '$(TargetFramework)' != 'netstandard2.0' ">
<ItemGroup Condition=" '$(TargetFramework)' != 'net472' ">
<PackageReference Include="System.ServiceModel.Http" Version="8.1.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ protected void GenerateServiceContractInterface()
}


this.Write("[System.ServiceModel.ServiceContract()]\r\npublic interface ");
this.Write("public interface ");

this.Write(this.ToStringHelper.ToStringWithCulture(this.ContractInterfaceName));

Expand Down Expand Up @@ -710,12 +710,7 @@ private void GenerateContractMethod(DomainOperationEntry operation)

this.Write(this.ToStringHelper.ToStringWithCulture(DomainContextGenerator.OperationHasSideEffects(operation).ToString().ToLower()));

this.Write(")]\r\n");


this.GenerateContractMethodAttributes(operation.Name);

this.Write("System.IAsyncResult Begin");
this.Write(")]\r\nSystem.IAsyncResult Begin");

this.Write(this.ToStringHelper.ToStringWithCulture(operation.Name));

Expand Down Expand Up @@ -757,7 +752,6 @@ private void GenerateContractMethod(DomainOperationEntry operation)

private void GenerateContractSubmitChangesMethod()
{
this.GenerateContractMethodAttributes("SubmitChanges");

this.Write("IAsyncResult BeginSubmitChanges(IEnumerable<ChangeSetEntry> changeSet, AsyncCallb" +
"ack callback, object asyncState);\r\nIEnumerable<ChangeSetEntry> EndSubmitChanges(" +
Expand All @@ -766,25 +760,6 @@ private void GenerateContractSubmitChangesMethod()

}

private void GenerateContractMethodAttributes(string operationName)
{
string domainServiceName = this.DomainServiceDescription.DomainServiceType.Name;
string actionString = string.Format(CultureInfo.InvariantCulture, DomainContextGenerator.DefaultActionSchema, domainServiceName, operationName);
string replyActionString = string.Format(CultureInfo.InvariantCulture, DomainContextGenerator.DefaultReplyActionSchema, domainServiceName, operationName);


this.Write("[OperationContract(AsyncPattern=true, Action=\"");

this.Write(this.ToStringHelper.ToStringWithCulture(actionString));

this.Write("\", ReplyAction=\"");

this.Write(this.ToStringHelper.ToStringWithCulture(replyActionString));

this.Write("\")]\t\r\n");


}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
}

#>
[System.ServiceModel.ServiceContract()]
public interface <#= this.ContractInterfaceName #>
<#+
this.GenerateOpeningBrace();
Expand All @@ -44,9 +43,6 @@ public interface <#= this.ContractInterfaceName #>
{
#>
[OpenRiaServices.Client.HasSideEffects(<#= DomainContextGenerator.OperationHasSideEffects(operation).ToString().ToLower() #>)]
<#+
this.GenerateContractMethodAttributes(operation.Name);
#>
System.IAsyncResult Begin<#= operation.Name #>(
<#+
foreach (DomainOperationParameter parameter in operation.Parameters)
Expand All @@ -67,21 +63,10 @@ System.AsyncCallback callback, object asyncState);

private void GenerateContractSubmitChangesMethod()
{
this.GenerateContractMethodAttributes("SubmitChanges");
#>
IAsyncResult BeginSubmitChanges(IEnumerable<ChangeSetEntry> changeSet, AsyncCallback callback, object asyncState);
IEnumerable<ChangeSetEntry> EndSubmitChanges(IAsyncResult result);
<#+
}

private void GenerateContractMethodAttributes(string operationName)
{
string domainServiceName = this.DomainServiceDescription.DomainServiceType.Name;
string actionString = string.Format(CultureInfo.InvariantCulture, DomainContextGenerator.DefaultActionSchema, domainServiceName, operationName);
string replyActionString = string.Format(CultureInfo.InvariantCulture, DomainContextGenerator.DefaultReplyActionSchema, domainServiceName, operationName);

#>
[OperationContract(AsyncPattern=true, Action="<#= actionString #>", ReplyAction="<#= replyActionString #>")]
<#+
}
#>
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ internal List<Attribute> GetContractServiceKnownTypes(DomainOperationEntry opera
// on the client when the [ServiceKnownType] is created.
t = new VirtualType(t.Name, CodeGenUtilities.TranslateNamespace(t), t.Assembly, t.BaseType);
}

knownTypeAttributes.Add(new ServiceKnownTypeAttribute(t));
}

return knownTypeAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net472' ">
<!-- Required for known type attributes -->
<PackageReference Include="System.ServiceModel.Primitives" Version="8.1.0" />
<!-- Required for validation attributes -->
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>
Expand Down
21 changes: 0 additions & 21 deletions src/OpenRiaServices.Tools/Framework/DomainServiceProxyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.ServiceModel;
using OpenRiaServices.Server;
using OpenRiaServices.Tools.SharedTypes;

Expand Down Expand Up @@ -468,11 +467,6 @@ private CodeTypeDeclaration GenerateContract(CodeTypeDeclaration proxyClass)
contractInterface.Comments.AddRange(CodeGenUtilities.GenerateSummaryCodeComment(comment, this.ClientProxyGenerator.IsCSharp));

contractInterface.IsInterface = true;
contractInterface.CustomAttributes.Add(
CodeGenUtilities.CreateAttributeDeclaration(
typeof(ServiceContractAttribute),
this.ClientProxyGenerator,
proxyClass));

// Used to track types registered with ServiceKnownTypeAttribute (for Custom methods)
HashSet<Type> registeredServiceTypes = new HashSet<Type>();
Expand Down Expand Up @@ -548,8 +542,6 @@ private void GenerateContractServiceKnownTypes(CodeTypeDeclaration contractInter
// on the client when the [ServiceKnownType] is created.
t = new VirtualType(t.Name, CodeGenUtilities.TranslateNamespace(t, this.ClientProxyGenerator), t.Assembly, t.BaseType);
}

knownTypeAttributes.Add(new ServiceKnownTypeAttribute(t));
}

if (knownTypeAttributes.Count > 0)
Expand Down Expand Up @@ -591,8 +583,6 @@ private void GenerateContractMethod(CodeTypeDeclaration contractInterface, Domai
// Generate <returns> doc comment
beginMethod.Comments.AddRange(CodeGenUtilities.GenerateReturnsCodeComment(Resource.CodeGen_DomainContext_ServiceContract_Begin_Method_Returns_Comment, this.ClientProxyGenerator.IsCSharp));

this.GenerateContractMethodAttributes(contractInterface, beginMethod, domainServiceName, operation.Name);

foreach (DomainOperationParameter parameter in operation.Parameters)
{
beginMethod.Parameters.Add(
Expand Down Expand Up @@ -691,8 +681,6 @@ private void GenerateContractSubmitChangesMethod(CodeTypeDeclaration contractInt
// Generate <returns> doc comment
beginQueryMethod.Comments.AddRange(CodeGenUtilities.GenerateReturnsCodeComment(Resource.CodeGen_DomainContext_ServiceContract_Begin_Method_Returns_Comment, this.ClientProxyGenerator.IsCSharp));

this.GenerateContractMethodAttributes(contractInterface, beginQueryMethod, domainServiceName, "SubmitChanges");

CodeTypeReference enumTypeRef = CodeGenUtilities.GetTypeReference(TypeConstants.IEnumerableFullName, contractInterface.UserData["Namespace"] as string, false);
enumTypeRef.TypeArguments.Add(CodeGenUtilities.GetTypeReference(TypeConstants.ChangeSetEntryTypeFullName, contractInterface.UserData["Namespace"] as string, false));

Expand Down Expand Up @@ -739,15 +727,6 @@ private void GenerateContractSubmitChangesMethod(CodeTypeDeclaration contractInt
"result"));
}

private void GenerateContractMethodAttributes(CodeTypeDeclaration contractInterface, CodeMemberMethod beginQueryMethod, string domainServiceName, string operationName)
{
CodeAttributeDeclaration operationContractAtt = CodeGenUtilities.CreateAttributeDeclaration(typeof(OperationContractAttribute), this.ClientProxyGenerator, contractInterface);
operationContractAtt.Arguments.Add(new CodeAttributeArgument("AsyncPattern", new CodePrimitiveExpression(true)));
operationContractAtt.Arguments.Add(new CodeAttributeArgument("Action", new CodePrimitiveExpression(string.Format(CultureInfo.InvariantCulture, DomainServiceProxyGenerator.DefaultActionSchema, domainServiceName, operationName))));
operationContractAtt.Arguments.Add(new CodeAttributeArgument("ReplyAction", new CodePrimitiveExpression(string.Format(CultureInfo.InvariantCulture, DomainServiceProxyGenerator.DefaultReplyActionSchema, domainServiceName, operationName))));
beginQueryMethod.CustomAttributes.Add(operationContractAtt);
}

/// <summary>
/// Determines if a given <see cref="Type"/> should be registered with a <see cref="ServiceKnownTypeAttribute"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Web" />
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Framework" />
Expand All @@ -48,8 +47,6 @@
<PackageReference Include="Microsoft.Build" Version="17.8.3" PrivateAssets="All" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.8.3" PrivateAssets="All" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.8.3" PrivateAssets="All" ExcludeAssets="Runtime" />
<!-- Required for known type attributes -->
<PackageReference Include="System.ServiceModel.Primitives" Version="8.1.0" />
<!-- Required for validation attributes -->
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<!-- MEF Attribute: TODO consider removing MEF support for .NET (non framework) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OpenRiaServices.Server.Test.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestDomainServices;
using IgnoreAttribute = Microsoft.VisualStudio.TestTools.UnitTesting.IgnoreAttribute;

namespace OpenRiaServices.Tools.Test
{
Expand Down Expand Up @@ -503,6 +504,7 @@ public void CodeGen_CustomAttrGen_CtrSelectorTest()

[TestMethod]
[Description("CustomAttributeGenerator generates full names correctly for attributes in VB.")]
[Ignore("See if we can use another attribute to verify thath the full name is correct, ServiceKnownTypeAttribute is no longer generated")]
public void CodeGen_ServiceKnownTypeAttrGen_VB_FullNames()
{
string generatedCode = TestHelper.GenerateCodeAssertSuccess("VB", new Type[] { typeof(DomainServiceWithCustomMethod) }, null, null, /* generateFullNames */ true);
Expand All @@ -511,6 +513,7 @@ public void CodeGen_ServiceKnownTypeAttrGen_VB_FullNames()

[TestMethod]
[Description("CustomAttributeGenerator generates full names correctly for types in attributes not shared on the client in VB.")]
[Ignore("See if we can use another attribute to verify thath the full name is correct, ServiceKnownTypeAttribute is no longer generated")]
public void CodeGen_ServiceKnownTypeAttrGen_VB_NoFullNames()
{
string generatedCode = TestHelper.GenerateCodeAssertSuccess("VB", new Type[] { typeof(DomainServiceWithCustomMethod) }, null, null, /* generateFullNames */ false);
Expand Down
Loading

0 comments on commit 5c4561d

Please sign in to comment.