Ejemplo n.º 1
0
        private void SyncAttach(KnowledgeBaseArticle original, KnowledgeBaseArticle article)
        {
            var repository = _repositoryFactory.GetRepositoryInstance();

            // removing attachments
            if (original != null)
            {
                foreach (var attach in original.Attachments)
                {
                    if (article != null || article.Attachments == null || !article.Attachments.Any(x => (x.AttachmentId == attach.AttachmentId)))
                    {
                        repository.Attach(attach);
                        repository.Remove(attach);
                    }
                }
            }

            // appending attachments
            if (article != null)
            {
                foreach (var attach in article.Attachments)
                {
                    if (original == null || original.Attachments == null || !original.Attachments.Any(x => (x.AttachmentId == attach.AttachmentId)))
                    {
                        attach.CommunicationItemId = article.KnowledgeBaseArticleId;
                        repository.Attach(attach);
                        repository.Add(attach);
                    }
                }
            }
            int i = repository.UnitOfWork.Commit();
        }
Ejemplo n.º 2
0
        public void AddKnowledgeBaseArticleToGroupTest()
        {
            var client = GetRepository();

            var groupFromDb = client.KnowledgeBaseGroups.Where(g => g.KnowledgeBaseGroupId == "ccb57007-dac9-4d8d-8bf4-47f2c3df3c3a")
                              .Expand(g => g.Parent).FirstOrDefault();

            Assert.IsNotNull(groupFromDb);
            Assert.IsNotNull(groupFromDb.Parent);

            client.Attach(groupFromDb);


            var articleToParent = new KnowledgeBaseArticle();

            articleToParent.Title   = "articleToParent";
            articleToParent.GroupId = groupFromDb.Parent.KnowledgeBaseGroupId;

            var articleToGroup = new KnowledgeBaseArticle();

            articleToGroup.Title   = "artickeToGroup";
            articleToGroup.GroupId = groupFromDb.KnowledgeBaseGroupId;

            client.Add(articleToParent);
            client.Add(articleToGroup);

            client.UnitOfWork.Commit();
        }
Ejemplo n.º 3
0
        private void CommitSelectedKnowledgeGroupArticles()
        {
            var adaptor              = new CommunicationAdaptor();
            var selectedGroupId      = (_selectedKnowledgeGroup as KnowledgeGroupViewModel) != null ? (_selectedKnowledgeGroup as KnowledgeGroupViewModel).OriginalItem.KnowledgeBaseGroupId : null;
            var communicationControl = KnowledgeArticleCommunicationControl as KnowledgeArticleCommunicationControlViewModel;
            var itemsForDelete       = communicationControl.GetItemsByState(CommunicationItemState.Deleted);
            var itemsForAppend       = communicationControl.GetItemsByState(CommunicationItemState.Appended);
            var itemsForModify       = communicationControl.GetItemsByState(CommunicationItemState.Modified);

            Task.Factory.StartNew(() =>
            {
                var repository       = _repositoryFactory.GetRepositoryInstance();
                ShowLoadingAnimation = true;
                // delete
                if (itemsForDelete != null && itemsForDelete.Count() > 0)
                {
                    foreach (CommunicationItemViewModel item in itemsForDelete)
                    {
                        KnowledgeBaseArticle original = adaptor.KnowledgeBaseArticleCommunicationViewModel2KnowledgeBaseArticle(item as CommunicationItemKnowledgeBaseArticleViewModel);
                        //SyncAttach(original, null);
                        repository.Attach(original);
                        repository.Remove(original);
                    }
                }
                // append
                if (itemsForAppend != null && itemsForAppend.Count() > 0 && selectedGroupId != null)
                {
                    foreach (CommunicationItemViewModel item in itemsForAppend)
                    {
                        KnowledgeBaseArticle article = adaptor.KnowledgeBaseArticleCommunicationViewModel2KnowledgeBaseArticle(item as CommunicationItemKnowledgeBaseArticleViewModel);
                        article.GroupId = selectedGroupId;
                        //SyncAttach(null, article);
                        repository.Add(article);
                    }
                }
                // modify
                if (itemsForModify != null && itemsForModify.Count() > 0)
                {
                    foreach (CommunicationItemViewModel item in itemsForModify)
                    {
                        var article     = adaptor.KnowledgeBaseArticleCommunicationViewModel2KnowledgeBaseArticle(item as CommunicationItemKnowledgeBaseArticleViewModel);
                        article.GroupId = selectedGroupId;
                        var original    = repository.KnowledgeBaseArticles.Where(x => x.KnowledgeBaseArticleId == article.KnowledgeBaseArticleId).SingleOrDefault();
                        //SyncAttach(original, article);
                        repository.Attach(original);
                        OnUIThread(() => original.InjectFrom(article));
                    }
                }
                int i = repository.UnitOfWork.Commit();
            })
            .ContinueWith(t =>
            {
                ShowLoadingAnimation = false;
            });
        }
Ejemplo n.º 4
0
 public NotApplicableProbeResult(string parentComponentId, string componentId,
                                 string probeId, string name, ComponentType componentType, KnowledgeBaseArticle article)
 {
     ParentComponentId = parentComponentId;
     ComponentId       = componentId;
     ComponentType     = componentType;
     Id        = probeId;
     Name      = name;
     KB        = article;
     Timestamp = DateTimeOffset.UtcNow;
 }
Ejemplo n.º 5
0
 public WarningProbeResult(string parentComponentId, string componentId, string probeId, string name,
                           ComponentType componentType, IReadOnlyList <ProbeData> probeData, KnowledgeBaseArticle article)
 {
     ParentComponentId = parentComponentId;
     ComponentId       = componentId;
     Id            = probeId;
     Name          = name;
     ComponentType = componentType;
     Data          = probeData;
     KB            = article;
     Status        = ProbeResultStatus.Warning;
     Timestamp     = DateTimeOffset.UtcNow;
 }
        public KnowledgeBaseArticle KnowledgeBaseArticleCommunicationViewModel2KnowledgeBaseArticle(CommunicationItemKnowledgeBaseArticleViewModel viewModel)
        {
            KnowledgeBaseArticle retVal = new KnowledgeBaseArticle
            {
                AuthorName = viewModel.AuthorName,
                Body       = viewModel.Body,
                Title      = viewModel.Title,
            };

            if (viewModel.Id != null)
            {
                retVal.KnowledgeBaseArticleId = viewModel.Id;
            }

            return(retVal);
        }
Ejemplo n.º 7
0
 private void PopulateKnowledgeArticleData(KnowledgeBaseGroup group, int count)
 {
     for (int i = 0; i < count; i++)
     {
         KnowledgeBaseArticle article = new KnowledgeBaseArticle()
         {
             Group        = group,
             AuthorName   = users[rnd.Next(users.Length)],
             ModifierName = users[rnd.Next(users.Length)],
             Created      = dates[rnd.Next(dates.Length)],
             LastModified = dates[rnd.Next(dates.Length)],
             Title        = knowledgeBaseArticleTitles[rnd.Next(knowledgeBaseArticleTitles.Length)],
             Body         = bodyes[rnd.Next(bodyes.Length)]
         };
         MockKnowledgeBaseArticleList.Add(article);
     }
 }
Ejemplo n.º 8
0
        public bool TryGet(string identifier, out IReadOnlyList <KnowledgeBaseArticle> articles)
        {
            if (_articles.Exists(x => x.Id == identifier))
            {
                try
                {
                    articles = _articles.Where(x => x.Id == identifier).ToList();
                    return(true);
                }
                catch
                {
                    articles = new KnowledgeBaseArticle[] { new MissingKnowledgeBaseArticle(identifier, ProbeResultStatus.NA) };
                    return(false);
                }
            }

            articles = new KnowledgeBaseArticle[] { new MissingKnowledgeBaseArticle(identifier, ProbeResultStatus.NA) };
            return(false);
        }
Ejemplo n.º 9
0
        public bool TryGet(string identifier, ProbeResultStatus status, out KnowledgeBaseArticle article)
        {
            if (_articles.Exists(x => x.Id == identifier))
            {
                try
                {
                    article = _articles.Single(x => x.Id == identifier && x.Status == status);
                    return(true);
                }
                catch
                {
                    article = new MissingKnowledgeBaseArticle(identifier, status);
                    return(false);
                }
            }

            article = new MissingKnowledgeBaseArticle(identifier, status);
            return(false);
        }
Ejemplo n.º 10
0
        public void KnowledgeBaseGroup_AddArticle()
        {
            // create group and arcicle KnowledgeBaseGroups
            var g = new KnowledgeBaseGroup()
            {
                Name = "g", Title = "g"
            };
            var a = new KnowledgeBaseArticle()
            {
                Title = "a", Body = "a"
            };
            string g_Id = g.KnowledgeBaseGroupId;
            string a_Id = a.KnowledgeBaseArticleId;

            var repository = GetRepository();

            EndTestAction.Add((() =>
            {
                repository.Remove(a);
                repository.Remove(g);
                repository.UnitOfWork.Commit();
            }));


            // add created items to DB
            repository.Attach(g);
            repository.Add(g);
            repository.UnitOfWork.Commit();


            a.GroupId = g.KnowledgeBaseGroupId;
            repository.Attach(a);
            repository.Add(a);
            repository.UnitOfWork.Commit();

            //KnowledgeBaseGroup is saved correctly?
            var a_check = repository.KnowledgeBaseArticles.Where(x => x.KnowledgeBaseArticleId == a_Id).SingleOrDefault();
            var g_check = repository.KnowledgeBaseGroups.Where(x => x.KnowledgeBaseGroupId == g_Id).SingleOrDefault();

            Assert.IsTrue(g_check != null && g_check.KnowledgeBaseGroupId == g_Id);
            Assert.IsTrue(a_check != null && a_check.KnowledgeBaseArticleId == a_Id && a_check.GroupId == g_check.KnowledgeBaseGroupId);
        }
        public CommunicationItemKnowledgeBaseArticleViewModel KnowledgeBaseArticle2KnowledgeBaseArticleCommunicationViewModel(KnowledgeBaseArticle item)
        {
            CommunicationItemKnowledgeBaseArticleViewModel retVal = new CommunicationItemKnowledgeBaseArticleViewModel
            {
                //LastModified = item.LastModified,
                //Created = item.Created,
                AuthorId   = item.AuthorId,
                AuthorName = item.AuthorName,
                Body       = item.Body,
                Title      = item.Title,
                Id         = item.KnowledgeBaseArticleId
            };

            if (item.Attachments != null)
            {
                foreach (var attachment in item.Attachments)
                {
                    retVal.Attachments.Add(Attachment2CommunicationAttachment(attachment));
                }
            }

            return(retVal);
        }