protected override IEnumerable <IObservable> UpdateObjectAndDependentData(TestItem objectToUpdate, TestItem objectToUpdateFrom)
            {
                IsUpdateDataCalled = true;
                UpdateDataCallArguments.Add(Tuple.Create(objectToUpdate, objectToUpdateFrom));

                return(AddObjectToUpdateToAffectedItems
                           ? ItemsToUpdate.Concat(ItemsToUpdateFrom).Concat(new[]
                {
                    objectToUpdate
                })
                           : ItemsToUpdate.Concat(ItemsToUpdateFrom));
            }
Beispiel #2
0
        private ItemsToUpdate GenerateItemsToUpdateModel(IEnumerable <KbItem> currentKnowledgeBaseItems, List <QnAItem> qnaItems, bool resetQuestion = false)
        {
            var itemsToUpdateModel = new ItemsToUpdate
            {
                name = KnowledgeBaseName,
                urls = new string[] { }
            };

            var kbItemsToUpdate = new List <KbItemToUpdate>();

            foreach (var kbItem in currentKnowledgeBaseItems)
            {
                var kbItemIdMetaDataItem = kbItem.metadata.FirstOrDefault(m => m.name == "itemid");

                if (kbItemIdMetaDataItem != null)
                {
                    // id convert
                    var qnaItem = qnaItems.FirstOrDefault(f => f.ItemId.ToString() == kbItemIdMetaDataItem.value);

                    if (qnaItem != null)
                    {
                        var updatedKbItem = new KbItemToUpdate
                        {
                            qnaId     = kbItem.qnaId,
                            answer    = qnaItem.Answer,
                            questions = new QuestionsUpdateModel()
                        };


                        if (resetQuestion)
                        {
                            var questionsToAdd    = qnaItem.Questions.ToList().Where(q => !kbItem.questions.ToList().Contains(q));
                            var questionsToDelete = kbItem.questions.ToList().Where(q => !questionsToAdd.Contains(q)); // Will delete questions that aren't in the documentation, resets qna-pairing..
                            updatedKbItem.questions.delete = questionsToDelete.ToArray();
                            updatedKbItem.questions.add    = questionsToAdd.ToArray();
                        }
                        else
                        {
                            var questionsToAdd = qnaItem.Questions.ToList();
                            updatedKbItem.questions.add = questionsToAdd.ToArray();
                        }


                        List <MetadataItem> metaDataItemsToDelete = new List <MetadataItem>();
                        metaDataItemsToDelete = kbItem.metadata
                                                .Where(m => !qnaItem.Metadata.Select(f => f.name).Contains(m.name)).ToList();


                        var metaDataItemsToAddOrUpdate = new List <MetadataItem>
                        {
                            new MetadataItem()
                            {
                                name  = "itemid",
                                value = qnaItem.ItemId.ToString()
                            },
                            new MetadataItem()
                            {
                                name  = "isactive",
                                value = qnaItem.IsActive.ToString()
                            }
                        };

                        foreach (var metadataItem in qnaItem.Metadata)
                        {
                            metaDataItemsToAddOrUpdate.Add(new MetadataItem()
                            {
                                name  = metadataItem.name,
                                value = metadataItem.value
                            });
                        }

                        updatedKbItem.metadata = new MetaDataUpdateModel
                        {
                            add    = metaDataItemsToAddOrUpdate.ToArray(),
                            delete = metaDataItemsToDelete.ToArray()
                        };

                        kbItemsToUpdate.Add(updatedKbItem);
                    }
                }
            }

            itemsToUpdateModel.qnaList = kbItemsToUpdate.ToArray();
            return(itemsToUpdateModel);
        }
Beispiel #3
0
        private ItemsToUpdate GenerateItemsToUpdateModel(IEnumerable <KbItem> currentKnowledgeBaseItems, List <QnAItem> qnaItems)
        {
            var itemsToUpdateModel = new ItemsToUpdate
            {
                name = KnowledgeBaseName,
                urls = new string[] { }
            };

            var kbItemsToUpdate = new List <KbItemToUpdate>();

            foreach (var kbItem in currentKnowledgeBaseItems)
            {
                var kbItemIdMetaDataItem = kbItem.metadata.FirstOrDefault(m => m.name == "itemId");

                if (kbItemIdMetaDataItem != null)
                {
                    var qnaItem = qnaItems.FirstOrDefault(f => f.ItemId == kbItemIdMetaDataItem.value);

                    if (qnaItem != null)
                    {
                        var updatedKbItem = new KbItemToUpdate
                        {
                            qnaId     = kbItem.qnaId,
                            answer    = qnaItem.Answer,
                            questions = new QuestionsUpdateModel()
                        };

                        var questionsToAdd = qnaItem.Questions.ToList();
                        updatedKbItem.questions.add = questionsToAdd.ToArray();

                        var questionsToDelete = kbItem.questions.ToList().Where(q => !questionsToAdd.Contains(q));
                        updatedKbItem.questions.delete = questionsToDelete.ToArray();

                        var metaDataItemsToDelete = kbItem.metadata
                                                    .Where(m => !qnaItem.Metadata.Select(f => f.Key).Contains(m.name)).ToList();

                        var metaDataItemsToAddOrUpdate = new List <MetaDataItem>
                        {
                            new MetaDataItem()
                            {
                                name  = "itemId",
                                value = qnaItem.ItemId
                            }
                        };

                        foreach (var metadataItem in qnaItem.Metadata)
                        {
                            metaDataItemsToAddOrUpdate.Add(new MetaDataItem()
                            {
                                name  = metadataItem.Key,
                                value = metadataItem.Value
                            });
                        }

                        updatedKbItem.metadata = new MetaDataUpdateModel
                        {
                            add    = metaDataItemsToAddOrUpdate.ToArray(),
                            delete = metaDataItemsToDelete.ToArray()
                        };

                        kbItemsToUpdate.Add(updatedKbItem);
                    }
                }
            }

            itemsToUpdateModel.qnaList = kbItemsToUpdate.ToArray();
            return(itemsToUpdateModel);
        }