Esempio n. 1
0
        public void ImportContentsByTxtZipFile(int nodeId, 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 = NodeManager.GetNodeInfo(Fso.PublishmentSystemId, nodeId);

            var contentInfoArrayList = TxtObject.GetContentsByTxtFile(directoryPath, Fso.PublishmentSystemInfo, nodeInfo);

            if (importStart > 1 || importCount > 0)
            {
                var theArrayList = new ArrayList();

                if (importStart == 0)
                {
                    importStart = 1;
                }
                if (importCount == 0)
                {
                    importCount = contentInfoArrayList.Count;
                }

                var firstIndex = contentInfoArrayList.Count - importStart - importCount + 1;
                if (firstIndex <= 0)
                {
                    firstIndex = 0;
                }

                var addCount = 0;
                for (var i = 0; i < contentInfoArrayList.Count; i++)
                {
                    if (addCount >= importCount)
                    {
                        break;
                    }
                    if (i >= firstIndex)
                    {
                        theArrayList.Add(contentInfoArrayList[i]);
                        addCount++;
                    }
                }

                contentInfoArrayList = theArrayList;
            }

            var tableName = NodeManager.GetTableName(Fso.PublishmentSystemInfo, nodeInfo);

            foreach (BackgroundContentInfo contentInfo in contentInfoArrayList)
            {
                contentInfo.IsChecked    = isChecked;
                contentInfo.CheckedLevel = checkedLevel;

                //int contentID = DataProvider.ContentDAO.Insert(tableName, this.FSO.PublishmentSystemInfo, contentInfo);

                if (isOverride)
                {
                    var existsIDs = DataProvider.ContentDao.GetIdListBySameTitleInOneNode(tableName, contentInfo.NodeId, contentInfo.Title);
                    if (existsIDs.Count > 0)
                    {
                        foreach (int id in existsIDs)
                        {
                            contentInfo.Id = id;
                            DataProvider.ContentDao.Update(tableName, Fso.PublishmentSystemInfo, contentInfo);
                        }
                    }
                    else
                    {
                        contentInfo.Id = DataProvider.ContentDao.Insert(tableName, Fso.PublishmentSystemInfo, contentInfo);
                    }
                }
                else
                {
                    contentInfo.Id = DataProvider.ContentDao.Insert(tableName, Fso.PublishmentSystemInfo, contentInfo);
                }

                //this.FSO.AddContentToWaitingCreate(contentInfo.NodeID, contentID);
            }
        }