Exemple #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(
                 "post",
                 Route = Routes.ExportKontent
                 )] ExportKontentRequest exportKontentRequest
            )
        {
            try
            {
                var(kml, managementApiKey, mode) = exportKontentRequest;

                kontentStore.Configure(managementApiKey);
                kmlParser.Options.Mode = mode;

                var parsedKml = kmlParser.ParseKml(kml);

                var globalGuid            = Guid.NewGuid();
                var activatedTypes        = new Dictionary <string, ContentType>();
                var activatedTypeSnippets = new Dictionary <string, ContentType>();

                foreach (var typeDescription in parsedKml.TypeDescriptions)
                {
                    var contentType = typeActivator.ActivateType(typeDescription, globalGuid);

                    if (contentType.External_id is null)
                    {
                        throw new ArgumentNullException(nameof(contentType.External_id));
                    }

                    activatedTypes.Add(contentType.External_id, contentType);
                }

                foreach (var typeDescription in parsedKml.SnippetTypeDescriptions)
                {
                    var contentType = typeActivator.ActivateTypeSnippet(typeDescription, globalGuid);

                    if (contentType.External_id is null)
                    {
                        throw new ArgumentNullException(nameof(contentType.External_id));
                    }

                    activatedTypeSnippets.Add(contentType.External_id, contentType);
                }

                foreach (var activatedTypeSnippet in activatedTypeSnippets)
                {
                    await kontentStore.AddContentTypeSnippet(activatedTypeSnippet.Value);
                }

                foreach (var activatedType in activatedTypes)
                {
                    await kontentStore.AddContentType(activatedType.Value);
                }

                return(LogOk());
            }
            catch (Exception ex)
            {
                return(LogException(ex));
            }
        }