Ejemplo n.º 1
0
        private int Validate_PublishmentSystemInfo(out string errorMessage)
        {
            try
            {
                var isHq = TranslateUtils.ToBool(IsHeadquarters.SelectedValue); // 是否主站
                var parentPublishmentSystemId = 0;
                var publishmentSystemDir      = string.Empty;

                if (isHq == false)
                {
                    if (DirectoryUtils.IsSystemDirectory(PublishmentSystemDir.Text))
                    {
                        errorMessage = "文件夹名称不能为系统文件夹名称!";
                        return(0);
                    }

                    parentPublishmentSystemId = TranslateUtils.ToInt(ParentPublishmentSystemID.SelectedValue);
                    publishmentSystemDir      = PublishmentSystemDir.Text;

                    var list = DataProvider.NodeDao.GetLowerSystemDirList(parentPublishmentSystemId);
                    if (list.IndexOf(publishmentSystemDir.ToLower()) != -1)
                    {
                        errorMessage = "已存在相同的发布路径!";
                        return(0);
                    }

                    if (!DirectoryUtils.IsDirectoryNameCompliant(publishmentSystemDir))
                    {
                        errorMessage = "文件夹名称不符合系统要求!";
                        return(0);
                    }
                }

                var nodeInfo = new NodeInfo();

                nodeInfo.NodeName       = nodeInfo.NodeIndexName = "首页";
                nodeInfo.NodeType       = ENodeType.BackgroundPublishNode;
                nodeInfo.ContentModelId = EContentModelTypeUtils.GetValue(EContentModelTypeUtils.GetEnumTypeByPublishmentSystemType(_publishmentSystemType));

                var publishmentSystemUrl = PageUtils.Combine(WebConfigUtils.ApplicationPath, publishmentSystemDir);

                var psInfo = BaseTable.GetDefaultPublishmentSystemInfo(PageUtils.FilterXss(PublishmentSystemName.Text), _publishmentSystemType, AuxiliaryTableForContent.SelectedValue, AuxiliaryTableForGovPublic.SelectedValue, AuxiliaryTableForGovInteract.SelectedValue, AuxiliaryTableForVote.SelectedValue, AuxiliaryTableForJob.SelectedValue, publishmentSystemDir, publishmentSystemUrl, parentPublishmentSystemId);

                if (psInfo.ParentPublishmentSystemId > 0)
                {
                    var parentPublishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(psInfo.ParentPublishmentSystemId);
                    psInfo.PublishmentSystemUrl = PageUtils.Combine(parentPublishmentSystemInfo.PublishmentSystemUrl, psInfo.PublishmentSystemDir);
                }

                psInfo.IsHeadquarters = isHq;

                psInfo.Additional.Charset     = Charset.SelectedValue;
                psInfo.IsCheckContentUseLevel = TranslateUtils.ToBool(IsCheckContentUseLevel.SelectedValue);
                if (psInfo.IsCheckContentUseLevel)
                {
                    psInfo.CheckContentLevel = TranslateUtils.ToInt(CheckContentLevel.SelectedValue);
                }

                var thePublishmentSystemId = DataProvider.NodeDao.InsertPublishmentSystemInfo(nodeInfo, psInfo, Body.AdministratorName);

                if (_permissions.IsSystemAdministrator && !_permissions.IsConsoleAdministrator)
                {
                    var publishmentSystemIdList = ProductPermissionsManager.Current.PublishmentSystemIdList ?? new List <int>();
                    publishmentSystemIdList.Add(thePublishmentSystemId);
                    BaiRongDataProvider.AdministratorDao.UpdatePublishmentSystemIdCollection(Body.AdministratorName, TranslateUtils.ObjectCollectionToString(publishmentSystemIdList));
                }

                Body.AddAdminLog($"新建{EPublishmentSystemTypeUtils.GetText(_publishmentSystemType)}站点", $"站点名称:{PageUtils.FilterXss(PublishmentSystemName.Text)}");

                //if (isHQ == EBoolean.False)
                //{
                //    string configFilePath = PathUtility.MapPath(psInfo, "@/web.config");
                //    if (FileUtils.IsFileExists(configFilePath))
                //    {
                //        FileUtility.UpdateWebConfig(configFilePath, psInfo.Additional.Charset);
                //    }
                //    else
                //    {
                //        FileUtility.CreateWebConfig(configFilePath, psInfo.Additional.Charset);
                //    }
                //}
                errorMessage = string.Empty;
                return(thePublishmentSystemId);
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
                return(0);
            }
        }