Ejemplo n.º 1
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);
        }