public static PcfControl GetPowerAppsControlFromJson(CombinedTemplateState template)
        {
            var pcfControl = new PcfControl()
            {
                Name = template.TemplateDisplayName, Version = template.Version
            };

            var dynamicControlDefinition = Utilities.JsonParse <PcfControlDoublyEncoded>(template.DynamicControlDefinitionJson);

            pcfControl.ControlNamespace   = dynamicControlDefinition.ControlNamespace;
            pcfControl.DisplayNameKey     = dynamicControlDefinition.DisplayNameKey;
            pcfControl.ControlConstructor = dynamicControlDefinition.ControlConstructor;
            pcfControl.Resources          = dynamicControlDefinition.Resources != null?Utilities.JsonParse <Resource[]>(dynamicControlDefinition.Resources) : null;

            pcfControl.Properties = dynamicControlDefinition.Properties != null?Utilities.JsonParse <IEnumerable <Property> >(dynamicControlDefinition.Properties) : null;

            pcfControl.AuthConfigProperties = dynamicControlDefinition.AuthConfigProperties != null?GetAutConfigProperties(dynamicControlDefinition.AuthConfigProperties) : null;

            pcfControl.DataConnectors = dynamicControlDefinition.DataConnectors != null?Utilities.JsonParse <IEnumerable <DataConnectorMetadata> >(dynamicControlDefinition.DataConnectors) : null;

            pcfControl.SubscribedFunctionalities = dynamicControlDefinition.SubscribedFunctionalities != null?Utilities.JsonParse <Dictionary <string, string> >(dynamicControlDefinition.SubscribedFunctionalities) : null;

            pcfControl.IncludedProperties = dynamicControlDefinition.IncludedProperties != null?Utilities.JsonParse <IEnumerable <Property> >(dynamicControlDefinition.IncludedProperties) : null;

            pcfControl.Events = dynamicControlDefinition.Events != null?Utilities.JsonParse <IEnumerable <Event> >(dynamicControlDefinition.Events) : null;

            pcfControl.CommonEvents = dynamicControlDefinition.CommonEvents != null?Utilities.JsonParse <IEnumerable <Event> >(dynamicControlDefinition.CommonEvents) : null;

            pcfControl.PropertyDependencies = dynamicControlDefinition.PropertyDependencies != null?Utilities.JsonParse <IEnumerable <PropertyDependency> >(dynamicControlDefinition.PropertyDependencies) : null;

            pcfControl.ExtensionData = dynamicControlDefinition.ExtensionData;

            return(pcfControl);
        }
        internal static string GenerateDynamicControlDefinition(PcfControl control)
        {
            // PowerApps controls require dynamic control definition added to control's template.
            // When generating DynamicControlDefinitionJson don't add Name and Version as those aren't part of it.
            PcfControlDoublyEncoded _dynamicControlDefinition = new PcfControlDoublyEncoded();

            _dynamicControlDefinition.ControlNamespace   = control.ControlNamespace;
            _dynamicControlDefinition.DisplayNameKey     = control.DisplayNameKey;
            _dynamicControlDefinition.ControlConstructor = control.ControlConstructor;
            var jsonOptions = new JsonSerializerOptions()
            {
                Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };

            _dynamicControlDefinition.Resources = control.Resources != null?JsonSerializer.Serialize(control.Resources, jsonOptions) : null;

            _dynamicControlDefinition.Properties = control.Properties != null?JsonSerializer.Serialize(control.Properties, jsonOptions) : null;

            _dynamicControlDefinition.IncludedProperties = control.IncludedProperties != null?JsonSerializer.Serialize(control.IncludedProperties, jsonOptions) : null;

            _dynamicControlDefinition.Events = control.Events != null?JsonSerializer.Serialize(control.Events, jsonOptions) : null;

            _dynamicControlDefinition.CommonEvents = control.CommonEvents != null?JsonSerializer.Serialize(control.CommonEvents, jsonOptions) : null;

            _dynamicControlDefinition.PropertyDependencies = control.PropertyDependencies != null?JsonSerializer.Serialize(control.PropertyDependencies, jsonOptions) : null;

            _dynamicControlDefinition.SubscribedFunctionalities = control.SubscribedFunctionalities != null?JsonSerializer.Serialize(control.SubscribedFunctionalities, jsonOptions) : null;

            _dynamicControlDefinition.AuthConfigProperties = control.AuthConfigProperties != null?JsonSerializer.Serialize(control.AuthConfigProperties, jsonOptions) : null;

            _dynamicControlDefinition.DataConnectors = control.DataConnectors != null?JsonSerializer.Serialize(control.DataConnectors, jsonOptions) : null;

            _dynamicControlDefinition.ExtensionData = control.ExtensionData ?? new Dictionary <string, object>();

            return(Utilities.JsonSerialize(_dynamicControlDefinition));
        }