Ejemplo n.º 1
0
        /// <summary>
        /// 应用初始化
        /// </summary>
        /// <param name="containerBuilder">容器构建器</param>
        public override void Initialize(ContainerBuilder containerBuilder)
        {
            //注册标识图设置
            TenantLogoSettings.RegisterSettings(tenantLogoSettingsElement);

            //注册ResourceAccessor的应用资源
            ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.Group.Resources.Resource", typeof(Spacebuilder.Group.Resources.Resource).Assembly);
            InvitationType.Register(new InvitationType {
                Key = InvitationTypeKeys.Instance().InviteJoinGroup(), Name = "邀请参加群组", Description = ""
            });
            InvitationType.Register(new InvitationType {
                Key = InvitationTypeKeys.Instance().ApplyJoinGroup(), Name = "申请加入群组", Description = ""
            });
            containerBuilder.Register(c => new GroupActivityReceiverGetter()).Named <IActivityReceiverGetter>(ActivityOwnerTypes.Instance().Group().ToString()).SingleInstance();
            //groupId与groupKey的查询器
            containerBuilder.Register(c => new DefaultGroupIdToGroupKeyDictionary()).As <GroupIdToGroupKeyDictionary>().SingleInstance();

            //注册全文检索搜索器
            containerBuilder.Register(c => new GroupSearcher("群组", "~/App_Data/IndexFiles/Group", true, 7)).As <ISearcher>().Named <ISearcher>(GroupSearcher.CODE).SingleInstance();

            ThemeService.RegisterThemeResolver(PresentAreaKeysOfBuiltIn.GroupSpace, new GroupSpaceThemeResolver());

            //群组推荐
            containerBuilder.Register(c => new GroupApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance();
            containerBuilder.Register(c => new GroupTenantAuthorizationHandler()).As <ITenantAuthorizationHandler>().SingleInstance();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 重建缩略图
        /// </summary>
        /// <returns></returns>
        public ActionResult RebuildingThumbnails()
        {
            IEnumerable <TenantAttachmentSettings> tenantAttachmentSettings = TenantAttachmentSettings.GetAll();

            ViewData["TenantAttachmentSettings"] = tenantAttachmentSettings;
            ViewData["TenantLogoSettings"]       = TenantLogoSettings.GetAll();

            IStoreProvider storeProvider = DIContainer.Resolve <IStoreProvider>();
            string         rootPath      = WebUtility.GetPhysicalFilePath("~");
            string         uploadsPath   = storeProvider.StoreRootPath;

            if (storeProvider.StoreRootPath.StartsWith(rootPath))
            {
                uploadsPath = uploadsPath.Replace(rootPath, "");
            }
            ViewData["uploadsPath"] = uploadsPath;
            Dictionary <string, string> ApplicationName = new Dictionary <string, string>();

            TenantTypeService        tenantTypeService = new TenantTypeService();
            IEnumerable <TenantType> tenantTypes       = tenantTypeService.Gets(null, null);

            foreach (var item in tenantTypes)
            {
                TenantType type = tenantTypeService.Get(item.TenantTypeId);
                ApplicationName[item.TenantTypeId] = type != null ? type.Name : item.Name;
            }

            ViewData["ApplicationName"] = ApplicationName;

            return(View());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="tenantTypeId">租户类型Id</param>
 public LogoService(string tenantTypeId)
 {
     this.TenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(tenantTypeId);
     if (this.TenantLogoSettings == null)
     {
         throw new ExceptionFacade("没有注册租户附件设置");
     }
     this.StoreProvider = DIContainer.ResolveNamed <IStoreProvider>(this.TenantLogoSettings.StoreProviderName);
 }
Ejemplo n.º 4
0
        public ActionResult Upgrading_Database_Ready()
        {
            SqlConnection sqlConnection = GetConnection();

            //注册应用中的Application.Config
            foreach (var applicationConfig in ApplicationConfigManager.Instance().GetAllApplicationConfigs())
            {
                if (applicationConfig.Element("tenantAttachmentSettings") != null)
                {
                    TenantAttachmentSettings.RegisterSettings(applicationConfig.Element("tenantAttachmentSettings"));
                }
                if (applicationConfig.Element("tenantLogoSettings") != null)
                {
                    TenantLogoSettings.RegisterSettings(applicationConfig.Element("tenantLogoSettings"));
                }
            }

            ConcurrentDictionary <string, string> messages = new ConcurrentDictionary <string, string>();

            //修改3.2版本的表名
            string reNameSqlFile = SetupHelper.GetUpgradeReNameFile();

            try
            {
                SetupHelper.ExecuteInFile(sqlConnection, reNameSqlFile, out messages);
            }
            catch (Exception e)
            {
                if (!messages.ContainsKey("在文件:" + reNameSqlFile + " 中产生异常"))
                {
                    messages["在文件:" + reNameSqlFile + " 中产生异常"] = e.Message + "\r\n";
                }
                else
                {
                    messages["在文件:" + reNameSqlFile + " 中产生异常"] += e.Message + "\r\n";
                }
            }

            foreach (var message in messages)
            {
                WriteLogFile(string.Format("{0}:{1}", message.Key, message.Value));
            }
            if (messages.Count > 0)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "升级数据库准备失败,请查看升级日志")));
            }
            else
            {
                return(Json(new StatusMessageData(StatusMessageType.Success, "升级数据库准备就绪。")));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 设置不同尺寸的Logo
        /// </summary>
        /// <param name="tenantTypeId"></param>
        /// <param name="fileName"></param>
        /// <param name="relativePath"></param>
        private void SetResizedLogo(string tenantTypeId, string fileName, string relativePath)
        {
            TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(tenantTypeId);

            if (tenantLogoSettings != null && tenantLogoSettings.ImageSizeTypes != null && tenantLogoSettings.ImageSizeTypes.Count > 0)
            {
                foreach (var imageSizeType in tenantLogoSettings.ImageSizeTypes.Values)
                {
                    string sizedFileName = storeProvider.GetSizeImageName(fileName, imageSizeType.Key, imageSizeType.Value);
                    storeProvider.DeleteFile(relativePath, sizedFileName);
                    IStoreFile file = storeProvider.GetResizedImage(relativePath, fileName, imageSizeType.Key, imageSizeType.Value);
                }
            }
        }
Ejemplo n.º 6
0
        public ActionResult _EditIdentificationType(IdentificationTypeEditModel editModel)
        {
            string fileName = string.Empty;
            Stream stream   = null;

            //获取上传图片
            HttpPostedFileBase logo = Request.Files["IdentificationTypeLogo"];

            //如果上传图片不为空则校验其扩展名和大小
            if (logo != null && logo.ContentLength > 0)
            {
                fileName = logo.FileName;

                //校验附件的扩展名
                ILogoSettingsManager logoSettingsManager = DIContainer.Resolve <ILogoSettingsManager>();
                LogoSettings         logoSettings        = logoSettingsManager.Get();
                if (!logoSettings.ValidateFileExtensions(fileName))
                {
                    return(Content(WarpJsonMessage(new StatusMessageData(StatusMessageType.Error, "只允许上传后缀名为 " + logoSettings.AllowedFileExtensions.TrimEnd(',') + " 的文件"))));
                }

                //校验附件的大小
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Identification());
                if (!tenantLogoSettings.ValidateFileLength(logo.ContentLength))
                {
                    return(Content(WarpJsonMessage(new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}KB", tenantLogoSettings.MaxLogoLength)))));
                }

                stream = logo.InputStream;
            }

            //如果IdentificationTypeId大于0则为编辑标识
            if (editModel.IdentificationTypeId > 0)
            {
                IdentificationType identificationType = editModel.AsIdentificationType();
                identificationService.UpdateIdentificationType(identificationType, stream);
            }
            //否则为创建标识
            else
            {
                if (logo == null || logo.ContentLength == 0)
                {
                    return(Content(WarpJsonMessage(new StatusMessageData(StatusMessageType.Error, "图片不能为空!"))));
                }
                IdentificationType identificationType = editModel.AsIdentificationType();
                identificationService.CreateIdentificationType(identificationType, stream);
            }
            return(Content(WarpJsonMessage(new StatusMessageData(StatusMessageType.Success, "操作成功!"))));
        }
Ejemplo n.º 7
0
        public ActionResult CreateRole(RoleEditModel model)
        {
            Stream             stream    = null;
            HttpPostedFileBase roleImage = Request.Files["RoleImage"];
            Role role = roleService.Get(model.RoleName);

            if (roleImage != null && !string.IsNullOrEmpty(roleImage.FileName))
            {
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Role());
                if (!tenantLogoSettings.ValidateFileLength(roleImage.ContentLength))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024)));
                    return(View(model));
                }

                LogoSettings logoSettings = DIContainer.Resolve <ILogoSettingsManager>().Get();
                if (!logoSettings.ValidateFileExtensions(roleImage.FileName))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions);
                    return(View(model));
                }

                stream          = roleImage.InputStream;
                model.RoleImage = roleImage.FileName;
            }
            else        //当取不到上传的图片文件名时RoleImage值保持不变
            {
                model.RoleImage = role != null ? role.RoleImage : string.Empty;
            }

            if (ModelState.IsValid)
            {
                if (role != null)
                {
                    WebUtility.SetStatusCodeForError(Response);
                    EditUserRole_GenerateFormItem();
                    model.RoleName = string.Empty;

                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "角色名已存在!");

                    return(View("_CreateRole", model));
                }

                role = model.AsRole();
                roleService.Create(role, stream);
            }

            return(RedirectToAction("ManageUsers"));
        }
Ejemplo n.º 8
0
        public ActionResult _ReBuildingLogs(string tenantTypeId)
        {
            TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(tenantTypeId);

            IStoreProvider storeProvider = DIContainer.Resolve <IStoreProvider>();

            if (tenantLogoSettings == null)
            {
                return(Content(string.Empty));
            }

            string path = WebUtility.GetPhysicalFilePath(Path.Combine(storeProvider.StoreRootPath, tenantLogoSettings.TenantLogoDirectory));

            ResetLogos(path, tenantLogoSettings);

            //重建缩略图的代码
            return(Redirect(SiteUrls.Instance().ControlPanelSuccess("执行成功", SiteUrls.Instance().RebuildingThumbnails())));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 应用初始化
        /// </summary>
        /// <param name="containerBuilder">容器构建器</param>
        public override void Initialize(ContainerBuilder containerBuilder)
        {
            //注册ResourceAccessor的应用资源
            ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.Bar.Resources.Resource", typeof(Spacebuilder.Bar.Resources.Resource).Assembly);

            //注册附件设置
            TenantAttachmentSettings.RegisterSettings(tenantAttachmentSettingsElement);
            //注册标识图设置
            TenantLogoSettings.RegisterSettings(tenantLogoSettingsElement);

            //注册帖吧正文解析器
            containerBuilder.Register(c => new BarBodyProcessor()).Named <IBodyProcessor>(TenantTypeIds.Instance().Bar()).SingleInstance();
            containerBuilder.Register(c => new BarSectionActivityReceiverGetter()).Named <IActivityReceiverGetter>(ActivityOwnerTypes.Instance().BarSection().ToString()).SingleInstance();
            containerBuilder.Register(c => new BarSearcher("帖吧", "~/App_Data/IndexFiles/Bar", true, 6)).As <ISearcher>().Named <ISearcher>(BarSearcher.CODE).SingleInstance();

            containerBuilder.Register(c => new BarApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance();

            containerBuilder.Register(c => new BarTenantAuthorizationHandler()).As <ITenantAuthorizationHandler>().SingleInstance();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 应用初始化
        /// </summary>
        /// <param name="containerBuilder">容器构建器</param>
        public override void Initialize(ContainerBuilder containerBuilder)
        {
            //注册ResourceAccessor的应用资源
            ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.Bar.Resources.Resource", typeof(Spacebuilder.Bar.Resources.Resource).Assembly);

            //注册附件设置
            TenantAttachmentSettings.RegisterSettings(tenantAttachmentSettingsElement);
            //注册标识图设置
            TenantLogoSettings.RegisterSettings(tenantLogoSettingsElement);

            //注册帖吧站点设置
            containerBuilder.Register(c => new BarSettingsManager()).As <IBarSettingsManager>().SingleInstance();
            //注册帖吧正文解析器
            containerBuilder.Register(c => new BarBodyProcessor()).Named <IBodyProcessor>(TenantTypeIds.Instance().Bar()).SingleInstance();
            containerBuilder.Register(c => new BarIndexEventModule()).As <IEventMoudle>().SingleInstance();
            containerBuilder.Register(c => new BarRatingEventModule()).As <IEventMoudle>().SingleInstance();
            containerBuilder.Register(c => new BarPostEventModule()).As <IEventMoudle>().SingleInstance();
            containerBuilder.Register(c => new BarThreadEventModule()).As <IEventMoudle>().SingleInstance();
            containerBuilder.Register(c => new BarSectionEventModule()).As <IEventMoudle>().SingleInstance();
            containerBuilder.Register(c => new BarSectionActivityReceiverGetter()).Named <IActivityReceiverGetter>(ActivityOwnerTypes.Instance().BarSection().ToString()).SingleInstance();
            containerBuilder.Register(c => new BarSearcher("帖吧", "~/App_Data/IndexFiles/Bar", true, 5)).As <ISearcher>().Named <ISearcher>(BarSearcher.CODE).SingleInstance();
            containerBuilder.Register(c => new BarOperationLogEventModule()).As <IEventMoudle>().SingleInstance();

            containerBuilder.Register(c => new BarApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance();

            containerBuilder.Register(c => new BarUrlGetter()).As <IBarUrlGetter>().SingleInstance();
            containerBuilder.Register(c => new GroupUrlGetter()).As <IBarUrlGetter>().SingleInstance();
            containerBuilder.Register(c => new BarCommentUrlGetter()).As <ICommentUrlGetter>().SingleInstance();
            containerBuilder.Register(c => new BarOwnerDataGetter()).As <IOwnerDataGetter>().SingleInstance();
            containerBuilder.Register(c => new BarPostOwnerDataGetter()).As <IOwnerDataGetter>().SingleInstance();

            containerBuilder.Register(c => new BarTenantAuthorizationHandler()).As <ITenantAuthorizationHandler>().SingleInstance();
            containerBuilder.Register(c => new BarThreadRecommendUrlGetter()).As <IRecommendUrlGetter>().SingleInstance();
            containerBuilder.Register(c => new BarSectionRecommendUrlGetter()).As <IRecommendUrlGetter>().SingleInstance();
            containerBuilder.Register(c => new BarThreadAtUserAssociatedUrlGetter()).As <IAtUserAssociatedUrlGetter>().SingleInstance();
            containerBuilder.Register(c => new BarPostAtUserAssociatedUrlGetter()).As <IAtUserAssociatedUrlGetter>().SingleInstance();
        }
Ejemplo n.º 11
0
        public ActionResult Create(GroupEditModel groupEditModel)
        {
            string errorMessage = null;

            if (ModelState.HasBannedWord(out errorMessage))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = errorMessage,
                    Title = "创建失败",
                    StatusMessageType = StatusMessageType.Error
                })));
            }

            System.IO.Stream   stream    = null;
            HttpPostedFileBase groupLogo = Request.Files["GroupLogo"];


            //已修改
            IUser user = UserContext.CurrentUser;

            if (user == null)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!")));
            }

            if (!new Authorizer().Group_Create(out errorMessage))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = errorMessage,
                    Title = errorMessage,
                    StatusMessageType = StatusMessageType.Error
                })));
            }
            if (groupLogo != null && !string.IsNullOrEmpty(groupLogo.FileName))
            {
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Group());
                if (!tenantLogoSettings.ValidateFileLength(groupLogo.ContentLength))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024)));
                    return(View(groupEditModel));
                }

                LogoSettings logoSettings = DIContainer.Resolve <ILogoSettingsManager>().Get();
                if (!logoSettings.ValidateFileExtensions(groupLogo.FileName))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions);
                    return(View(groupEditModel));
                }
                stream = groupLogo.InputStream;
                groupEditModel.Logo = groupLogo.FileName;
            }
            GroupEntity group = groupEditModel.AsGroupEntity();

            bool result = groupService.Create(user.UserId, group);

            if (stream != null)
            {
                groupService.UploadLogo(group.GroupId, stream);
            }
            //设置分类
            if (groupEditModel.CategoryId > 0)
            {
                categoryService.AddItemsToCategory(new List <long>()
                {
                    group.GroupId
                }, groupEditModel.CategoryId, 0);
            }
            //设置标签
            string relatedTags = Request.Form.Get <string>("RelatedTags");

            if (!string.IsNullOrEmpty(relatedTags))
            {
                tagService.AddTagsToItem(relatedTags, group.GroupId, group.GroupId);
            }
            //发送邀请
            if (!string.IsNullOrEmpty(groupEditModel.RelatedUserIds))
            {
                //已修改
                IEnumerable <long> userIds = Request.Form.Gets <long>("RelatedUserIds", null);
                groupService.SendInvitations(group, user, string.Empty, userIds);
            }
            return(Redirect(SiteUrls.Instance().GroupHome(group.GroupKey)));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 根据配置重置Logo
        /// </summary>
        /// <param name="path"></param>
        /// <param name="settings"></param>
        private void ResetLogos(string path, TenantLogoSettings settings)
        {
            if (!Directory.Exists(path))
            {
                return;
            }

            if (settings == null || settings.ImageSizeTypes == null || settings.ImageSizeTypes.Count == 0)
            {
                return;
            }

            IStoreProvider storeProvider = DIContainer.Resolve <IStoreProvider>();

            string[] files = Directory.GetFiles(path);

            List <string> originalList = new List <string>();
            List <string> fileList     = new List <string>();

            foreach (var file in files)
            {
                if (file.EndsWith(".db"))
                {
                    continue;
                }

                string fileName = GetUploadFileName(file);

                if (originalList.Contains(fileName))
                {
                    continue;
                }

                originalList.Add(fileName);

                foreach (var type in settings.ImageSizeTypes.Values)
                {
                    string name     = storeProvider.GetSizeImageName(GetFileNameWistOutPath(file), type.Key, type.Value);
                    string filePath = Path.Combine(path, name);
                    if (!fileList.Contains(filePath))
                    {
                        fileList.Add(filePath);
                    }
                    if (files.Contains(filePath))
                    {
                        continue;
                    }

                    try
                    {
                        storeProvider.GetResizedImage(path, GetUploadFileName(filePath), type.Key, type.Value);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            //删除无用数据
            foreach (var file in files)
            {
                string name = GetFileNameWistOutPath(file);
                if (!fileList.Contains(file) && GetUploadFileName(file) != name && GetOriginalFileName(file) != name)
                {
                    System.IO.File.Delete(file);
                }
            }

            string[] paths = Directory.GetDirectories(path);
            foreach (var item in paths)
            {
                ResetLogos(item, settings);
            }
        }
Ejemplo n.º 13
0
        public ActionResult EditSection(BarSectionEditModel model)
        {
            HttpPostedFileBase logoImage         = Request.Files["LogoImage"];
            string             logoImageFileName = string.Empty;
            Stream             stream            = null;

            if (logoImage != null && !string.IsNullOrEmpty(logoImage.FileName))
            {
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().BarSection());
                if (!tenantLogoSettings.ValidateFileLength(logoImage.ContentLength))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("Logo文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024)));
                    return(View(model));
                }

                LogoSettings logoSettings = DIContainer.Resolve <ISettingsManager <LogoSettings> >().Get();
                if (!logoSettings.ValidateFileExtensions(logoImage.FileName))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "Logo文件是不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions);
                    return(View(model));
                }
                stream            = logoImage.InputStream;
                logoImageFileName = logoImage.FileName;
            }


            IEnumerable <long> managerUserIds = Request.Form.Gets <long>("ManagerUserIds");

            if (model.SectionId == 0)
            {
                BarSection section = model.AsBarSection();

                //long userId = Request.QueryString.Gets<long>(model.UserId, new List<long>()).FirstOrDefault();


                section.UserId = Request.Form.Gets <long>("UserId", new List <long>()).FirstOrDefault();
                if (section.UserId == 0)
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "请输入吧主信息");
                    return(View(model));
                }
                section.LogoImage    = logoImageFileName;
                section.DisplayOrder = model.DisplayOrder ?? 100;
                if (managerUserIds != null && managerUserIds.Count() > 0)
                {
                    managerUserIds = managerUserIds.Where(n => n != section.UserId);
                }

                bool isCreated = barSectionService.Create(section, UserContext.CurrentUser.UserId, managerUserIds, stream);

                categoryService.AddItemsToCategory(new List <long> {
                    section.SectionId
                }, model.CategoryId);

                if (isCreated)
                {
                    TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "创建成功");
                    return(Redirect(SiteUrls.Instance().EditSection(section.SectionId)));
                }
                ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "创建失败");
                return(View(model));
            }
            else
            {
                BarSection section = model.AsBarSection();



                long userId = Request.Form.Gets <long>("UserId", new List <long>()).FirstOrDefault();
                if (userId == 0)
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "必须输入吧主信息");
                    ViewData["ManagerUserIds"]    = barSectionService.GetSectionManagers(section.SectionId).Select(n => n.UserId);
                    ISettingsManager <BarSettings> manager = DIContainer.Resolve <ISettingsManager <BarSettings> >();
                    BarSettings settings = manager.Get();
                    ViewData["SectionManagerMaxCount"] = settings.SectionManagerMaxCount;
                    return(View(model));
                }
                section.UserId = userId;
                if (!string.IsNullOrEmpty(logoImageFileName))
                {
                    section.LogoImage = logoImageFileName;
                }
                section.DisplayOrder = model.DisplayOrder ?? 100;
                barSectionService.Update(section, UserContext.CurrentUser.UserId, managerUserIds, stream);
                categoryService.ClearCategoriesFromItem(section.SectionId, 0, TenantTypeIds.Instance().BarSection());
                categoryService.AddItemsToCategory(new List <long> {
                    section.SectionId
                }, model.CategoryId);

                TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功");
                return(Redirect(SiteUrls.Instance().EditSection(model.SectionId)));
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 初始化程序安装步骤
        /// </summary>
        /// <returns></returns>
        void InitializeSetup()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.Register(c => new DefaultCacheService(new RuntimeMemoryCache(), 1.0F)).As <ICacheService>().SingleInstance();
            containerBuilder.RegisterAssemblyTypes(Assembly.Load("Spacebuilder.Common")).Where(t => t.Name.EndsWith("SettingsManager")).AsImplementedInterfaces().SingleInstance();
            containerBuilder.Register(c => new DefaultStoreProvider(@"~/Uploads")).As <IStoreProvider>().Named <IStoreProvider>("CommonStorageProvider").SingleInstance();
            //注册PageResourceManager
            bool pageResourceDebugEnabled = false;

            if (ConfigurationManager.AppSettings["PageResource:DebugEnabled"] != null)
            {
                if (!bool.TryParse(ConfigurationManager.AppSettings["PageResource:DebugEnabled"], out pageResourceDebugEnabled))
                {
                    pageResourceDebugEnabled = false;
                }
            }

            //注册标题图的配置
            TenantLogoSettings.RegisterSettings(LogoConfigManager.Instance().GetAllLogoConfigs());

            string resourceSite = null;

            if (ConfigurationManager.AppSettings["PageResource:Site"] != null)
            {
                resourceSite = ConfigurationManager.AppSettings["PageResource:Site"];
            }
            //用户业务逻辑
            containerBuilder.Register(c => new UserService()).As <IUserService>().SingleInstance();
            containerBuilder.Register(c => new PageResourceManager("Spacebuilder v4.3正式版")
            {
                ResourceSite = resourceSite
            }).As <IPageResourceManager>().InstancePerHttpRequest();
            IContainer container = containerBuilder.Build();

            //将Autofac容器中的实例注册到mvc自带DI容器中(这样才获取到每请求缓存的实例)
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            DIContainer.RegisterContainer(container);

            //注册皮肤选择器
            Type themeResolverType = Type.GetType("Spacebuilder.Setup.SetupThemeResolver,Spacebuilder.Setup");
            ConstructorInvoker themeResolverConstructor = themeResolverType.DelegateForCreateInstance();
            IThemeResolver     themeResolver            = themeResolverConstructor() as IThemeResolver;

            ThemeService.RegisterThemeResolver("Channel", themeResolver);

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new ThemedViewEngine());

            string extensionForOldIIS = ".aspx";
            int    iisVersion         = 0;

            if (!int.TryParse(System.Configuration.ConfigurationManager.AppSettings["IISVersion"], out iisVersion))
            {
                iisVersion = 7;
            }
            if (iisVersion >= 7)
            {
                extensionForOldIIS = string.Empty;
            }

            RouteTable.Routes.MapRoute(
                "Channel_Home", // Route name
                string.IsNullOrEmpty(extensionForOldIIS) ? "" : "Home" + extensionForOldIIS,
                new { controller = "Install", action = "Start", area = "Setup" }
                );

            RouteTable.Routes.MapRoute(
                "Install_Home",  // Route name
                string.IsNullOrEmpty(extensionForOldIIS) ? "Install" : "Install" + extensionForOldIIS,
                new { controller = "Install", action = "Start", area = "Setup" }
                );

            RouteTable.Routes.MapRoute(
                "Install_Common",
                "Install/{action}" + extensionForOldIIS,
                new { controller = "Install", action = "Start", area = "Setup" });

            RouteTable.Routes.MapRoute(
                "Upgrade_Home",  // Route name
                "Upgrade" + extensionForOldIIS,
                new { controller = "Upgrade", action = "Ready", area = "Setup" }
                );

            RouteTable.Routes.MapRoute(
                "Upgrade_Common",
                "Upgrade/{action}" + extensionForOldIIS,
                new { controller = "Upgrade", action = "Ready", area = "Setup" });
        }
        public ActionResult EditTopic(TagEditModel tagEditModel)
        {
            System.IO.Stream stream = null;

            //是否创建
            bool isCreate = tagEditModel.TagId == 0;

            if (isCreate)
            {
                ViewData["editTopicTitle"] = "创建话题";
            }
            else
            {
                ViewData["editTopicTitle"] = "编辑话题";
            }

            TagService         tagService = new TagService(tagEditModel.TenantTypeId);
            IEnumerable <long> userIds    = Request.Form.Gets <long>("RelatedObjectIds");

            //是特色标签
            if (tagEditModel.IsFeatured)
            {
                HttpPostedFileBase tagLogo  = Request.Files["tagLogo"];
                string             fileName = tagLogo == null ? "" : tagLogo.FileName;
                if (string.IsNullOrEmpty(fileName) && string.IsNullOrEmpty(tagEditModel.FeaturedImage))
                {
                    //标签分组下拉框
                    SelectList topicGroups = GetTagGroupSelectList(tagEditModel.TopicGroupId, tagEditModel.TenantTypeId);
                    ViewData["topicGroups"] = topicGroups;

                    //取到用户设置的相关标签
                    ViewData["seletedUserIds"] = userIds;

                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "图片不能为空");

                    return(View(tagEditModel));
                }
                else if (!string.IsNullOrEmpty(fileName))
                {
                    //校验附件的扩展名
                    ILogoSettingsManager logoSettingsManager = DIContainer.Resolve <ILogoSettingsManager>();
                    if (!logoSettingsManager.Get().ValidateFileExtensions(fileName))
                    {
                        //标签分组下拉框
                        SelectList topicGroups = GetTagGroupSelectList(tagEditModel.TopicGroupId, tagEditModel.TenantTypeId);
                        ViewData["topicGroups"] = topicGroups;

                        //取到用户设置的相关标签
                        ViewData["seletedUserIds"] = userIds;

                        ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "只允许上传后缀名为 .gif .jpg .jpeg .png 的文件");

                        return(View(tagEditModel));
                    }

                    //校验附件的大小
                    TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Tag());
                    if (!tenantLogoSettings.ValidateFileLength(tagLogo.ContentLength))
                    {
                        //标签分组下拉框
                        SelectList topicGroups = GetTagGroupSelectList(tagEditModel.TopicGroupId, tagEditModel.TenantTypeId);
                        ViewData["topicGroups"] = topicGroups;

                        //取到用户设置的相关标签
                        ViewData["seletedUserIds"] = userIds;

                        ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}KB", tenantLogoSettings.MaxLogoLength));

                        return(View(tagEditModel));
                    }

                    stream = tagLogo.InputStream;
                    tagEditModel.FeaturedImage = fileName;
                }
            }

            //获取相关微博
            IEnumerable <long> seletedUserIds = userIds;

            //创建
            if (isCreate)
            {
                Tag tag = tagEditModel.AsTag();
                tagService.Create(tag, stream);

                //添加到分组
                if (tagEditModel.TopicGroupId > 0)
                {
                    tagService.BatchAddGroupsToTag(new List <long>()
                    {
                        tagEditModel.TopicGroupId
                    }, tagEditModel.TagName);
                }
            }//更新
            else
            {
                Tag tag = tagEditModel.AsTag();
                tagService.Update(tag, stream);

                //添加到分组
                if (tagEditModel.TopicGroupId > 0)
                {
                    tagService.BatchAddGroupsToTag(new List <long>()
                    {
                        tagEditModel.TopicGroupId
                    }, tagEditModel.TagName);
                }
            }

            return(RedirectToAction("ManageMicroblogTopics"));
        }
Ejemplo n.º 16
0
        public ActionResult EditTag(TagEditModel tagEditModel)
        {
            System.IO.Stream stream = null;

            //是否创建
            bool isCreate = tagEditModel.TagId == 0;

            if (isCreate)
            {
                ViewData["editTagTitle"] = "创建标签";
            }
            else
            {
                ViewData["editTagTitle"] = "编辑标签";
            }

            TagService tagService = new TagService(tagEditModel.TenantTypeId);

            //是特色标签
            if (tagEditModel.IsFeatured)
            {
                HttpPostedFileBase tagLogo  = Request.Files["tagLogo"];
                string             fileName = tagLogo == null ? "" : tagLogo.FileName;
                if (string.IsNullOrEmpty(fileName) && string.IsNullOrEmpty(tagEditModel.FeaturedImage))
                {
                    //所属租户类型下拉框
                    SelectList tenants = GetTenantSelectList(MultiTenantServiceKeys.Instance().Tag(), tagEditModel.TenantTypeId);
                    ViewData["tenants"] = tenants;

                    //标签分组下拉框
                    SelectList tagGroups = GetTagGroupSelectList(tagEditModel.GroupId, tagEditModel.TenantTypeId);
                    ViewData["tagGroups"] = tagGroups;

                    //取到用户设置的相关标签
                    ViewData["seletedTagNames"] = tagEditModel.RelatedTags[1].Split(',').ToList <string>();

                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "图片不能为空");

                    return(View(tagEditModel));
                }
                else if (!string.IsNullOrEmpty(fileName))
                {
                    //校验附件的扩展名
                    ILogoSettingsManager logoSettingsManager = DIContainer.Resolve <ILogoSettingsManager>();
                    if (!logoSettingsManager.Get().ValidateFileExtensions(fileName))
                    {
                        //所属租户类型下拉框
                        SelectList tenants = GetTenantSelectList(MultiTenantServiceKeys.Instance().Tag(), tagEditModel.TenantTypeId);
                        ViewData["tenants"] = tenants;

                        //标签分组下拉框
                        SelectList tagGroups = GetTagGroupSelectList(tagEditModel.GroupId, tagEditModel.TenantTypeId);
                        ViewData["tagGroups"] = tagGroups;

                        //取到用户设置的相关标签
                        ViewData["seletedTagNames"] = tagEditModel.RelatedTags[1].Split(',').ToList <string>();

                        ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "只允许上传后缀名为 .gif .jpg .jpeg .png 的文件");

                        return(View(tagEditModel));
                    }

                    //校验附件的大小
                    TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Tag());
                    if (!tenantLogoSettings.ValidateFileLength(tagLogo.ContentLength))
                    {
                        //所属租户类型下拉框
                        SelectList tenants = GetTenantSelectList(MultiTenantServiceKeys.Instance().Tag(), tagEditModel.TenantTypeId);
                        ViewData["tenants"] = tenants;

                        //标签分组下拉框
                        SelectList tagGroups = GetTagGroupSelectList(tagEditModel.GroupId, tagEditModel.TenantTypeId);
                        ViewData["tagGroups"] = tagGroups;

                        //取到用户设置的相关标签
                        ViewData["seletedTagNames"] = tagEditModel.RelatedTags[1].Split(',').ToList <string>();

                        ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}KB", tenantLogoSettings.MaxLogoLength));

                        return(View(tagEditModel));
                    }

                    stream = tagLogo.InputStream;
                    tagEditModel.FeaturedImage = fileName;
                }
            }

            //获取相关标签
            string relatedTags = tagEditModel.RelatedTags[1];

            //创建
            if (isCreate)
            {
                Tag tag = tagEditModel.AsTag();
                tagService.Create(tag, stream);

                //添加到分组
                if (tagEditModel.GroupId > 0)
                {
                    tagService.BatchAddGroupsToTag(new List <long>()
                    {
                        tagEditModel.GroupId
                    }, tagEditModel.TagName);
                }

                //创建相关标签
                if (!string.IsNullOrEmpty(relatedTags))
                {
                    tagService.AddRelatedTagsToTag(relatedTags, 0, tag.TagId);
                }
            }//更新
            else
            {
                Tag tag = tagEditModel.AsTag();
                tagService.Update(tag, stream);

                //添加到分组
                if (tagEditModel.GroupId > 0)
                {
                    tagService.BatchAddGroupsToTag(new List <long>()
                    {
                        tagEditModel.GroupId
                    }, tagEditModel.TagName);
                }

                //创建相关标签
                if (!string.IsNullOrEmpty(relatedTags))
                {
                    tagService.ClearRelatedTagsFromTag(tagEditModel.TagId);
                    tagService.AddRelatedTagsToTag(relatedTags, 0, tagEditModel.TagId);
                }
            }

            return(RedirectToAction("ManageTags"));
        }
        public ActionResult _EditTag(TagEditModel tagEditModel)
        {
            System.IO.Stream stream = null;

            //是否创建
            bool isCreate = tagEditModel.TagId == 0;

            if (isCreate)
            {
                ViewData["editTagTitle"] = "创建标签";
            }
            else
            {
                ViewData["editTagTitle"] = "编辑标签";
            }

            TagService tagService = new TagService(tagEditModel.TenantTypeId);

            //是特色标签
            if (tagEditModel.IsFeatured)
            {
                HttpPostedFileBase tagLogo  = Request.Files["tagLogo"];
                string             fileName = tagLogo == null ? "" : tagLogo.FileName;
                if (string.IsNullOrEmpty(fileName) && string.IsNullOrEmpty(tagEditModel.FeaturedImage))
                {
                    return(Content(System.Web.Helpers.Json.Encode(new StatusMessageData(StatusMessageType.Error, "请选择上传的图片!"))));
                }
                else if (!string.IsNullOrEmpty(fileName))
                {
                    //校验附件的扩展名
                    ISettingsManager <LogoSettings> logoSettingsManager = DIContainer.Resolve <ISettingsManager <LogoSettings> >();
                    if (!logoSettingsManager.Get().ValidateFileExtensions(fileName))
                    {
                        return(Content(System.Web.Helpers.Json.Encode(new StatusMessageData(StatusMessageType.Error, "只允许上传后缀名为 .gif .jpg .jpeg .png 的文件!"))));
                    }

                    //校验附件的大小
                    TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Tag());
                    if (!tenantLogoSettings.ValidateFileLength(tagLogo.ContentLength))
                    {
                        return(Content(System.Web.Helpers.Json.Encode(new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}KB", tenantLogoSettings.MaxLogoLength)))));
                    }

                    stream = tagLogo.InputStream;
                    tagEditModel.FeaturedImage = fileName;
                }
            }

            //获取相关标签
            string relatedTags = tagEditModel.RelatedTags[1];

            //创建
            if (isCreate)
            {
                Tag tag = tagEditModel.AsTag();
                tagService.Create(tag, stream);

                //添加到分组
                if (tagEditModel.GroupId > 0)
                {
                    tagService.BatchAddGroupsToTag(new List <long>()
                    {
                        tagEditModel.GroupId
                    }, tagEditModel.TagName);
                }

                //创建相关标签
                if (!string.IsNullOrEmpty(relatedTags))
                {
                    tagService.AddRelatedTagsToTag(relatedTags, 0, tag.TagId);
                }
            }//更新
            else
            {
                Tag tag = tagEditModel.AsTag();
                tagService.Update(tag, stream);

                //添加到分组
                if (tagEditModel.GroupId > 0)
                {
                    tagService.BatchAddGroupsToTag(new List <long>()
                    {
                        tagEditModel.GroupId
                    }, tagEditModel.TagName);
                }

                //创建相关标签
                if (!string.IsNullOrEmpty(relatedTags))
                {
                    tagService.ClearRelatedTagsFromTag(tagEditModel.TagId);
                    tagService.AddRelatedTagsToTag(relatedTags, 0, tagEditModel.TagId);
                }
            }
            return(Content(System.Web.Helpers.Json.Encode(new StatusMessageData(StatusMessageType.Success, "操作成功!"))));
        }
Ejemplo n.º 18
0
        public ActionResult EditGroup(string spaceKey, GroupEditModel groupEditModel)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!")));
            }
            System.IO.Stream   stream    = null;
            HttpPostedFileBase groupLogo = Request.Files["GroupLogo"];

            if (groupLogo != null && !string.IsNullOrEmpty(groupLogo.FileName))
            {
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Group());
                if (!tenantLogoSettings.ValidateFileLength(groupLogo.ContentLength))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024)));
                    return(View(groupEditModel));
                }

                LogoSettings logoSettings = DIContainer.Resolve <ILogoSettingsManager>().Get();
                if (!logoSettings.ValidateFileExtensions(groupLogo.FileName))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions);
                    return(View(groupEditModel));
                }
                stream = groupLogo.InputStream;
                groupEditModel.Logo = groupLogo.FileName;
            }

            GroupEntity group = groupEditModel.AsGroupEntity();


            //设置分类
            if (groupEditModel.CategoryId > 0)
            {
                categoryService.ClearCategoriesFromItem(group.GroupId, 0, TenantTypeIds.Instance().Group());
                categoryService.AddItemsToCategory(new List <long>()
                {
                    group.GroupId
                }, groupEditModel.CategoryId, 0);
            }


            //已修改
            //设置标签
            string relatedTags = Request.Form.Get <string>("RelatedTags");

            if (!string.IsNullOrEmpty(relatedTags))
            {
                tagService.ClearTagsFromItem(group.GroupId, group.GroupId);
                tagService.AddTagsToItem(relatedTags, group.GroupId, group.GroupId);
            }
            if (stream != null)
            {
                groupService.UploadLogo(group.GroupId, stream);
            }

            groupService.Update(currentUser.UserId, group);
            TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功!");
            return(Redirect(SiteUrls.Instance().EditGroup(group.GroupKey)));
        }