Esempio n. 1
0
        public void LastModTimeShouldReturnLastModDateOfFileInDirOrSubDir()
        {
            Touch("j.txt", new DateTime(2010, 5, 6));
            Touch(@"test\j.txt", new DateTime(2010, 5, 20));

            var directoryUtils = new DirectoryUtils();
            Assert.That(directoryUtils.GetLastModTimeForDirectory(Dir), Is.EqualTo(new DateTime(2010, 5, 20)));
        }
Esempio n. 2
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            PageUtils.CheckRequestParameter("siteId");

            _exportObject = new ExportObject(SiteId, AuthRequest.AdminName);

            if (IsPostBack)
            {
                return;
            }

            VerifyAdministratorPermissions(ConfigManager.SettingsPermissions.Site);

            if (SiteInfo.IsRoot)
            {
                TbSiteTemplateDir.Text = "T_" + SiteInfo.SiteName;
            }
            else
            {
                TbSiteTemplateDir.Text = "T_" + SiteInfo.SiteDir.Replace("\\", "_");
            }
            TbSiteTemplateName.Text = SiteInfo.SiteName;

            EBooleanUtils.AddListItems(RblIsSaveAllFiles, "全部文件", "指定文件");
            ControlUtils.SelectSingleItemIgnoreCase(RblIsSaveAllFiles, true.ToString());

            var siteDirList = DataProvider.SiteDao.GetLowerSiteDirListThatNotIsRoot();
            var fileSystems = FileManager.GetFileSystemInfoExtendCollection(PathUtility.GetSitePath(SiteInfo), true);

            foreach (FileSystemInfoExtend fileSystem in fileSystems)
            {
                if (!fileSystem.IsDirectory)
                {
                    continue;
                }

                var isSiteDirectory = false;
                if (SiteInfo.IsRoot)
                {
                    foreach (var siteDir in siteDirList)
                    {
                        if (StringUtils.EqualsIgnoreCase(siteDir, fileSystem.Name))
                        {
                            isSiteDirectory = true;
                        }
                    }
                }
                if (!isSiteDirectory && !DirectoryUtils.IsSystemDirectory(fileSystem.Name))
                {
                    CblDirectoriesAndFiles.Items.Add(new ListItem(fileSystem.Name, fileSystem.Name.ToLower()));
                }
            }
            foreach (FileSystemInfoExtend fileSystem in fileSystems)
            {
                if (fileSystem.IsDirectory || StringUtils.EqualsIgnoreCase(fileSystem.Name, "web.config"))
                {
                    continue;
                }
                if (!PathUtility.IsSystemFile(fileSystem.Name))
                {
                    CblDirectoriesAndFiles.Items.Add(new ListItem(fileSystem.Name, fileSystem.Name.ToLower()));
                }
            }

            EBooleanUtils.AddListItems(RblIsSaveContents, "保存内容数据", "不保存内容数据");
            ControlUtils.SelectSingleItemIgnoreCase(RblIsSaveContents, true.ToString());

            EBooleanUtils.AddListItems(RblIsSaveAllChannels, "全部栏目", "指定栏目");
            ControlUtils.SelectSingleItemIgnoreCase(RblIsSaveAllChannels, true.ToString());

            LtlChannelTree.Text = GetChannelTreeHtml();
        }
Esempio n. 3
0
        public int GetSiteTemplateCount()
        {
            var directorys = DirectoryUtils.GetDirectoryPaths(_rootPath);

            return(directorys.Length);
        }
Esempio n. 4
0
 private SiteTemplateManager(string rootPath)
 {
     _rootPath = rootPath;
     DirectoryUtils.CreateDirectoryIfNotExists(_rootPath);
 }
Esempio n. 5
0
        static void DrawContentConfig()
        {
            ScopeChange.Begin();

            //PB.i.enableAssetBundleBuild = HEditorGUILayout.ToggleLeft( S._EnableAssetBundleBuild, PB.i.enableAssetBundleBuild );
            //HEditorGUI.DrawDebugRectAtLastRect();
            PB.i.enableOldStyleProjectSettings = HEditorGUILayout.ToggleLeft(S._Usingtheold_styleProjectSettings, PB.i.enableOldStyleProjectSettings);
            GUILayout.Space(8);
            PB.i.enableExlusionAssets = HEditorGUILayout.ToggleLeft(S._Enablingassetexclusionatbuildtime, PB.i.enableExlusionAssets);

            GUILayout.Label(S._ExclusionAssetsList, EditorStyles.boldLabel);

            if (s_exclusionContents == null)
            {
                if (PB.i.exclusionAssets == null)
                {
                    PB.i.exclusionAssets = new List <PB.ExclusionSets>();
                }

                //foreach(var p in PB.i.exclusionAssets ) {
                //	Debug.Log( GUIDUtils.GetAssetPath( p.GUID ) );
                //}
                s_exclusionContents = PB.i.exclusionAssets.Select(x => x.GUID.ToAssetPath()).OrderBy(value => value).Select(x => new GUIContent(x, AssetDatabase.GetCachedIcon(x))).ToArray();
            }

            int removeIndex = -1;

            ScopeVertical.Begin(EditorStyles.helpBox);
            for (int i = 0; i < s_exclusionContents.Length; i++)
            {
                var s = s_exclusionContents[i];
                ScopeHorizontal.Begin();
                GUILayout.Label(EditorHelper.TempContent(""), GUILayout.ExpandWidth(true), GUILayout.Height(18));
                ScopeHorizontal.End();

                var rc = GUILayoutUtility.GetLastRect();
                GUI.Box(rc, "", Styles.projectBrowserHeaderBgMiddle);
                GUI.Label(rc, s, Styles.labelAndIcon);
                rc.x     = rc.xMax - 16;
                rc.width = 16;
                if (HEditorGUI.IconButton(rc, EditorIcon.minus))
                {
                    removeIndex = i;
                }
            }
            GUILayout.FlexibleSpace();
            if (0 <= removeIndex)
            {
                var findGUID = s_exclusionContents[removeIndex].text.ToGUID();
                var rIndex   = PB.i.exclusionAssets.FindIndex(x => x.GUID == findGUID);
                PB.i.exclusionAssets.RemoveAt(rIndex);
                s_exclusionContents = null;
                s_changed           = true;
            }
            ScopeVertical.End();

            var dropRc = GUILayoutUtility.GetLastRect();
            var evt    = Event.current;

            switch (evt.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
                if (!dropRc.Contains(evt.mousePosition))
                {
                    break;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                void AddFiles(params string[] paths)
                {
                    PB.i.exclusionAssets.AddRange(paths.Select(x => new PB.ExclusionSets(x.ToGUID(), x)).ToArray());
                    PB.i.exclusionAssets = PB.i.exclusionAssets.Distinct(x => x.GUID).ToList();
                    PB.Save();
                }

                string[] DirFiles(string path)
                {
                    return(DirectoryUtils.GetFiles(path, "*", SearchOption.AllDirectories).Where(x => x.Extension() != ".meta").ToArray());
                }

                if (evt.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();
                    if (DragAndDrop.paths.Length == 1)
                    {
                        if (Directory.Exists(DragAndDrop.paths[0]))
                        {
                            var m = new GenericMenu();
                            m.AddItem(S._Registerasafolder, false, (context) => {
                                AddFiles((string)context);
                            }, DragAndDrop.paths[0]);
                            m.AddItem(S._Registeringfilescontainedinafolder, false, (context) => {
                                AddFiles(DirFiles((string)context));
                                ;
                            }, DragAndDrop.paths[0]);
                            m.DropDownAtMousePosition();
                        }
                        else
                        {
                            AddFiles(DragAndDrop.paths);
                        }
                    }
                    else
                    {
                        bool dirChekc = false;
                        foreach (var s in DragAndDrop.paths)
                        {
                            if (Directory.Exists(s))
                            {
                                dirChekc = true;
                                break;
                            }
                        }
                        if (dirChekc)
                        {
                            var m = new GenericMenu();
                            m.AddItem(S._Registerasafolder, false, (context) => {
                                AddFiles((string[])context);
                            }, DragAndDrop.paths);
                            m.AddItem(S._Registeringfilescontainedinafolder, false, (context) => {
                                foreach (var s in ((string[])context))
                                {
                                    if (Directory.Exists(s))
                                    {
                                        AddFiles(DirFiles(s));
                                    }
                                    else
                                    {
                                        AddFiles(s);
                                    }
                                }
                            }, DragAndDrop.paths);
                            m.DropDownAtMousePosition();
                        }
                        else
                        {
                            AddFiles(DragAndDrop.paths);
                        }
                    }

                    DragAndDrop.activeControlID = 0;

                    s_exclusionContents = null;
                }
                s_changed = true;
                Event.current.Use();
                break;
            }

            if (ScopeChange.End())
            {
                s_changed = true;
            }
        }
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            var isSuccess = false;

            try
            {
                var channelInfo = ChannelManager.GetChannelInfo(SiteId, _channelId);

                var filePath = channelInfo.FilePath;

                if (PhFilePath.Visible)
                {
                    TbFilePath.Text = TbFilePath.Text.Trim();
                    if (!string.IsNullOrEmpty(TbFilePath.Text) && !StringUtils.EqualsIgnoreCase(filePath, TbFilePath.Text))
                    {
                        if (!DirectoryUtils.IsDirectoryNameCompliant(TbFilePath.Text))
                        {
                            FailMessage("栏目页面路径不符合系统要求!");
                            return;
                        }

                        if (PathUtils.IsDirectoryPath(TbFilePath.Text))
                        {
                            TbFilePath.Text = PageUtils.Combine(TbFilePath.Text, "index.html");
                        }

                        var filePathArrayList = DataProvider.ChannelDao.GetAllFilePathBySiteId(SiteId);
                        filePathArrayList.AddRange(DataProvider.TemplateMatchDao.GetAllFilePathBySiteId(SiteId));
                        if (filePathArrayList.IndexOf(TbFilePath.Text) != -1)
                        {
                            FailMessage("栏目修改失败,栏目页面路径已存在!");
                            return;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(TbChannelFilePathRule.Text))
                {
                    var filePathRule = TbChannelFilePathRule.Text.Replace("|", string.Empty);
                    if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule))
                    {
                        FailMessage("栏目页面命名规则不符合系统要求!");
                        return;
                    }
                    if (PathUtils.IsDirectoryPath(filePathRule))
                    {
                        FailMessage("栏目页面命名规则必须包含生成文件的后缀!");
                        return;
                    }
                }

                if (!string.IsNullOrEmpty(TbContentFilePathRule.Text))
                {
                    var filePathRule = TbContentFilePathRule.Text.Replace("|", string.Empty);
                    if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule))
                    {
                        FailMessage("内容页面命名规则不符合系统要求!");
                        return;
                    }
                    if (PathUtils.IsDirectoryPath(filePathRule))
                    {
                        FailMessage("内容页面命名规则必须包含生成文件的后缀!");
                        return;
                    }
                }

                if (TbFilePath.Text != PageUtility.GetInputChannelUrl(SiteInfo, channelInfo, false))
                {
                    channelInfo.FilePath = TbFilePath.Text;
                }
                if (TbChannelFilePathRule.Text != PathUtility.GetChannelFilePathRule(SiteInfo, _channelId))
                {
                    channelInfo.ChannelFilePathRule = TbChannelFilePathRule.Text;
                }
                if (TbContentFilePathRule.Text != PathUtility.GetContentFilePathRule(SiteInfo, _channelId))
                {
                    channelInfo.ContentFilePathRule = TbContentFilePathRule.Text;
                }

                DataProvider.ChannelDao.Update(channelInfo);

                CreateManager.CreateChannel(SiteId, _channelId);

                AuthRequest.AddSiteLog(SiteId, _channelId, 0, "设置页面命名规则", $"栏目:{channelInfo.ChannelName}");

                isSuccess = true;
            }
            catch (Exception ex)
            {
                FailMessage(ex, ex.Message);
            }

            if (isSuccess)
            {
                LayerUtils.CloseAndRedirect(Page, PageConfigurationCreateRule.GetRedirectUrl(SiteId, _channelId));
            }
        }
Esempio n. 7
0
        public static async Task UsePluginsAsync(this IApplicationBuilder app, ISettingsManager settingsManager,
                                                 IPluginManager pluginManager, IErrorLogRepository errorLogRepository)
        {
            var logger = app.ApplicationServices.GetService <ILoggerFactory>()
                         .CreateLogger <IApplicationBuilder>();

            foreach (var plugin in pluginManager.Plugins)
            {
                if (plugin.Disabled)
                {
                    continue;
                }

                logger.LogInformation("Using Plugin '{0}'", plugin.PluginId);

                DirectoryUtils.CreateDirectoryIfNotExists(plugin.WebRootPath);

                var fileProvider = new PhysicalFileProvider(plugin.WebRootPath);
                app.UseStaticFiles(
                    new StaticFileOptions
                {
                    FileProvider = fileProvider
                });
            }

            var configures = pluginManager.GetExtensions <IPluginConfigure>();

            if (configures != null)
            {
                foreach (var configure in configures)
                {
                    configure.Configure(app);
                }
            }

            var database = settingsManager.Database;

            var tables = settingsManager.GetTables();

            foreach (var table in tables.Where(table => !string.IsNullOrEmpty(table.Id)))
            {
                List <TableColumn> columns;
                if (StringUtils.EqualsIgnoreCase(table.Type, Types.TableTypes.Custom))
                {
                    columns = table.Columns;
                }
                else if (StringUtils.EqualsIgnoreCase(table.Type, Types.TableTypes.Content))
                {
                    columns = database.GetTableColumns(null);
                    columns.AddRange(database.GetTableColumns <Content>());
                    if (table.Columns != null)
                    {
                        foreach (var tableColumn in table.Columns.Where(tableColumn =>
                                                                        !columns.Any(x => StringUtils.EqualsIgnoreCase(x.AttributeName, tableColumn.AttributeName))))
                        {
                            columns.Add(tableColumn);
                        }
                    }
                }
                else
                {
                    columns = database.GetTableColumns(table.Columns);
                }

                if (columns == null || columns.Count == 0)
                {
                    continue;
                }

                try
                {
                    logger.LogInformation("Sync Plugin Table '{0}'", table.Id);
                    if (!await database.IsTableExistsAsync(table.Id))
                    {
                        await database.CreateTableAsync(table.Id, columns);
                    }
                    else
                    {
                        await database.AlterTableAsync(table.Id, columns);
                    }
                }
                catch
                {
                    // ignored
                }
            }
        }
Esempio n. 8
0
        public string GetSolutionFolder()
        {
            var relativePath = Path.GetDirectoryName(SolutionFilePath);

            return(DirectoryUtils.SafeGetFullPath(relativePath));
        }
Esempio n. 9
0
        private void CreateMshc(BuildContext context)
        {
            string workingDir = _helpDirectory;

            // 1. Delete any empty folder in the source directory...
            string mediaDir = Path.Combine(_helpSource, "media");

            if (Directory.Exists(mediaDir))
            {
                if (DirectoryUtils.IsDirectoryEmpty(mediaDir))
                {
                    Directory.Delete(mediaDir);
                }
            }
            string imageDir = Path.Combine(_helpSource, "images");

            if (Directory.Exists(imageDir))
            {
                if (DirectoryUtils.IsDirectoryEmpty(imageDir))
                {
                    Directory.Delete(imageDir);
                }
            }
            string mathDir = Path.Combine(_helpSource, "maths");

            if (Directory.Exists(mathDir))
            {
                if (DirectoryUtils.IsDirectoryEmpty(mathDir))
                {
                    Directory.Delete(mathDir);
                }
            }

            string metadataFile = Path.Combine(workingDir, "metadata.xml");

            using (ZipFile zipMshc = new ZipFile())
            {
                BeginMetadata(metadataFile, _helpName);

                zipMshc.UseZip64WhenSaving = Zip64Option.AsNecessary;

                zipMshc.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;

                zipMshc.AddProgress += new EventHandler <AddProgressEventArgs>(OnZipAddProgress);

                zipMshc.AddDirectory(_helpSource, null);

                //zipMshc.AddProgress -= new EventHandler<AddProgressEventArgs>(OnZipAddProgress);

                EndMetadata();

                string outputMetaFile = Path.Combine(_helpSource, "metadata.xml");
                if (File.Exists(outputMetaFile))
                {
                    File.Delete(outputMetaFile);
                }
                File.Move(metadataFile, outputMetaFile);

                zipMshc.AddFile(outputMetaFile, "");

                zipMshc.SaveProgress += new EventHandler <SaveProgressEventArgs>(OnZipSaveProgress);
                zipMshc.Save(Path.Combine(_helpOutputDir, _helpName + ".mshc"));
            }
        }
Esempio n. 10
0
        public async Task <string> ExportChannelsAsync(List <int> channelIdList, string filePath)
        {
            var siteContentDirectoryPath = PathUtils.Combine(DirectoryUtils.GetDirectoryPath(filePath), PathUtils.GetFileNameWithoutExtension(filePath));

            DirectoryUtils.DeleteDirectoryIfExists(siteContentDirectoryPath);
            DirectoryUtils.CreateDirectoryIfNotExists(siteContentDirectoryPath);

            var allChannelIdList = new List <int>();

            foreach (var channelId in channelIdList)
            {
                if (!allChannelIdList.Contains(channelId))
                {
                    allChannelIdList.Add(channelId);
                    var nodeInfo = await _databaseManager.ChannelRepository.GetAsync(channelId);

                    var childChannelIdList = await _databaseManager.ChannelRepository.GetChannelIdsAsync(nodeInfo.SiteId, nodeInfo.Id, ScopeType.Descendant);

                    allChannelIdList.AddRange(childChannelIdList);
                }
            }

            var sitePath = await _pathManager.GetSitePathAsync(_site);

            var siteIe = new SiteIe(_pathManager, _databaseManager, _caching, _site, siteContentDirectoryPath);

            foreach (var channelId in allChannelIdList)
            {
                await siteIe.ExportAsync(_site, channelId, true);
            }

            var imageUploadDirectoryPath = PathUtils.Combine(siteContentDirectoryPath, _site.ImageUploadDirectoryName);

            DirectoryUtils.DeleteDirectoryIfExists(imageUploadDirectoryPath);
            DirectoryUtils.Copy(PathUtils.Combine(sitePath, _site.ImageUploadDirectoryName), imageUploadDirectoryPath);

            var videoUploadDirectoryPath = PathUtils.Combine(siteContentDirectoryPath, _site.VideoUploadDirectoryName);

            DirectoryUtils.DeleteDirectoryIfExists(videoUploadDirectoryPath);
            DirectoryUtils.Copy(PathUtils.Combine(sitePath, _site.VideoUploadDirectoryName), videoUploadDirectoryPath);

            var fileUploadDirectoryPath = PathUtils.Combine(siteContentDirectoryPath, _site.FileUploadDirectoryName);

            DirectoryUtils.DeleteDirectoryIfExists(fileUploadDirectoryPath);
            DirectoryUtils.Copy(PathUtils.Combine(sitePath, _site.FileUploadDirectoryName), fileUploadDirectoryPath);

            AtomFeed feed  = AtomUtility.GetEmptyFeed();
            var      entry = AtomUtility.GetEmptyEntry();

            AtomUtility.AddDcElement(entry.AdditionalElements, "ImageUploadDirectoryName", _site.ImageUploadDirectoryName);
            AtomUtility.AddDcElement(entry.AdditionalElements, "VideoUploadDirectoryName", _site.VideoUploadDirectoryName);
            AtomUtility.AddDcElement(entry.AdditionalElements, "FileUploadDirectoryName", _site.FileUploadDirectoryName);

            feed.Entries.Add(entry);
            var uploadFolderPath = PathUtils.Combine(siteContentDirectoryPath, BackupUtility.UploadFolderName);

            DirectoryUtils.CreateDirectoryIfNotExists(uploadFolderPath);
            var uploadFilePath = PathUtils.Combine(uploadFolderPath, BackupUtility.UploadFileName);

            feed.Save(uploadFilePath);

            _pathManager.CreateZip(filePath, siteContentDirectoryPath);

            DirectoryUtils.DeleteDirectoryIfExists(siteContentDirectoryPath);

            return(PathUtils.GetFileName(filePath));
        }
Esempio n. 11
0
        public async Task ExportFilesToSiteAsync(string siteTemplatePath, bool isAllFiles, IList <string> directories, IList <string> files, bool isCreateMetadataDirectory)
        {
            DirectoryUtils.CreateDirectoryIfNotExists(siteTemplatePath);

            var siteDirList = await _databaseManager.SiteRepository.GetSiteDirsAsync(0);

            var sitePath = await _pathManager.GetSitePathAsync(_site);

            var directoryNames = DirectoryUtils.GetDirectoryNames(sitePath);
            var fileNames      = DirectoryUtils.GetFileNames(sitePath);

            foreach (var directoryName in directoryNames)
            {
                var srcPath  = PathUtils.Combine(sitePath, directoryName);
                var destPath = PathUtils.Combine(siteTemplatePath, directoryName);

                if (!isAllFiles && !ListUtils.ContainsIgnoreCase(directories, directoryName))
                {
                    continue;
                }

                var isSiteDirectory = false;

                if (_site.Root)
                {
                    foreach (var siteDir in siteDirList)
                    {
                        if (StringUtils.EqualsIgnoreCase(siteDir, directoryName))
                        {
                            isSiteDirectory = true;
                        }
                    }
                }
                if (!isSiteDirectory && !_pathManager.IsSystemDirectory(directoryName))
                {
                    DirectoryUtils.CreateDirectoryIfNotExists(destPath);
                    DirectoryUtils.MoveDirectory(srcPath, destPath, false);
                }
            }

            foreach (var fileName in fileNames)
            {
                var srcPath  = PathUtils.Combine(sitePath, fileName);
                var destPath = PathUtils.Combine(siteTemplatePath, fileName);

                if (!isAllFiles && !ListUtils.ContainsIgnoreCase(files, fileName))
                {
                    continue;
                }

                FileUtils.CopyFile(srcPath, destPath);
            }

            //var fileSystems = FileUtility.GetFileSystemInfoExtendCollection(await _pathManager.GetSitePathAsync(_site));
            //foreach (FileSystemInfoExtend fileSystem in fileSystems)
            //{
            //    var srcPath = PathUtils.Combine(sitePath, fileSystem.Name);
            //    var destPath = PathUtils.Combine(siteTemplatePath, fileSystem.Name);

            //    if (fileSystem.IsDirectory)
            //    {
            //        if (!isAllFiles && !StringUtils.ContainsIgnoreCase(directories, fileSystem.Name)) continue;

            //        var isSiteDirectory = false;

            //        if (_site.Root)
            //        {
            //            foreach (var siteDir in siteDirList)
            //            {
            //                if (StringUtils.EqualsIgnoreCase(siteDir, fileSystem.Name))
            //                {
            //                    isSiteDirectory = true;
            //                }
            //            }
            //        }
            //        if (!isSiteDirectory && !_pathManager.IsSystemDirectory(fileSystem.Name))
            //        {
            //            DirectoryUtils.CreateDirectoryIfNotExists(destPath);
            //            DirectoryUtils.MoveDirectory(srcPath, destPath, false);
            //        }
            //    }
            //    else
            //    {
            //        if (!isAllFiles && !StringUtils.ContainsIgnoreCase(files, fileSystem.Name)) continue;

            //        FileUtils.CopyFile(srcPath, destPath);
            //    }
            //}

            if (isCreateMetadataDirectory)
            {
                var siteTemplateMetadataPath = _pathManager.GetSiteTemplateMetadataPath(siteTemplatePath, string.Empty);
                DirectoryUtils.CreateDirectoryIfNotExists(siteTemplateMetadataPath);
            }
        }
Esempio n. 12
0
        public IHttpActionResult Update(int siteId, int channelId)
        {
            try
            {
                var request = new AuthenticatedRequest();
                var isAuth  = request.IsApiAuthenticated &&
                              AccessTokenManager.IsScope(request.ApiToken, AccessTokenManager.ScopeChannels) ||
                              request.IsAdminLoggin &&
                              request.AdminPermissions.HasChannelPermissions(siteId, channelId,
                                                                             ConfigManager.ChannelPermissions.ChannelEdit);
                if (!isAuth)
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                channelInfo.Additional.Load(request.GetPostObject <Dictionary <string, object> >());

                if (request.IsPostExists(ChannelAttribute.ChannelName))
                {
                    channelInfo.ChannelName = request.GetPostString(ChannelAttribute.ChannelName);
                }

                if (request.IsPostExists(ChannelAttribute.IndexName))
                {
                    var indexName = request.GetPostString(ChannelAttribute.IndexName);
                    if (!channelInfo.IndexName.Equals(indexName) && !string.IsNullOrEmpty(indexName))
                    {
                        var indexNameList = DataProvider.ChannelDao.GetIndexNameList(siteId);
                        if (indexNameList.IndexOf(indexName) != -1)
                        {
                            return(BadRequest("栏目属性修改失败,栏目索引已存在!"));
                        }
                    }
                    channelInfo.IndexName = indexName;
                }

                if (request.IsPostExists(ChannelAttribute.ContentModelPluginId))
                {
                    var contentModelPluginId = request.GetPostString(ChannelAttribute.ContentModelPluginId);
                    if (channelInfo.ContentModelPluginId != contentModelPluginId)
                    {
                        channelInfo.ContentModelPluginId = contentModelPluginId;
                    }
                }

                if (request.IsPostExists(ChannelAttribute.ContentRelatedPluginIds))
                {
                    channelInfo.ContentRelatedPluginIds = request.GetPostString(ChannelAttribute.ContentRelatedPluginIds);
                }

                if (request.IsPostExists(ChannelAttribute.FilePath))
                {
                    var filePath = request.GetPostString(ChannelAttribute.FilePath);
                    filePath = filePath.Trim();
                    if (!channelInfo.FilePath.Equals(filePath) && !string.IsNullOrEmpty(filePath))
                    {
                        if (!DirectoryUtils.IsDirectoryNameCompliant(filePath))
                        {
                            return(BadRequest("栏目页面路径不符合系统要求!"));
                        }

                        if (PathUtils.IsDirectoryPath(filePath))
                        {
                            filePath = PageUtils.Combine(filePath, "index.html");
                        }

                        var filePathList = DataProvider.ChannelDao.GetAllFilePathBySiteId(siteId);
                        if (filePathList.IndexOf(filePath) != -1)
                        {
                            return(BadRequest("栏目修改失败,栏目页面路径已存在!"));
                        }
                    }
                    channelInfo.FilePath = filePath;
                }

                if (request.IsPostExists(ChannelAttribute.ChannelFilePathRule))
                {
                    var channelFilePathRule = request.GetPostString(ChannelAttribute.ChannelFilePathRule);

                    if (!string.IsNullOrEmpty(channelFilePathRule))
                    {
                        var filePathRule = channelFilePathRule.Replace("|", string.Empty);
                        if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule))
                        {
                            return(BadRequest("栏目页面命名规则不符合系统要求!"));
                        }
                        if (PathUtils.IsDirectoryPath(filePathRule))
                        {
                            return(BadRequest("栏目页面命名规则必须包含生成文件的后缀!"));
                        }
                    }

                    channelInfo.ChannelFilePathRule = channelFilePathRule;
                }

                if (request.IsPostExists(ChannelAttribute.ContentFilePathRule))
                {
                    var contentFilePathRule = request.GetPostString(ChannelAttribute.ContentFilePathRule);

                    if (!string.IsNullOrEmpty(contentFilePathRule))
                    {
                        var filePathRule = contentFilePathRule.Replace("|", string.Empty);
                        if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule))
                        {
                            return(BadRequest("内容页面命名规则不符合系统要求!"));
                        }
                        if (PathUtils.IsDirectoryPath(filePathRule))
                        {
                            return(BadRequest("内容页面命名规则必须包含生成文件的后缀!"));
                        }
                    }

                    channelInfo.ContentFilePathRule = contentFilePathRule;
                }

                if (request.IsPostExists(ChannelAttribute.GroupNameCollection))
                {
                    channelInfo.GroupNameCollection = request.GetPostString(ChannelAttribute.GroupNameCollection);
                }

                if (request.IsPostExists(ChannelAttribute.ImageUrl))
                {
                    channelInfo.ImageUrl = request.GetPostString(ChannelAttribute.ImageUrl);
                }

                if (request.IsPostExists(ChannelAttribute.Content))
                {
                    channelInfo.Content = request.GetPostString(ChannelAttribute.Content);
                }

                if (request.IsPostExists(ChannelAttribute.Keywords))
                {
                    channelInfo.Keywords = request.GetPostString(ChannelAttribute.Keywords);
                }

                if (request.IsPostExists(ChannelAttribute.Description))
                {
                    channelInfo.Description = request.GetPostString(ChannelAttribute.Description);
                }

                if (request.IsPostExists(ChannelAttribute.LinkUrl))
                {
                    channelInfo.LinkUrl = request.GetPostString(ChannelAttribute.LinkUrl);
                }

                if (request.IsPostExists(ChannelAttribute.LinkType))
                {
                    channelInfo.LinkType = request.GetPostString(ChannelAttribute.LinkType);
                }

                if (request.IsPostExists(ChannelAttribute.ChannelTemplateId))
                {
                    channelInfo.ChannelTemplateId = request.GetPostInt(ChannelAttribute.ChannelTemplateId);
                }

                if (request.IsPostExists(ChannelAttribute.ContentTemplateId))
                {
                    channelInfo.ContentTemplateId = request.GetPostInt(ChannelAttribute.ContentTemplateId);
                }

                DataProvider.ChannelDao.Update(channelInfo);

                return(Ok(new
                {
                    Value = channelInfo.ToDictionary()
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Esempio n. 13
0
        public IHttpActionResult Create(int siteId)
        {
            try
            {
                var request  = new AuthenticatedRequest();
                var parentId = request.GetPostInt(ChannelAttribute.ParentId, siteId);

                var isAuth = request.IsApiAuthenticated &&
                             AccessTokenManager.IsScope(request.ApiToken, AccessTokenManager.ScopeChannels) ||
                             request.IsAdminLoggin &&
                             request.AdminPermissions.HasChannelPermissions(siteId, parentId,
                                                                            ConfigManager.ChannelPermissions.ChannelAdd);
                if (!isAuth)
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var contentModelPluginId    = request.GetPostString(ChannelAttribute.ContentModelPluginId);
                var contentRelatedPluginIds = request.GetPostString(ChannelAttribute.ContentRelatedPluginIds);

                var channelName         = request.GetPostString(ChannelAttribute.ChannelName);
                var indexName           = request.GetPostString(ChannelAttribute.IndexName);
                var filePath            = request.GetPostString(ChannelAttribute.FilePath);
                var channelFilePathRule = request.GetPostString(ChannelAttribute.ChannelFilePathRule);
                var contentFilePathRule = request.GetPostString(ChannelAttribute.ContentFilePathRule);
                var groupNameCollection = request.GetPostString(ChannelAttribute.GroupNameCollection);
                var imageUrl            = request.GetPostString(ChannelAttribute.ImageUrl);
                var content             = request.GetPostString(ChannelAttribute.Content);
                var keywords            = request.GetPostString(ChannelAttribute.Keywords);
                var description         = request.GetPostString(ChannelAttribute.Description);
                var linkUrl             = request.GetPostString(ChannelAttribute.LinkUrl);
                var linkType            = request.GetPostString(ChannelAttribute.LinkType);
                var channelTemplateId   = request.GetPostInt(ChannelAttribute.ChannelTemplateId);
                var contentTemplateId   = request.GetPostInt(ChannelAttribute.ContentTemplateId);

                var channelInfo = new ChannelInfo
                {
                    SiteId                  = siteId,
                    ParentId                = parentId,
                    ContentModelPluginId    = contentModelPluginId,
                    ContentRelatedPluginIds = contentRelatedPluginIds
                };

                if (!string.IsNullOrEmpty(indexName))
                {
                    var indexNameList = DataProvider.ChannelDao.GetIndexNameList(siteId);
                    if (indexNameList.IndexOf(indexName) != -1)
                    {
                        return(BadRequest("栏目添加失败,栏目索引已存在!"));
                    }
                }

                if (!string.IsNullOrEmpty(filePath))
                {
                    if (!DirectoryUtils.IsDirectoryNameCompliant(filePath))
                    {
                        return(BadRequest("栏目页面路径不符合系统要求!"));
                    }

                    if (PathUtils.IsDirectoryPath(filePath))
                    {
                        filePath = PageUtils.Combine(filePath, "index.html");
                    }

                    var filePathList = DataProvider.ChannelDao.GetAllFilePathBySiteId(siteId);
                    if (filePathList.IndexOf(filePath) != -1)
                    {
                        return(BadRequest("栏目添加失败,栏目页面路径已存在!"));
                    }
                }

                if (!string.IsNullOrEmpty(channelFilePathRule))
                {
                    if (!DirectoryUtils.IsDirectoryNameCompliant(channelFilePathRule))
                    {
                        return(BadRequest("栏目页面命名规则不符合系统要求!"));
                    }
                    if (PathUtils.IsDirectoryPath(channelFilePathRule))
                    {
                        return(BadRequest("栏目页面命名规则必须包含生成文件的后缀!"));
                    }
                }

                if (!string.IsNullOrEmpty(contentFilePathRule))
                {
                    if (!DirectoryUtils.IsDirectoryNameCompliant(contentFilePathRule))
                    {
                        return(BadRequest("内容页面命名规则不符合系统要求!"));
                    }
                    if (PathUtils.IsDirectoryPath(contentFilePathRule))
                    {
                        return(BadRequest("内容页面命名规则必须包含生成文件的后缀!"));
                    }
                }

                //var parentChannelInfo = ChannelManager.GetChannelInfo(siteId, parentId);
                //var styleInfoList = TableStyleManager.GetChannelStyleInfoList(parentChannelInfo);
                //var extendedAttributes = BackgroundInputTypeParser.SaveAttributes(siteInfo, styleInfoList, Request.Form, null);
                channelInfo.Additional.Load(request.GetPostObject <Dictionary <string, object> >());
                //foreach (string key in attributes)
                //{
                //    channelInfo.Additional.SetExtendedAttribute(key, attributes[key]);
                //}

                channelInfo.ChannelName         = channelName;
                channelInfo.IndexName           = indexName;
                channelInfo.FilePath            = filePath;
                channelInfo.ChannelFilePathRule = channelFilePathRule;
                channelInfo.ContentFilePathRule = contentFilePathRule;

                channelInfo.GroupNameCollection = groupNameCollection;
                channelInfo.ImageUrl            = imageUrl;
                channelInfo.Content             = content;
                channelInfo.Keywords            = keywords;
                channelInfo.Description         = description;
                channelInfo.LinkUrl             = linkUrl;
                channelInfo.LinkType            = linkType;
                channelInfo.ChannelTemplateId   = channelTemplateId;
                channelInfo.ContentTemplateId   = contentTemplateId;

                channelInfo.AddDate = DateTime.Now;
                channelInfo.Id      = DataProvider.ChannelDao.Insert(channelInfo);
                //栏目选择投票样式后,内容

                CreateManager.CreateChannel(siteId, channelInfo.Id);

                request.AddSiteLog(siteId, "添加栏目", $"栏目:{channelName}");

                return(Ok(new
                {
                    Value = channelInfo.ToDictionary()
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Esempio n. 14
0
 public CleanDirectory()
 {
     DirectoryUtils = new DirectoryUtils();
 }
Esempio n. 15
0
        public void ShouldDeleteDirectory()
        {
            string dir = "test";
            FileSystemTestHelper.RecreateDirectory(dir);

            Assert.That(Directory.Exists(dir));

            Touch(@"test\one.txt", "one");

            var directoryUtils = new DirectoryUtils();

            directoryUtils.DeleteDirectory(dir);
            Assert.That(!Directory.Exists(dir));

            directoryUtils.DeleteDirectory(dir);
            Assert.That(!Directory.Exists(dir));
        }
Esempio n. 16
0
        public async Task ExecuteAsync(IPluginJobContext context)
        {
            if (!CliUtils.ParseArgs(_options, context.Args))
            {
                return;
            }

            if (_isHelp)
            {
                PrintUsage();
                return;
            }

            var contentRootPath = _settingsManager.ContentRootPath;

            if (!CliUtils.IsSsCmsExists(contentRootPath))
            {
                var(success, result, failureMessage) = await _apiService.GetReleasesAsync(_settingsManager.Version, null);

                if (!success)
                {
                    await WriteUtils.PrintErrorAsync(failureMessage);

                    return;
                }

                var proceed = ReadUtils.GetYesNo($"Do you want to install SS CMS in {contentRootPath}?");
                if (!proceed)
                {
                    return;
                }

                Console.WriteLine($"Downloading SS CMS {result.Cms.Version}...");
                var directoryPath = CloudUtils.Dl.DownloadCms(_pathManager, _settingsManager.OSArchitecture, result.Cms.Version);

                await WriteUtils.PrintSuccessAsync($"{result.Cms.Version} download successfully!");

                DirectoryUtils.Copy(directoryPath, contentRootPath, true);
            }

            InstallUtils.Init(contentRootPath);

            if (!await _configRepository.IsNeedInstallAsync())
            {
                await WriteUtils.PrintErrorAsync($"SS CMS has been installed in {contentRootPath}");

                return;
            }

            var databaseTypeInput = ReadUtils.GetSelect("Database type", new List <string>
            {
                DatabaseType.MySql.GetValue().ToLower(),
                DatabaseType.SqlServer.GetValue().ToLower(),
                DatabaseType.PostgreSql.GetValue().ToLower(),
                DatabaseType.SQLite.GetValue().ToLower()
            });

            var databaseType          = TranslateUtils.ToEnum(databaseTypeInput, DatabaseType.MySql);
            var databaseName          = string.Empty;
            var databaseHost          = string.Empty;
            var isDatabaseDefaultPort = true;
            var databasePort          = 0;
            var databaseUserName      = string.Empty;
            var databasePassword      = string.Empty;

            if (databaseType != DatabaseType.SQLite)
            {
                databaseHost          = ReadUtils.GetString("Database hostname / IP:");
                isDatabaseDefaultPort = ReadUtils.GetYesNo("Use default port?");

                if (!isDatabaseDefaultPort)
                {
                    databasePort = ReadUtils.GetInt("Database port:");
                }
                databaseUserName = ReadUtils.GetString("Database userName:"******"Database password:"******"Database name", databaseNames);
            }

            var databaseConnectionString = InstallUtils.GetDatabaseConnectionString(databaseType, databaseHost, isDatabaseDefaultPort, databasePort, databaseUserName, databasePassword, databaseName);

            var isProtectData = ReadUtils.GetYesNo("Protect settings in sscms.json?");

            _settingsManager.SaveSettings(isProtectData, false, false, databaseType, databaseConnectionString, string.Empty, string.Empty, null, null);

            await WriteUtils.PrintSuccessAsync("SS CMS was download and ready for install, please run: sscms install database");
        }
Esempio n. 17
0
        public static void RecoverySite(int siteId, bool isDeleteChannels, bool isDeleteTemplates, bool isDeleteFiles, bool isZip, string path, bool isOverride, bool isUseTable, string administratorName)
        {
            var importObject = new ImportObject(siteId, administratorName);

            var siteInfo = SiteManager.GetSiteInfo(siteId);

            var siteTemplatePath = path;

            if (isZip)
            {
                //解压文件
                siteTemplatePath = PathUtils.GetTemporaryFilesPath(EBackupTypeUtils.GetValue(EBackupType.Site));
                DirectoryUtils.DeleteDirectoryIfExists(siteTemplatePath);
                DirectoryUtils.CreateDirectoryIfNotExists(siteTemplatePath);

                ZipUtils.ExtractZip(path, siteTemplatePath);
            }
            var siteTemplateMetadataPath = PathUtils.Combine(siteTemplatePath, DirectoryUtils.SiteTemplates.SiteTemplateMetadata);

            if (isDeleteChannels)
            {
                var channelIdList = ChannelManager.GetChannelIdList(ChannelManager.GetChannelInfo(siteId, siteId), EScopeType.Children, string.Empty, string.Empty, string.Empty);
                foreach (var channelId in channelIdList)
                {
                    DataProvider.ChannelDao.Delete(siteId, channelId);
                }
            }
            if (isDeleteTemplates)
            {
                var templateInfoList =
                    DataProvider.TemplateDao.GetTemplateInfoListBySiteId(siteId);
                foreach (var templateInfo in templateInfoList)
                {
                    if (templateInfo.IsDefault == false)
                    {
                        DataProvider.TemplateDao.Delete(siteId, templateInfo.Id);
                    }
                }
            }
            if (isDeleteFiles)
            {
                DirectoryUtility.DeleteSiteFiles(siteInfo);
            }

            //导入文件
            importObject.ImportFiles(siteTemplatePath, isOverride);

            //导入模板
            var templateFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.FileTemplate);

            importObject.ImportTemplates(templateFilePath, isOverride, administratorName);

            //导入辅助表
            var tableDirectoryPath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.Table);

            //导入站点设置
            var configurationFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.FileConfiguration);

            importObject.ImportConfiguration(configurationFilePath);

            //导入栏目及内容
            var siteContentDirectoryPath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.SiteContent);

            importObject.ImportChannelsAndContents(0, siteContentDirectoryPath, isOverride);

            //导入表样式及清除缓存
            if (isUseTable)
            {
                importObject.ImportTableStyles(tableDirectoryPath);
            }
            importObject.RemoveDbCache();

            CacheUtils.ClearAll();
        }
Esempio n. 18
0
        //public static List<ContentModelInfo> GetAllContentModels(SiteInfo siteInfo)
        //{
        //    var cacheName = nameof(GetAllContentModels) + siteInfo.Id;
        //    var contentModels = GetCache<List<ContentModelInfo>>(cacheName);
        //    if (contentModels != null) return contentModels;

        //    contentModels = new List<ContentModelInfo>();

        //    foreach (var pluginInfo in GetEnabledPluginInfoLists<IContentModel>())
        //    {
        //        var model = pluginInfo.Plugin as IContentModel;

        //        if (model == null) continue;

        //        var tableName = siteInfo.AuxiliaryTableForContent;
        //        var tableType = EAuxiliaryTableType.BackgroundContent;
        //        if (model.ContentTableColumns != null && model.ContentTableColumns.Count > 0)
        //        {
        //            tableName = pluginInfo.Id;
        //            tableType = EAuxiliaryTableType.Custom;
        //        }

        //        contentModels.Add(new ContentModelInfo(
        //            pluginInfo.Id,
        //            pluginInfo.Id,
        //            $"插件:{pluginInfo.Metadata.DisplayName}",
        //            tableName,
        //            tableType,
        //            PageUtils.GetPluginDirectoryUrl(pluginInfo.Id, pluginInfo.Metadata.Icon))
        //        );
        //    }

        //    SetCache(cacheName, contentModels);

        //    return contentModels;
        //}



        //public static List<ContentModelInfo> GetAllContentModels(SiteInfo siteInfo)
        //{
        //    var cacheName = nameof(GetAllContentModels) + siteInfo.Id;
        //    var contentModels = GetCache<List<ContentModelInfo>>(cacheName);
        //    if (contentModels != null) return contentModels;

        //    contentModels = new List<ContentModelInfo>();

        //    foreach (var pluginInfo in GetEnabledPluginInfoLists<IContentModel>())
        //    {
        //        var model = pluginInfo.Plugin as IContentModel;

        //        if (model == null) continue;

        //        var links = new List<PluginContentLink>();
        //        if (model.ContentLinks != null)
        //        {
        //            links.AddRange(model.ContentLinks.Select(link => new PluginContentLink
        //            {
        //                Text = link.Text,
        //                Href = PageUtils.GetPluginDirectoryUrl(pluginInfo.Id, link.Href),
        //                Target = link.Target
        //            }));
        //        }
        //        var tableName = siteInfo.AuxiliaryTableForContent;
        //        var tableType = EAuxiliaryTableType.BackgroundContent;
        //        if (model.IsCustomContentTable && model.CustomContentTableColumns != null && model.CustomContentTableColumns.Count > 0)
        //        {
        //            tableName = pluginInfo.Id;
        //            tableType = EAuxiliaryTableType.Custom;
        //        }

        //        contentModels.Add(new ContentModelInfo(
        //            pluginInfo.Id,
        //            pluginInfo.Id,
        //            $"插件:{pluginInfo.Metadata.DisplayName}",
        //            tableName,
        //            tableType,
        //            PageUtils.GetPluginDirectoryUrl(pluginInfo.Id, pluginInfo.Metadata.Icon),
        //            links)
        //        );
        //    }

        //    SetCache(cacheName, contentModels);

        //    return contentModels;
        //}



        //public static Dictionary<string, Func<PluginRenderContext, string>> GetRenders()
        //{
        //    var renders = new Dictionary<string, Func<PluginRenderContext, string>>();

        //    var pluginInfoList = GetEnabledPluginInfoList<IRender>();
        //    if (pluginInfoList != null && pluginInfoList.Count > 0)
        //    {
        //        foreach (var pluginInfo in pluginInfoList)
        //        {
        //            var plugin = pluginInfo.Plugin as IRender;
        //            if (plugin?.Render != null)
        //            {
        //                renders.Add(pluginInfo.Metadata.Id, plugin.Render);
        //            }
        //            //if (!(pluginInfo.Plugin is IRender plugin)) continue;

        //            //if (plugin.Render != null)
        //            //{
        //            //    renders.Add(pluginInfo.Metadata.Id, plugin.Render);
        //            //}
        //        }
        //    }

        //    return renders;
        //}

        //public static List<Action<object, FileSystemEventArgs>> GetFileSystemChangedActions()
        //{
        //    var actions = new List<Action<object, FileSystemEventArgs>>();

        //    var plugins = GetEnabledFeatures<IFileSystem>();
        //    if (plugins != null && plugins.Count > 0)
        //    {
        //        foreach (var plugin in plugins)
        //        {
        //            if (plugin.FileSystemChanged != null)
        //            {
        //                actions.Add(plugin.FileSystemChanged);
        //            }
        //        }
        //    }

        //    return actions;
        //}



        //public static bool Install(string pluginId, string version, out string errorMessage)
        //{
        //    errorMessage = string.Empty;
        //    if (string.IsNullOrEmpty(pluginId)) return false;

        //    try
        //    {
        //        if (IsExists(pluginId))
        //        {
        //            errorMessage = $"插件 {pluginId} 已存在";
        //            return false;
        //        }
        //        var directoryPath = PathUtils.GetPluginPath(pluginId);
        //        DirectoryUtils.DeleteDirectoryIfExists(directoryPath);

        //        var zipFilePath = PathUtility.GetTemporaryFilesPath(pluginId + ".zip");
        //        FileUtils.DeleteFileIfExists(zipFilePath);

        //        var downloadUrl = $"http://download.siteserver.cn/plugins/{pluginId}/{version}/{pluginId}.zip";
        //        WebClientUtils.SaveRemoteFileToLocal(downloadUrl, zipFilePath);

        //        ZipUtils.UnpackFiles(zipFilePath, directoryPath);
        //        FileUtils.DeleteFileIfExists(zipFilePath);

        //        string dllDirectoryPath;
        //        var metadata = GetPluginMetadata(pluginId, out dllDirectoryPath, out errorMessage);
        //        if (metadata == null)
        //        {
        //            return false;
        //        }

        //        //SaveMetadataToJson(metadata);
        //    }
        //    catch (Exception ex)
        //    {
        //        errorMessage = ex.Message;
        //        return false;
        //    }

        //    return true;
        //}

        public static void Delete(string pluginId)
        {
            DirectoryUtils.DeleteDirectoryIfExists(PathUtils.GetPluginPath(pluginId));
            ClearCache();
        }
Esempio n. 19
0
        private int Validate_SiteInfo(out string errorMessage)
        {
            try
            {
                var isHq         = TranslateUtils.ToBool(RblIsRoot.SelectedValue); // 是否主站
                var parentSiteId = 0;
                var siteDir      = string.Empty;

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

                    parentSiteId = TranslateUtils.ToInt(DdlParentId.SelectedValue);
                    siteDir      = TbSiteDir.Text;

                    var list = DataProvider.SiteDao.GetLowerSiteDirList(parentSiteId);
                    if (list.IndexOf(siteDir.ToLower()) != -1)
                    {
                        errorMessage = "已存在相同的发布路径!";
                        return(0);
                    }

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

                var nodeInfo = new ChannelInfo();

                nodeInfo.ChannelName          = nodeInfo.IndexName = "首页";
                nodeInfo.ParentId             = 0;
                nodeInfo.ContentModelPluginId = string.Empty;

                var psInfo = new SiteInfo
                {
                    SiteName  = PageUtils.FilterXss(TbSiteName.Text),
                    SiteDir   = siteDir,
                    TableName = DdlTableName.SelectedValue,
                    ParentId  = parentSiteId,
                    IsRoot    = isHq
                };

                psInfo.Additional.IsCheckContentLevel = TranslateUtils.ToBool(RblIsCheckContentUseLevel.SelectedValue);

                if (psInfo.Additional.IsCheckContentLevel)
                {
                    psInfo.Additional.CheckContentLevel = TranslateUtils.ToInt(DdlCheckContentLevel.SelectedValue);
                }
                psInfo.Additional.Charset = DdlCharset.SelectedValue;

                var theSiteId = DataProvider.ChannelDao.InsertSiteInfo(nodeInfo, psInfo, AuthRequest.AdminName);

                if (AuthRequest.AdminPermissions.IsSystemAdministrator && !AuthRequest.AdminPermissions.IsConsoleAdministrator)
                {
                    var siteIdList = AuthRequest.AdminPermissions.SiteIdList ?? new List <int>();
                    siteIdList.Add(theSiteId);
                    DataProvider.AdministratorDao.UpdateSiteIdCollection(AuthRequest.AdminName, TranslateUtils.ObjectCollectionToString(siteIdList));
                }

                AuthRequest.AddAdminLog("创建新站点", $"站点名称:{PageUtils.FilterXss(TbSiteName.Text)}");

                errorMessage = string.Empty;
                return(theSiteId);
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
                return(0);
            }
        }
Esempio n. 20
0
        private void OptimizeClassicStyles(BuildContext context)
        {
            BuildLogger logger = context.Logger;

            string startMessage = "Started style optimization for Classic Style";
            string endMessage   = "Completed style optimization for Classic Style";

            logger.WriteLine(startMessage, BuildLoggerLevel.Info);

            BuildSettings settings      = context.Settings;
            string        sandassistDir = settings.SandAssistDirectory;

            if (!Directory.Exists(sandassistDir))
            {
                logger.WriteLine("Sandcastle Assist directory does not exists.",
                                 BuildLoggerLevel.Warn);

                logger.WriteLine(endMessage, BuildLoggerLevel.Info);
                return;
            }

            string formatDir = Path.Combine(sandassistDir,
                                            @"Optimizations\Vs2005\Chm");

            if (!Directory.Exists(formatDir))
            {
                logger.WriteLine("The format directory does not exists.",
                                 BuildLoggerLevel.Warn);

                logger.WriteLine(endMessage, BuildLoggerLevel.Info);
                return;
            }

            // 1. For the icons: the directory must exist and not empty...
            string iconsDir  = Path.Combine(formatDir, @"Icons");
            string targetDir = Path.Combine(_helpSource, "icons");

            if (Directory.Exists(iconsDir) && Directory.Exists(targetDir) &&
                !DirectoryUtils.IsDirectoryEmpty(iconsDir))
            {
                try
                {
                    BuildDirCopier dirCopier = new BuildDirCopier();
                    dirCopier.Overwrite = true;
                    dirCopier.Recursive = false;

                    if (logger != null)
                    {
                        logger.WriteLine("Replacing stock icons with: " + iconsDir,
                                         BuildLoggerLevel.Info);
                    }

                    int fileCopies = dirCopier.Copy(iconsDir, targetDir);

                    if (logger != null)
                    {
                        logger.WriteLine(String.Format(
                                             "Total of {0} icons or images replaced.", fileCopies),
                                         BuildLoggerLevel.Info);
                    }
                }
                catch (Exception ex)
                {
                    if (logger != null)
                    {
                        logger.WriteLine(ex, BuildLoggerLevel.Error);
                    }
                }
            }

            // 2. For the style-sheets: the directory must exist and not empty...
            string stylesDir = Path.Combine(formatDir, @"Styles");

            targetDir = Path.Combine(_helpSource, "styles");
            if (Directory.Exists(stylesDir) && Directory.Exists(targetDir) &&
                !DirectoryUtils.IsDirectoryEmpty(stylesDir))
            {
                try
                {
                    BuildDirCopier dirCopier = new BuildDirCopier();
                    dirCopier.Overwrite = true;
                    dirCopier.Recursive = false;

                    if (logger != null)
                    {
                        logger.WriteLine("Replacing stock styles with: " + stylesDir,
                                         BuildLoggerLevel.Info);
                    }

                    int fileCopies = dirCopier.Copy(stylesDir, targetDir);

                    if (logger != null)
                    {
                        logger.WriteLine(String.Format(
                                             "Total of {0} styles replaced.", fileCopies),
                                         BuildLoggerLevel.Info);
                    }
                }
                catch (Exception ex)
                {
                    if (logger != null)
                    {
                        logger.WriteLine(ex, BuildLoggerLevel.Error);
                    }
                }
            }

            // 3. For the scripts: the directory must exist and not empty...
            string scriptsDir = Path.Combine(formatDir, @"Scripts");

            targetDir = Path.Combine(_helpSource, "scripts");
            if (Directory.Exists(scriptsDir) && Directory.Exists(targetDir) &&
                !DirectoryUtils.IsDirectoryEmpty(scriptsDir))
            {
                try
                {
                    BuildDirCopier dirCopier = new BuildDirCopier();
                    dirCopier.Overwrite = true;
                    dirCopier.Recursive = false;

                    if (logger != null)
                    {
                        logger.WriteLine("Replacing stock scripts with: " + scriptsDir,
                                         BuildLoggerLevel.Info);
                    }

                    int fileCopies = dirCopier.Copy(scriptsDir, targetDir);

                    if (logger != null)
                    {
                        logger.WriteLine(String.Format(
                                             "Total of {0} scripts replaced.", fileCopies),
                                         BuildLoggerLevel.Info);
                    }
                }
                catch (Exception ex)
                {
                    if (logger != null)
                    {
                        logger.WriteLine(ex, BuildLoggerLevel.Error);
                    }
                }
            }

            logger.WriteLine(endMessage, BuildLoggerLevel.Info);
        }
Esempio n. 21
0
 public virtual int OnExecute()
 {
     DirectoryUtils.SetBasePath(Path);
     return((int)ExecuteResultEnum.Succeeded);
 }
 private static void OnEditorUpdate()
 {
     DirectoryUtils.EnsureFolderExists(ResourcePath, refreshAfterCreation: true);
     EnsureConfigExists();
 }
        internal static void DeleteFile(string filename)
        {
            Verify.ArgumentNotNullOrEmpty(filename, "filename");

            DirectoryUtils.DeleteFile(filename, true);
        }
Esempio n. 24
0
        public override bool Export(ProjectAssetContainer container, string dirPath)
        {
            string subPath  = Path.Combine(dirPath, ProjectSettingsName);
            string fileName = $"{EditorBuildSettings.ClassID.ToString()}.asset";
            string filePath = Path.Combine(subPath, fileName);

            if (!DirectoryUtils.Exists(subPath))
            {
                DirectoryUtils.CreateDirectory(subPath);
            }

            BuildSettings       asset  = (BuildSettings)Asset;
            IEnumerable <Scene> scenes = asset.Scenes.Select(t => new Scene(t, container.SceneNameToGUID(t)));

            EditorBuildSettings.Initialize(scenes);
            AssetExporter.Export(container, EditorBuildSettings, filePath);

            fileName = $"{EditorSettings.ClassID.ToString()}.asset";
            filePath = Path.Combine(subPath, fileName);

            AssetExporter.Export(container, EditorSettings, filePath);

            if (NavMeshProjectSettings != null)
            {
                fileName = $"{NavMeshProjectSettings.ExportName}.asset";
                filePath = Path.Combine(subPath, fileName);

                AssetExporter.Export(container, NavMeshProjectSettings, filePath);
            }
            if (NetworkManager != null)
            {
                fileName = $"{NetworkManager.ExportName}.asset";
                filePath = Path.Combine(subPath, fileName);

                AssetExporter.Export(container, NetworkManager, filePath);
            }
            if (Physics2DSettings != null)
            {
                fileName = $"{Physics2DSettings.ExportName}.asset";
                filePath = Path.Combine(subPath, fileName);

                AssetExporter.Export(container, Physics2DSettings, filePath);
            }
            if (UnityConnectSettings != null)
            {
                fileName = $"{UnityConnectSettings.ExportName}.asset";
                filePath = Path.Combine(subPath, fileName);

                AssetExporter.Export(container, UnityConnectSettings, filePath);
            }
            if (QualitySettings != null)
            {
                fileName = $"{QualitySettings.ExportName}.asset";
                filePath = Path.Combine(subPath, fileName);

                AssetExporter.Export(container, QualitySettings, filePath);
            }

            fileName = $"ProjectVersion.txt";
            filePath = Path.Combine(subPath, fileName);

            using (FileStream file = FileUtils.Create(filePath))
            {
                using (StreamWriter writer = new InvariantStreamWriter(file, Encoding.UTF8))
                {
                    writer.Write("m_EditorVersion: 2017.3.0f3");
                }
            }
            return(true);
        }
Esempio n. 25
0
        public static bool UpdatePackage(string idWithVersion, bool isSsCms, out string errorMessage)
        {
            try
            {
                var packagePath = PathUtils.GetPackagesPath(idWithVersion);

                string nuspecPath;
                string dllDirectoryPath;
                var    metadata = GetPackageMetadataFromPackages(idWithVersion, out nuspecPath, out dllDirectoryPath, out errorMessage);
                if (metadata == null)
                {
                    return(false);
                }

                if (isSsCms)
                {
                    var packageWebConfigPath = PathUtils.Combine(packagePath, WebConfigUtils.WebConfigFileName);
                    if (!FileUtils.IsFileExists(packageWebConfigPath))
                    {
                        errorMessage = $"升级包 {WebConfigUtils.WebConfigFileName} 文件不存在";
                        return(false);
                    }

                    WebConfigUtils.UpdateWebConfig(packageWebConfigPath, WebConfigUtils.IsProtectData,
                                                   WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString, WebConfigUtils.AdminDirectory,
                                                   WebConfigUtils.SecretKey, WebConfigUtils.IsNightlyUpdate);

                    //DirectoryUtils.Copy(PathUtils.Combine(packagePath, DirectoryUtils.SiteFiles.DirectoryName),
                    //    PathUtils.GetSiteFilesPath(string.Empty), true);
                    //DirectoryUtils.Copy(PathUtils.Combine(packagePath, DirectoryUtils.SiteServer.DirectoryName),
                    //    PathUtils.GetAdminDirectoryPath(string.Empty), true);
                    //DirectoryUtils.Copy(PathUtils.Combine(packagePath, DirectoryUtils.Bin.DirectoryName),
                    //    PathUtils.GetBinDirectoryPath(string.Empty), true);
                    //FileUtils.CopyFile(packageWebConfigPath,
                    //    PathUtils.Combine(WebConfigUtils.PhysicalApplicationPath, WebConfigUtils.WebConfigFileName),
                    //    true);
                }
                else
                {
                    var pluginPath = PathUtils.GetPluginPath(metadata.Id);
                    DirectoryUtils.CreateDirectoryIfNotExists(pluginPath);

                    DirectoryUtils.Copy(PathUtils.Combine(packagePath, "content"), pluginPath, true);
                    DirectoryUtils.Copy(dllDirectoryPath, PathUtils.Combine(pluginPath, "Bin"), true);

                    //var dependencyPackageDict = GetDependencyPackages(metadata);
                    //foreach (var dependencyPackageId in dependencyPackageDict.Keys)
                    //{
                    //    var dependencyPackageVersion = dependencyPackageDict[dependencyPackageId];
                    //    var dependencyDdlDirectoryPath =
                    //        FindDllDirectoryPath(
                    //            PathUtils.GetPackagesPath($"{dependencyPackageId}.{dependencyPackageVersion}"));
                    //    DirectoryUtils.Copy(dependencyDdlDirectoryPath, PathUtils.Combine(pluginPath, "Bin"), true);
                    //}

                    var configFilelPath = PathUtils.Combine(pluginPath, $"{metadata.Id}.nuspec");
                    FileUtils.CopyFile(nuspecPath, configFilelPath, true);

                    PluginManager.ClearCache();
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                return(false);
            }

            return(true);
        }
Esempio n. 26
0
 public void SetUp()
 {
     DirectoryUtils.ClearDir(_rootPath, true);
     TestObj = new DownloadDirectories(_rootPath);
 }
Esempio n. 27
0
        public bool IsSiteTemplateDirectoryExists(string siteTemplateDir)
        {
            var siteTemplatePath = PathUtils.Combine(_rootPath, siteTemplateDir);

            return(DirectoryUtils.IsDirectoryExists(siteTemplatePath));
        }
Esempio n. 28
0
 public void TearDown()
 {
     DirectoryUtils.ClearDir(_rootPath, false);
 }
Esempio n. 29
0
        public static async Task RecoverySiteAsync(ICacheManager cacheManager, IPathManager pathManager, IDatabaseManager databaseManager, CacheUtils caching, Site site, bool isDeleteChannels, bool isDeleteTemplates, bool isDeleteFiles, bool isZip, string path, bool isOverride, bool isUseTable, int adminId, string guid)
        {
            var importObject = new ImportObject(pathManager, databaseManager, caching, site, adminId);

            var siteTemplatePath = path;

            if (isZip)
            {
                //解压文件
                siteTemplatePath = pathManager.GetTemporaryFilesPath(BackupType.Site.GetValue());
                DirectoryUtils.DeleteDirectoryIfExists(siteTemplatePath);
                DirectoryUtils.CreateDirectoryIfNotExists(siteTemplatePath);

                pathManager.ExtractZip(path, siteTemplatePath);
            }
            var siteTemplateMetadataPath = PathUtils.Combine(siteTemplatePath, DirectoryUtils.SiteFiles.SiteTemplates.SiteTemplateMetadata);

            if (isDeleteChannels)
            {
                var channelIdList = await databaseManager.ChannelRepository.GetChannelIdsAsync(site.Id, site.Id, ScopeType.Children);

                foreach (var channelId in channelIdList)
                {
                    await databaseManager.ContentRepository.TrashContentsAsync(site, channelId, adminId);

                    await databaseManager.ChannelRepository.DeleteAsync(site, channelId, adminId);
                }
            }
            if (isDeleteTemplates)
            {
                var summaries = await databaseManager.TemplateRepository.GetSummariesAsync(site.Id);

                foreach (var summary in summaries)
                {
                    if (summary.DefaultTemplate == false)
                    {
                        await databaseManager.TemplateRepository.DeleteAsync(pathManager, site, summary.Id);
                    }
                }
            }
            if (isDeleteFiles)
            {
                await pathManager.DeleteSiteFilesAsync(site);
            }

            //导入文件
            await importObject.ImportFilesAsync(siteTemplatePath, isOverride, guid);

            //导入模板
            var templateFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteFiles.SiteTemplates.FileTemplate);
            await importObject.ImportTemplatesAsync(templateFilePath, isOverride, adminId, guid);

            //导入辅助表
            var tableDirectoryPath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteFiles.SiteTemplates.Table);

            //导入站点设置
            var configurationFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteFiles.SiteTemplates.FileConfiguration);
            await importObject.ImportConfigurationAsync(configurationFilePath, guid);

            //导入栏目及内容
            var siteContentDirectoryPath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteFiles.SiteTemplates.SiteContent);
            await importObject.ImportChannelsAndContentsAsync(0, siteContentDirectoryPath, isOverride, guid);

            //导入表样式及清除缓存
            if (isUseTable)
            {
                await importObject.ImportTableStylesAsync(tableDirectoryPath, guid);
            }

            cacheManager.Clear();
        }
Esempio n. 30
0
        public static void CreateExcelFileForInputContents(string filePath, PublishmentSystemInfo publishmentSystemInfo,
                                                           InputInfo inputInfo)
        {
            DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath));
            FileUtils.DeleteFileIfExists(filePath);

            var head = new List <string>();
            var rows = new List <List <string> >();

            var relatedidentityes = RelatedIdentities.GetRelatedIdentities(ETableStyle.InputContent,
                                                                           publishmentSystemInfo.PublishmentSystemId, inputInfo.InputID);
            var tableStyleInfoList = TableStyleManager.GetTableStyleInfoList(ETableStyle.InputContent,
                                                                             DataProvider.InputContentDao.TableName, relatedidentityes);

            if (tableStyleInfoList.Count == 0)
            {
                throw new Exception("表单无字段,无法导出");
            }

            foreach (var tableStyleInfo in tableStyleInfoList)
            {
                head.Add(tableStyleInfo.DisplayName);
            }

            if (inputInfo.IsReply)
            {
                head.Add("回复");
            }
            head.Add("添加时间");

            var contentIdList = DataProvider.InputContentDao.GetContentIdListWithChecked(inputInfo.InputID);

            foreach (var contentId in contentIdList)
            {
                var contentInfo = DataProvider.InputContentDao.GetContentInfo(contentId);
                if (contentInfo != null)
                {
                    var row = new List <string>();

                    foreach (var tableStyleInfo in tableStyleInfoList)
                    {
                        var value = contentInfo.Attributes.Get(tableStyleInfo.AttributeName);

                        if (!string.IsNullOrEmpty(value))
                        {
                            value = InputParserUtility.GetContentByTableStyle(value, publishmentSystemInfo,
                                                                              ETableStyle.InputContent, tableStyleInfo);
                        }

                        row.Add(StringUtils.StripTags(value));
                    }

                    if (inputInfo.IsReply)
                    {
                        row.Add(StringUtils.StripTags(contentInfo.Reply));
                    }
                    row.Add(DateUtils.GetDateAndTimeString(contentInfo.AddDate));

                    rows.Add(row);
                }
            }

            CsvUtils.Export(filePath, head, rows);
        }
Esempio n. 31
0
        public async Task ExecuteAsync(IPluginJobContext context)
        {
            if (!CliUtils.ParseArgs(_options, context.Args))
            {
                return;
            }

            if (_isHelp)
            {
                PrintUsage();
                return;
            }

            var directory = _directory;

            if (string.IsNullOrEmpty(directory))
            {
                directory = $"backup/{DateTime.Now:yyyy-MM-dd}";
            }

            var treeInfo = new TreeInfo(_settingsManager, directory);

            DirectoryUtils.CreateDirectoryIfNotExists(treeInfo.DirectoryPath);

            var configPath = CliUtils.GetConfigPath(_settingsManager);

            if (!FileUtils.IsFileExists(configPath))
            {
                await WriteUtils.PrintErrorAsync($"The sscms.json file does not exist: {configPath}");

                return;
            }

            await Console.Out.WriteLineAsync($"Database type: {_settingsManager.DatabaseType.GetDisplayName()}");

            await Console.Out.WriteLineAsync($"Database connection string: {_settingsManager.DatabaseConnectionString}");

            await Console.Out.WriteLineAsync($"Backup folder: {treeInfo.DirectoryPath}");

            //WebConfigUtils.Load(_settingsManager.ContentRootPath, webConfigPath);

            //if (string.IsNullOrEmpty(WebConfigUtils.ConnectionString))
            //{
            //    await CliUtils.PrintErrorAsync($"{webConfigPath} 中数据库连接字符串 connectionString 未设置");
            //    return;
            //}

            //await Console.Out.WriteLineAsync($"数据库类型: {_settingsManager.Database.DatabaseType.GetValue()}");
            //await Console.Out.WriteLineAsync($"连接字符串: {WebConfigUtils.ConnectionString}");
            //await Console.Out.WriteLineAsync($"备份文件夹: {treeInfo.DirectoryPath}");

            //var (isConnectionWorks, errorMessage) = await _settingsManager.Database.IsConnectionWorksAsync();
            //if (!isConnectionWorks)
            //{
            //    await CliUtils.PrintErrorAsync($"数据库连接错误:{errorMessage}");
            //    return;
            //}

            var(isConnectionWorks, errorMessage) = await _settingsManager.Database.IsConnectionWorksAsync();

            if (!isConnectionWorks)
            {
                await WriteUtils.PrintErrorAsync($"Unable to connect to database, error message:{errorMessage}");

                return;
            }

            if (_excludes == null)
            {
                _excludes = new List <string>();
            }
            _excludes.Add("bairong_Log");
            _excludes.Add("bairong_ErrorLog");
            _excludes.Add("siteserver_ErrorLog");
            _excludes.Add("siteserver_Log");
            _excludes.Add("siteserver_Tracking");

            var errorLogFilePath = CliUtils.DeleteErrorLogFileIfExists(CommandName, _settingsManager);

            await Backup(_settingsManager, _databaseManager, _includes, _excludes, _maxRows, treeInfo, errorLogFilePath);

            await WriteUtils.PrintRowLineAsync();

            await WriteUtils.PrintSuccessAsync("backup database to folder successfully!");
        }
Esempio n. 32
0
        public static void CreateExcelFileForTrackingContents(string filePath, string startDateString,
                                                              string endDateString, PublishmentSystemInfo publishmentSystemInfo, int nodeId, int contentId, int totalNum,
                                                              bool isDelete)
        {
            DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath));
            FileUtils.DeleteFileIfExists(filePath);

            var head = new List <string>
            {
                "目标页面",
                "上级栏目",
                "上上级栏目",
                "IP地址",
                "访问时间",
                "访问来源"
            };
            var rows = new List <List <string> >();

            var target      = string.Empty;
            var upChannel   = string.Empty;
            var upupChannel = string.Empty;

            if (contentId != 0)
            {
                var tableName = NodeManager.GetTableName(publishmentSystemInfo, nodeId);
                target    = BaiRongDataProvider.ContentDao.GetValue(tableName, contentId, ContentAttribute.Title);
                upChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, nodeId);
                if (nodeId != publishmentSystemInfo.PublishmentSystemId)
                {
                    upupChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId,
                                                          NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId, nodeId));
                }
            }

            var begin = DateUtils.SqlMinValue;

            if (!string.IsNullOrEmpty(startDateString))
            {
                begin = TranslateUtils.ToDateTime(startDateString);
            }
            var end = TranslateUtils.ToDateTime(endDateString);

            var ipAddresses =
                DataProvider.TrackingDao.GetContentIpAddressArrayList(publishmentSystemInfo.PublishmentSystemId, nodeId,
                                                                      contentId, begin, end);
            var trackingInfoArrayList =
                DataProvider.TrackingDao.GetTrackingInfoArrayList(publishmentSystemInfo.PublishmentSystemId, nodeId,
                                                                  contentId, begin, end);

            var ipAddressWithNumSortedList = new SortedList();

            foreach (string ipAddress in ipAddresses)
            {
                if (ipAddressWithNumSortedList[ipAddress] != null)
                {
                    ipAddressWithNumSortedList[ipAddress] = (int)ipAddressWithNumSortedList[ipAddress] + 1;
                }
                else
                {
                    ipAddressWithNumSortedList[ipAddress] = 1;
                }
            }

            foreach (TrackingInfo trackingInfo in trackingInfoArrayList)
            {
                if (contentId == 0)
                {
                    if (trackingInfo.PageContentId != 0)
                    {
                        var tableName = NodeManager.GetTableName(publishmentSystemInfo, trackingInfo.PageNodeId);
                        target = BaiRongDataProvider.ContentDao.GetValue(tableName, trackingInfo.PageContentId,
                                                                         ContentAttribute.Title);
                        upChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId,
                                                            trackingInfo.PageNodeId);
                        if (trackingInfo.PageNodeId != publishmentSystemInfo.PublishmentSystemId)
                        {
                            upupChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId,
                                                                  NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId,
                                                                                          trackingInfo.PageNodeId));
                        }
                    }
                    else if (trackingInfo.PageNodeId != 0)
                    {
                        target = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId,
                                                         trackingInfo.PageNodeId);
                        if (trackingInfo.PageNodeId != publishmentSystemInfo.PublishmentSystemId)
                        {
                            var upChannelId = NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId,
                                                                      trackingInfo.PageNodeId);
                            upChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, upChannelId);
                            if (upChannelId != publishmentSystemInfo.PublishmentSystemId)
                            {
                                upupChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId,
                                                                      NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId, upChannelId));
                            }
                        }
                    }
                }
                var ipAddress  = trackingInfo.IpAddress;
                var accessDate = trackingInfo.AccessDateTime.ToString(DateUtils.FormatStringDateTime);
                var referrer   = trackingInfo.Referrer;

                rows.Add(new List <string>
                {
                    target,
                    upChannel,
                    upupChannel,
                    ipAddress,
                    accessDate,
                    referrer
                });
            }

            CsvUtils.Export(filePath, head, rows);

            if (isDelete)
            {
                DataProvider.TrackingDao.DeleteAll(publishmentSystemInfo.PublishmentSystemId);
            }
        }
Esempio n. 33
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="path">string</param>
 /// <param name="globalConfiguration">Common.Config.GlobalConfiguration</param>
 public SignatureLoader(string path, Common.Config.GlobalConfiguration globalConfiguration, DirectoryUtils directoryUtils)
 {
     CurrentPath = path;
     this.globalConfiguration = globalConfiguration;
     DirectoryUtils           = directoryUtils;
 }
Esempio n. 34
0
 public void LastModTimeShouldReturnLastModDateOfDirectoryIfNoFiles()
 {
     var directoryUtils = new DirectoryUtils();
     Assert.That(directoryUtils.GetLastModTimeForDirectory(Dir), Is.EqualTo(new DateTime(2010, 5, 1)));
 }