/// <summary>
        /// Returns a list of content revisions.
        /// </summary>
        /// <param name="contentID">the ID of the content to load</param>
        /// <param name="siteID">the site ID of the content</param>
        /// <returns>a list of revision objects</returns>
        public IList <IContentRevision> GetContentRevisions(Guid contentID, int siteID)
        {
            var list = new List <IContentRevision>();

            using (SqlConnection conn = (SqlConnection)_factory.GetConnection())
            {
                SqlCommand comm = (SqlCommand)_factory.GetCommand("GetRevisionsForContent");
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue("@contentID", contentID);
                comm.Parameters.AddWithValue("@siteID", siteID);
                try
                {
                    conn.Open();
                    var reader = comm.ExecuteReader();
                    while (reader.Read())
                    {
                        var cRow = new ContentRevision
                        {
                            VersionID = reader.GetGuid(0),
                            ContentID = contentID,
                            IsLive    = reader.GetBoolean(1),
                            TimeStamp = reader.GetDateTime(2)
                        };
                        list.Add(cRow);
                    }
                }
                finally
                {
                    conn.Close();
                }
            }
            return(list);
        }
Ejemplo n.º 2
0
        public IContentRevision LoadRevision(Guid revisionID)
        {
            // handle loading a revision here
            IContentRevision r = new ContentRevision();

            return(r);
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Saves an entry for this piece of content.
    /// </summary>
    private void SaveNewContent()
    {
        IContentEntity   e = new ContentEntity();
        IContentRevision r = new ContentRevision();

        FillEntity(e);
        FillRevision(e, r);

        var rows = new List <ContentRow>();

        FillContentRows(r, rows);

        _content.SaveEntity(e);
        _content.SaveRevision(r);
        _content.SaveRows(r, rows);

        Response.Redirect("/admin/content.aspx");
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Snapshot을 SnapshotDTO를 통해서 Create 하는 함수
        /// </summary>
        /// <param name="req">
        /// SnapshotDTO
        /// </param>
        /// <returns></returns>
        public EnvelopeDTO <SnapshotDTO> Any(SnapshotCreateRequestDTO req)
        {
            // 단정하기.
            Debug.Assert(req.Snapshot.Id == 0);
            Debug.Assert(req.Snapshot.ContentRevisions != null);

            var Snapshot = req.Snapshot;

            using (var entities = new CrawlerStorage())
            {
                try
                {
                    // 가장 최근의 TimePeriod를 가져온다.
                    var timeperiod = entities.TimePeriods.OrderByDescending(t => t.Scheduled).FirstOrDefault();

                    var snapshot = new Snapshot
                    {
                        For_Timeperiod = timeperiod.Id,
                        Taken          = Snapshot.Taken,
                        For_BoardId    = Snapshot.For_BoardId
                    };

                    entities.Snapshots.Add(snapshot);

                    // 해당하는 boardId의 가장 최근의 Snapshot을 가져온다.
                    var LastSnapshot = entities.Snapshots.Where(p => p.For_BoardId == Snapshot.For_BoardId).OrderByDescending(t => t.Id).FirstOrDefault();
                    if (LastSnapshot != null)
                    {
                        foreach (var eachCurrentRevision in Snapshot.ContentRevisions)
                        {
                            foreach (var eachLastRevision in LastSnapshot.SnapshotToContentRevisions)
                            {
                                if (eachCurrentRevision.CheckSum.Equals(eachLastRevision.ContentRevision.CheckSum))
                                {
                                    eachCurrentRevision.id = eachLastRevision.ContentRevision.Id;
                                }
                            }
                        }
                    }


                    int         contentseq = 0;
                    List <long> sizelist   = new List <long>();

                    if (Snapshot.ContentRevisions == null)
                    {
                        return(Fail <SnapshotDTO>("발생하면 안됨."));
                    }

                    foreach (var contentRevision in Snapshot.ContentRevisions)
                    {
                        // 이미 뭔가 있는 상황
                        if (contentRevision.id != 0)
                        {
                            var snapshotTocontentrevision = new SnapshotToContentRevision
                            {
                                Has_ContentRevisionId = contentRevision.id,
                                Seqno    = ++contentseq,
                                Snapshot = snapshot
                            };

                            entities.SnapshotToContentRevisions.Add(snapshotTocontentrevision);
                            continue;
                        }

                        // snapshotcontentrevision.id -> snapshotcontentrevision가 DB에 있었던 정보인지 아닌지 판단함

                        var newContentRevision = new ContentRevision
                        {
                            Details        = contentRevision.Details,
                            Details_Html   = contentRevision.Details_Html,
                            Crawled        = contentRevision.Crawled,
                            RecommandCount = contentRevision.recommandCount,
                            ViewCount      = contentRevision.viewCount,
                            CheckSum       = contentRevision.CheckSum
                        };

                        var contentChecksum = Convert.ToBase64String(HashHelper.ObjectToMD5Hash(contentRevision.Content.Url_Params));

                        var existingContent = entities.Contents.SingleOrDefault(p => p.CheckSum.Equals(contentChecksum));

                        var content = existingContent == null ? new Content
                        {
                            Article      = contentRevision.Content.Article,
                            Contents_URL = contentRevision.Content.Contents_URL,
                            ContentGuId  = Guid.NewGuid(),
                            Url_Params   = contentRevision.Content.Url_Params,
                            CheckSum     = Convert.ToBase64String(HashHelper.ObjectToMD5Hash(contentRevision.Content.Url_Params))
                        } : existingContent;

                        // 글 중에서 그림이 없는 글이 있을 수 있으므로 그림 여부 판단 -> 없으면 if문 해당 안되므로 저장을 안함.
                        if (contentRevision.SrcDatas != null)
                        {
                            foreach (var data in contentRevision.SrcDatas)
                            {
                                // 그림 데이터 중에서 originalpayload가 없는 경우, commonCrawler에서 다운로드 이미지 하는 부분에서 isDepricated 변수가 true로 넘어오므로 판단할 수 있다.

                                if (data == null || data.OriginalPayload == null)
                                {
                                    continue;
                                }

                                var srcdataChecksum = Convert.ToBase64String(HashHelper.ObjectToMD5Hash(data.OriginalPayload));

                                var existingSrcdataId = entities.Srcdatas.Where(s => s.CheckSum.Equals(srcdataChecksum)).Select(s => s.Id).FirstOrDefault();

                                // ExistSrcdata는 기존 DB에서 가지고 있던 Srcdata 이미지와 중복되는지 여부를 판단 해준다.
                                if (existingSrcdataId == 0)
                                {
                                    var srcdata = new Srcdata {
                                        SrcGuId              = Guid.NewGuid(),
                                        Original_SourceUrl   = data.SourceUrl,
                                        Content              = content,
                                        FileName             = data.FileName,
                                        OriginalPayload      = data.OriginalPayload,
                                        OriginalPayload_Size = data.OriginalPayload_Size,
                                        CheckSum             = srcdataChecksum
                                    };

                                    entities.Srcdatas.Add(srcdata);
                                }
                            }
                        }
                        newContentRevision.Content = content;
                        entities.ContentRevisions.Add(newContentRevision);
                        entities.SnapshotToContentRevisions.Add(new SnapshotToContentRevision
                        {
                            ContentRevision = newContentRevision,
                            Snapshot        = snapshot,
                            Seqno           = ++contentseq,
                        });
                    }
                    try
                    {
                        entities.SaveChanges();
                        return(Succeeded(new SnapshotDTO()));
                    }
                    catch (Exception e)
                    {
                        return(null);
                    }
                }

                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           validationErrors.Entry.Entity.ToString(),
                                                           validationError.ErrorMessage);
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    throw raise;
                }
            }
        }