private void addFeedInfo(Follower f) { String msg = MbTemplate.GetFeed("¹Ø×¢ÁË", f.Target.Name, Link.ToMember(f.Target), "", f.Target.PicSX); IMicroblogService microblogService = ObjectContext.Create <IMicroblogService>(typeof(MicroblogService)); microblogService.AddSimplePrivate(f.User, msg, typeof(Follower).FullName, f.Target.Id, f.Ip); }
private static int importDirect(SpiderArticle art, SpiderImport item, ContentSection section, ContentApp app) { ContentPostService postService = ObjectContext.Create <ContentPostService>(); ContentPost post = new ContentPost(); post.Title = art.Title; post.Content = art.Body; if (art.IsPic == 1) { post.CategoryId = PostCategory.Img; post.ImgLink = art.PicUrl; } post.SourceLink = art.Url; post.Creator = item.Creator; post.CreatorUrl = item.Creator.Url; post.PageSection = section; post.OwnerId = app.OwnerId; post.OwnerType = app.OwnerType; post.OwnerUrl = app.OwnerUrl; post.AppId = app.Id; postService.Insert(post, ""); return(post.Id); }
// 保存图片大小等信息 private void updatePhotoSize(PhotoPost post) { String photoPath = post.DataUrl; Dictionary <String, PhotoInfo> dic = new Dictionary <String, PhotoInfo>(); foreach (KeyValuePair <String, ThumbInfo> kv in ThumbConfig.GetPhotoConfig()) { String xpath = Img.GetThumbPath(strUtil.Join(sys.Path.DiskPhoto, photoPath), kv.Key); String thumbPath = PathHelper.Map(xpath); if (file.Exists(thumbPath) == false) { continue; } Size size = Img.GetPhotoSize(thumbPath); dic.Add(kv.Key, new PhotoInfo { Width = size.Width, Height = size.Height }); } String str = ObjectContext.Create <PhotoInfoHelper>().ConvertString(dic); if (strUtil.IsNullOrEmpty(str)) { return; } post.SizeInfo = str; post.update(); log("重新统计成功=" + post.Id + ",path=" + photoPath); }
/// <summary> /// 安装某个app /// </summary> /// <param name="appType">必须事先IApp的类型,比如ForumApp</param> /// <param name="owner"></param> /// <param name="creator"></param> /// <param name="appName">app名称</param> /// <returns></returns> public virtual IMemberApp Install(Type appType, IMember owner, User creator, String appName) { IApp objApp = ObjectContext.Create <IApp>(appType); objApp.OwnerId = owner.Id; objApp.OwnerType = owner.GetType().FullName; objApp.OwnerUrl = owner.Url; db.insert(objApp); AppInstaller info = GetByType(appType); IMemberApp mApp = ObjectContext.Create <IMemberApp>(getMemberAppType(owner)); mApp.Creator = creator; mApp.CreatorUrl = creator.Url; mApp.AppInfoId = info.Id; mApp.AppOid = objApp.Id; mApp.Name = appName; if (mApp.GetType().IsSubclassOf(typeof(CacheObject))) { cdb.insert((CacheObject)mApp); } else { db.insert(mApp); } return(mApp); }
/// <summary> /// 获取聚合区块对应的 BinderController。加载模板的时候,检查是否已经自定义了模板。 /// </summary> /// <param name="section"></param> /// <param name="ctx"></param> /// <returns></returns> public static ISectionBinder GetBinder(ContentSection section, MvcContext ctx) { IContentSectionTemplateService TplService = ObjectContext.Create <IContentSectionTemplateService>(typeof(ContentSectionTemplateService)); ContentSectionTemplate template = TplService.GetById(section.TemplateId); String binderName = string.Format("wojilu.Web.Controller.Content.Binder.{0}BinderController", template.TemplateName); ControllerBase controller = ControllerFactory.FindController(binderName, ctx) as ControllerBase; if (controller == null) { throw new Exception("ISectionBinder not found:" + binderName); } String customTemplateStr = getCustomTemplateBody(section, ctx); // 自定义模板 if (strUtil.HasText(customTemplateStr)) { controller.viewContent(customTemplateStr); return(controller as ISectionBinder); } else { Template currentView = controller.utils.getTemplateByFileName(BinderUtils.GetBinderTemplatePath(template)); controller.utils.setCurrentView(currentView); return(controller as ISectionBinder); } }
private void importPrivate(long startId, long endId) { IList clist = ndb.find(commentType, "Id>=" + startId + " and Id<=" + endId + " order by Id asc").list(); logger.Info("old comment count=" + clist.Count); foreach (IComment x in clist) { // 如果已经导入,那么就删除已有的OpenComment OpenComment oc = hasImport(x); if (oc != null) { deleteOpenComment(oc); deleteTransLog(oc); } OpenComment comment = getOpenComment(x); OpenCommentService service = ObjectContext.Create <OpenCommentService>(); service.Import(comment); logTransInfo(x, comment); } }
private void runJobSingle(HtmlJobItem x) { try { Object p = ObjectContext.Create(x.Name); if (strUtil.HasText(x.Ids)) { rft.CallMethod(p, x.Method, new object[] { x.Ids }); cdb.delete(x); } else if (x.PostId > 0) { rft.CallMethod(p, x.Method, new object[] { x.PostId }); cdb.delete(x); } else { logger.Info("param is invalid. type=" + x.Name + ", method=" + x.Method); } } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); } }
public void setFirstUser() { SiteInitHelper initHelper = ObjectContext.Create <SiteInitHelper>(); if (initHelper.HasInit() == false) { initHelper.InitSite(); } String name = ctx.Post("name"); String email = ctx.Post("email"); String pwd = ctx.Post("pwd"); String pageUrl = ctx.Post("url"); User user = new User(); user.Name = name; user.Pwd = pwd; user.Email = email; user.Url = strUtil.IsNullOrEmpty(pageUrl) ? "admin" : pageUrl; user = userService.Register(user, ctx); if (ctx.HasErrors) { echoText(errors.ErrorsText); } else { RegHelper.CheckUserSpace(user, ctx); loginService.Login(user, LoginTime.Forever, ctx.Ip, ctx); echoAjaxOk(); } }
/// <summary> /// 从ObjectContext中创建非单例controller,并初始化(注入ctx和controller所属的appType) /// </summary> /// <param name="controllerType"></param> /// <param name="ctx"></param> /// <returns></returns> public static ControllerBase FindController(Type controllerType, MvcContext ctx) { if (controllerType == null) { return(null); } ControllerBase controller = null; try { controller = ObjectContext.Create(controllerType) as ControllerBase; } catch (Exception ex) { throw new Exception("创建控制器失败,controller=" + controllerType.FullName, ex); } if (controller == null) { return(null); } ObjectContext.InterceptProperty(controller); controller.setContext(ctx); setControllerAppInfo(controllerType, controller); return(controller); }
public void testObserveMethodObserver() { TObservedTarget obj = ObjectContext.Create <TObservedTarget>(); obj.count = 8; int count = obj.Save(2); Assert.AreEqual(13, count); }
public void setUserAndApp() { try { // 1)初始化网站基本信息 SiteInitHelper initHelper = ObjectContext.Create <SiteInitHelper>(); if (initHelper.HasInit() == false) { initHelper.InitSite(); } // 2)创建用户 String name = ctx.Post("name"); String email = ctx.Post("email"); String pwd = ctx.Post("pwd"); String pageUrl = ctx.Post("url"); User user = new User(); user.Name = name; user.Pwd = pwd; user.Email = email; user.Url = strUtil.IsNullOrEmpty(pageUrl) ? "admin" : pageUrl; user = userService.Register(user, ctx); if (ctx.HasErrors) { echoText(errors.ErrorsText); return; } RegHelper.CheckUserSpace(user, ctx); loginService.Login(user, LoginTime.Forever, ctx.Ip, ctx); // 3)初始化owner/viewer initOwner(ctx); initViewer(ctx, user); // 4) 网站名称 String siteName = ctx.Post("siteName"); updateSiteName(siteName); // 5)安装app int siteType = ctx.PostInt("siteType"); initSiteApp(siteType, user); echoAjaxOk(); } catch (Exception ex) { logger.Fatal("安装出错。错误信息如下:" + Environment.NewLine + "Message=" + ex.Message + Environment.NewLine + "Source=" + ex.Source + Environment.NewLine + "StackTrace=" + Environment.NewLine + ex.StackTrace + Environment.NewLine ); echoText("安装出错,请检查/framework/log/下日志"); } }
private IMemberApp createContentApp(MvcContext ctx, String appName, String appUrl, String themeId) { IMember owner = ctx.owner.obj; NewsInstaller x = ObjectContext.Create <NewsInstaller>(); IMemberApp mapp = x.Install(ctx, owner, appName, wojilu.Common.AppBase.AccessStatus.Public, themeId, appUrl); // 初始化权限,否则无法访问 base.initAppPermission(mapp); return(mapp); }
private PhotoInfo getSizeDic(string key) { if (_sizeInfo == null) { _sizeInfo = ObjectContext.Create <PhotoInfoHelper>().GetInfo(this.SizeInfo); } PhotoInfo ret; _sizeInfo.TryGetValue(key, out ret); return(ret); }
private static void addFrinedFeedInfo(User user, User friend, long id, String ip) { String userLink = Link.ToMember(friend); String lnkInfo = string.Format("<a href=\"{0}\">{1}</a>", userLink, friend.Name); String actionName = string.Format("和 {0} 成为朋友", lnkInfo); String msg = MbTemplate.GetFeed(actionName, null, userLink, null, friend.PicSX); IMicroblogService microblogService = ObjectContext.Create <IMicroblogService>(typeof(MicroblogService)); microblogService.AddSimplePrivate(user, msg, typeof(FriendShip).FullName, id, ip); }
public void setUserAndApp() { // 1)初始化网站基本信息 SiteInitHelper initHelper = ObjectContext.Create <SiteInitHelper>(); if (initHelper.HasInit() == false) { initHelper.InitSite(); } // 2)创建用户 String name = ctx.Post("name"); String email = ctx.Post("email"); String pwd = ctx.Post("pwd"); String pageUrl = ctx.Post("url"); User user = new User(); user.Name = name; user.Pwd = pwd; user.Email = email; user.Url = strUtil.IsNullOrEmpty(pageUrl) ? "admin" : pageUrl; user = userService.Register(user, ctx); if (ctx.HasErrors) { echoText(errors.ErrorsText); return; } RegHelper.CheckUserSpace(user, ctx); loginService.Login(user, LoginTime.Forever, ctx.Ip, ctx); // 3)初始化owner/viewer initOwner(ctx); initViewer(ctx, user); // 4) 网站名称 String siteName = ctx.Post("siteName"); updateSiteName(siteName); // 5)安装app int siteType = ctx.PostInt("siteType"); initSiteApp(siteType, user); echoAjaxOk(); }
public void testOverloadMethod() { //NewAopService x = AopContext.CreateProxyBySub<NewAopService>(); NewAopService x = ObjectContext.Create <NewAopService>(); Boolean isSubClass = x.GetType().IsSubclassOf(typeof(NewAopService)); Assert.IsTrue(isSubClass); x.count = 8; Assert.AreEqual(8, x.Save()); // 没有参数,所以结果没有被修改 Assert.AreEqual(8 + 6 / 2, x.Save(6)); // 参数被拦截,并除以2 Assert.AreEqual("11zhangsan", x.Save(6, "zhangsan")); // 参数被拦截,并除以2 }
private Type getMemberAppType(IMember owner) { foreach (KeyValuePair <String, Type> kv in ObjectContext.Instance.TypeList) { if (rft.IsInterface(kv.Value, typeof(IMemberApp))) { IMemberApp obj = ObjectContext.Create <IMemberApp>(kv.Value); if (obj.OwnerType == owner.GetType().FullName) { return(kv.Value); } } } return(null); }
private static string getCustomTemplateBody(ContentSection section, MvcContext ctx) { if (section.CustomTemplateId <= 0) { return(null); } IContentCustomTemplateService ctService = ObjectContext.Create <IContentCustomTemplateService>(typeof(ContentCustomTemplateService)); ContentCustomTemplate ct = ctService.GetById(section.CustomTemplateId, ctx.owner.Id); if (ct == null) { return(null); } return(ct.Content); }
public CodeController() { codeService = ObjectContext.Create <CodeService>(); List <String> rootNs = MvcConfig.Instance.RootNamespace; foreach (String ns in rootNs) { String topLayoutStr = strUtil.Join(ns, "LayoutController", "."); Type topLayoutType = null; ObjectContext.Instance.TypeList.TryGetValue(topLayoutStr, out topLayoutType); if (topLayoutType != null) { HideLayout(topLayoutType); } } }
private void createFullSite() { // 完整安装 CmsInstaller x1 = ObjectContext.Create <CmsInstaller>(); LinkInstaller x2 = ObjectContext.Create <LinkInstaller>(); // 门户首页 IMemberApp mappPortal = x1.CreatePortal(ctx, "首页", "default"); // 新闻 IMemberApp mappNews = x1.CreateNews(ctx, "新闻资讯", "news"); // 论坛 ObjectContext.Create <ForumInstaller>().Init(ctx, "讨论区", "bbs"); // 微博 ObjectContext.Create <MicroblogInstaller>().Init(ctx, "微博", "t"); // 瀑布流 ObjectContext.Create <WaterfallInstaller>().Init(ctx, "图片", "pic"); // 下载 ObjectContext.Create <DownloadInstaller>().Init(ctx, "资源下载", "download"); // 博客 x2.AddBlog(ctx, "博客", "blog"); // 群组 x2.AddGroup(ctx, "群组", "group"); // 用户 x2.AddUser(ctx, "用户列表", "user"); // tag x2.AddTag(ctx, "Tag", "tags"); // 设置安装完毕 config.Instance.Site.IsInstall = true; config.Instance.Site.Update("IsInstall", true); // 生成静态页面 HtmlInstallerHelper htmlHelper = ObjectContext.Create <HtmlInstallerHelper>(); htmlHelper.MakeHtml(ctx, mappPortal, mappNews); }
public override void After(object returnValue, MethodInfo method, object[] args, object target) { Microblog blog = args[0] as Microblog; if (blog == null || blog.ParentId > 0) { return; } if (blog.User == null || blog.User.Id <= 0) { return; } if (QQWeiboJobHelper.IsQQWeiboSync(blog.Id)) { return; // 是否已经同步过 } UserConnect uc = ObjectContext.Create <UserConnectService>() .GetConnectInfo(blog.User.Id, typeof(QQWeiboConnect).FullName); // 1. 检查:用户是否绑定,是否允许同步 if (uc == null) { return; // 绑定 } if (uc.NoSync == 1) { logger.Info("取消同步,因为用户明确禁止"); return; } // 2. 获取 access token AccessToken x = new AccessToken(); x.Token = uc.AccessToken; x.Uid = uc.Uid; // 3. 同步 QQWeiboConnect connect = AuthConnectFactory.GetConnect(typeof(QQWeiboConnect).FullName) as QQWeiboConnect; connect.Publish(x, _blogContent, getPicDiskPath(blog.Pic)); // 设置已经同步标记 QQWeiboJobHelper.AddQQWeiboSyncItem(blog.Id); }
public void testSizeInfo() { Dictionary <String, PhotoInfo> dic = new Dictionary <String, PhotoInfo>(); dic.Add("s", new PhotoInfo { Width = 68, Height = 68 }); dic.Add("sx", new PhotoInfo { Width = 80, Height = 120 }); dic.Add("m", new PhotoInfo { Width = 180, Height = 500 }); String str = ObjectContext.Create <PhotoInfoHelper>().ConvertString(dic); Assert.AreEqual("s=68/68,sx=80/120,m=180/500", str); }
private static AuthConnect initConnect(Type t, AuthConnectConfig x) { AuthConnect obj = ObjectContext.Create(t) as AuthConnect; if (strUtil.IsNullOrEmpty(x.ConsumerKey)) { throw new Exception(String.Format("请设置 Consumer Key: {0}", x.Name)); } if (strUtil.IsNullOrEmpty(x.ConsumerSecret)) { throw new Exception(String.Format("请设置 Consumer Secret: {0}", x.Name)); } obj.ConsumerKey = x.ConsumerKey; obj.ConsumerSecret = x.ConsumerSecret; return(obj); }
public virtual ITheme GetThemeById(AppInstaller installer, String id) { if (strUtil.IsNullOrEmpty(installer.ThemeType)) { return(null); } Type themeType = ObjectContext.GetType(installer.ThemeType); if (themeType == null) { return(null); } ITheme obj = ObjectContext.Create <ITheme>(themeType); return(obj.GetById(id)); }
private static Dictionary <String, IInitHelper> getInitList() { Dictionary <String, IInitHelper> map = new Dictionary <String, IInitHelper>(); foreach (KeyValuePair <String, Type> kv in ObjectContext.Instance.TypeList) { if (rft.IsInterface(kv.Value, typeof(IInitHelper)) == false) { continue; } IInitHelper obj = ObjectContext.Create(kv.Value) as IInitHelper; map.Add(obj.GetMemberType().Name.ToLower(), obj); } return(map); }
private void addComment(object[] args, object target) { ForumPost post = args[0] as ForumPost; ForumTopic topic = ForumTopic.findById(post.TopicId); User creator = args[1] as User; IMember owner = args[2] as IMember; IApp app = args[3] as IApp; OpenComment c = new OpenComment(); c.Content = strUtil.ParseHtml(post.Content); c.TargetUrl = alink.ToAppData(topic); c.TargetDataType = typeof(ForumTopic).FullName; c.TargetDataId = topic.Id; c.TargetTitle = topic.Title; c.TargetUserId = topic.Creator.Id; c.OwnerId = owner.Id; c.AppId = app.Id; c.FeedId = getFeedId(topic); c.Ip = post.Ip; c.Author = creator.Name; c.ParentId = 0; c.AtId = 0; c.Member = creator; Result result = commentService.CreateNoNotification(c); // 修复comment额外的replies更新 IForumTopicService topicService = ObjectContext.Create <IForumTopicService>(typeof(ForumTopicService)); topic.Replies = topicService.CountReply(post.TopicId); topic.update("Replies"); // 同步表 CommentSync x = new CommentSync(); x.Post = post; x.Comment = result.Info as OpenComment; x.insert(); }
public void testRead() { // s=68/68,sx=80/120,m=180/500 String str = "s=68/68,sx=80/120,m=180/500"; Dictionary <String, PhotoInfo> dic = ObjectContext.Create <PhotoInfoHelper>().GetInfo(str); Assert.AreEqual(dic.Count, 3); Assert.AreEqual(68, dic["s"].Width); Assert.AreEqual(68, dic["s"].Height); Assert.AreEqual(80, dic["sx"].Width); Assert.AreEqual(120, dic["sx"].Height); Assert.AreEqual(180, dic["m"].Width); Assert.AreEqual(500, dic["m"].Height); }
private void createCmsSite() { CmsInstaller x1 = ObjectContext.Create <CmsInstaller>(); LinkInstaller x2 = ObjectContext.Create <LinkInstaller>(); // 门户首页 IMemberApp mappPortal = x1.CreatePortal(ctx, "首页", "default"); // 新闻 IMemberApp mappNews = x1.CreateNews(ctx, "新闻资讯", "news"); // 设置安装完毕 updateSiteDone(); // 生成静态页面 HtmlInstallerHelper htmlHelper = ObjectContext.Create <HtmlInstallerHelper>(); htmlHelper.MakeHtml(ctx, mappPortal, mappNews); }
public virtual List <ITheme> GetThemeList(AppInstaller installer) { List <ITheme> list = new List <ITheme>(); if (strUtil.IsNullOrEmpty(installer.ThemeType)) { return(list); } Type themeType = ObjectContext.GetType(installer.ThemeType); if (themeType == null) { return(list); } ITheme obj = ObjectContext.Create <ITheme>(themeType); return(obj.GetAll()); }
// 保存图片大小等信息 private void updatePhotoSize(PhotoPost post) { String photoPath = post.DataUrl; if (strUtil.IsNullOrEmpty(photoPath)) { return; } if (photoPath.ToLower().StartsWith("http://")) { return; } if (photoPath.StartsWith("/")) { return; } Dictionary <String, PhotoInfo> dic = new Dictionary <String, PhotoInfo>(); foreach (KeyValuePair <String, ThumbInfo> kv in ThumbConfig.GetPhotoConfig()) { String xpath = Img.GetThumbPath(strUtil.Join(sys.Path.DiskPhoto, photoPath), kv.Key); String thumbPath = PathHelper.Map(xpath); Size size = Img.GetPhotoSize(thumbPath); dic.Add(kv.Key, new PhotoInfo { Width = size.Width, Height = size.Height }); } String str = ObjectContext.Create <PhotoInfoHelper>().ConvertString(dic); if (strUtil.IsNullOrEmpty(str)) { return; } post.SizeInfo = str; post.update(); }