public void NewTagCreationCreatesItsParagraphs()
        {
            var tag = new DocumentTag("TEST_TAG");

            Assert.NotNull(tag.Opening);
            Assert.Null(tag.Opening.Parent);
            Assert.NotNull(tag.Closing);
            Assert.Null(tag.Closing.Parent);
        }
Exemplo n.º 2
0
        public void AddDocumentToTag(Document document, Tag tag)
        {
            DocumentTag documentTag = new DocumentTag()
            {
                Document = document,
                Tag      = tag
            };

            document.DocumentTags.Add(documentTag);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新标签状态
        /// </summary>
        /// <param name="documentModel"></param>
        /// <returns></returns>
        public CommonResult UpdateState(int intDocumentUID, ItemState ItemState)
        {
            DocumentTag documentTag = db.DocumentTag.Where(d => d.UID == intDocumentUID).FirstOrDefault();

            documentTag.State = (int)ItemState;
            db.SaveChanges();
            //AllServices.ActionLogService.AddLog("更新项目信息",model.ToJson(),Enums.ActionCategory.Update);
            Log4NetHelper.Info("更新关联文件标签记录", "ID:" + intDocumentUID);
            return(CommonResult.Instance());
        }
Exemplo n.º 4
0
        public void ManyTagsGettingFromDocumentCorrect()
        {
            using (var document = new DocxDocument(Resources.WithManyTags))
            {
                var tags = DocumentTag.Get(document.GetWordDocument(), "SUB");

                Assert.NotNull(tags);
                Assert.AreEqual(3, tags.Count());
            }
        }
Exemplo n.º 5
0
        public DocxDocumentTagContextBuilder(WordprocessingDocument document, string tagName)
            : base(document)
        {
            _documentTags = DocumentTag.Get(document, tagName);

            foreach (DocumentTag documentTag in _documentTags)
            {
                ClearBetweenElements(documentTag.Opening, documentTag.Closing);
            }
            SaveDocument();
        }
Exemplo n.º 6
0
        public IDocumentTagContextBuilder AppendTag(string tagName, Action <IDocumentTagContextBuilder> options)
        {
            var tag = new DocumentTag(tagName);

            AppendElements(tag.Opening, tag.Closing);

            SaveDocument();

            options(new DocxDocumentTagContextBuilder(Document, tagName));
            return(this);
        }
        public async Task <BasicApiResponse <ReadDocumentTagResponse> > Handle(GetDocumentTagBySlugQuery query, CancellationToken cancellationToken)
        {
            DocumentTag tag = await _repository.FindBySlugAsync(_authenticatedUser.UserId, query.Slug);

            if (tag == null)
            {
                throw new ApiProblemDetailsException($"Record with slug: {query.Slug} does not exist.", StatusCodes.Status404NotFound);
            }

            ReadDocumentTagResponse dto = _mapper.Map <ReadDocumentTagResponse>(tag);

            return(new BasicApiResponse <ReadDocumentTagResponse>(dto));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 更新图片标签
        /// </summary>
        /// <param name="strTag"></param>
        /// <param name="intDocumentUID"></param>
        /// <returns></returns>
        public CommonResult UpdateTag(string strTag, int intDocumentUID)
        {
            var userModel = AllServices.UserService.GetUserBySession();

            DocumentTag documentTag = new DocumentTag();

            documentTag.UID         = AllServices.DocumentTagService.GetByDocumentUID(intDocumentUID).UID;
            documentTag.DocumentUID = intDocumentUID;
            documentTag.Tag         = strTag;
            documentTag.Editor      = userModel.UserName;
            documentTag.EditTime    = DateTime.Now;
            documentTag.State       = (int)ItemState.Enable;
            return(AllServices.DocumentTagService.Update(documentTag));
        }
Exemplo n.º 9
0
 public static DocumentTagModel ToDocumenTagModel(this DocumentTag dbDocumentTag)
 {
     return(new DocumentTagModel()
     {
         DocumentTagId = new DocumentTagId()
         {
             Value = dbDocumentTag.DocumentTagId
         },
         TagName = dbDocumentTag.TagName,
         Description = dbDocumentTag.Description,
         Created = dbDocumentTag.Created,
         Modified = dbDocumentTag.Modified,
         Deleted = dbDocumentTag.Deleted
     });
 }
Exemplo n.º 10
0
        ///<summary>
        /// Sets visibility for tag specified by <paramref name="tagName"/>
        ///</summary>
        ///<param name="tagName">Tag name</param>
        ///<param name="isVisible">Shows tag if set to true, otherwise hides it</param>
        public void SetTagVisibility(string tagName, bool isVisible)
        {
            var documentTags = DocumentTag.Get(_wordDocument, tagName);

            foreach (var documentTag in documentTags)
            {
                var paragraph = documentTag.Opening.NextSibling();
                while (paragraph as Paragraph != documentTag.Closing)
                {
                    SetVisibilityInParagraphProperty(paragraph, isVisible);

                    SetVisibilityInParagraphRuns(paragraph, isVisible);

                    paragraph = paragraph.NextSibling();
                }
            }
        }
Exemplo n.º 11
0
        public async Task AddTag(IDocument document, Tag tag)
        {
            Ensure.NotNull(document, $"{nameof(document)} cannot be null.");
            Ensure.NotNull(tag, $"{nameof(tag)} cannot be null.");

            var docTag = _db.DocumentTags.FirstOrDefault(x => x.TagName == tag.TagName && x.DocumentId == document.DocumentId);

            //If already added, return
            if (docTag != null)
            {
                return;
            }

            docTag = new DocumentTag
            {
                DocumentId = document.DocumentId,
                TagName    = tag.TagName
            };

            _db.DocumentTags.Add(docTag);
            await _db.SaveChangesAsync();
        }
Exemplo n.º 12
0
        public ActionResult UploadDetial()
        {
            int      intUID   = Request["UID"].ToInt32();
            Document document = AllServices.DocumentService.GetByUID(intUID);

            if (document != null)
            {
                DocumentTag           documentTag        = AllServices.DocumentTagService.GetByDocumentUID(document.UID);
                List <DocumentFolder> listDocumentFolder = AllServices.DocumentFolderService.GetByDocumentUID(document.UID);

                DataModel dataModel = new DataModel();
                dataModel.Add("Document", document);
                dataModel.Add("DocumentTag", documentTag);
                dataModel.Add("ListDocumentFolder", listDocumentFolder);
                ViewBag.CommonResult = CommonResult.Instance(1, null, dataModel).ToJson();
            }
            else
            {
                ViewBag.CommonResult = CommonResult.Instance().ToJson();
            }
            return(View("UploadDetial"));
        }
Exemplo n.º 13
0
        private Dictionary <string, DocumentTag> ParseTagRules(XmlNode tagAttributeListNode)
        {
            var         tags    = new Dictionary <string, DocumentTag>(StringComparer.InvariantCultureIgnoreCase);
            XmlNodeList tagList = tagAttributeListNode.SelectNodes("tag");

            foreach (XmlNode tagNode in tagList)
            {
                if (tagNode.NodeType == XmlNodeType.Element)
                {
                    string name   = tagNode.Attributes["name"]?.Value;
                    string action = tagNode.Attributes["action"]?.Value;

                    var tag = new DocumentTag(name, action);

                    XmlNodeList attributeList = tagNode.SelectNodes("attribute");
                    foreach (XmlNode attributeNode in attributeList)
                    {
                        if (IsCommonAttributeRule(attributeNode))
                        {
                            DocumentAttribute commonAttribute = GetCommonAttribute(attributeNode.Attributes["name"].Value);

                            if (commonAttribute != null)
                            {
                                string onInvalid   = attributeNode.Attributes["onInvalid"]?.Value;
                                string description = attributeNode.Attributes["description"]?.Value;
                                if (!string.IsNullOrEmpty(onInvalid))
                                {
                                    commonAttribute.OnInvalid = onInvalid;
                                }
                                if (!string.IsNullOrEmpty(description))
                                {
                                    commonAttribute.Description = description;
                                }

                                tag.AddAllowedAttribute((DocumentAttribute)commonAttribute.Clone());
                            }
                        }
                        else
                        {
                            var     allowedRegExps = new List <string>();
                            XmlNode regExpListNode = attributeNode.SelectNodes("regexp-list")[0];
                            if (regExpListNode != null)
                            {
                                XmlNodeList regExpList = regExpListNode.SelectNodes("regexp");
                                foreach (XmlNode regExpNode in regExpList)
                                {
                                    string regExpName = regExpNode.Attributes["name"]?.Value;
                                    string value      = regExpNode.Attributes["value"]?.Value;
                                    if (!string.IsNullOrEmpty(regExpName))
                                    {
                                        //AntiSamyPattern pattern = getRegularExpression(regExpName);
                                        string pattern = GetRegularExpression(regExpName);
                                        if (pattern != null)
                                        {
                                            allowedRegExps.Add(pattern);
                                        }

                                        //attribute.addAllowedRegExp(pattern.Pattern);
                                        else
                                        {
                                            throw new PolicyException("Regular expression '" + regExpName + "' was referenced as a common regexp in definition of '" + tag.Name + "', but does not exist in <common-regexp>");
                                        }
                                    }
                                    else if (!string.IsNullOrEmpty(value))
                                    {
                                        allowedRegExps.Add(RegexpBegin + value + RegexpEnd);
                                    }
                                }
                            }

                            var     allowedValues   = new List <string>();
                            XmlNode literalListNode = attributeNode.SelectNodes("literal-list")[0];
                            if (literalListNode != null)
                            {
                                XmlNodeList literalNodes = literalListNode.SelectNodes("literal");
                                foreach (XmlNode literalNode in literalNodes)
                                {
                                    string value = literalNode.Attributes["value"]?.Value;
                                    if (!string.IsNullOrEmpty(value))
                                    {
                                        allowedValues.Add(value);
                                    }
                                    else if (literalNode.Value != null)
                                    {
                                        allowedValues.Add(literalNode.Value);
                                    }
                                }
                            }

                            /* Custom attribute for this tag */
                            var attribute = new DocumentAttribute(attributeNode.Attributes["name"].Value,
                                                                  allowedRegExps,
                                                                  allowedValues,
                                                                  attributeNode.Attributes["onInvalid"]?.Value,
                                                                  attributeNode.Attributes["description"]?.Value);
                            tag.AddAllowedAttribute(attribute);
                        }
                    }

                    tags.Add(name, tag);
                }
            }
            return(tags);
        }
Exemplo n.º 14
0
        public void NewTagOpeningTagNameShoulbBeEnclosedInWavedBrackets()
        {
            var tag = new DocumentTag("TEST_TAG");

            Assert.AreEqual("{TEST_TAG}", tag.OpeningName);
        }
Exemplo n.º 15
0
        public void NewTagClosingTagNameShouldBeEnclosedInWavedBracketsWithSlash()
        {
            var tag = new DocumentTag("TEST_TAG");

            Assert.Equal("{/TEST_TAG}", tag.ClosingName);
        }
        public IDocumentTagContextBuilder AppendTag(string tagName, Action<IDocumentTagContextBuilder> options)
        {
            var tag = new DocumentTag(tagName);

            AppendElements(tag.Opening, tag.Closing);

            SaveDocument();

            options(new DocxDocumentTagContextBuilder(Document, tagName));
            return this;
        }
Exemplo n.º 17
0
        public void NewTagClosingTagNameShouldBeEnclosedInWavedBracketsWithSlash()
        {
            var tag = new DocumentTag("TEST_TAG");

            Assert.AreEqual("{/TEST_TAG}", tag.ClosingName);
        }
Exemplo n.º 18
0
        public void NewTagNameShouldBeCorrect()
        {
            var tag = new DocumentTag("TEST_TAG");

            Assert.Equal("TEST_TAG", tag.Name);
        }
Exemplo n.º 19
0
        public void CreateDocumentTag()
        {
            DocumentTag newDocTag = new DocumentTag();

            using (var uow = new XbtContext())
            {
                var repoDocGroup = new GenericRepository <DocumentGroup>(uow);

                var newDocumentGroup = new DocumentGroup()
                {
                    Name        = "Credit Documents",
                    Description = "Documents used in the credit department"
                };

                repoDocGroup.Insert(newDocumentGroup);

                //Retrieve Inserted document

                var insertedDocumentGroup = repoDocGroup.GetById(newDocumentGroup.Id);

                var repoDocType = new GenericRepository <DocumentType>(uow);

                var newDocumentType = new DocumentType()
                {
                    Name              = "Document Type 3",
                    Description       = "Document type description 3",
                    DocumentGroup     = insertedDocumentGroup,
                    DocumentDirectory = @"\TestDocuments",
                };

                repoDocType.Insert(newDocumentType);

                var repoDocTag = new GenericRepository <DocumentTag>(uow);

                var insertedDocumentType = repoDocType.GetById(newDocumentType.Id);

                newDocTag.Name          = "New Doc Tag";
                newDocTag.Description   = "New Doc Tag Description";
                newDocTag.DocumentTypes = new List <DocumentType>()
                {
                    insertedDocumentType
                };

                repoDocTag.Insert(newDocTag);
                try
                {
                    uow.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //Retrieve validation errors
                    ex.EntityValidationErrors.ToList().ForEach
                    (
                        v =>
                    {
                        v.ValidationErrors.ToList().ForEach
                        (
                            e =>
                        {
                            System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                        }
                        );
                    }
                    );

                    //If we have reached here the test has failed
                    Assert.Fail("Test failed");
                }
            }

            //Retreive the modified document tag using a new unit of work and repository
            //to ensure values are retreived from database instead of in memory graph
            var uowDoctag = new XbtContext();

            var repoExistingDocTag   = new GenericRepository <DocumentTag>(uowDoctag);
            var retrievedDocumentTag = repoExistingDocTag.Get().FirstOrDefault();

            Assert.AreEqual(retrievedDocumentTag.Name, newDocTag.Name);
        }
Exemplo n.º 20
0
        public void NewTagNameShouldBeCorrect()
        {
            var tag = new DocumentTag("TEST_TAG");

            Assert.AreEqual("TEST_TAG", tag.Name);
        }
Exemplo n.º 21
0
        public void NewTagOpeningTagNameShoulbBeEnclosedInWavedBrackets()
        {
            var tag = new DocumentTag("TEST_TAG");

            Assert.Equal("{TEST_TAG}", tag.OpeningName);
        }
Exemplo n.º 22
0
 public async Task <DocumentTag> Update(DocumentTag documentTag)
 {
     return(await _documentTagRepository.Update(documentTag));
 }