Exemplo n.º 1
0
        public void TemplateManagerTest_UseProjectMappedFolderHierarchy_LoadVariantFolder()
        {
            var path1 = Path.Combine(_testLocation, "Variant1", "TeamProjectCollectionUrl", "ProjectCollectionName", "TeamProjectName");
            var path2 = Path.Combine(_testLocation, "Variant2", "TeamProjectCollectionUrl", "ProjectCollectionName", "TeamProjectName");

            Directory.CreateDirectory(path1);
            Directory.CreateDirectory(path2);
            foreach (var file in new DirectoryInfo(_testLocation).GetFiles("*.*", SearchOption.TopDirectoryOnly))
            {
                file.CopyTo(Path.Combine(path1, file.Name));
                file.MoveTo(Path.Combine(path2, file.Name));
            }

            var templateBundle = new TemplateBundle("ProjectMappedFolderHierarchy", _testLocation, _guid);

            templateBundle.HasProjectMappedFolderHierarchy = true;
            _templateManager.AddTemplateBundle(templateBundle);

            Assert.AreEqual("TeamProjectCollectionUrl", templateBundle.Templates.First().ServerName);
            Assert.AreEqual("ProjectCollectionName", templateBundle.Templates.First().ProjectCollectionName);
            Assert.AreEqual("TeamProjectName", templateBundle.Templates.First().ProjectName);

            // save, load and make sure setting was applied correctly
            _templateManager.SaveTemplateBundles();
            var templateManager = new TemplateManager();

            // 3! Two variants and the default
            Assert.AreEqual(2, templateManager.TemplateBundles.First(x => x.ShowName.Equals("ProjectMappedFolderHierarchy")).Templates.Count);
            Assert.IsTrue(templateManager.TemplateBundles.First(x => x.ShowName.Equals("ProjectMappedFolderHierarchy")).HasProjectMappedFolderHierarchy);
        }
Exemplo n.º 2
0
        public void TemplateManagerTest_UseProjectMappedFolderHierarchy_ShouldParseFolderStructureAndSaveSetting()
        {
            var path = Path.Combine(_testLocation, "TeamProjectCollectionUrl", "ProjectCollectionName", "TeamProjectName");

            Directory.CreateDirectory(path);
            foreach (var file in new DirectoryInfo(_testLocation).GetFiles("*.*", SearchOption.TopDirectoryOnly))
            {
                file.MoveTo(Path.Combine(path, file.Name));
            }

            var templateBundle = new TemplateBundle("ProjectMappedFolderHierarchy", _testLocation, _guid);

            templateBundle.HasProjectMappedFolderHierarchy = true;
            _templateManager.AddTemplateBundle(templateBundle);

            Assert.AreEqual("TeamProjectCollectionUrl", templateBundle.Templates.First().ServerName);
            Assert.AreEqual("ProjectCollectionName", templateBundle.Templates.First().ProjectCollectionName);
            Assert.AreEqual("TeamProjectName", templateBundle.Templates.First().ProjectName);

            // save, load and make sure setting was applied correctly
            _templateManager.SaveTemplateBundles();
            var templateManager = new TemplateManager();

            Assert.IsTrue(templateManager.TemplateBundles.First(x => x.ShowName.Equals("ProjectMappedFolderHierarchy")).HasProjectMappedFolderHierarchy);
        }
        private async ValueTask WriteMessageGroupAsync(MessageGroup messageGroup)
        {
            var templateContext = new MessageGroupTemplateContext(Context, messageGroup);
            var templateBundle  = await TemplateBundle.ResolveAsync();

            await _writer.WriteLineAsync(
                await templateBundle.MessageGroupTemplate.RenderAsync(templateContext)
                );
        }
        public override async ValueTask WritePreambleAsync()
        {
            var templateContext = new LayoutTemplateContext(Context, _themeName, _messageCount);
            var templateBundle  = await TemplateBundle.ResolveAsync();

            await _writer.WriteLineAsync(
                await templateBundle.PreambleTemplate.RenderAsync(templateContext)
                );
        }
Exemplo n.º 5
0
        //----------------------------------------------- 开放方法 --------------------------------------------------------------------

        public virtual TemplateBundle registerTemplateBundle(List <OneLineStoryTemplate> oneLineStoryTemplates, List <ShortStoryTemplate> shortStoryTemplates, List <ActionLink> actionLinks)
        {
            TemplateBundle t = new TemplateBundle();

            t.OneLineStoryTemplatesStr = Json.ToStringList(oneLineStoryTemplates);
            t.ShortStoryTemplatesStr   = Json.ToStringList(shortStoryTemplates);
            t.ActionLinksStr           = Json.ToStringList(actionLinks);
            db.insert(t);

            return(t);
        }
Exemplo n.º 6
0
        private void initTemplateBundle()
        {
            // 1
            TemplateBundle tpl1 = new TemplateBundle();

            tpl1.OneLineStoryTemplatesStr = "[{ Title: \"{*actor*} 发表了新日志 {*blog*}\" }]";
            db.insert(tpl1);

            // 2
            TemplateBundle tt = new TemplateBundle();

            tt.insert();
            tt.delete();

            // 3
            TemplateBundle tpl3 = new TemplateBundle();

            tpl3.ShortStoryTemplatesStr = "[{ Title: \"{*actor*} 上传了{*photoCount*}张 新照片。\", Body: \"{*photos*}\"  }]";
            db.insert(tpl3);

            // 4
            tt.insert();
            tt.delete();


            // 5
            TemplateBundle tpl5 = new TemplateBundle();

            tpl5.OneLineStoryTemplatesStr = "[{ Title: \"{*actor*} 发表了论坛主题 {*topic*}\" }]";
            db.insert(tpl5);

            // 6
            TemplateBundle tpl6 = new TemplateBundle();

            tpl6.OneLineStoryTemplatesStr = "[{ Title: \"{*actor*} 发表了论坛帖子 {*post*}\" }]";
            db.insert(tpl6);

            // 7
            tt.insert();
            tt.delete();

            // 8
            tt.insert();
            tt.delete();


            TemplateBundle tpl9 = new TemplateBundle();

            tpl9.OneLineStoryTemplatesStr = "[{ Title: \"{*actor*} 和 {*friend*} 成为了好友\" }]";
            db.insert(tpl9);
        }
Exemplo n.º 7
0
        private void addFeedInfo(ForumPost data)
        {
            String lnkPost = alink.ToAppData(data);
            String post    = string.Format("<a href=\"{0}\">{1}</a>", lnkPost, data.Title);

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("post", post);
            String templateData = JSON.DicToString(dic);

            TemplateBundle tplBundle = TemplateBundle.GetForumPostTemplateBundle();

            feedService.publishUserAction(data.Creator, typeof(ForumPost).FullName, tplBundle.Id, templateData, "");
        }
Exemplo n.º 8
0
        private void addFeedInfo(BlogPost data)
        {
            String lnkPost = alink.ToAppData(data);
            String blog    = string.Format("<a href=\"{0}\">{1}</a>", lnkPost, data.Title);

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("blog", blog);
            String templateData = Json.ToString(dic);

            TemplateBundle tplBundle = TemplateBundle.GetBlogTemplateBundle();

            new FeedService().publishUserAction(data.Creator, typeof(BlogPost).FullName, tplBundle.Id, templateData, "", data.Ip);
        }
        public override async ValueTask WritePostambleAsync()
        {
            // Flush current message group
            if (_messageGroupBuffer.Any())
            {
                await WriteMessageGroupAsync(MessageGroup.Join(_messageGroupBuffer));
            }

            var templateContext = new LayoutTemplateContext(Context, _themeName, _messageCount);
            var templateBundle  = await TemplateBundle.ResolveAsync();

            await _writer.WriteLineAsync(
                await templateBundle.PostambleTemplate.RenderAsync(templateContext)
                );
        }
        private void SetupBundles(BundleCollection collection)
        {
            var options = new TemplateCompilerOptions
            {
                ModuleName = "myapp",
                Prefix     = "/templates",
                WorkingDir = "../../../fixtures"
            };

            var bundle =
                new TemplateBundle("~/templates", options).Include("~/template1.html");

            bundle.Transforms.Clear();
            collection.Add(bundle);
        }
Exemplo n.º 11
0
        private static void addFrinedFeedInfo(User user, User friend, String ip)
        {
            String userLink = Link.ToMember(friend);

            String lnkInfo = string.Format("<a href=\"{0}\">{1}</a>", userLink, friend.Name);

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("friend", lnkInfo);
            dic.Add("friendId", friend.Id);
            String templateData = Json.ToString(dic);

            TemplateBundle tplBundle = TemplateBundle.GetFriendsTemplateBundle();

            new FeedService().publishUserAction(user, typeof(FriendShip).FullName, tplBundle.Id, templateData, "", ip);
        }
Exemplo n.º 12
0
        private static string ProcessarScript(string caminhoRelativo)
        {
            var bundle = new TemplateBundle(caminhoRelativo);

            try
            {
                BundleTable.Bundles.Add(bundle);

                var template = new TemplateItem(bundle);
                return(template.ToString());
            }
            finally
            {
                BundleTable.Bundles.Remove(bundle);
            }
        }
Exemplo n.º 13
0
        public void Register(BlockContext blockContext, BlockTemplate blockTemplate)
        {
            var templateDict = EnsureCreated(blockContext);

            if (templateDict.ContainsKey(blockTemplate))
            {
                throw new ArgumentException("Block template with given Id is already registered");
            }

            var bundle = new TemplateBundle {
                template       = blockTemplate,
                valuesCache    = GetValues(blockContext, blockTemplate),
                valuesAreDirty = false
            };

            templateDict.Add(blockTemplate, bundle);
        }
Exemplo n.º 14
0
        // flash上传(逐个保存)
        public void SaveUpload()
        {
            int albumId          = ctx.PostInt("PhotoAlbumId");
            int systemCategoryId = ctx.PostInt("SystemCategoryId");

            if (ctx.HasUploadFiles == false)
            {
                echoText(lang("exPlsUpload"));
                return;
            }

            HttpFile file = ctx.GetFileSingle();

            logger.Info(file.FileName + "=>" + file.ContentType);

            Result result = Uploader.SaveImg(file);

            if (result.HasErrors)
            {
                errors.Join(result);
                echoText(result.ErrorsText);
            }
            else
            {
                PhotoPost post = newPost(Path.GetFileNameWithoutExtension(file.FileName), result.Info.ToString(), albumId, systemCategoryId);
                PhotoApp  app  = ctx.app.obj as PhotoApp;
                postService.CreatePost(post, app);

                // 统计
                User user = ctx.owner.obj as User;
                user.Pins = PhotoPost.count("OwnerId=" + user.Id);
                user.update("Pins");

                // feed
                String photoHtml = string.Format("<a href='{0}'><img src='{1}'/></a> ", alink.ToAppData(post), post.ImgThumbUrl);

                String templateData = string.Format("photoCount: {0}, photos: \"{1}\" ", 1, photoHtml);
                templateData = "{" + templateData + "}";
                TemplateBundle tplBundle = TemplateBundle.GetPhotoTemplateBundle();
                feedService.publishUserAction((User)ctx.viewer.obj, typeof(PhotoPost).FullName, tplBundle.Id, templateData, "", ctx.Ip);
                echoAjaxOk();
            }
        }
Exemplo n.º 15
0
        public virtual void publishUserAction(User creator, string dataType, long templateBundleId, string templateData, string bodyGeneral, string ip)
        {
            // 模板数据是 json 字符串类型;也就是 key-value 对
            // 除了自定义的键外,比如 {*gift*}, {*mood*}, {*score*}
            // 还有系统保留的4个键:images, flash, mp3, video

            Feed feed = new Feed();

            feed.Creator     = creator;
            feed.DataType    = dataType;
            feed.BodyGeneral = bodyGeneral;

            TemplateBundle t = getRegisteredTemplateBundleByID(templateBundleId);

            // 判断是单行模式还是多行模式
            List <OneLineStoryTemplate> onelineTemplates    = t.GetOneLineStoryTemplates(  );
            List <ShortStoryTemplate>   shortStoryTemplates = t.GetShortStoryTemplates(  );

            // 如果是单行模式,只解析出标题的模板与数据
            if (onelineTemplates.Count > 0)
            {
                OneLineStoryTemplate tpl = onelineTemplates[0];
                //feed.TitleTemplate = getTitleTemplate( onelineTemplates, templateData, dataKeyCount );
                feed.TitleTemplate = tpl.Title;
                feed.TitleData     = templateData;
            }
            // 如果是多行模式,除了标题,还要解析出主干部分的模板和数据,以及评论
            else if (shortStoryTemplates.Count > 0)
            {
                ShortStoryTemplate tpl = shortStoryTemplates[0];
                feed.TitleTemplate = tpl.Title;
                feed.TitleData     = PlatformTemplate.GetVarData(tpl.Title, templateData);

                feed.BodyTemplate = tpl.Body;
                feed.BodyData     = PlatformTemplate.GetVarData(tpl.Body, templateData);
            }
            else
            {
                throw new NotImplementedException("TemplateBundle(id:" + templateBundleId + ")" + lang.get("exTemplateNotFound"));
            }

            db.insert(feed);
        }
Exemplo n.º 16
0
        //public Feed GetByIdWithComments( int id ) {
        //    Feed feed = GetById( id );
        //    List<FeedComment> comments = FeedComment.find( "RootId="+id + " order by Id" ).list();
        //    feed.setComments( comments );
        //    return feed;
        //}
        //----------------------------------------------- 开放方法 --------------------------------------------------------------------
        public virtual TemplateBundle registerTemplateBundle( List<OneLineStoryTemplate> oneLineStoryTemplates, List<ShortStoryTemplate> shortStoryTemplates, List<ActionLink> actionLinks )
        {
            TemplateBundle t = new TemplateBundle();
            t.OneLineStoryTemplatesStr = SimpleJsonString.ConvertList( oneLineStoryTemplates );
            t.ShortStoryTemplatesStr = SimpleJsonString.ConvertList( shortStoryTemplates );
            t.ActionLinksStr = SimpleJsonString.ConvertList( actionLinks );
            db.insert( t );

            return t;
        }
Exemplo n.º 17
0
        public void InitTemplateBundle()
        {
            // 1
            TemplateBundle tpl1 = new TemplateBundle();
            tpl1.OneLineStoryTemplatesStr = "[{ Title: \"{*actor*} 发表了新日志 {*blog*}\" }]";
            db.insert( tpl1 );

            // 2
            TemplateBundle tt = new TemplateBundle();
            tt.insert();
            tt.delete();

            // 3
            TemplateBundle tpl3 = new TemplateBundle();
            tpl3.ShortStoryTemplatesStr = "[{ Title: \"{*actor*} 上传了{*photoCount*}张 新照片。\", Body: \"{*photos*}\"  }]";
            db.insert( tpl3 );

            // 4
            tt.insert();
            tt.delete();

            // 5
            TemplateBundle tpl5 = new TemplateBundle();
            tpl5.OneLineStoryTemplatesStr = "[{ Title: \"{*actor*} 发表了论坛主题 {*topic*}\" }]";
            db.insert( tpl5 );

            // 6
            TemplateBundle tpl6 = new TemplateBundle();
            tpl6.OneLineStoryTemplatesStr = "[{ Title: \"{*actor*} 发表了论坛帖子 {*post*}\" }]";
            db.insert( tpl6 );

            // 7
            tt.insert();
            tt.delete();

            // 8
            tt.insert();
            tt.delete();

            TemplateBundle tpl9 = new TemplateBundle();
            tpl9.OneLineStoryTemplatesStr = "[{ Title: \"{*actor*} 和 {*friend*} 成为了好友\" }]";
            db.insert( tpl9 );
        }
Exemplo n.º 18
0
        public void Create()
        {
            int albumId          = ctx.PostInt("PhotoAlbumId");
            int systemCategoryId = ctx.PostInt("SystemCategoryId");

            if (albumId <= 0)
            {
                errors.Add(alang("exAlbumSelect"));
                run(NewPost, albumId);
                return;
            }

            if (systemCategoryId <= 0)
            {
                errors.Add(alang("exSysCategoryRequire"));
                run(NewPost, albumId);
                return;
            }

            if (ctx.GetFiles().Count <= 0)
            {
                errors.Add(alang("exUploadImg"));
                run(NewPost, albumId);
                return;
            }

            List <PhotoPost> imgs = new List <PhotoPost>();

            for (int i = 0; i < ctx.GetFiles().Count; i++)
            {
                HttpFile file = ctx.GetFiles()[i];

                if (file.ContentLength < 10)
                {
                    continue;
                }

                // 发生任何错误,则返回
                Result result = Uploader.SaveImg(file);
                if (result.HasErrors)
                {
                    echo(result.ErrorsHtml);
                    return;
                }

                PhotoPost post = newPost(ctx.Post("Text" + (i + 1)), result.Info.ToString(), albumId, systemCategoryId);
                PhotoApp  app  = ctx.app.obj as PhotoApp;
                postService.CreatePost(post, app);
                imgs.Add(post);
            }

            // 如果没有上传的图片
            if (imgs.Count == 0)
            {
                errors.Add(alang("exUploadImg"));
                run(NewPost, albumId);
                return;
            }

            // 统计
            User user = ctx.owner.obj as User;

            user.Pins = PhotoPost.count("OwnerId=" + user.Id);
            user.update("Pins");

            // feed消息
            int    photoCount = imgs.Count;
            String photoHtml  = "";

            foreach (PhotoPost post in imgs)
            {
                photoHtml += string.Format("<a href='{0}'><img src='{1}'/></a> ", alink.ToAppData(post), post.ImgThumbUrl);
            }

            String templateData = string.Format("photoCount: {0}, photos: \"{1}\" ", photoCount, photoHtml);

            templateData = "{" + templateData + "}";
            TemplateBundle tplBundle = TemplateBundle.GetPhotoTemplateBundle();

            feedService.publishUserAction((User)ctx.viewer.obj, typeof(PhotoPost).FullName, tplBundle.Id, templateData, "", ctx.Ip);

            echoRedirectPart(lang("opok"), to(new MyController().My), 1);
        }