Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UWP] Change MeetsRequirements method to Requirements property #3421

Merged
merged 3 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/uwp/Renderer/AdaptiveCardRenderer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="lib\AdaptiveHighlightColorConfig.cpp" />
<ClCompile Include="lib\AdaptiveRequirement.cpp" />
<ClCompile Include="lib\ElementTagContent.cpp" />
<ClInclude Include="lib\AdaptiveActionElement.h" />
<ClInclude Include="lib\AdaptiveActionInvoker.h" />
Expand Down Expand Up @@ -176,6 +177,7 @@
<ClInclude Include="lib\AdaptiveRemoteResourceInformation.h" />
<ClInclude Include="lib\AdaptiveRenderArgs.h" />
<ClInclude Include="lib\AdaptiveRenderContext.h" />
<ClInclude Include="lib\AdaptiveRequirement.h" />
<ClInclude Include="lib\AdaptiveRichTextBlock.h" />
<ClInclude Include="lib\AdaptiveRichTextBlockRenderer.h" />
<ClInclude Include="lib\AdaptiveSeparator.h" />
Expand Down
2 changes: 2 additions & 0 deletions source/uwp/Renderer/AdaptiveCardRenderer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<ClCompile Include="lib\ElementTagContent.cpp" />
<ClCompile Include="lib\AdaptiveFontTypeDefinition.cpp" />
<ClCompile Include="lib\AdaptiveFontTypesDefinition.cpp" />
<ClCompile Include="lib\AdaptiveRequirement.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="lib\AdaptiveCard.h" />
Expand Down Expand Up @@ -229,6 +230,7 @@
<ClInclude Include="lib\ElementTagContent.h" />
<ClInclude Include="lib\AdaptiveFontTypeDefinition.h" />
<ClInclude Include="lib\AdaptiveFontTypesDefinition.h" />
<ClInclude Include="lib\AdaptiveRequirement.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="idl\AdaptiveCards.Rendering.Uwp.idl" />
Expand Down
18 changes: 17 additions & 1 deletion source/uwp/Renderer/idl/AdaptiveCards.Rendering.Uwp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ AdaptiveNamespaceStart
interface Windows.Foundation.Collections.IVector<AdaptiveRemoteResourceInformation*>;
interface Windows.Foundation.Collections.IVector<AdaptiveToggleVisibilityTarget*>;
interface Windows.Foundation.Collections.IVector<AdaptiveImage*>;
interface Windows.Foundation.Collections.IVector<AdaptiveRequirement*>;
}

[
Expand All @@ -434,8 +435,8 @@ AdaptiveNamespaceStart
FallbackType FallbackType;
IAdaptiveCardElement FallbackContent;
Windows.Data.Json.JsonObject AdditionalProperties;
Windows.Foundation.Collections.IVector<AdaptiveRequirement> Requirements { get; };

Boolean MeetsRequirements(AdaptiveFeatureRegistration featureRegistration);
Windows.Data.Json.JsonObject ToJson();
};

Expand Down Expand Up @@ -1593,6 +1594,21 @@ AdaptiveNamespaceStart
Windows.Foundation.Collections.ValueSet AsValueSet();
};

[
#ifdef ADAPTIVE_CARDS_WINDOWS
interface_name("Windows.Internal.AdaptiveCards.Rendering.Uwp.IAdaptiveRequirement", 45B7321F-BB3C-48B8-B98E-6483927C47D7),
contract(InternalContract, 1),
internal
#endif
]
runtimeclass AdaptiveRequirement
{
AdaptiveRequirement(String requirementName, String requirementversion);

String Name;
String Version;
}

[
#ifdef ADAPTIVE_CARDS_WINDOWS
interface_name("Windows.Internal.AdaptiveCards.Rendering.Uwp.IAdaptiveFeatureRegistration", b2a455fd-385c-45eb-89ce-007b7ed0a815),
Expand Down
7 changes: 4 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveActionSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ namespace AdaptiveNamespace
return AdaptiveCardElementBase::put_IsVisible(isVisible);
}

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value)
IFACEMETHODIMP get_Requirements(
_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
return AdaptiveCardElementBase::MeetsRequirements(featureRegistration, value);
return AdaptiveCardElementBase::get_Requirements(requirements);
}


IFACEMETHODIMP ToJson(_Out_ ABI::Windows::Data::Json::IJsonObject** result)
{
return AdaptiveCardElementBase::ToJson(result);
Expand Down
42 changes: 17 additions & 25 deletions source/uwp/Renderer/lib/AdaptiveCardElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "AdaptiveFeatureRegistration.h"
#include "SemanticVersion.h"
#include "Util.h"
#include "Vector.h"

using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
Expand Down Expand Up @@ -35,9 +36,8 @@ namespace AdaptiveNamespace
RETURN_IF_FAILED(GenerateElementProjection(fallbackObject, m_fallbackContent.GetAddressOf()));
}
}

m_requires = sharedModel->GetRequirements();

m_requirements = Microsoft::WRL::Make<Vector<AdaptiveRequirement*>>();
GenerateRequirementsProjection(sharedModel->GetRequirements(), m_requirements.Get());
return S_OK;
}

Expand Down Expand Up @@ -102,6 +102,16 @@ namespace AdaptiveNamespace
IFACEMETHODIMP AdaptiveCardElementBase::put_FallbackContent(_In_ ABI::AdaptiveNamespace::IAdaptiveCardElement* content)
{
m_fallbackContent = content;

if (content == nullptr && m_fallbackType == ABI::AdaptiveNamespace::FallbackType::Content)
{
m_fallbackType = ABI::AdaptiveNamespace::FallbackType::None;
}
else if (content != nullptr)
{
m_fallbackType = ABI::AdaptiveNamespace::FallbackType::Content;
}

return S_OK;
}

Expand Down Expand Up @@ -137,22 +147,11 @@ namespace AdaptiveNamespace
return S_OK;
}

IFACEMETHODIMP AdaptiveCardElementBase::MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value) try
IFACEMETHODIMP AdaptiveCardElementBase::get_Requirements(
ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
*value = true;

std::shared_ptr<AdaptiveSharedNamespace::BaseCardElement> sharedModel;
RETURN_IF_FAILED(GetSharedModel(sharedModel));

ComPtr<AdaptiveFeatureRegistration> featureRegistrationImpl = PeekInnards<AdaptiveFeatureRegistration>(featureRegistration);
std::shared_ptr<AdaptiveSharedNamespace::FeatureRegistration> sharedFeatureRegistration =
featureRegistrationImpl->GetSharedFeatureRegistration();

*value = sharedModel->MeetsRequirements(*sharedFeatureRegistration);
return S_OK;
return m_requirements.CopyTo(requirements);
}
CATCH_RETURN;

IFACEMETHODIMP AdaptiveCardElementBase::ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result)
{
Expand All @@ -171,14 +170,7 @@ namespace AdaptiveNamespace
sharedCardElement->SetHeight(static_cast<AdaptiveSharedNamespace::HeightType>(m_height));
sharedCardElement->SetFallbackType(MapUwpFallbackTypeToShared(m_fallbackType));

if (!m_requires->empty())
{
auto requirements = sharedCardElement->GetRequirements();
for (const auto& requirement : *m_requires)
{
requirements->emplace(requirement);
}
}
RETURN_IF_FAILED(GenerateSharedRequirements(m_requirements.Get(), sharedCardElement->GetRequirements()));

if (m_fallbackType == ABI::AdaptiveNamespace::FallbackType::Content)
{
Expand Down
5 changes: 2 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveCardElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ namespace AdaptiveNamespace
IFACEMETHODIMP get_Height(_Out_ ABI::AdaptiveNamespace::HeightType* height);
IFACEMETHODIMP put_Height(ABI::AdaptiveNamespace::HeightType height);

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value);
IFACEMETHODIMP get_Requirements(_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements);

IFACEMETHODIMP ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result);

Expand All @@ -61,6 +60,6 @@ namespace AdaptiveNamespace
InternalId m_internalId;
ABI::AdaptiveNamespace::FallbackType m_fallbackType;
Microsoft::WRL::ComPtr<ABI::AdaptiveNamespace::IAdaptiveCardElement> m_fallbackContent;
std::shared_ptr<std::unordered_map<std::string, SemanticVersion>> m_requires;
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>> m_requirements;
};
}
6 changes: 3 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveChoiceSetInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ namespace AdaptiveNamespace
return AdaptiveCardElementBase::put_AdditionalProperties(value);
}

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value)
IFACEMETHODIMP get_Requirements(
_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
return AdaptiveCardElementBase::MeetsRequirements(featureRegistration, value);
return AdaptiveCardElementBase::get_Requirements(requirements);
}

IFACEMETHODIMP ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result)
Expand Down
6 changes: 3 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ namespace AdaptiveNamespace
return AdaptiveCardElementBase::put_AdditionalProperties(value);
}

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value)
IFACEMETHODIMP get_Requirements(
_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
return AdaptiveCardElementBase::MeetsRequirements(featureRegistration, value);
return AdaptiveCardElementBase::get_Requirements(requirements);
}

IFACEMETHODIMP ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result)
Expand Down
6 changes: 3 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveColumnSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ namespace AdaptiveNamespace
return AdaptiveCardElementBase::put_AdditionalProperties(value);
}

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value)
IFACEMETHODIMP get_Requirements(
_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
return AdaptiveCardElementBase::MeetsRequirements(featureRegistration, value);
return AdaptiveCardElementBase::get_Requirements(requirements);
}

IFACEMETHODIMP ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result)
Expand Down
6 changes: 3 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ namespace AdaptiveNamespace
return AdaptiveCardElementBase::put_AdditionalProperties(value);
}

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value)
IFACEMETHODIMP get_Requirements(
_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
return AdaptiveCardElementBase::MeetsRequirements(featureRegistration, value);
return AdaptiveCardElementBase::get_Requirements(requirements);
}

IFACEMETHODIMP ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result)
Expand Down
6 changes: 3 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveDateInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ namespace AdaptiveNamespace
return AdaptiveCardElementBase::put_AdditionalProperties(value);
}

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value)
IFACEMETHODIMP get_Requirements(
_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
return AdaptiveCardElementBase::MeetsRequirements(featureRegistration, value);
return AdaptiveCardElementBase::get_Requirements(requirements);
}

IFACEMETHODIMP ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result)
Expand Down
6 changes: 3 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveFactSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ namespace AdaptiveNamespace
return AdaptiveCardElementBase::put_AdditionalProperties(value);
}

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value)
IFACEMETHODIMP get_Requirements(
_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
return AdaptiveCardElementBase::MeetsRequirements(featureRegistration, value);
return AdaptiveCardElementBase::get_Requirements(requirements);
}

IFACEMETHODIMP ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result)
Expand Down
6 changes: 3 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ namespace AdaptiveNamespace
return AdaptiveCardElementBase::put_AdditionalProperties(value);
}

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value)
IFACEMETHODIMP get_Requirements(
_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
return AdaptiveCardElementBase::MeetsRequirements(featureRegistration, value);
return AdaptiveCardElementBase::get_Requirements(requirements);
}

IFACEMETHODIMP ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result)
Expand Down
6 changes: 3 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveImageSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ namespace AdaptiveNamespace
return AdaptiveCardElementBase::put_AdditionalProperties(value);
}

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value)
IFACEMETHODIMP get_Requirements(
_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
return AdaptiveCardElementBase::MeetsRequirements(featureRegistration, value);
return AdaptiveCardElementBase::get_Requirements(requirements);
}

IFACEMETHODIMP ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result)
Expand Down
6 changes: 3 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveMedia.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ namespace AdaptiveNamespace
return AdaptiveCardElementBase::put_Height(height);
}

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value)
IFACEMETHODIMP get_Requirements(
_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
return AdaptiveCardElementBase::MeetsRequirements(featureRegistration, value);
return AdaptiveCardElementBase::get_Requirements(requirements);
}

IFACEMETHODIMP ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result)
Expand Down
6 changes: 3 additions & 3 deletions source/uwp/Renderer/lib/AdaptiveNumberInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ namespace AdaptiveNamespace
return AdaptiveCardElementBase::put_AdditionalProperties(value);
}

IFACEMETHODIMP MeetsRequirements(_In_ ABI::AdaptiveNamespace::IAdaptiveFeatureRegistration* featureRegistration,
_Out_ boolean* value)
IFACEMETHODIMP get_Requirements(
_COM_Outptr_ ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::AdaptiveRequirement*>** requirements)
{
return AdaptiveCardElementBase::MeetsRequirements(featureRegistration, value);
return AdaptiveCardElementBase::get_Requirements(requirements);
}

IFACEMETHODIMP ToJson(_COM_Outptr_ ABI::Windows::Data::Json::IJsonObject** result)
Expand Down
35 changes: 35 additions & 0 deletions source/uwp/Renderer/lib/AdaptiveRequirement.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "pch.h"
#include "AdaptiveRequirement.h"

using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::AdaptiveNamespace;

namespace AdaptiveNamespace
{
HRESULT AdaptiveRequirement::RuntimeClassInitialize() { return S_OK; }

HRESULT AdaptiveRequirement::RuntimeClassInitialize(_In_ HSTRING name, _In_ HSTRING version)
{
m_name.Set(name);
m_version.Set(version);
return S_OK;
}

HRESULT AdaptiveRequirement::RuntimeClassInitialize(const std::pair<const std::string, AdaptiveCards::SemanticVersion>& sharedRequirement) noexcept
{
RETURN_IF_FAILED(UTF8ToHString(sharedRequirement.first, m_name.GetAddressOf()));
RETURN_IF_FAILED(UTF8ToHString((std::string)sharedRequirement.second, m_version.GetAddressOf()));
return S_OK;
}

HRESULT AdaptiveRequirement::get_Name(_Outptr_ HSTRING* value) { return m_name.CopyTo(value); }

HRESULT AdaptiveRequirement::put_Name(_In_ HSTRING value) { return m_name.Set(value); }

HRESULT AdaptiveRequirement::get_Version(_Outptr_ HSTRING* value) { return m_version.CopyTo(value); }

HRESULT AdaptiveRequirement::put_Version(_In_ HSTRING value) { return m_version.Set(value); }
}
Loading