예제 #1
0
        public override void OnFileSaved()
        {
            base.OnFileSaved();

            if (!UserConnection.GetIsFeatureEnabled("LinkPreview"))
            {
                return;
            }

            var fileType = Entity.GetTypedColumnValue <Guid>("TypeId");

            if (fileType == Terrasoft.WebApp.FileConsts.LinkTypeUId)
            {
                var url = Entity.GetTypedColumnValue <string>("Name").Trim();
                if (IsURLValid(url))
                {
                    LinkPreview     linkPreview     = new LinkPreview();
                    LinkPreviewInfo linkPreviewInfo = linkPreview.GetWebPageLinkPreview(url);
                    if (linkPreviewInfo != null)
                    {
                        LinkPreviewProvider linkPreviewProvider = new LinkPreviewProvider(UserConnection);
                        linkPreviewProvider.SaveLinkPreviewInfo(linkPreviewInfo, Entity.PrimaryColumnValue);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Save link preview info by entity record id.
        /// </summary>
        /// <param name="linkPreviewInfo">Link preview info.</param>
        /// <param name="entityRecordId">Entity record id.</param>
        /// <returns>New link preview info record id.</returns>
        public Guid SaveLinkPreviewInfo(LinkPreviewInfo linkPreviewInfo, Guid entityRecordId)
        {
            string data   = JsonConvert.SerializeObject(linkPreviewInfo);
            Guid   id     = Guid.NewGuid();
            var    insert =
                new Insert(_userConnection)
                .Into(_linkPreviewDataEntityName)
                .Set("Id", Column.Parameter(id))
                .Set("Url", Column.Parameter(linkPreviewInfo.Url))
                .Set("EntityId", Column.Parameter(entityRecordId))
                .Set("Data", Column.Parameter(Encoding.UTF8.GetBytes(data)));

            insert.Execute();
            return(id);
        }