Skip to content

Commit 1bfd583

Browse files
committed
Refactor MSDN Doc Provider into it's own task assembly and refactor task assembly compliation.
0 parents  commit 1bfd583

9 files changed

Lines changed: 1952 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.IO;
3+
using Microsoft.Build.Framework;
4+
using Microsoft.Build.Utilities;
5+
using SharpGen.CppModel;
6+
using SharpGenTools.Sdk;
7+
8+
namespace SharpGen.Doc.Msdn.Tasks
9+
{
10+
public class MsdnDocTask : Task
11+
{
12+
[Required]
13+
public ITaskItem DocumentationCache { get; set; }
14+
15+
[Required]
16+
public ITaskItem CppModule { get; set; }
17+
18+
19+
public bool ShadowCopy { get; set; }
20+
21+
public override bool Execute()
22+
{
23+
BindingRedirectResolution.Enable();
24+
var docProvider = new MsdnProvider(message => Log.LogMessage(message));
25+
26+
var module = CppModel.CppModule.Read(CppModule.ItemSpec);
27+
28+
var cache = new DocItemCache();
29+
30+
var cachePath = ShadowCopy ? Path.GetTempFileName() : DocumentationCache.ItemSpec;
31+
32+
if (File.Exists(DocumentationCache.ItemSpec))
33+
{
34+
if (ShadowCopy)
35+
{
36+
File.Copy(DocumentationCache.ItemSpec, cachePath, true);
37+
}
38+
cache = DocItemCache.Read(cachePath);
39+
}
40+
41+
var documented = docProvider.ApplyDocumentation(cache, module).Result;
42+
43+
cache.Write(cachePath);
44+
45+
if (ShadowCopy)
46+
{
47+
File.Copy(cachePath, DocumentationCache.ItemSpec, true);
48+
File.Delete(cachePath);
49+
}
50+
51+
documented.Write(CppModule.ItemSpec);
52+
53+
return true;
54+
}
55+
}
56+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net46;netstandard1.3</TargetFrameworks>
5+
<PackageId>SharpGen.Doc.Msdn.Tasks</PackageId>
6+
<NoPackageAnalysis>true</NoPackageAnalysis>
7+
<!-- forces SDK to copy dependencies into build output to make packing easier -->
8+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
9+
<BuildOutputTargetFolder>tools</BuildOutputTargetFolder>
10+
<DevelopmentDependency>true</DevelopmentDependency>
11+
<Description>MSDN Doc Provider for SharpGenTools.Sdk</Description>
12+
<SharpGenSdkPackage>true</SharpGenSdkPackage>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\SharpGen.Doc.Msdn\SharpGen.Doc.Msdn.csproj" />
17+
<ProjectReference Include="..\SharpGen\SharpGen.csproj" />
18+
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.3.409" />
19+
<Content Include="**/*.props" Exclude="obj/**" PackagePath="build;buildMultiTargeting" />
20+
<Content Include="**/*.targets" Exclude="obj/**" PackagePath="build;buildMultiTargeting" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<Compile Include="..\SharpGenTools.Sdk\BindingRedirectResolution.cs" Link="BindingRedirectResolution.cs" />
25+
</ItemGroup>
26+
27+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<PropertyGroup>
3+
<DocProviderTargets>$(DocProviderTargets);DocumentCppModuleFromMsdn</DocProviderTargets>
4+
</PropertyGroup>
5+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project>
2+
<ItemGroup>
3+
<MsdnDocProvider Include="../tools/netstandard1.3/SharpGen.Doc.Msdn.Tasks.dll" />
4+
<MsdnDocumentationCheckFile Include="$(SharpGenIntermediateDir)MsdnDocumentation.checkfile" />
5+
</ItemGroup>
6+
7+
<UsingTask TaskName="MsdnDocTask" AssemblyFile="@(MsdnDocProvider)" />
8+
9+
<Target
10+
Name="DocumentCppModuleFromMsdn"
11+
Inputs="@(ParsedCppModule);@(MsdnDocProvider)"
12+
Outputs="@(MsdnDocumentationCheckFile)"
13+
DependsOnTargets="ParseCPlusPlus"
14+
Condition="'$(SharpGenGenerateDoc)' == 'true' and '@(SharpGenMapping)' != ''" >
15+
<MsdnDocTask
16+
CppModule="@(ParsedCppModule)"
17+
DocumentationCache="@(SharpGenDocumentationCache)"
18+
ShadowCopy="$(ShadowCopyDocumentationOutput)"
19+
/>
20+
<Touch Files="@(MsdnDocumentationCheckFile)" AlwaysCreate="True" />
21+
</Target>
22+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
3+
"Version": "15.0.11010.660",
4+
"GettingStartedDocument": {
5+
"Uri": "https://go.microsoft.com/fwlink/?linkid=858517"
6+
}
7+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
// //
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
namespace MTPS
11+
{
12+
13+
14+
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.0")]
15+
[System.ServiceModel.ServiceContractAttribute(Namespace="urn:msdn-com:public-content-syndication", ConfigurationName="MTPS.ContentServicePortType")]
16+
internal partial interface ContentServicePortType
17+
{
18+
}
19+
20+
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.0")]
21+
internal interface ContentServicePortTypeChannel : MTPS.ContentServicePortType, System.ServiceModel.IClientChannel
22+
{
23+
}
24+
25+
[System.Diagnostics.DebuggerStepThroughAttribute()]
26+
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.0")]
27+
internal partial class ContentServicePortTypeClient : System.ServiceModel.ClientBase<MTPS.ContentServicePortType>, MTPS.ContentServicePortType
28+
{
29+
30+
/// <summary>
31+
/// Implement this partial method to configure the service endpoint.
32+
/// </summary>
33+
/// <param name="serviceEndpoint">The endpoint to configure</param>
34+
/// <param name="clientCredentials">The client credentials</param>
35+
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);
36+
37+
public ContentServicePortTypeClient(EndpointConfiguration endpointConfiguration) :
38+
base(ContentServicePortTypeClient.GetBindingForEndpoint(endpointConfiguration), ContentServicePortTypeClient.GetEndpointAddress(endpointConfiguration))
39+
{
40+
this.Endpoint.Name = endpointConfiguration.ToString();
41+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
42+
}
43+
44+
public ContentServicePortTypeClient(EndpointConfiguration endpointConfiguration, string remoteAddress) :
45+
base(ContentServicePortTypeClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
46+
{
47+
this.Endpoint.Name = endpointConfiguration.ToString();
48+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
49+
}
50+
51+
public ContentServicePortTypeClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
52+
base(ContentServicePortTypeClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
53+
{
54+
this.Endpoint.Name = endpointConfiguration.ToString();
55+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
56+
}
57+
58+
public ContentServicePortTypeClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
59+
base(binding, remoteAddress)
60+
{
61+
}
62+
63+
public virtual System.Threading.Tasks.Task OpenAsync()
64+
{
65+
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
66+
}
67+
68+
public virtual System.Threading.Tasks.Task CloseAsync()
69+
{
70+
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
71+
}
72+
73+
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
74+
{
75+
if ((endpointConfiguration == EndpointConfiguration.ContentService))
76+
{
77+
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
78+
result.MaxBufferSize = int.MaxValue;
79+
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
80+
result.MaxReceivedMessageSize = int.MaxValue;
81+
result.AllowCookies = true;
82+
return result;
83+
}
84+
if ((endpointConfiguration == EndpointConfiguration.ContentService12))
85+
{
86+
System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
87+
System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
88+
textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None);
89+
result.Elements.Add(textBindingElement);
90+
System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
91+
httpBindingElement.AllowCookies = true;
92+
httpBindingElement.MaxBufferSize = int.MaxValue;
93+
httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
94+
result.Elements.Add(httpBindingElement);
95+
return result;
96+
}
97+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
98+
}
99+
100+
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
101+
{
102+
if ((endpointConfiguration == EndpointConfiguration.ContentService))
103+
{
104+
return new System.ServiceModel.EndpointAddress("http://services.msdn.microsoft.com/ContentServices/ContentService.asmx");
105+
}
106+
if ((endpointConfiguration == EndpointConfiguration.ContentService12))
107+
{
108+
return new System.ServiceModel.EndpointAddress("http://services.msdn.microsoft.com/ContentServices/ContentService.asmx");
109+
}
110+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
111+
}
112+
113+
public enum EndpointConfiguration
114+
{
115+
116+
ContentService,
117+
118+
ContentService12,
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)