public void ImportContentsByTxtZipFile(int channelId, string zipFilePath, bool isOverride, int importStart, int importCount, bool isChecked, int checkedLevel) { var directoryPath = PathUtils.GetTemporaryFilesPath("contents"); DirectoryUtils.DeleteDirectoryIfExists(directoryPath); DirectoryUtils.CreateDirectoryIfNotExists(directoryPath); ZipUtils.UnpackFiles(zipFilePath, directoryPath); var nodeInfo = ChannelManager.GetChannelInfo(_siteInfo.Id, channelId); var contentInfoList = TxtObject.GetContentListByTxtFile(directoryPath, _siteInfo, nodeInfo); if (importStart > 1 || importCount > 0) { var theList = new List <ContentInfo>(); if (importStart == 0) { importStart = 1; } if (importCount == 0) { importCount = contentInfoList.Count; } var firstIndex = contentInfoList.Count - importStart - importCount + 1; if (firstIndex <= 0) { firstIndex = 0; } var addCount = 0; for (var i = 0; i < contentInfoList.Count; i++) { if (addCount >= importCount) { break; } if (i >= firstIndex) { theList.Add(contentInfoList[i]); addCount++; } } contentInfoList = theList; } var tableName = ChannelManager.GetTableName(_siteInfo, nodeInfo); foreach (var contentInfo in contentInfoList) { contentInfo.IsChecked = isChecked; contentInfo.CheckedLevel = checkedLevel; //int contentID = DataProvider.ContentDAO.Insert(tableName, this.FSO.SiteInfo, contentInfo); if (isOverride) { var existsIDs = DataProvider.ContentDao.GetIdListBySameTitle(tableName, contentInfo.ChannelId, contentInfo.Title); if (existsIDs.Count > 0) { foreach (int id in existsIDs) { contentInfo.Id = id; DataProvider.ContentDao.Update(tableName, _siteInfo, contentInfo); } } else { contentInfo.Id = DataProvider.ContentDao.Insert(tableName, _siteInfo, contentInfo); } } else { contentInfo.Id = DataProvider.ContentDao.Insert(tableName, _siteInfo, contentInfo); } //this.FSO.AddContentToWaitingCreate(contentInfo.ChannelId, contentID); } }
public async Task ImportContentsByTxtZipFileAsync(int channelId, string zipFilePath, bool isOverride, int importStart, int importCount, bool isChecked, int checkedLevel) { var directoryPath = _pathManager.GetTemporaryFilesPath("contents"); DirectoryUtils.DeleteDirectoryIfExists(directoryPath); DirectoryUtils.CreateDirectoryIfNotExists(directoryPath); _pathManager.ExtractZip(zipFilePath, directoryPath); var channelInfo = await _databaseManager.ChannelRepository.GetAsync(channelId); var contentInfoList = TxtObject.GetContentListByTxtFile(directoryPath, _site, channelInfo); if (importStart > 1 || importCount > 0) { var theList = new List <Content>(); if (importStart == 0) { importStart = 1; } if (importCount == 0) { importCount = contentInfoList.Count; } var firstIndex = contentInfoList.Count - importStart - importCount + 1; if (firstIndex <= 0) { firstIndex = 0; } var addCount = 0; for (var i = 0; i < contentInfoList.Count; i++) { if (addCount >= importCount) { break; } if (i >= firstIndex) { theList.Add(contentInfoList[i]); addCount++; } } contentInfoList = theList; } foreach (var contentInfo in contentInfoList) { contentInfo.Checked = isChecked; contentInfo.CheckedLevel = checkedLevel; //int contentID = _databaseManager.ContentDAO.Insert(tableName, this.FSO.Site, contentInfo); if (isOverride) { var existsIDs = await _databaseManager.ContentRepository.GetContentIdsBySameTitleAsync(_site, channelInfo, contentInfo.Title); if (existsIDs.Count > 0) { foreach (int id in existsIDs) { contentInfo.Id = id; await _databaseManager.ContentRepository.UpdateAsync(_site, channelInfo, contentInfo); } } else { contentInfo.Id = await _databaseManager.ContentRepository.InsertAsync(_site, channelInfo, contentInfo); } } else { contentInfo.Id = await _databaseManager.ContentRepository.InsertAsync(_site, channelInfo, contentInfo); } //this.FSO.AddContentToWaitingCreate(contentInfo.ChannelId, contentID); } }