private WordRange GetNextEntry(WordRange range)
 {
     return range.Find(TagName, false, true);
 }
 private WordRange GetNextEntry(WordRange range, string tagName)
 {
     return range.Find(tagName, false, true);
 }
        protected override void ApplyEntry(WordRange range, object source)
        {
            var product = source as IProduct;

            if (product == null)
                return;

            string text = range.Text;
            string argument = GetArgumentName(text);

            if (string.IsNullOrEmpty(argument))
                return;

            string line = ComposeLine(product, argument);

            if (line == null)
                return;

            if (string.Equals(argument, "title", StringComparison.InvariantCultureIgnoreCase))
            {
                range.AddHyperLink(product.Url, line);
            }
            else
            {
                InsertLines(range, new string[] { line });
            }
        }
 private void DeleteTag(WordRange range, string tag)
 {
     string[] stringsToDelete = {tag + "^13", tag};
     for (int i = 0; i < stringsToDelete.Length; i++)
     {
         if (range.Delete(stringsToDelete[i]));
     }
 }
 private static void AddBookmark(object item, WordRange nextEntry)
 {
     var bookmark = item as IBookmark;
     if (bookmark != null)
     {
         nextEntry.AddBookmark(bookmark.BookmarkName);
     }
 }
        public void Apply(WordRange range, object source)
        {
            foreach (IReplacement replacement in Replacements)
            {
                replacement.Apply(range, source);
            }
            foreach (KeyValuePair<string, ReplacementsTree> entry in _subRanges)
            {
                string tagName = entry.Key;
                WordRange nextEntry = GetNextEntry(range, tagName);
                int index = 0;
                ReplacementsTree replacementsTree = entry.Value;
                IList<object> items = replacementsTree.GetItems(source);
                while (nextEntry != null)
                {
                    if (items.Count == 0)
                    {
                        nextEntry.Replace(tagName, string.Empty);
                    }
                    else
                    {
                        if (index < items.Count)
                        {
                            if (index < items.Count - 1)
                            {
                                nextEntry.InsertAfter(nextEntry);
                            }
                            object item = items[index];
                            replacementsTree.Apply(nextEntry, item);

                            AddBookmark(item, nextEntry);
                            index++;

                            if (index == items.Count)
                            {
                                index = 0;
                            }
                        }

                        WordRange expandedRange = nextEntry.GetExpandedRange(0, 1);
                        string expandedText = expandedRange.Text;
                        if (!(expandedText.Length > nextEntry.Text.Length && expandedText[expandedText.Length - 1] == '\r'))
                        {
                            expandedRange = nextEntry;
                        }
                        string[] tags = tagName.Split('*');
                        for (int i = 0; i < tags.Length; i++)
                        {
                            DeleteTag(expandedRange, tags[i]);
                        }
                    }
                    nextEntry = GetNextEntry(range, tagName);
                }
            }
            
        }
 public void Apply(WordRange range, object source)
 {
     WordRange nextEntry = GetNextEntry(range);
     while (nextEntry != null)
     {
         ApplyEntry(nextEntry, source);
         ClearoutPatternEntries(nextEntry);
         nextEntry = GetNextEntry(range);
     }
 }
        protected void InsertLines(WordRange range, string[] lines)
        {
            if (lines == null || lines.Length == 0)
                return;

            int linesCount = lines.Length;
            for (int i = 0; i < linesCount - 1; i++)
            {
                range.InsertAfter(lines[i] + "\n");
            }

            range.InsertAfter(lines[linesCount - 1]);
        }
        protected override void ApplyEntry(WordRange range, object source)
        {
            var product = source as IProduct;

            if (product != null)
            {
                if (!string.IsNullOrEmpty(product.ImageFileName))
                {
                    if (File.Exists(product.ImageFileName))
                    {
                        range.InsertPicture(product.ImageFileName);
                    }
                }
            }
        }
Beispiel #10
0
 public void InsertAfter(WordRange wordRange)
 {
     Range newRange = GetNextRange();
     newRange.FormattedText = wordRange._range;
 }
 protected override void ApplyEntry(WordRange range, object source)
 {
     var category = (ICategory) source;
     InsertLines(range, new string[] {category.CategoryName});
 }
 protected override void ApplyEntry(WordRange range, object source)
 {
     InsertLines(range, new string[] {DateTime.Now.ToString("dd.MM.yyyy")});
 }
Beispiel #13
0
        public void InsertAfter(WordRange wordRange)
        {
            Range newRange = GetNextRange();

            newRange.FormattedText = wordRange._range;
        }
 protected override void ApplyEntry(WordRange range, object source)
 {
     InsertLines(range, new string[] { DateTime.Now.ToString("dd MMMM yyyy г", CultureInfo.GetCultureInfo("RU-ru")) });
 }
 private void ClearoutPatternEntries(WordRange range)
 {
     range.Replace(TagName, string.Empty);
 }
 protected override void ApplyEntry(WordRange range, object source)
 {
     var section = (Section) source;
     InsertLines(range, new string[] {section.SectionName});
 }
 protected abstract void ApplyEntry(WordRange range, object source);