示例#1
0
        public CuratedExperience ConvertA2JAuthorToCuratedExperience(JObject a2jSchema, bool isFromAdminImport = false)
        {
            var             curatedExperience = new CuratedExperience();
            var             a2jProperties     = a2jSchema.Properties();
            GuidedAssistant resource          = null;

            curatedExperience.CuratedExperienceId = Guid.NewGuid();
            curatedExperience.Title = a2jProperties.GetValue("title");

            if (!isFromAdminImport)
            {
                resource = MapResourceProperties(a2jProperties, curatedExperience.CuratedExperienceId);
                dbService.CreateItemAsync(resource, dbSettings.ResourcesCollectionId);
            }

            var pages = ((JObject)a2jProperties.Where(x => x.Name == "pages").FirstOrDefault()?.Value).Properties();

            foreach (var page in pages)
            {
                var pageProperties   = ((JObject)page.FirstOrDefault()).Properties();
                var componentFields  = GetFields(pageProperties);
                var componentButtons = GetButtons(pageProperties);
                var componentCodes   = GetCodes(pageProperties);

                curatedExperience.Components.Add(new CuratedExperienceComponent
                {
                    ComponentId = Guid.NewGuid(),
                    Name        = pageProperties.GetValue("name"),
                    Help        = pageProperties.GetValue("help").RemoveHtmlTags(),
                    Learn       = pageProperties.GetValue("learn").RemoveHtmlTags(),
                    Text        = pageProperties.GetValue("text").RemoveHtmlTags(keepTextFormatingTags: true, keepHyperlinkTags: true).RemoveCustomA2JFunctions(),
                    Fields      = componentFields,
                    Buttons     = componentButtons,
                    Code        = componentCodes
                });
            }

            // find out the first question in the list and add it to top (A2J Author doesn't order the pages in the json array, it depends on
            // an additional xml file to arrange the questions!)
            var firstQuestion      = curatedExperience.Components.Where(x => x.Name == a2jProperties.GetValue("firstPage")).First();
            var firstQuestionIndex = curatedExperience.Components.IndexOf(firstQuestion);

            curatedExperience.Components.RemoveAt(firstQuestionIndex);
            curatedExperience.Components.Insert(0, firstQuestion);

            dbService.CreateItemAsync(curatedExperience, dbSettings.CuratedExperiencesCollectionId);
            return(curatedExperience);
        }
示例#2
0
        public async Task <object> CreateGuidedAssistantResource(string resourceTitle, CuratedTemplate curatedTemplate, string curatedExperienceId)
        {
            var resourceDetails = await topicsResourcesBusinessLogic.GetResourceDetailAsync(resourceTitle, Constants.GuidedAssistant);

            List <GuidedAssistant> resources = JsonUtilities.DeserializeDynamicObject <List <GuidedAssistant> >(resourceDetails);
            Int64 maxVersion = default(Int64);

            foreach (var resource in resources)
            {
                var resourceDetail = JsonUtilities.DeserializeDynamicObject <GuidedAssistant>(resource);
                if (resourceDetail.Version == default(Int64))
                {
                    resourceDetail.Version = IncrementVersion(default(Int64));
                }
                if (maxVersion.CompareTo(resourceDetail.Version) < 0)
                {
                    maxVersion = resourceDetail.Version;
                }
                resourceDetail.IsActive = false;

                await backendDatabaseService.UpdateItemAsync(resourceDetail.ResourceId.ToString(),
                                                             JObject.FromObject(resourceDetail), cosmosDbSettings.ResourcesCollectionId);
            }

            var topicDetails = await topicsResourcesBusinessLogic.GetTopicDetailsAsync(resourceTitle);

            List <Topic> topics = JsonUtilities.DeserializeDynamicObject <List <Topic> >(topicDetails);

            if (topics.Count > 0)
            {
                var             guidedAssistantResource = new GuidedAssistant();
                List <TopicTag> topicTags = new List <TopicTag>();
                List <Location> locations = new List <Location>();

                foreach (var topic in topics)
                {
                    topicTags.Add(new TopicTag {
                        TopicTags = topic.Id
                    });
                    foreach (var location in topic.Location)
                    {
                        locations.Add(location);
                    }
                }

                guidedAssistantResource.ResourceId          = Guid.NewGuid();
                guidedAssistantResource.Name                = curatedTemplate.Name;
                guidedAssistantResource.Description         = curatedTemplate.Description;
                guidedAssistantResource.TopicTags           = topicTags;
                guidedAssistantResource.Location            = locations;
                guidedAssistantResource.Version             = IncrementVersion(maxVersion);
                guidedAssistantResource.IsActive            = true;
                guidedAssistantResource.ResourceType        = Constants.GuidedAssistant;
                guidedAssistantResource.CuratedExperienceId = curatedExperienceId;

                await backendDatabaseService.CreateItemAsync(guidedAssistantResource, cosmosDbSettings.ResourcesCollectionId);

                return(adminSettings.SuccessMessage + " New Curated Experience ID " + curatedExperienceId);
            }
            return(string.Format(CultureInfo.InvariantCulture, adminSettings.MissingTopicMessage, resourceTitle));
        }