Exemplo n.º 1
0
 public async Task <ContentEntry> GetContentById(Guid Id, int skipCount = 0, int pageSize = 20)
 {
     return(await ApiMessage.WrapData(async() =>
     {
         return await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == Id, "MediaResource", "Category", "Category.ContentList");
     }));
 }
Exemplo n.º 2
0
        public async Task CreateComment(Comment commentModel)
        {
            //向文章作者发送提示
            var _content = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == commentModel.ContentEntryId, "ContentEntryInfo");

            if (_content.ContentEntryInfo != null)
            {
                await sandBoxBusiness.SendAlertTo(new SandBoxMessage
                {
                    Content           = $"文章 : <a href='/Forum/PostList?Id={_content.Id}'>{_content.Title}</a> 有新的回复",
                    MessageType       = SandBoxMessageType.PostEntryComment,
                    CreateTime        = DateTime.Now,
                    FromUserAccountId = commentModel.UserAccountId.Value,
                    ToUserAccountId   = _content.ContentEntryInfo.UserAccountId
                });
            }

            //向引用回复作者发送提示
            if (commentModel.ParentComment != null)
            {
                await sandBoxBusiness.SendAlertTo(new SandBoxMessage
                {
                    Content           = $"文章 : <a href='/Forum/PostList?Id={_content.Id}'>{_content.Title}</a> 有新的回复",
                    MessageType       = SandBoxMessageType.PostEntryCommentSubComment,
                    CreateTime        = DateTime.Now,
                    FromUserAccountId = commentModel.UserAccountId.Value,
                    ToUserAccountId   = commentModel.ParentComment.UserAccountId.Value
                });
            }
            await ContentAccessor.Add <Comment>(commentModel);
        }
Exemplo n.º 3
0
    public async Task <IActionResult> Export(
        CancellationToken cancellationToken = default)
    {
        var contents = new List <Content>();

        var pagedContents = new SearchResponse <Content>
        {
            Skip = -100,
            Take = 100,
        };

        do
        {
            pagedContents.Skip += pagedContents.Take;

            pagedContents = await ContentAccessor
                            .SearchContentAsync(
                new ContentSearchRequest(),
                pagedContents.Skip,
                pagedContents.Take,
                cancellationToken);

            contents.AddRange(pagedContents.Items);
        }while (pagedContents.TotalCount >=
                pagedContents.Skip + pagedContents.Take);

        return(Ok(contents));
    }
Exemplo n.º 4
0
 public async Task <ApiMessage> CreateContent(ContentEntry content)
 {
     return(await ApiMessage.Wrap(async() =>
     {
         content.CreateTime = DateTime.Now;
         await ContentAccessor.AddOrUpdate(content);
     }));
 }
Exemplo n.º 5
0
        public async Task <Tuple <IList <UserAccountLoginLog>, int> > GetLoginLogByUserId(Guid userId, int skipCount, int pageSize)
        {
            var total = await ContentAccessor.Count <UserAccountLoginLog>(x => x.UserAccountEntryId == userId);

            var contentList = await ContentAccessor.ListAsync <UserAccountLoginLog>(x => x.UserAccountEntryId == userId, skipCount, pageSize);

            return(Tuple.Create(contentList, total));
        }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Id"></param>
 /// <param name="skipCount"></param>
 /// <param name="pageSize"></param>
 /// <returns>文章内容, 评论总数</returns>
 public async Task <Tuple <ContentEntry, int> > GetContentWityCommentById(Guid Id, int skipCount = 0, int pageSize = 20)
 {
     return(await ApiMessage.WrapData(async() =>
     {
         var contentEnry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == Id, "MediaResource");
         var totalNum = await ContentAccessor.Count <Comment>(x => x.ContentEntryId == Id);
         return Tuple.Create(contentEnry, totalNum);
     }));
 }
Exemplo n.º 7
0
 public async Task <List <ContentEntry> > GetContentListByCategoryName(string categoryName, int num)
 {
     return(await ContentAccessor.All <ContentEntry>().Where(x => x.Category.Name == categoryName & !x.IsFaq)
            .OrderByDescending(x => x.IsTop)
            .OrderByDescending(x => x.Order)
            .OrderByDescending(x => x.CreateTime)
            .Take(num)
            .ToListAsync());
 }
Exemplo n.º 8
0
        public async Task <IList <PostEntry> > GetContentCommentExtPostEntry(Guid conId, int skipCount, int pageSize)
        {
            //通过cate 名找到话题
            var postEntryMapCategory = await ContentAccessor.ListOrderByDescendingAsync <ContentPostEntryMapping>(x => x.Id == conId);

            var postEntryList = await ContentAccessor.ListOrderByDescendingAsync <PostEntry>(x => postEntryMapCategory.Any(c => c.PostEntryId == x.Id), skipCount, pageSize, "UserAccountEntry");

            return(postEntryList);
        }
Exemplo n.º 9
0
 public async Task <List <ContentEntry> > GetKnowledgeArticleList(string search, Guid Id, int pageIndex, int pageSize)
 {
     search = search?.Trim();
     if (string.IsNullOrEmpty(search))
     {
         return((await ContentAccessor.ListAsync <ContentEntry>(x => x.Category.Id == Id, pageIndex, pageSize, "Tags")).ToList());
     }
     else
     {
         return((await ContentAccessor.ListAsync <ContentEntry>(x => x.Category.Id == Id &&
                                                                (x.Title.Contains(search) || x.Content.Contains(search)), pageIndex, pageSize, "Tags")).ToList());
     }
 }
Exemplo n.º 10
0
        public async Task AppenContentMediaResource(Guid contentId, List <FileEntry> fileEntryList)
        {
            var content = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == contentId, "MediaResource");

            if (content.MediaResource == null)
            {
                content.MediaResource = new List <FileEntry> {
                };
            }
            content.MediaResource.AddRange(fileEntryList);

            await ContentAccessor.Update(content);
        }
Exemplo n.º 11
0
 public async Task <string> GetPrevContentId(ContentEntry cEntry)
 {
     if (cEntry.Order == 0)
     {
         return(null);
     }
     else
     {
         return(await ApiMessage.WrapData(async() =>
         {
             var prevEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Order == cEntry.Order - 1 && x.Category == cEntry.Category);
             return prevEntry.Id.ToString();
         }));
     }
 }
Exemplo n.º 12
0
        public override bool SetValue(object newValue)
        {
            if (newValue != null && newValue is ContentAccessor newAccessor)
            {
                accessor = newAccessor;
                rawValue = accessor;

                if (nameKey != null)
                {
                    nameKey.control.SetValue(accessor.nameKey);
                }
                return(subInspector != null?subInspector.control.SetValue(accessor.content) : true);
            }
            return(false);
        }
Exemplo n.º 13
0
        public async Task CreateContentCommentExtPostEntry(Comment comment)
        {
            var contentModel = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == comment.ContentEntry.Id, "Category");

            var topicTxt = contentModel.Category.Name + "|" + contentModel.Title;
            //设置话题为漫画名
            var topic = new PostEntryTopic()
            {
                CreateTime = DateTime.Now,
                Id         = Guid.NewGuid(),
                Text       = topicTxt,
                PosterId   = comment.UserAccount.Id
            };
            var topicExt = new ContentExtPostEntryTopic()
            {
                Id        = Guid.NewGuid(),
                TopicText = topicTxt,
                LinkId    = contentModel.Id,
                LinkType  = "category"
            };
            //评论
            var postentryModel = new PostEntry()
            {
                Id             = Guid.NewGuid(),
                CreateTime     = DateTime.Now,
                PostEntryTopic = topicTxt,
                UserId         = comment.UserAccount.Id,
                TimeStamp      = TimeStamp.Get(),
                TextContent    = comment.Content
            };

            //目前是一条漫画评论对应一个话题, 为防止以后出现多话题, 保留此表
            var contentPostentryMapping = new ContentPostEntryMapping()
            {
                Id          = Guid.NewGuid(),
                ContentId   = contentModel.Id,
                PostEntryId = postentryModel.Id,
                CreateTime  = DateTime.Now
            };

            await ContentAccessor.Add(topic);

            await ContentAccessor.Add(topicExt);

            await ContentAccessor.Add(postentryModel);

            await ContentAccessor.Add(contentPostentryMapping);
        }
Exemplo n.º 14
0
        //public Task CreateContentWithTag(ContentEntry contentEntry, string v1, string v2)
        //{
        //    throw new NotImplementedException();
        //}
        public async Task <ApiMessage> CreateContentWithTag(ContentEntry content, string tagName)
        {
            return(await ApiMessage.Wrap(async() =>
            {
                //var categoryEntity = await CategoryAccessor.OneAsync<Categories>(x => x.Name == tagName);
                //if (categoryEntity == null)
                //{
                //    categoryEntity = new Categories
                //    {
                //        Name = tagName,
                //        CreateTime = DateTime.Now,
                //        Id = Guid.NewGuid()
                //    };
                //    await CategoryAccessor.Add(categoryEntity);
                //}

                var contentEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == content.Id);
                if (contentEntry == null)
                {
                    contentEntry = new ContentEntry
                    {
                        Id = Guid.NewGuid(),
                        CategoryId = content.CategoryId,
                        Content = content.Content,
                        CreateTime = DateTime.Now,
                        IsFaq = content.IsFaq,
                        IsTop = content.IsTop,
                        Title = content.Title,
                        Tags = new List <Tags> {
                            new Tags {
                                Name = tagName
                            }
                        }
                    };
                    await ContentAccessor.Add(contentEntry);
                }
                else
                {
                    contentEntry.CategoryId = content.CategoryId;
                    contentEntry.Content = content.Content;
                    contentEntry.IsFaq = content.IsFaq;
                    contentEntry.IsTop = content.IsTop;
                    contentEntry.Title = content.Title;
                    await ContentAccessor.Update(contentEntry);
                }
            }));
        }
Exemplo n.º 15
0
        public async Task <Tuple <IList <Categories>, int> > GetCategoryByTagName(string tagName, int pageSkip, int pageSize)
        {
            var categoryList = await ContentAccessor.ListOrderByDescendingAsync <Categories>(x => x.Status != ContentStatus.Close &&
                                                                                             x.ContentList != null &&
                                                                                             x.ContentList.Count > 0 &&
                                                                                             x.Tags.Any(c => c.Name == tagName)
                                                                                             , pageSkip, pageSize, "MediaResource");

            await ResetCategoryCoverImg(categoryList);

            var count = await ContentAccessor.Count <Categories>(x => x.Status != ContentStatus.Close &&
                                                                 x.ContentList != null &&
                                                                 x.ContentList.Count > 0 &&
                                                                 x.Tags.Any(c => c.Name == tagName));

            return(Tuple.Create(categoryList, count));
        }
Exemplo n.º 16
0
        public async Task <string> GetNextContentId(ContentEntry cEntry)
        {
            var contentCountOfCategory = cEntry.Category.ContentList.Count;

            if (cEntry.Order + 1 == contentCountOfCategory)
            {
                return(null);
            }
            else
            {
                return(await ApiMessage.WrapData(async() =>
                {
                    var nextEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Order == cEntry.Order + 1 && x.Category == cEntry.Category);
                    return nextEntry.Id.ToString();
                }));
            }
        }
Exemplo n.º 17
0
    public bool FindEvent(string eventName, out StoryEvent outEvent)
    {
        outEvent = null;
        if (eventName == null || events == null)
        {
            return(false);
        }

        ContentAccessor eventCA = events.Find(o => string.Compare(eventName, o.nameKey, StringComparison.InvariantCultureIgnoreCase) == 0);

        if (eventCA != null && eventCA.TryLoadContent(out object eventObj))
        {
            outEvent = eventObj as StoryEvent;
            return(true);
        }
        return(false);
    }
Exemplo n.º 18
0
        public async Task <Tuple <List <ContentEntry>, int> > GetContentListByCategoryName(string categoryName, int skipCount, int pageSize)
        {
            var dbSet       = ContentAccessor.All <ContentEntry>().Where(x => x.Category.Name == categoryName & !x.IsFaq);
            var contetnList = await dbSet
                              .Include("MediaResource")
                              .OrderByDescending(x => x.IsTop)
                              .OrderByDescending(x => x.Order)
                              .OrderByDescending(x => x.CreateTime)
                              .Skip(skipCount)
                              .Take(pageSize)
                              .ToListAsync();

            var total = await dbSet.CountAsync();

            return(Tuple.Create(contetnList, total));
            //throw new NotImplementedException();
        }
Exemplo n.º 19
0
    public bool GetEvent(int index, out StoryEvent outEvent)
    {
        outEvent = null;
        if (events == null || index < 0 || index >= events.Count)
        {
            return(false);
        }

        ContentAccessor eventCA = events[index];

        if (!eventCA.TryLoadContent(out object eventObj))
        {
            return(false);
        }

        outEvent = eventObj as StoryEvent;
        return(true);
    }
Exemplo n.º 20
0
    public async Task <IActionResult> Import(
        [FromForm] SetupModel setupModel,
        CancellationToken cancellationToken = default)
    {
        if (!ModelState.IsValid)
        {
            Response.StatusCode = StatusCodes
                                  .Status400BadRequest;
            return(View(nameof(Index)));
        }

        var contents = await JsonSerializer
                       .DeserializeAsync <IEnumerable <Content> >(
            setupModel.ImportFile.OpenReadStream(),
            JsonSerializerOptions,
            cancellationToken);

        if (contents != null)
        {
            foreach (var content in contents)
            {
                var existingContent = await ContentAccessor
                                      .GetContentAsync(
                    content.Path,
                    cancellationToken);

                if (existingContent != null)
                {
                    content.Id = existingContent.Id;
                    await ContentAccessor.UpdateContentAsync(
                        content, cancellationToken);
                }
                else
                {
                    await ContentAccessor.AddContentAsync(
                        content, cancellationToken);
                }
            }
        }

        return(RedirectToAction(
                   "Index",
                   "Content"));
    }
Exemplo n.º 21
0
        public async Task <ApiMessage> CreateContentWithCategory(ContentEntry content, string categoryName)
        {
            return(await ApiMessage.Wrap(async() =>
            {
                var categoryEntity = await CategoryAccessor.OneAsync <Categories>(x => x.Name == categoryName);
                if (categoryEntity == null)
                {
                    categoryEntity = new Categories
                    {
                        Name = categoryName,
                        CreateTime = DateTime.Now,
                        Id = Guid.NewGuid()
                    };
                    await CategoryAccessor.Add(categoryEntity);
                }

                var contentEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == content.Id);
                if (contentEntry == null)
                {
                    contentEntry = new ContentEntry
                    {
                        Id = Guid.NewGuid(),
                        Category = categoryEntity,
                        Content = content.Content,
                        CreateTime = DateTime.Now,
                        IsFaq = content.IsFaq,
                        IsTop = content.IsTop,
                        Title = content.Title
                    };
                    await ContentAccessor.Add(contentEntry);
                }
                else
                {
                    contentEntry.Category = categoryEntity;
                    contentEntry.Content = content.Content;
                    contentEntry.IsFaq = content.IsFaq;
                    contentEntry.IsTop = content.IsTop;
                    contentEntry.Title = content.Title;
                    await ContentAccessor.Update(contentEntry);
                }
            }));
        }
Exemplo n.º 22
0
        /// <summary>
        /// 阅读时写入用户阅读记录
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="userId"></param>
        /// <param name="skipCount"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task <ContentEntry> GetContentByIdSetLog(Guid Id, string userId, int skipCount = 0, int pageSize = 20)
        {
            return(await ApiMessage.WrapData(async() =>
            {
                var contentEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == Id, "MediaResource", "Category", "Category.ContentList");

                if (!string.IsNullOrEmpty(userId))
                {
                    await ContentAccessor.Add(new ContentUserReadLog
                    {
                        CreateTime = DateTime.Now,
                        Id = Guid.NewGuid(),
                        Categories = contentEntry.Category,
                        UserId = Guid.Parse(userId),
                        ContentEntry = contentEntry
                    });
                }
                return contentEntry;
            }));
        }
Exemplo n.º 23
0
        public async Task CreateMultiContent(Guid pid, string contentName, int count)
        {
            var category = await ContentAccessor.OneAsync <Categories>(x => x.Status != ContentStatus.Close && x.Id == pid);

            var contentList = new List <ContentEntry>();

            for (int i = 1; i <= count; i++)
            {
                contentList.Add(new ContentEntry
                {
                    Category   = category,
                    Title      = $"{contentName} 第{i}话",
                    Order      = i,
                    CreateTime = DateTime.Now,
                    Id         = Guid.NewGuid()
                });
            }
            await ContentAccessor.All <ContentEntry>().AddRangeAsync(contentList);

            await ContentAccessor.SaveAsync();
        }
        /// <summary>
        /// Fetches the current resource.
        /// </summary>
        public virtual void LoadCurrent()
        {
            if (!IsContentVisible)
            {
                return;
            }

            if (ContentAccessor == null)
            {
                Debug.LogError("The presenter's content is null.");
                return;
            }

            if (Formatter == null)
            {
                Debug.LogError("The presenter's content formatter is null.");
            }

#if UNITY_UWP
            IsContentReady = false;
            ContentAccessor.GetCurrentResource <T>(Formatter, OnContentReady);
#endif
        }
Exemplo n.º 25
0
        public async Task <Dictionary <Tuple <Guid, string>, List <ContentEntry> > > GetContentWithCategory(string pCategoryName, int pageSize)
        {
            var categoryList = await ContentAccessor.All <Categories>()
                               .Where(x => x.ParentCategory.Name == pCategoryName)
                               .ToListAsync();

            var dictContent = new Dictionary <Tuple <Guid, string>, List <ContentEntry> >();

            foreach (var categoryItem in categoryList)
            {
                var contentList = await ContentAccessor.All <ContentEntry>().Where(x => x.Category.Id == categoryItem.Id).ToListAsync();

                var tuple = Tuple.Create(categoryItem.Id, categoryItem.Name);
                dictContent.Add(tuple, contentList);
            }
            return(dictContent);

            //var contentList = await ContentAccessor.All<ContentEntry>()
            //                                .Where(x => x.Category.Name == pCategoryName)
            //                                .Select(x => new
            //                                {
            //                                    Category = x.Category,
            //                                    Content = x
            //                                })
            //                                .GroupBy(x => x.Category.Name)
            //                                .ToDictionaryAsync(x => x.Key, c => c.Select(v => v.Content));
            //var cateList = ContentAccessor.All<Categories>()
            //                            .Where(x => x.ParentCategory.Name == pCategoryName)
            //                            .Select(x => new
            //                            {
            //                                Category = x,
            //                                ContentList = x.ContentList.Take(pageSize).ToList()
            //                            })
            //                            .GroupBy(x => x.Category.Name);

            //return await cateList.ToDictionaryAsync(x => x.Key, c => c.Select(v => v.ContentList));
        }
Exemplo n.º 26
0
        private ContentAccessor NumberTest(string contentTypeName)
        {
            decimal originalValue;
            decimal currentValue;
            decimal handlerValue;
            string fieldName = "Number";
            decimal defaultValue = 0m;
            decimal testValue = 123m;
            decimal defaultHandlerValue = defaultValue;
            decimal testHandlerValue = testValue;

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#1");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#2");
            handlerValue = (decimal)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#4");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#6");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#7");
            handlerValue = (decimal)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#9");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#11");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#12");
            handlerValue = (decimal)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#13");

            return contentAcc;
        }
Exemplo n.º 27
0
        private ContentAccessor WhoAndWhenTest(string contentTypeName)
        {
            WhoAndWhenField.WhoAndWhenData originalValue;
            WhoAndWhenField.WhoAndWhenData currrenValue;
            //WhoAndWhenField.WhoAndWhenData defultValue;
            //WhoAndWhenField.WhoAndWhenData testValue;
            User originalUserValue;
            User currentUserValue;
            NodeList<Node> handlerUserValue;
            DateTime originalDateValue;
            DateTime currentDateValue;
            DateTime handlerDateValue;
            string fieldName = "WhoAndWhen";
            string userPropertyName = "Who";
            string datePropertyName = "When";
            User defaultUserValue = null;
            User testUserValue = User.Administrator;
            DateTime defaultDateValue = DateTime.MinValue;
            DateTime testDateValue = new DateTime(2001, 4, 17);
            DateTime defaultHandlerDateValue = defaultDateValue;
            DateTime testHandlerDateValue = testDateValue;

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (WhoAndWhenField.WhoAndWhenData)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue.Who == defaultUserValue && ItIsDateTimeDefault(originalValue.When), contentTypeName + "####1 Storage2: DateTime default value");
            //Assert.IsTrue(originalValue.Who == defaultUserValue && ((TimeSpan)(DateTime.Now - originalValue.When)).TotalMinutes < 1, contentTypeName + "####1 Storage2: DateTime default value");
            currrenValue = (WhoAndWhenField.WhoAndWhenData)content[fieldName];
            Assert.IsTrue(currrenValue.Who == defaultUserValue && ItIsDateTimeDefault(currrenValue.When), contentTypeName + "#2");
            handlerUserValue = (NodeList<Node>)content.ContentHandler[userPropertyName];
            handlerDateValue = (DateTime)content.ContentHandler[datePropertyName];
            Assert.IsTrue(handlerUserValue.Count == 0 && ItIsDateTimeDefault(handlerDateValue), contentTypeName + "#3");

            content[fieldName] = new WhoAndWhenField.WhoAndWhenData(testUserValue, testDateValue);
            originalValue = (WhoAndWhenField.WhoAndWhenData)content.Fields[fieldName].OriginalValue;
            originalUserValue = originalValue.Who;
            originalDateValue = originalValue.When;
            Assert.IsTrue(originalUserValue == defaultUserValue && ItIsDateTimeDefault(originalDateValue), contentTypeName + "#1");
            currrenValue = (WhoAndWhenField.WhoAndWhenData)content[fieldName];
            currentUserValue = currrenValue.Who;
            currentDateValue = currrenValue.When;
            Assert.IsTrue(currentUserValue == testUserValue && currentDateValue == testDateValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (WhoAndWhenField.WhoAndWhenData)content.Fields[fieldName].OriginalValue;
            originalUserValue = originalValue.Who;
            originalDateValue = originalValue.When;
            Assert.IsTrue(originalUserValue.Id == testUserValue.Id && originalDateValue == testDateValue, contentTypeName + "#6");
            currrenValue = (WhoAndWhenField.WhoAndWhenData)content[fieldName];
            currentUserValue = currrenValue.Who;
            currentDateValue = currrenValue.When;
            Assert.IsTrue(currentUserValue == testUserValue && currentDateValue == testDateValue, contentTypeName + "#7");
            handlerUserValue = (NodeList<Node>)content.ContentHandler[userPropertyName];
            handlerDateValue = (DateTime)content.ContentHandler[datePropertyName];
            Assert.IsTrue(handlerUserValue[0].Id == User.Administrator.Id && handlerDateValue == testDateValue, contentTypeName + "#8");

            WhoAndWhenField.WhoAndWhenData defaultValue = new WhoAndWhenField.WhoAndWhenData();
            defaultValue.Who = defaultUserValue;
            defaultValue.When = DateTime.Now;
            content[fieldName] = defaultValue;
            originalValue = (WhoAndWhenField.WhoAndWhenData)content.Fields[fieldName].OriginalValue;
            originalUserValue = originalValue.Who;
            originalDateValue = originalValue.When;
            Assert.IsTrue(originalUserValue.Id == testUserValue.Id && originalDateValue == testDateValue, contentTypeName + "#9");
            currrenValue = (WhoAndWhenField.WhoAndWhenData)content[fieldName];
            currentUserValue = currrenValue.Who;
            currentDateValue = currrenValue.When;
            Assert.IsTrue(currentUserValue == defaultUserValue && ItIsDateTimeDefault(currentDateValue), contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (WhoAndWhenField.WhoAndWhenData)content.Fields[fieldName].OriginalValue;
            originalUserValue = originalValue.Who;
            originalDateValue = originalValue.When;
            Assert.IsTrue(originalUserValue == defaultUserValue && ItIsDateTimeDefault(originalDateValue), contentTypeName + "#11");
            currrenValue = (WhoAndWhenField.WhoAndWhenData)content[fieldName];
            currentUserValue = currrenValue.Who;
            currentDateValue = currrenValue.When;
            Assert.IsTrue(currentUserValue == defaultUserValue && ItIsDateTimeDefault(currentDateValue), contentTypeName + "#12");
            handlerUserValue = (NodeList<Node>)content.ContentHandler[userPropertyName];
            handlerDateValue = (DateTime)content.ContentHandler[datePropertyName];
            Assert.IsTrue(handlerUserValue.Count == 0, contentTypeName + "#13");
            Assert.IsTrue(ItIsDateTimeDefault(handlerDateValue), contentTypeName + "#14");

            return contentAcc;
        }
Exemplo n.º 28
0
        private ContentAccessor BooleanTest(string contentTypeName)
        {
            bool originalValue;
            bool currentValue;
            int handlerValue;
            string fieldName = "Boolean";
            bool defaultValue = false;
            bool testValue = true;
            int defaultHandlerValue = 0;
            int testHandlerValue = 1;

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (bool)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#1");
            currentValue = (bool)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#2");
            handlerValue = (int)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (bool)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#4");
            currentValue = (bool)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (bool)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#6");
            currentValue = (bool)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#7");
            handlerValue = (int)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (bool)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#9");
            currentValue = (bool)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (bool)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#11");
            currentValue = (bool)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#12");
            handlerValue = (int)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#13");

            return contentAcc;
        }
Exemplo n.º 29
0
        private ContentAccessor LongTextTest(string contentTypeName)
        {
            string originalValue;
            string currentValue;
            string handlerValue;
            string fieldName = "LongText";
            string defaultValue = (string)PropertyType.GetDefaultValue(DataType.Text);
            string testValue = "TestValue";
            string defaultHandlerValue = defaultValue;
            string testHandlerValue = testValue;

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (string)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#1");
            currentValue = (string)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#2");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (string)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#4");
            currentValue = (string)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (string)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#6");
            currentValue = (string)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#7");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (string)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#9");
            currentValue = (string)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (string)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#11");
            currentValue = (string)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#12");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#13");

            return contentAcc;
        }
Exemplo n.º 30
0
        public void FieldOnHandler_Ref_Query()
        {
            string fieldName = "Query";

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;
            ReferenceField field = (ReferenceField)content.Fields[fieldName];

            List<Node> refs;

            handler.GeneralReference = new Node[0];
            refs = new List<Node>();
            refs.Add(User.Administrator);
            field.SetData(refs);
            contentAcc.SaveFields();
            Assert.IsFalse(field.IsValid, "#1");

            handler.GeneralReference = new Node[0];
            refs = new List<Node>();
            refs.Add(ContentTypeManager.Current.GetContentTypeByName("Car"));
            field.SetData(refs);
            contentAcc.SaveFields();
            Assert.IsTrue(field.IsValid, "#2");
        }
Exemplo n.º 31
0
        public void FieldOnHandler_Ref_MultipleNull()
        {
            string fieldName = "MultipleNull";

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;
            ReferenceField field = (ReferenceField)content.Fields[fieldName];

            Node node0 = User.Administrator;
            Node node1 = Repository.Root;
            Node node2 = ContentTypeManager.Current.GetContentTypeByName("GenericContent");
            bool[] flags = new bool[12];

            var refs = new List<Node>();
            field.SetData(refs);
            contentAcc.SaveFields();	//-- content: empty
            flags[0] = field.IsValid;
            flags[1] = content.IsValid;
            flags[2] = handler.GeneralReference.ToList().Count == 0;

            handler.GeneralReference = new Node[0];
            refs = new List<Node>();
            refs.Add(node0);
            field.SetData(refs);
            contentAcc.SaveFields();	//-- content: node0
            flags[3] = field.IsValid;
            flags[4] = content.IsValid;
            flags[5] = handler.GeneralReference.ToList().Count == 1;

            handler.GeneralReference = new Node[0];
            refs = new List<Node>();
            refs.Add(node0);
            refs.Add(node1);
            field.SetData(refs);
            contentAcc.SaveFields();	//-- content: node0, node1
            flags[6] = field.IsValid;
            flags[7] = content.IsValid;
            flags[8] = handler.GeneralReference.ToList().Count == 2;

            handler.GeneralReference = new Node[0];
            refs = new List<Node>();
            refs.Add(node0);
            refs.Add(node1);
            refs.Add(node2);
            field.SetData(refs);
            contentAcc.SaveFields();	//-- content: node0, node1, node2
            flags[9] = field.IsValid;
            flags[10] = content.IsValid;
            flags[11] = handler.GeneralReference.ToList().Count == 3;

            string error = "";
            for (int i = 0; i < flags.Length; i++)
                if (!flags[i])
                    error = String.Concat(error, "#", i, " ");

            Assert.IsTrue(error.Length == 0, "False flags: " + error);
        }
Exemplo n.º 32
0
        public void FieldOnHandler_GeneralReference()
        {
            string fieldName = "GeneralReference";

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;
            ReferenceField field = (ReferenceField)content.Fields[fieldName];
            var nodeList = handler.GeneralReference.ToList();

            Assert.IsTrue(nodeList.Count == 0, "#1");

            var nodes = new List<Node>(new Node[] { User.Administrator });
            content[fieldName] = nodes;
            nodes.Add(Repository.Root);
            content[fieldName] = nodes;
            contentAcc.SaveFields();
            nodes.Add(ContentTypeManager.Current.GetContentTypeByName("GenericContent"));

            var values = handler.GeneralReference.ToList();

            Assert.IsTrue(values.Count == 2, "#2");
            Assert.IsTrue(values[0].Id == User.Administrator.Id, "#3");
            Assert.IsTrue(values[1].Id == Repository.Root.Id, "#4");
        }
Exemplo n.º 33
0
        private ContentAccessor DatetimeTest(string contentTypeName)
        {
            DateTime originalValue;
            DateTime currentValue;
            DateTime handlerValue;
            string fieldName = "DateTime";
            DateTime defaultValue = DateTime.MinValue;
            DateTime testValue = DateTime.Parse("2008-06-04 12:34:56");
            DateTime defaultHandlerValue = defaultValue;
            DateTime testHandlerValue = testValue;

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (DateTime)content.Fields[fieldName].OriginalValue;
            currentValue = (DateTime)content[fieldName];
            handlerValue = (DateTime)content.ContentHandler[fieldName];
            Assert.IsTrue(ItIsDateTimeDefault(originalValue), contentTypeName + "####1: Storage2: DateTime default value");
            Assert.IsTrue(ItIsDateTimeDefault(currentValue), contentTypeName + "#2");
            Assert.IsTrue(ItIsDateTimeDefault(handlerValue), contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (DateTime)content.Fields[fieldName].OriginalValue;
            currentValue = (DateTime)content[fieldName];
            Assert.IsTrue(ItIsDateTimeDefault(originalValue), contentTypeName + "#4");
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (DateTime)content.Fields[fieldName].OriginalValue;
            currentValue = (DateTime)content[fieldName];
            handlerValue = (DateTime)content.ContentHandler[fieldName];
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#6");
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#7");
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (DateTime)content.Fields[fieldName].OriginalValue;
            currentValue = (DateTime)content[fieldName];
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#9");
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (DateTime)content.Fields[fieldName].OriginalValue;
            currentValue = (DateTime)content[fieldName];
            handlerValue = (DateTime)content.ContentHandler[fieldName];
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#11");
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#12");
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#13");

            return contentAcc;
        }
Exemplo n.º 34
0
        public void FieldOnHandler_NumberOnInt32()
        {
            int originalValue;
            int currentValue;
            Int32 handlerValue;
            string fieldName = "Int32";
            int defaultValue = 0;
            int testValue = 123;
            int testIntValue = 123;
            Int32 defaultHandlerValue = 0;
            Int32 testHandlerValue = 123;

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;

            originalValue = (int)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#1");
            currentValue = (int)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#2");
            handlerValue = handler.Int32;
            Assert.IsTrue(handlerValue == defaultHandlerValue, "#3");

            content[fieldName] = testValue;
            originalValue = (int)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#4");
            currentValue = (int)content[fieldName];
            Assert.IsTrue(currentValue == testValue, "#5");
            contentAcc.SaveFields();
            originalValue = (int)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testIntValue, "#6");
            currentValue = (int)content[fieldName];
            Assert.IsTrue(currentValue == testValue, "#7");
            handlerValue = handler.Int32;
            Assert.IsTrue(handlerValue == testHandlerValue, "#8");

            content[fieldName] = defaultValue;
            originalValue = (int)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testIntValue, "#9");
            currentValue = (int)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#10");
            contentAcc.SaveFields();
            originalValue = (int)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#11");
            currentValue = (int)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#12");
            handlerValue = handler.Int32;
            Assert.IsTrue(handlerValue == defaultHandlerValue, "#13");
        }
Exemplo n.º 35
0
        private ContentAccessor HyperLinkTest(string contentTypeName)
        {
            string fieldName = "HyperLink";
            HyperLinkField.HyperlinkData originalValue;
            HyperLinkField.HyperlinkData currentValue;
            HyperLinkField.HyperlinkData defaultValue = new HyperLinkField.HyperlinkData();
            HyperLinkField.HyperlinkData testValue = new HyperLinkField.HyperlinkData("testHref", "testText", "testTitle", "testTarget");
            string handlerValue;
            string defaultHandlerValue = (string)PropertyType.GetDefaultValue(DataType.String);
            string testHandlerValue = "<a href=\"testHref\" target=\"testTarget\" title=\"testTitle\">testText</a>";

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (HyperLinkField.HyperlinkData)content.Fields[fieldName].OriginalValue;
            currentValue = (HyperLinkField.HyperlinkData)content[fieldName];
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(originalValue.Href == defaultValue.Href, contentTypeName + "#1a");
            Assert.IsTrue(originalValue.Text == defaultValue.Text, contentTypeName + "#1b");
            Assert.IsTrue(originalValue.Title == defaultValue.Title, contentTypeName + "#1c");
            Assert.IsTrue(originalValue.Target == defaultValue.Target, contentTypeName + "#1d");
            Assert.IsTrue(currentValue.Href == defaultValue.Href, contentTypeName + "#2a");
            Assert.IsTrue(currentValue.Text == defaultValue.Text, contentTypeName + "#2b");
            Assert.IsTrue(currentValue.Title == defaultValue.Title, contentTypeName + "#2c");
            Assert.IsTrue(currentValue.Target == defaultValue.Target, contentTypeName + "#2d");
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (HyperLinkField.HyperlinkData)content.Fields[fieldName].OriginalValue;
            currentValue = (HyperLinkField.HyperlinkData)content[fieldName];
            Assert.IsTrue(originalValue.Href == defaultValue.Href, contentTypeName + "#4a");
            Assert.IsTrue(originalValue.Text == defaultValue.Text, contentTypeName + "#4b");
            Assert.IsTrue(originalValue.Title == defaultValue.Title, contentTypeName + "#4c");
            Assert.IsTrue(originalValue.Target == defaultValue.Target, contentTypeName + "#4d");
            Assert.IsTrue(currentValue.Href == testValue.Href, contentTypeName + "#5a");
            Assert.IsTrue(currentValue.Text == testValue.Text, contentTypeName + "#5b");
            Assert.IsTrue(currentValue.Title == testValue.Title, contentTypeName + "#5c");
            Assert.IsTrue(currentValue.Target == testValue.Target, contentTypeName + "#5d");

            contentAcc.SaveFields();
            originalValue = (HyperLinkField.HyperlinkData)content.Fields[fieldName].OriginalValue;
            currentValue = (HyperLinkField.HyperlinkData)content[fieldName];
            Assert.IsTrue(originalValue.Href == testValue.Href, contentTypeName + "#6a");
            Assert.IsTrue(originalValue.Text == testValue.Text, contentTypeName + "#6b");
            Assert.IsTrue(originalValue.Title == testValue.Title, contentTypeName + "#6c");
            Assert.IsTrue(originalValue.Target == testValue.Target, contentTypeName + "#6d");
            Assert.IsTrue(currentValue.Href == testValue.Href, contentTypeName + "#7a");
            Assert.IsTrue(currentValue.Text == testValue.Text, contentTypeName + "#7b");
            Assert.IsTrue(currentValue.Title == testValue.Title, contentTypeName + "#7c");
            Assert.IsTrue(currentValue.Target == testValue.Target, contentTypeName + "#7d");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (HyperLinkField.HyperlinkData)content.Fields[fieldName].OriginalValue;
            currentValue = (HyperLinkField.HyperlinkData)content[fieldName];
            Assert.IsTrue(originalValue.Href == testValue.Href, contentTypeName + "#9a");
            Assert.IsTrue(originalValue.Text == testValue.Text, contentTypeName + "#9b");
            Assert.IsTrue(originalValue.Title == testValue.Title, contentTypeName + "#9c");//renameok
            Assert.IsTrue(originalValue.Target == testValue.Target, contentTypeName + "#9d");
            Assert.IsTrue(currentValue.Href == defaultValue.Href, contentTypeName + "#10a");
            Assert.IsTrue(currentValue.Text == defaultValue.Text, contentTypeName + "#10b");
            Assert.IsTrue(currentValue.Title == defaultValue.Title, contentTypeName + "#10c");//renameok
            Assert.IsTrue(currentValue.Target == defaultValue.Target, contentTypeName + "#10d");

            contentAcc.SaveFields();
            originalValue = (HyperLinkField.HyperlinkData)content.Fields[fieldName].OriginalValue;
            currentValue = (HyperLinkField.HyperlinkData)content[fieldName];
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(originalValue.Href == defaultValue.Href, contentTypeName + "#11a");
            Assert.IsTrue(originalValue.Text == defaultValue.Text, contentTypeName + "#11b");
            Assert.IsTrue(originalValue.Title == defaultValue.Title, contentTypeName + "#11c"); //renameok
            Assert.IsTrue(originalValue.Target == defaultValue.Target, contentTypeName + "#11d");
            Assert.IsTrue(currentValue.Href == defaultValue.Href, contentTypeName + "#12a");
            Assert.IsTrue(currentValue.Text == defaultValue.Text, contentTypeName + "#12b");
            Assert.IsTrue(currentValue.Title == defaultValue.Title, contentTypeName + "#12c");//renameok
            Assert.IsTrue(currentValue.Target == defaultValue.Target, contentTypeName + "#12d");
            Assert.IsTrue(handlerValue == "<a></a>", contentTypeName + "#13");

            return contentAcc;

        }
Exemplo n.º 36
0
 public async Task DeleteKnowledgeArticle(Guid Id)
 {
     await ContentAccessor.Delete <ContentEntry>(x => x.Id == Id);
 }
Exemplo n.º 37
0
 public async Task UpdateKnowledgeArticle(ContentEntry contentEntry)
 {
     await ContentAccessor.Update(contentEntry);
 }
Exemplo n.º 38
0
 public async Task <ContentEntry> GetKnowledgeArticle(Guid Id)
 {
     return(await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == Id));
 }
Exemplo n.º 39
0
 public async Task CreateFaqArticle(ContentEntry contentEntry)
 {
     await ContentAccessor.Add(contentEntry);
 }
Exemplo n.º 40
0
        private ContentAccessor VersionTest(string contentTypeName)
        {
            VersionNumber originalValue;
            VersionNumber currentValue;
            string handlerValue;
            string fieldName = "VersionNumber";
            VersionNumber defaultValue = null;
            VersionNumber testValue = new VersionNumber(5, 6, VersionStatus.Draft);
            string defaultHandlerValue = (string)PropertyType.GetDefaultValue(DataType.String);
            string testHandlerValue = testValue.ToString();

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#1");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#2");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#4");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#6");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#7");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#9");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#11");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#12");
            handlerValue = (string)content.ContentHandler[fieldName];
            //Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#13");
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "####13: Storage2: Expected: [null], current: [empty]");

            return contentAcc;
        }
Exemplo n.º 41
0
        public void FieldOnHandler_NumberOnUInt64()
        {
            decimal originalValue;
            decimal currentValue;
            UInt64 handlerValue;
            string fieldName = "UInt64";
            decimal defaultValue = 0;
            decimal testValue = 123.456m;
            decimal testIntValue = 123m;
            UInt64 defaultHandlerValue = 0;
            UInt64 testHandlerValue = 123;

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;

            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#1");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#2");
            handlerValue = handler.UInt64;
            Assert.IsTrue(handlerValue == defaultHandlerValue, "#3");

            content[fieldName] = testValue;
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#4");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == testValue, "#5");
            contentAcc.SaveFields();
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testIntValue, "#6");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == testValue, "#7");
            handlerValue = handler.UInt64;
            Assert.IsTrue(handlerValue == testHandlerValue, "#8");

            content[fieldName] = defaultValue;
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testIntValue, "#9");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#10");
            contentAcc.SaveFields();
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#11");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#12");
            handlerValue = handler.UInt64;
            Assert.IsTrue(handlerValue == defaultHandlerValue, "#13");
        }
Exemplo n.º 42
0
        public void Field_ParseContent()
        {
            var fieldData = new Dictionary<string, string>();
            fieldData.Add("Byte", "256");
            fieldData.Add("Single", Double.MaxValue.ToString(System.Globalization.CultureInfo.InvariantCulture));
            var content = Content.CreateNewAndParse("FieldOnHandlerTest", _testRoot, "asdf", fieldData);
            Assert.IsFalse(content.IsValid);

            var sb = new StringBuilder();
            foreach (var fieldName in content.Fields.Keys)
                //if(content.Fields[fieldName].ValidationResult != null)
                sb.Append(fieldName).Append(": ").AppendLine(content.Fields[fieldName].GetValidationMessage());

            Assert.IsTrue(content.Fields["Byte"].GetValidationMessage() != "Successful");
            Assert.IsTrue(content.Fields["Single"].GetValidationMessage() != "Successful");

            var contentAcc = new ContentAccessor(content);
            contentAcc.SaveFields();
        }
Exemplo n.º 43
0
        public void FieldOnHandler_UserReference()
        {
            string fieldName = "UserReference";

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;
            ReferenceField field = (ReferenceField)content.Fields[fieldName];

            Assert.IsNull(handler.UserReference, "#1");
            content[fieldName] = User.Administrator;
            contentAcc.SaveFields();
            Assert.IsTrue(handler.UserReference.Id == User.Administrator.Id, "#2");
        }
Exemplo n.º 44
0
        public static bool CreateNewProject(string campaignName, string parentDirectory, ContentLoadSource defaultSaveLocation, DateTime ingameStartTime, out Campaign outCampaign)
        {
            // Create the campaign directories and folder structure:
            if (!CreateProjectDirectories(campaignName, parentDirectory, out string projectRootDir))
            {
                outCampaign = null;
                return(false);
            }

            // Create a project object, for later serialization to file:
            Project project = new Project()
            {
                name     = campaignName,
                rootPath = projectRootDir,
            };

            // Set the new project as active, thus updating content root directories to the new project's:
            if (!ProjectManager.LoadProject(project))
            {
                Debug.LogError("[ProjectCreator] Error! Failed to load and activate newly created project!");
                outCampaign = null;
                return(false);
            }

            // Create basic contents for the project and its main campaign:
            string     storylineName = $"{campaignName} Timeline";
            StoryEvent startEvent    = new StoryEvent()
            {
                name        = $"{campaignName} beginning",
                description = "The player characters first meet in the taproom of their hostel, attracted by a scream of terror. " +
                              "Seconds later, the woman at the origin of the scream collapses; blood running from her eyes, she dies on the spot. " +
                              "On her hand, a strange marking has appeared, strangely similar to the symbol Baal, the god of death.",
                startTime = ingameStartTime,
                storyline = new ContentAccessor(storylineName),
            };
            ContentAccessor startEventCA = new ContentAccessor(startEvent.name, startEvent);

            ContentLoader.SaveContent(startEventCA, out ContentRefAndHandle startEventRaH, defaultSaveLocation);

            StoryLine storyline = new StoryLine()
            {
                name        = storylineName,
                description = $"This is the main storyline of the '{campaignName}' campaign, telling the tale of a group " +
                              "of unlikely companions banding together to vanquish the great evil that is threatening their home.",
                startTime = ingameStartTime,
                endTime   = ingameStartTime + new TimeSpan(1, 0, 0, 0),
                events    = new List <ContentAccessor>(new ContentAccessor[] { startEventCA }),
            };
            ContentAccessor storylineCA = new ContentAccessor(storylineName, storyline);

            ContentLoader.SaveContent(storylineCA, out ContentRefAndHandle storylineRaH, defaultSaveLocation);

            Campaign campaign = new Campaign()
            {
                name          = campaignName,
                description   = "A grand adventure involving great heroes, vile foes, and an excessive number of murder hobos.",
                mainStoryline = new ContentAccessor(storyline.name, storyline),
            };
            ContentAccessor campaignCA = new ContentAccessor(campaignName, campaign);

            ContentLoader.SaveContent(campaignCA, out ContentRefAndHandle campaignRaH, defaultSaveLocation);

            WorldMap worldMap = new WorldMap()
            {
                name        = $"{campaignName} World Map",
                description = "The home world of our great heroes, and the place they persistently haunt in quest for murder and loot.",
            };
            ContentAccessor worldMapCA = new ContentAccessor(worldMap.name, worldMap);

            ContentLoader.SaveContent(worldMapCA, out ContentRefAndHandle worldMapRaH, defaultSaveLocation);

            // Link the above contents to the project:
            project.mainCampaign = campaignCA;
            project.mainWorldMap = worldMapCA;
            ContentAccessor projectCA = new ContentAccessor(project.name, project);

            // Save project to file:
            ContentLoader.SaveContent(projectCA, out ContentRefAndHandle projectRaH, ContentLoadSource.File);

            // Output the newly created and populated campaign object and return success:
            outCampaign = campaign;
            return(true);
        }
Exemplo n.º 45
0
        public void FieldOnHandler_UsersReference()
        {
            string fieldName = "UsersReference";

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;
            ReferenceField field = (ReferenceField)content.Fields[fieldName];
            var userList = handler.UsersReference.ToList();

            Assert.IsTrue(userList.Count == 0, "#1");
            var users = new User[] { User.Administrator, User.Visitor };
            content[fieldName] = users;
            contentAcc.SaveFields();
            userList = handler.UsersReference.ToList();

            Assert.IsTrue(userList.Count == 2, "#2");
            Assert.IsTrue(userList[0].Id == User.Administrator.Id, "#3");
            Assert.IsTrue(userList[1].Id == User.Visitor.Id, "#4");
        }