Пример #1
0
        public IDictionary <int, string> ClonePubArchive(int sourceSiteId, int targetSiteId, int toCid, int[] archiveIdArray, bool includeExtend, bool includeTempateBind, bool includeRelatedLink)
        {
            int totalFailed  = 0;
            int totalSuccess = 0;

            IDictionary <int, string> errDict = new Dictionary <int, string>();
            bool isFailed;
            bool shouldReSave;

            IContentContainer srcContent = this._contentRep.GetContent(sourceSiteId);
            IContentContainer tarContent = this._contentRep.GetContent(targetSiteId);

            foreach (int archiveId in archiveIdArray)
            {
                IArchive srcArchive = srcContent.GetArchiveById(archiveId);
                IArchive tarArchive = this.CopyArchive(targetSiteId, toCid, srcArchive);

                isFailed     = false;
                shouldReSave = false;

                if (includeTempateBind && srcArchive.Template != null &&
                    srcArchive.Template.BindType == TemplateBindType.ArchiveTemplate &&
                    !string.IsNullOrEmpty(srcArchive.Template.TplPath))
                {
                    tarArchive.SetTemplatePath(srcArchive.Template.TplPath);
                    shouldReSave = true;
                }

                //克隆扩展
                if (includeExtend)
                {
                    this.CloneArchiveExtendValue(srcArchive, tarArchive, errDict, ref isFailed,
                                                 ref shouldReSave);
                }
                //包含关联链接
                if (includeRelatedLink)
                {
                    this.CloneArchiveRelatedLink(srcArchive, tarArchive);
                }

                if (isFailed)
                {
                    this._archiveRep.DeleteArchive(targetSiteId, tarArchive.GetAggregaterootId());
                    totalFailed += 1;
                }
                else if (shouldReSave)
                {
                    tarArchive.Save();
                    totalSuccess += 1;
                }
            }

            return(errDict);
        }
Пример #2
0
        public ArchiveDto GetArchiveById(int siteId, int archiveId)
        {
            IContentContainer ic      = this._contentRep.GetContent(siteId);
            IArchive          archive = ic.GetArchiveById(archiveId);

            if (archive == null)
            {
                return(default(ArchiveDto));
            }
            return(ArchiveDto.ConvertFrom(archive, true, true, true));
        }
Пример #3
0
        public DataTransfer.Result SaveArchive(int siteId, int catId, ArchiveDto archiveDto)
        {
            CmsArchiveEntity value = archiveDto.ToArchiveEntity();

            value.CatId  = catId;
            value.SiteId = siteId;
            IContentContainer ic = this._contentRep.GetContent(siteId);
            IArchive          ia;

            if (archiveDto.Id <= 0)
            {
                ia = ic.CreateArchive(new CmsArchiveEntity());
            }
            else
            {
                ia = ic.GetArchiveById(archiveDto.Id);
            }

            Error err = ia.Set(value);

            if (err == null)
            {
                // 更新模板
                if (!String.IsNullOrEmpty(archiveDto.TemplatePath))
                {
                    ia.SetTemplatePath(archiveDto.TemplatePath);
                }
                // 设置扩展属性
                err = ia.SetExtendValue(archiveDto.ExtendValues);
                // 保存文档
                if (err == null)
                {
                    err = ia.Save();
                }
            }
            DataTransfer.Result r = new DataTransfer.Result();
            if (err == null)
            {
                r.Data = new Dictionary <String, String>();
                r.Data.Add("ArchiveId", ia.GetAggregaterootId().ToString());
            }
            else
            {
                r.ErrCode = 1;
                r.ErrMsg  = err.Message;
            }
            return(r);
        }
Пример #4
0
        public int SaveArchive(int siteId, ArchiveDto archiveDto)
        {
            IContentContainer ic = this._contentRep.GetContent(siteId);
            IArchive          archive;

            if (archiveDto.Id <= 0)
            {
                archive = ic.CreateArchive(-1, archiveDto.StrId, archiveDto.Category.Id, archiveDto.Title);
            }
            else
            {
                archive = ic.GetArchiveById(archiveDto.Id);

                //修改栏目
                if (archiveDto.Category.Id != archive.Category.Id)
                {
                    ISite site = this._siteRep.GetSiteById(siteId);
                    archive.Category = site.GetCategory(archiveDto.Category.Id);
                }
            }


            archive.LastModifyDate = DateTime.Now;
            archive.Content        = archiveDto.Content;
            archive.Alias          = archiveDto.Alias;
            archive.Author         = archiveDto.Author;
            archive.Flags          = archiveDto.Flags;
            archive.Outline        = archiveDto.Outline;
            archive.Source         = archiveDto.Source;
            archive.Tags           = archiveDto.Tags;
            archive.Thumbnail      = archiveDto.Thumbnail;
            archive.Title          = archiveDto.Title;
            archive.SmallTitle     = archiveDto.SmallTitle;
            archive.Location       = archiveDto.Location;
            archive.ExtendValues   = archiveDto.ExtendValues;

            //只更新自己的模板
            if (archiveDto.IsSelfTemplate ||
                (archive.Id == -1 && !String.IsNullOrEmpty(archiveDto.TemplatePath))
                )
            {
                archive.UpdateTemplateBind(archiveDto.TemplatePath);
            }

            return(archive.Save());
        }
Пример #5
0
        public IDictionary <int, string> ClonePubArchive(int sourceSiteId, int targetSiteId, int toCid, int[] archiveIdArray, bool includeExtend, bool includeTempateBind, bool includeRelatedLink)
        {
            int totalFailed  = 0;
            int totalSuccess = 0;

            IDictionary <int, string> errDict = new Dictionary <int, string>();
            bool isFailed;
            bool shouldReSave;

            IContentContainer srcContent = this._contentRep.GetContent(sourceSiteId);
            IContentContainer tarContent = this._contentRep.GetContent(targetSiteId);

            foreach (int archiveId in archiveIdArray)
            {
                var srcArchive = srcContent.GetArchiveById(archiveId);

                var tarArchive = tarContent.CreateArchive(0, IdGenerator.GetNext(5), toCid, srcArchive.Title);

                tarArchive.CreateDate     = DateTime.Now;
                tarArchive.LastModifyDate = tarArchive.CreateDate;
                tarArchive.Content        = srcArchive.Content;
                tarArchive.Alias          = srcArchive.Alias;
                tarArchive.PublisherId    = srcArchive.PublisherId;
                tarArchive.Flags          = srcArchive.Flags;
                tarArchive.Outline        = srcArchive.Outline;
                tarArchive.Source         = srcArchive.Source;
                tarArchive.Tags           = srcArchive.Tags;
                tarArchive.Location       = srcArchive.Location;
                tarArchive.Thumbnail      = srcArchive.Thumbnail;
                tarArchive.SmallTitle     = srcArchive.SmallTitle;
                tarArchive.ViewCount      = srcArchive.ViewCount;

                isFailed     = false;
                shouldReSave = false;
                if (tarArchive.Save() > 0)
                {
                    if (includeTempateBind && srcArchive.Template != null &&
                        srcArchive.Template.BindType == TemplateBindType.ArchiveTemplate &&
                        !string.IsNullOrEmpty(srcArchive.Template.TplPath))
                    {
                        tarArchive.SetTemplatePath(srcArchive.Template.TplPath);
                        shouldReSave = true;
                    }

                    //克隆扩展
                    if (includeExtend)
                    {
                        this.CloneArchiveExtendValue(srcArchive, tarArchive, errDict, ref isFailed,
                                                     ref shouldReSave);
                    }

                    //包含关联链接
                    if (includeRelatedLink)
                    {
                        this.CloneArchiveRelatedLink(srcArchive, tarArchive);
                    }

                    if (isFailed)
                    {
                        this._archiveRep.DeleteArchive(targetSiteId, tarArchive.Id);
                    }
                    else if (shouldReSave)
                    {
                        tarArchive.Save();
                    }
                }

                if (isFailed)
                {
                    totalFailed += 1;
                }
                else
                {
                    totalSuccess += 1;
                }
            }

            return(errDict);
        }