public bool AddArchive(string archive_path)
 {
     if (archive_path != null && File.Exists(archive_path))
     {
         try
         {
             using (var arc = ArchiveFactory.Open(archive_path))
             {
                 if (arc.Entries != null)
                 {
                     foreach (var entry in arc.Entries)
                     {
                         var itm_info = new ListItemInfo(
                             archive_path,
                             entry.FilePath,
                             entry.Size,
                             entry.IsDirectory ? "Archive/Directory" : "Archive/File",
                             entry.IsDirectory,
                             !entry.IsDirectory,
                             true);
                         this.AddToList(itm_info);
                     }
                 }
             }
             return(true);
         }
         catch (Exception) { return(false); }
     }
     return(false);
 }
Exemplo n.º 2
0
        public void AddList(ListItemInfo list)
        {
            try
            {
                list.Name = list.Name.Trim();

                ObjectPersistence persistence = new ObjectPersistence(DbAccess);
                Criteria cri = new Criteria();
                cri.Add(Expression.Equal("Name", list.Name));
                if (!string.IsNullOrEmpty(list.Id))
                {
                    cri.Add(Expression.NotEqual("Id", list.Id));
                }
                IList<ListItemInfo> tmpList = persistence.GetList<ListItemInfo>(cri);
                if (tmpList.Count > 0)
                {
                    throw new FacadeException("列表名称已经存在,请重新输入!");
                }
                ListItemEntity entity = new ListItemEntity();
                entity.Name = list.Name;
                PageManager manager = new PageManager(DbAccess);
                manager.AddEntity<ListItemEntity>(entity);
                list.Id = entity.Id;
            }
            catch (Exception ex)
            {
                throw HandleException("Page", "AddList - " + list.Name, ex);
            }
        }
Exemplo n.º 3
0
        private static ListItemInfo GetListItemInfoByNumIdAndStyleId(XDocument numbering,
                                                                     XDocument styles, int numId, string paragraphStyle)
        {
            // If you have to find the w:lvl by style id, then we can't find it in the
            // w:lvlOverride, as that requires that you have determined the level already.
            var listItemInfo = new ListItemInfo(true);
            var num          = numbering.Root
                               .Elements(W.num).FirstOrDefault(e => (int)e.Attribute(W.numId) == numId);

            listItemInfo.AbstractNumId = (int)num.Elements(W.abstractNumId)
                                         .Attributes(W.val).FirstOrDefault();
            var a           = listItemInfo.AbstractNumId;
            var abstractNum = numbering.Root
                              .Elements(W.abstractNum).FirstOrDefault(e => (int)e.Attribute(W.abstractNumId) == a);
            var numStyleLink = (string)abstractNum.Element(W.numStyleLink)
                               .Attributes(W.val).FirstOrDefault();

            if (numStyleLink != null)
            {
                var style = styles.Root
                            .Elements(W.style)
                            .FirstOrDefault(e => (string)e.Attribute(W.styleId) == numStyleLink);
                var numPr  = style.Elements(W.pPr).Elements(W.numPr).FirstOrDefault();
                var lNumId = (int)numPr.Elements(W.numId).Attributes(W.val).FirstOrDefault();
                return(GetListItemInfoByNumIdAndStyleId(numbering, styles, lNumId,
                                                        paragraphStyle));
            }

            listItemInfo.Lvl   = abstractNum.Elements(W.lvl).FirstOrDefault(e => (string)e.Element(W.pStyle) == paragraphStyle);
            listItemInfo.Start = (int?)listItemInfo.Lvl.Elements(W.start).Attributes(W.val)
                                 .FirstOrDefault();
            return(listItemInfo);
        }
 // Returns an item to the pool to be re-used later
 private void ReturnPooledObj(ListItemInfo listItemInfo)
 {
     listItemInfo.obj.SetActive(false);
     listItemInfo.obj.transform.SetParent(pooledObjContainer.transform, false);
     visibleObjs.Remove(listItemInfo);
     pooledObjs.Add(listItemInfo);
 }
Exemplo n.º 5
0
        public void AddList(ListItemInfo list)
        {
            try
            {
                list.Name = list.Name.Trim();

                ObjectPersistence persistence = new ObjectPersistence(DbAccess);
                Criteria          cri         = new Criteria();
                cri.Add(Expression.Equal("Name", list.Name));
                if (!string.IsNullOrEmpty(list.Id))
                {
                    cri.Add(Expression.NotEqual("Id", list.Id));
                }
                IList <ListItemInfo> tmpList = persistence.GetList <ListItemInfo>(cri);
                if (tmpList.Count > 0)
                {
                    throw new FacadeException("列表名称已经存在,请重新输入!");
                }
                ListItemEntity entity = new ListItemEntity();
                entity.Name = list.Name;
                PageManager manager = new PageManager(DbAccess);
                manager.AddEntity <ListItemEntity>(entity);
                list.Id = entity.Id;
            }
            catch (Exception ex)
            {
                throw HandleException("Page", "AddList - " + list.Name, ex);
            }
        }
Exemplo n.º 6
0
        private static string FormatListItem(ListItemInfo lii, int[] levelNumbers, int ilvl,
                                             string lvlText, XDocument styles, string languageCultureName, ListItemRetrieverSettings settings)
        {
            string[] formatTokens = GetFormatTokens(lvlText).ToArray();
            XElement lvl          = lii.Lvl(ilvl);
            bool     isLgl        = lvl.Elements(W.isLgl).Any();
            string   listItem     = formatTokens.Select((t, l) =>
            {
                if (t.Substring(0, 1) != "%")
                {
                    return(t);
                }
                int indentationLevel;
                if (!Int32.TryParse(t.Substring(1), out indentationLevel))
                {
                    return(t);
                }
                indentationLevel -= 1;
                if (indentationLevel >= levelNumbers.Length)
                {
                    indentationLevel = levelNumbers.Length - 1;
                }
                int levelNumber       = levelNumbers[indentationLevel];
                string levelText      = null;
                XElement rlvl         = lii.Lvl(indentationLevel);
                string numFmtForLevel = (string)rlvl.Elements(W.numFmt).Attributes(W.val).FirstOrDefault();
                if (numFmtForLevel == null)
                {
                    var numFmtElement = rlvl.Elements(MC.AlternateContent).Elements(MC.Choice).Elements(W.numFmt).FirstOrDefault();
                    if (numFmtElement != null && (string)numFmtElement.Attribute(W.val) == "custom")
                    {
                        numFmtForLevel = (string)numFmtElement.Attribute(W.format);
                    }
                }
                if (numFmtForLevel != "none")
                {
                    if (isLgl && numFmtForLevel != "decimalZero")
                    {
                        numFmtForLevel = "decimal";
                    }
                }
                if (languageCultureName != null && settings != null)
                {
                    if (settings.ListItemTextImplementations.ContainsKey(languageCultureName))
                    {
                        var impl  = settings.ListItemTextImplementations[languageCultureName];
                        levelText = impl(languageCultureName, levelNumber, numFmtForLevel);
                    }
                }
                if (levelText == null)
                {
                    levelText = ListItemTextGetter_Default.GetListItemText(languageCultureName, levelNumber, numFmtForLevel);
                }
                return(levelText);
            }).StringConcatenate();

            return(listItem);
        }
    // Positions the scroll item in the proper place in the content
    private void PositionListItem(ListItemInfo listItemInfo, float listPos, bool addedItemAtBeginning)
    {
        // Get the items size
        RectTransform objRectT = listItemInfo.obj.transform as RectTransform;
        float         objSize  = isVertical ? objRectT.rect.height : objRectT.rect.width;

        // Need to account for the spacing between items
        float spacingOffset = 0;

        if (addedItemAtBeginning)
        {
            spacingOffset = isVertical ? spacing : -spacing;
        }
        else if (listItemInfo.index != 0)
        {
            spacingOffset = isVertical ? -spacing : spacing;
        }

        float sizeOffset = (addedItemAtBeginning ? objSize : 0);
        float pos        = isVertical ? listPos + spacingOffset + sizeOffset : listPos + spacingOffset - sizeOffset;

        SetAnchoredPosition(objRectT, pos);

        // If the objects size doesn't match its cached size then we need to re-size the contents RectTransform
        if (!cachedSizes.ContainsKey(listItemInfo.index) || objSize != cachedSizes[listItemInfo.index])
        {
            float   defaultSize     = listInfo.usedSavedSize ? listInfo.SavedAvgSize : 0;
            float   sizeDifference  = objSize - (!cachedSizes.ContainsKey(listItemInfo.index) ? defaultSize : cachedSizes[listItemInfo.index]);
            Vector2 contentsNewSize = new Vector2(content.sizeDelta.x, content.sizeDelta.y);
            bool    includeSpacing  = (!cachedSizes.ContainsKey(listItemInfo.index) && listItemInfo.index != itemCount - 1);

            if (isVertical)
            {
                contentsNewSize.y += sizeDifference + (includeSpacing ? this.spacing : 0);
            }
            else
            {
                contentsNewSize.x += sizeDifference + (includeSpacing ? this.spacing : 0);
            }

            content.sizeDelta = contentsNewSize;

            if (addedItemAtBeginning)
            {
                sizeDifference += (!cachedSizes.ContainsKey(listItemInfo.index) && listItemInfo.index != 0) ? spacing : 0;
                sizeDifference *= isVertical ? 1 : -1;
                ShiftContentBy(sizeDifference);
            }

            // Negate the old size then add the new size (we are not using sizeDifference for a reason, ei. defaultSize)
            listInfo.currentTotalSize -= !cachedSizes.ContainsKey(listItemInfo.index) ? 0 : cachedSizes[listItemInfo.index];
            listInfo.currentTotalSize += objSize;
            listInfo.currentCount     += !cachedSizes.ContainsKey(listItemInfo.index) ? 1 : 0;

            cachedSizes[listItemInfo.index] = objSize;
        }
    }
 public void AddItem(ListItemInfo newItem)
 {
     ItemsCollection.Add(newItem);
     if (!gameObject.activeInHierarchy)
     {
         return;
     }
     if (ListCount < maxListSize)
     {
         SpawnItem().GetComponent <ListItem>().ItemInfo = newItem;
     }
 }
Exemplo n.º 9
0
        public static ListItemInfo GetListItemInfo(XDocument numXDoc, XDocument stylesXDoc, XElement paragraph)
        {
            // The following is an optimization - only determine ListItemInfo once for a
            // paragraph.
            ListItemInfo listItemInfo = paragraph.Annotation <ListItemInfo>();

            if (listItemInfo != null)
            {
                return(listItemInfo);
            }
            throw new OpenXmlPowerToolsException("Attempting to retrieve ListItemInfo before initialization");
        }
Exemplo n.º 10
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         PageFacade facade = PageHelper.GetPageFacade(this.Page);
         string     listId = Request["lid"];
         if (string.IsNullOrEmpty(listId))
         {
             listId = Guid.Empty.ToString("N");
         }
         hlnkCancel.NavigateUrl = string.Format("EditList.aspx?id={0}", listId);
         if (listId != Guid.Empty.ToString("N"))
         {
             ListItemInfo listItem = facade.GetListItemById(listId);
             if (listItem != null)
             {
                 if (IsAdd)
                 {
                     lblTitle.Text = "添加子页面 -> " + listItem.Name;
                 }
                 else
                 {
                     string           htmlId   = Request["id"];
                     HtmlItemFullInfo htmlItem = facade.GetHtmlItemById(htmlId);
                     if (htmlItem != null)
                     {
                         BindHtmlInfo(htmlItem);
                         lblTitle.Text = "编辑页面 -> " + listItem.Name + " -> " + htmlItem.Name;
                     }
                 }
             }
         }
         else
         {
             if (IsAdd)
             {
                 lblTitle.Text = "添加子页面 -> <其他>";
             }
             else
             {
                 string           htmlId   = Request["id"];
                 HtmlItemFullInfo htmlItem = facade.GetHtmlItemById(htmlId);
                 if (htmlItem != null)
                 {
                     BindHtmlInfo(htmlItem);
                     lblTitle.Text = "编辑页面 -> <其他> -> " + htmlItem.Name;
                 }
             }
         }
     }
 }
Exemplo n.º 11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PageFacade facade = PageHelper.GetPageFacade(this.Page);
            if (!IsAdd)
            {
                lblNameTag.Visible = false;
                string id = Request["id"];
                if (id == Guid.Empty.ToString("N"))
                {
                    lblTitle.Text    = "编辑列表 - <其他>";
                    txtName.Text     = "<其他>";
                    txtName.Enabled  = false;
                    lbtnSave.Enabled = false;
                }
                else
                {
                    ListItemInfo listItem = facade.GetListItemById(id);
                    if (listItem != null)
                    {
                        lblTitle.Text = "编辑列表 - " + listItem.Name;
                        txtName.Text  = listItem.Name;
                    }
                    else
                    {
                        lblTitle.Text           = "编辑列表 - 发生错误";
                        lblInformation.Visible  = true;
                        lblInformation.Text     = "此列表不存在,可能已经被删除!";
                        lblInformation.CssClass = "Error";

                        hlnkAddSub.Enabled = false;
                        lbtnSave.Enabled   = false;
                        return;
                    }
                }
                IList <HtmlItemInfo> list = facade.GetHtmlItemsByParent(id);
                rptHtmlList.DataSource = list;
                rptHtmlList.DataBind();
                lbtnSave.Text          = "<span>修改列表名称</span>";
                hlnkAddSub.NavigateUrl = "EditContent.aspx?lid=" + id;
            }
            else
            {
                lblTitle.Text      = "新增列表页面";
                lbtnSave.Text      = "<span>新增列表</span>";
                hlnkAddSub.Visible = false;
            }
        }
    }
        private static int GetLevelNumberForLevel(XDocument numbering, XDocument styles,
                                                  XElement paragraph, int level)
        {
            ListItemInfo listItemInfo         = GetListItemInfo(numbering, styles, paragraph);
            int          paragraphLevel       = (int)listItemInfo.Lvl.Attribute(W.ilvl);
            var          paragraphsToConsider = ParagraphsToConsiderWhenCounting(numbering, styles,
                                                                                 paragraph, level)
                                                .Select(o => o.LevelNumbersArray.Take(paragraphLevel + 1)
                                                        .Select(z => z.ToString() + ".").StringConcatenate())
                                                .GroupBy(o => o);
            int levelNumberForLevel = paragraphsToConsider.Count();

            return(levelNumberForLevel);
        }
    /// <summary>
    /// Creates a new list item to be positioned in the list.
    /// </summary>
    private void GenerateListItem(int index, float position, bool topItem)
    {
        if (itemRendererFactory == null)
        {
            Debug.LogError("Item Renderer Factory is not set!");
            return;
        }

        int          itemType     = onGetItemType(index);
        ListItemInfo listItemInfo = GetPooledObj(itemType);

        // Get the list items object and set up some parameters
        listItemInfo.index = index;
        IListItemView view = listItemInfo.view;

        if (listItemInfo.obj == null)
        {
            listItemInfo.obj = itemRendererFactory(index, content);
            Assert.IsNotNull(listItemInfo.obj);
            view             = listItemInfo.obj.GetComponent <IListItemView>();
            view.OnSelected += OnSelectedItemBroadcast;
        }

        Assert.IsNotNull(view);
        Assert.IsNotNull(dataProvider);
        Assert.IsTrue(index >= 0 && index < dataProvider.Count, "DataProvider index is out of range!");

        view.isSelected   = (index == _isSelectedIndex);
        view.viewData     = dataProvider[index];
        listItemInfo.view = view;


        listItemInfo.obj.SetActive(true);
        listItemInfo.obj.transform.SetParent(content, false);

        SetupRectTransform(listItemInfo.obj.transform as RectTransform);

        visibleObjs.Add(listItemInfo);

        if (!CanvasUpdateRegistry.IsRebuildingLayout())
        {
            Canvas.ForceUpdateCanvases();
        }

        PositionListItem(listItemInfo, position, topItem);

        UpdateListItems();
    }
 public void AddItemAt(ListItemInfo newItem, int position)
 {
     if (position > -1 && position < firstItemIndex)
     {
         itemsCollection.Insert(position, newItem);
         firstItemIndex++;
     }
     else if (position < LastItemIndex)
     {
         itemsCollection.Insert(position, newItem);
     }
     else if (position <= ItemsCount)
     {
         itemsCollection.Insert(position, newItem);
     }
 }
Exemplo n.º 15
0
    protected void lbtnSave_Click(object sender, EventArgs e)
    {
        string name = txtName.Text;

        if (name.Trim() == "")
        {
            JavascriptAlert("请填入列表名称!");
            return;
        }
        try
        {
            string     msg, url;
            PageFacade facade = PageHelper.GetPageFacade(this.Page);
            if (IsAdd)
            {
                ListItemInfo list = new ListItemInfo();
                list.Name = name;
                facade.AddList(list);

                msg = string.Format("添加列表成功 - \"{0}\"", name);
                url = "EditList.aspx?id=" + list.Id;
                JavascriptAlertAndRedirectAndRefreshParent(msg, url);
            }
            else
            {
                ListItemInfo list = facade.GetListItemById(Request["id"]);
                if (list == null)
                {
                    JavascriptAlert("失败 - 此列表不存在,可能已经被删除!");
                    return;
                }
                list.Name = name;
                facade.ModifyListName(Request["id"], name);
                msg = string.Format("修改列表成功 - \"{0}\"", name);
                url = "EditList.aspx?id=" + list.Id;
                JavascriptAlertAndRedirect(msg, url);
            }
        }
        catch (FacadeException ex)
        {
            JavascriptAlert(ex.Message);
        }
        catch
        {
            JavascriptAlert(@"保存列表发生未知错误,请联系系统配置人员!");
        }
    }
Exemplo n.º 16
0
    protected void lbtnSave_Click(object sender, EventArgs e)
    {
        string name = txtName.Text;
        if (name.Trim() == "")
        {
            JavascriptAlert("请填入列表名称!");
            return;
        }
        try
        {
            string msg, url;
            PageFacade facade = PageHelper.GetPageFacade(this.Page);
            if (IsAdd)
            {
                ListItemInfo list = new ListItemInfo();
                list.Name = name;
                facade.AddList(list);

                msg = string.Format("添加列表成功 - \"{0}\"", name);
                url = "EditList.aspx?id=" + list.Id;
                JavascriptAlertAndRedirectAndRefreshParent(msg, url);
            }
            else
            {
                ListItemInfo list = facade.GetListItemById(Request["id"]);
                if (list == null)
                {
                    JavascriptAlert("失败 - 此列表不存在,可能已经被删除!");
                    return;
                }
                list.Name = name;
                facade.ModifyListName(Request["id"], name);
                msg = string.Format("修改列表成功 - \"{0}\"", name);
                url = "EditList.aspx?id=" + list.Id;
                JavascriptAlertAndRedirect(msg, url);
            }
        }
        catch (FacadeException ex)
        {
            JavascriptAlert(ex.Message);
        }
        catch
        {
            JavascriptAlert(@"保存列表发生未知错误,请联系系统配置人员!");
        }
    }
        private static IEnumerable <LevelNumbers> ParagraphsToConsiderWhenCounting(
            XDocument numbering, XDocument styles, XElement paragraph, int levelNumber)
        {
            ListItemInfo listItemInfo = GetListItemInfo(numbering, styles, paragraph);
            int?         lvlRestart   = (int?)listItemInfo.Lvl.Elements(W.lvlRestart)
                                        .Attributes(W.val).FirstOrDefault();
            int paragraphLevel = (int)listItemInfo.Lvl.Attribute(W.ilvl);
            IEnumerable <XElement> paragraphsBeforeSelf = paragraph
                                                          .ElementsBeforeSelfReverseDocumentOrder().Where(e => e.Name == W.p);

            foreach (var p in paragraphsBeforeSelf)
            {
                ListItemInfo pListItemInfo = GetListItemInfo(numbering, styles, p);
                if (!pListItemInfo.IsListItem ||
                    pListItemInfo.AbstractNumId != listItemInfo.AbstractNumId)
                {
                    continue;
                }
                LevelNumbers pLevelNumbers = p.Annotation <LevelNumbers>();
                int          pLevel        = (int)pListItemInfo.Lvl.Attribute(W.ilvl);
                if (pLevel > levelNumber)
                {
                    yield return(pLevelNumbers);
                }
                if (lvlRestart == null)
                {
                    if (pLevel < levelNumber)
                    {
                        yield break;
                    }
                }
                else
                {
                    if (pLevel < levelNumber && pLevel > lvlRestart - 1)
                    {
                        continue;
                    }
                    else if (pLevel < levelNumber)
                    {
                        yield break;
                    }
                }
                yield return(pLevelNumbers);
            }
        }
        private int AddToList(ListItemInfo info)
        {
            if (info != null)
            {
                var itm = this.lstExplorer.Items.Add(info.Name);
                itm.SubItems.Add(info.strSize);
                itm.SubItems.Add(info.Type);
                itm.Tag = info;

                if (this.ShowTreeView)
                {
                    this.UpdateTreeView();
                }

                return(itm.Index);
            }
            return(-1);
        }
Exemplo n.º 19
0
 public IList <ListItemInfo> GetListItems()
 {
     try
     {
         ObjectPersistence    persistence = new ObjectPersistence(DbAccess);
         IList <ListItemInfo> list        = persistence.GetAll <ListItemInfo>(new SortInfo("CreateTime", SortDirection.Desc));
         ListItemInfo         other       = new ListItemInfo();
         other.Id             = Guid.Empty.ToString("N");
         other.Name           = "<其他>";
         other.CreateTime     = DateTime.Now;
         other.LastUpdateTime = DateTime.Now;
         list.Insert(0, other);
         return(list);
     }
     catch (Exception ex)
     {
         throw HandleException("Page", "GetListItems", ex);
     }
 }
    // Gets a pooled object, if there are no available pooled objects then create a ListItemInfo with a null obj so one can
    // be created in IContentFilled GetListItem.
    private ListItemInfo GetPooledObj(int itemType)
    {
        ListItemInfo listItemInfo = null;

        for (int i = 0; i < pooledObjs.Count; i++)
        {
            if (itemType == pooledObjs[i].itemType)
            {
                listItemInfo = pooledObjs[i];
                pooledObjs.RemoveAt(i);
                break;
            }
        }

        if (listItemInfo == null)
        {
            listItemInfo          = new ListItemInfo();
            listItemInfo.itemType = itemType;
        }

        return(listItemInfo);
    }
        public static string RetrieveListItem(WordprocessingDocument wordDoc,
                                              XElement paragraph, string bulletReplacementString)
        {
            string pt = paragraph.Elements(W.r).Elements(W.t).Select(e => e.Value)
                        .StringConcatenate();
            NumberingDefinitionsPart numberingDefinitionsPart =
                wordDoc.MainDocumentPart.NumberingDefinitionsPart;

            if (numberingDefinitionsPart == null)
            {
                return(null);
            }
            StyleDefinitionsPart styleDefinitionsPart = wordDoc.MainDocumentPart
                                                        .StyleDefinitionsPart;

            if (styleDefinitionsPart == null)
            {
                return(null);
            }
            XDocument    numbering    = numberingDefinitionsPart.GetXDocument();
            XDocument    styles       = styleDefinitionsPart.GetXDocument();
            ListItemInfo listItemInfo = GetListItemInfo(numbering, styles, paragraph);

            if (listItemInfo.IsListItem)
            {
                string lvlText = (string)listItemInfo.Lvl.Elements(W.lvlText)
                                 .Attributes(W.val).FirstOrDefault();
                int[] levelNumbers = GetLevelNumbers(numbering, styles, paragraph);
                paragraph.AddAnnotation(new LevelNumbers()
                {
                    LevelNumbersArray = levelNumbers
                });
                string listItem = FormatListItem(listItemInfo.Lvl, levelNumbers, lvlText,
                                                 bulletReplacementString);
                return(listItem);
            }
            return(null);
        }
Exemplo n.º 22
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PageFacade facade = PageHelper.GetPageFacade(this.Page);
            string     listId = Request["id"];
            if (!string.IsNullOrEmpty(listId))
            {
                ListItemInfo list  = facade.GetListItemById(listId);
                string[]     names = list.Name.Split(new char[] { '#' }, 2);
                lblTitle.Text = names[0];
                if (names.Length > 1)
                {
                    hasEName          = true;
                    lblGrayTitle.Text = names[1];
                }

                IList <HtmlItemInfo> htmlList = facade.GetHtmlItemsByParent(listId);
                rptList.DataSource = htmlList;
                rptList.DataBind();
            }
        }
    }
Exemplo n.º 23
0
        private static ListItemInfo GetListItemInfoByNumIdAndIlvl(XDocument numbering,
                                                                  XDocument styles, int numId, int ilvl)
        {
            if (numId == 0)
            {
                return(new ListItemInfo(false));
            }

            var listItemInfo = new ListItemInfo(true);
            var num          = numbering.Root
                               .Elements(W.num).FirstOrDefault(e => (int)e.Attribute(W.numId) == numId);

            if (num == null)
            {
                return(new ListItemInfo(false));
            }

            listItemInfo.AbstractNumId = (int?)num.Elements(W.abstractNumId)
                                         .Attributes(W.val).FirstOrDefault();
            var lvlOverride = num
                              .Elements(W.lvlOverride).FirstOrDefault(e => (int)e.Attribute(W.ilvl) == ilvl);

            // If there is a w:lvlOverride element, and if the w:lvlOverride contains a
            // w:lvl element, then return it.  Otherwise, go look in the abstract numbering
            // definition.
            if (lvlOverride != null)
            {
                // Get the startOverride, if there is one.
                listItemInfo.Start = (int?)num.Elements(W.lvlOverride)
                                     .Where(o => (int)o.Attribute(W.ilvl) == ilvl).Elements(W.startOverride)
                                     .Attributes(W.val).FirstOrDefault();
                listItemInfo.Lvl = lvlOverride.Element(W.lvl);
                if (listItemInfo.Lvl != null)
                {
                    if (listItemInfo.Start == null)
                    {
                        listItemInfo.Start = (int?)listItemInfo.Lvl.Elements(W.start)
                                             .Attributes(W.val).FirstOrDefault();
                    }

                    return(listItemInfo);
                }
            }

            var a           = listItemInfo.AbstractNumId;
            var abstractNum = numbering.Root
                              .Elements(W.abstractNum).FirstOrDefault(e => (int)e.Attribute(W.abstractNumId) == a);
            var numStyleLink = (string)abstractNum.Elements(W.numStyleLink)
                               .Attributes(W.val).FirstOrDefault();

            if (numStyleLink != null)
            {
                var style = styles.Root
                            .Elements(W.style)
                            .FirstOrDefault(e => (string)e.Attribute(W.styleId) == numStyleLink);
                var numPr  = style.Elements(W.pPr).Elements(W.numPr).FirstOrDefault();
                var lNumId = (int)numPr.Elements(W.numId).Attributes(W.val)
                             .FirstOrDefault();
                return(GetListItemInfoByNumIdAndIlvl(numbering, styles, lNumId, ilvl));
            }

            for (int l = ilvl; l >= 0; --l)
            {
                listItemInfo.Lvl = abstractNum
                                   .Elements(W.lvl).FirstOrDefault(e => (int)e.Attribute(W.ilvl) == l);
                if (listItemInfo.Lvl == null)
                {
                    continue;
                }

                if (listItemInfo.Start == null)
                {
                    listItemInfo.Start = (int?)listItemInfo.Lvl.Elements(W.start)
                                         .Attributes(W.val).FirstOrDefault();
                }

                return(listItemInfo);
            }

            return(new ListItemInfo(false));
        }
Exemplo n.º 24
0
        public static ListItem RetrieveListItem(XDocument numbering, XDocument styles,
                                                XElement paragraph)
        {
            // The following is an optimization - only determine ListItemInfo once for a
            // paragraph.
            var listItem = paragraph.Annotation <ListItem>();

            if (listItem != null)
            {
                return(listItem);
            }

            var paragraphNumberingProperties = paragraph.Elements(W.pPr)
                                               .Elements(W.numPr).FirstOrDefault();

            var paragraphStyle = (string)paragraph.Elements(W.pPr).Elements(W.pStyle)
                                 .Attributes(W.val).FirstOrDefault();

            ListItemInfo listItemInfo;

            if (paragraphNumberingProperties != null &&
                paragraphNumberingProperties.Element(W.numId) != null)
            {
                // Paragraph numbering properties must contain a numId.
                var numId = (int)paragraphNumberingProperties.Elements(W.numId)
                            .Attributes(W.val).FirstOrDefault();

                var ilvl = (int?)paragraphNumberingProperties.Elements(W.ilvl)
                           .Attributes(W.val).FirstOrDefault();

                if (ilvl != null)
                {
                    listItemInfo = GetListItemInfoByNumIdAndIlvl(numbering, styles, numId,
                                                                 (int)ilvl);
                    paragraph.AddAnnotation(listItemInfo);
                    return(new ListItem(paragraph, listItemInfo.AbstractNumId, numId, ilvl, listItemInfo.IsListItem));
                }

                if (paragraphStyle != null)
                {
                    listItemInfo = GetListItemInfoByNumIdAndStyleId(numbering, styles,
                                                                    numId, paragraphStyle);
                    paragraph.AddAnnotation(listItemInfo);
                    return(new ListItem(paragraph, listItemInfo.AbstractNumId, numId, ilvl, listItemInfo.IsListItem));
                }

                listItemInfo = new ListItemInfo(false);
                paragraph.AddAnnotation(listItemInfo);
                return(new ListItem(paragraph, listItemInfo.AbstractNumId, numId, ilvl, listItemInfo.IsListItem));
            }

            if (paragraphStyle != null)
            {
                var style = styles.Root.Elements(W.style).FirstOrDefault(s => (string)s.Attribute(W.type) == "paragraph" &&
                                                                         (string)s.Attribute(W.styleId) == paragraphStyle);

                var styleNumberingProperties = style?.Elements(W.pPr)
                                               .Elements(W.numPr).FirstOrDefault();
                if (styleNumberingProperties?.Element(W.numId) != null)
                {
                    var numId = (int)styleNumberingProperties.Elements(W.numId)
                                .Attributes(W.val).FirstOrDefault();

                    var ilvl = (int?)styleNumberingProperties.Elements(W.ilvl)
                               .Attributes(W.val).FirstOrDefault();

                    if (ilvl == null)
                    {
                        ilvl = 0;
                    }

                    listItemInfo = GetListItemInfoByNumIdAndIlvl(numbering, styles,
                                                                 numId, (int)ilvl);
                    paragraph.AddAnnotation(listItemInfo);
                    return(new ListItem(paragraph, listItemInfo.AbstractNumId, numId, ilvl, listItemInfo.IsListItem));
                }
            }

            listItemInfo = new ListItemInfo(false);
            paragraph.AddAnnotation(listItemInfo);
            return(new ListItem(paragraph, listItemInfo.AbstractNumId, null, null, listItemInfo.IsListItem));
        }
 private static ListItemInfo GetListItemInfoByNumIdAndIlvl(XDocument numbering,
     XDocument styles, int numId, int ilvl)
 {
     if (numId == 0)
         return new ListItemInfo(false);
     ListItemInfo listItemInfo = new ListItemInfo(true);
     XElement num = numbering.Root.Elements(W.num)
         .Where(e => (int)e.Attribute(W.numId) == numId).FirstOrDefault();
     if (num == null)
         return new ListItemInfo(false);
     listItemInfo.AbstractNumId = (int?)num.Elements(W.abstractNumId)
         .Attributes(W.val).FirstOrDefault();
     XElement lvlOverride = num.Elements(W.lvlOverride)
         .Where(e => (int)e.Attribute(W.ilvl) == ilvl).FirstOrDefault();
     // If there is a w:lvlOverride element, and if the w:lvlOverride contains a
     // w:lvl element, then return it.  Otherwise, go look in the abstract numbering
     // definition.
     if (lvlOverride != null)
     {
         // Get the startOverride, if there is one.
         listItemInfo.Start = (int?)num.Elements(W.lvlOverride)
             .Where(o => (int)o.Attribute(W.ilvl) == ilvl).Elements(W.startOverride)
             .Attributes(W.val).FirstOrDefault();
         listItemInfo.Lvl = lvlOverride.Element(W.lvl);
         if (listItemInfo.Lvl != null)
         {
             if (listItemInfo.Start == null)
                 listItemInfo.Start = (int?)listItemInfo.Lvl.Elements(W.start)
                     .Attributes(W.val).FirstOrDefault();
             return listItemInfo;
         }
     }
     int? a = listItemInfo.AbstractNumId;
     XElement abstractNum = numbering.Root.Elements(W.abstractNum)
         .Where(e => (int)e.Attribute(W.abstractNumId) == a).FirstOrDefault();
     string numStyleLink = (string)abstractNum.Elements(W.numStyleLink)
         .Attributes(W.val).FirstOrDefault();
     if (numStyleLink != null)
     {
         XElement style = styles.Root.Elements(W.style)
             .Where(e => (string)e.Attribute(W.styleId) == numStyleLink)
             .FirstOrDefault();
         XElement numPr = style.Elements(W.pPr).Elements(W.numPr).FirstOrDefault();
         int lNumId = (int)numPr.Elements(W.numId).Attributes(W.val)
             .FirstOrDefault();
         return GetListItemInfoByNumIdAndIlvl(numbering, styles, lNumId, ilvl);
     }
     for (int l = ilvl; l >= 0; --l)
     {
         listItemInfo.Lvl = abstractNum.Elements(W.lvl)
             .Where(e => (int)e.Attribute(W.ilvl) == l).FirstOrDefault();
         if (listItemInfo.Lvl == null)
             continue;
         if (listItemInfo.Start == null)
             listItemInfo.Start = (int?)listItemInfo.Lvl.Elements(W.start)
                 .Attributes(W.val).FirstOrDefault();
         return listItemInfo;
     }
     return new ListItemInfo(false);
 }
 private static ListItemInfo GetListItemInfoByNumIdAndStyleId(XDocument numbering,
     XDocument styles, int numId, string paragraphStyle)
 {
     // If you have to find the w:lvl by style id, then we can't find it in the
     // w:lvlOverride, as that requires that you have determined the level already.
     ListItemInfo listItemInfo = new ListItemInfo(true);
     XElement num = numbering.Root.Elements(W.num)
         .Where(e => (int)e.Attribute(W.numId) == numId).FirstOrDefault();
     listItemInfo.AbstractNumId = (int)num.Elements(W.abstractNumId)
         .Attributes(W.val).FirstOrDefault();
     int? a = listItemInfo.AbstractNumId;
     XElement abstractNum = numbering.Root.Elements(W.abstractNum)
         .Where(e => (int)e.Attribute(W.abstractNumId) == a).FirstOrDefault();
     string numStyleLink = (string)abstractNum.Element(W.numStyleLink)
         .Attributes(W.val).FirstOrDefault();
     if (numStyleLink != null)
     {
         XElement style = styles.Root.Elements(W.style)
             .Where(e => (string)e.Attribute(W.styleId) == numStyleLink)
             .FirstOrDefault();
         XElement numPr = style.Elements(W.pPr).Elements(W.numPr).FirstOrDefault();
         int lNumId = (int)numPr.Elements(W.numId).Attributes(W.val).FirstOrDefault();
         return GetListItemInfoByNumIdAndStyleId(numbering, styles, lNumId,
             paragraphStyle);
     }
     listItemInfo.Lvl = abstractNum.Elements(W.lvl)
         .Where(e => (string)e.Element(W.pStyle) == paragraphStyle).FirstOrDefault();
     listItemInfo.Start = (int?)listItemInfo.Lvl.Elements(W.start).Attributes(W.val)
         .FirstOrDefault();
     return listItemInfo;
 }
Exemplo n.º 27
0
        /// <summary>
        ///     This method requests the server to add elements to the list that have been added to the local ClientBase copy
        ///     of the list. For example, after using the AddNewDataObjectToList() method add a set of data objects to the local
        ///     ClientBase copy of the list, this method is called to add them to the server's copy of the list in a single call.
        /// </summary>
        /// <returns> The list of elements that were not added to the server or null is call to server failed.</returns>
        protected IEnumerable <TClientElementListItemBase>?CommitAddItemsInternal()
        {
            var listInstanceIdsCollection = new List <ListItemInfo>();

            foreach (TClientElementListItemBase listItem in ListItemsManager)
            {
                if (!listItem.IsInServerList && listItem.PreparedForAdd)
                {
                    var listInstanceId = new ListItemInfo
                    {
                        ElementId   = listItem.ElementId,
                        ClientAlias = listItem.ClientAlias,
                    };
                    listInstanceIdsCollection.Add(listInstanceId);
                }
                listItem.PreparedForAdd = false;
            }

            var resultItems = new List <TClientElementListItemBase>();

            if (listInstanceIdsCollection.Count > 0)
            {
                try
                {
                    List <AddItemToListResult> result = Context.AddItemsToList(ListServerAlias,
                                                                               listInstanceIdsCollection);

                    foreach (AddItemToListResult r in result)
                    {
                        TClientElementListItemBase?listItem = null;
                        if (ListItemsManager.TryGetValue(r.AliasResult.ClientAlias, out listItem))
                        {
                            listItem.ServerAlias = r.AliasResult.ServerAlias;
                            listItem.StatusCode  = (StatusCode)r.AliasResult.StatusCode;
                            listItem.ValueTypeId = r.DataTypeId;
                            listItem.IsReadable  = r.IsReadable;
                            listItem.IsWritable  = r.IsWritable;

                            if (listItem.StatusCode == StatusCode.OK)
                            {
                                listItem.IsInServerList = true;
                            }
                            else
                            {
                                ListItemsManager.Remove(listItem.ClientAlias);
                                // remove values that the server failed to add
                                listItem.ClientAlias    = 0;
                                listItem.IsInClientList = false;
                                resultItems.Add(listItem);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    foreach (ListItemInfo ar in listInstanceIdsCollection)
                    {
                        ListItemsManager.Remove(ar.ClientAlias); // remove values that the server failed to add
                    }
                    return(null);
                }
            }

            return(resultItems);
        }
    /// <summary>
    /// Returns any objects no longer visible to the pool and generates new items at the front/back of the list.
    /// </summary>
    private bool UpdateListItems()
    {
        float topPosValue    = isVertical ? content.anchoredPosition.y : -content.anchoredPosition.x;
        float bottomPosValue = topPosValue + ViewportSize;

        int highestIndex = int.MaxValue;
        int lowestIndex  = int.MinValue;

        float highestVal = float.MinValue;
        float lowestVal  = float.MaxValue;

        for (int i = visibleObjs.Count - 1; i >= 0; i--)
        {
            ListItemInfo  listItemInfo = visibleObjs[i];
            RectTransform childRectT   = listItemInfo.obj.transform as RectTransform;

            float val1 = isVertical ? -1 * childRectT.anchoredPosition.y : childRectT.anchoredPosition.x;
            float val2 = isVertical ? childRectT.rect.height : childRectT.rect.width;

            if (val1 < lowestVal)
            {
                lowestVal   = val1;
                lowestIndex = listItemInfo.index;
            }
            else if (val1 == lowestVal && lowestIndex > listItemInfo.index)
            {
                lowestIndex = listItemInfo.index;
            }

            if (val1 + val2 > highestVal)
            {
                highestVal   = val1 + val2;
                highestIndex = listItemInfo.index;
            }
            else if (val1 + val2 == highestVal && highestIndex < listItemInfo.index)
            {
                highestIndex = listItemInfo.index;
            }

            if (val1 + val2 <= topPosValue || val1 >= bottomPosValue)
            {
                ReturnPooledObj(listItemInfo);
            }
        }

        // Check if content has scrolled so much that the front most item has scolled past the end of the viewport
        if (lowestVal >= bottomPosValue)
        {
            // Calculate how many items we think will go in that gap
            float gapSize       = lowestVal - topPosValue;
            int   numItemsInGap = Mathf.CeilToInt(gapSize / listInfo.CurrentAvgSize);

            // Calculate what item to go to
            int gotoIndex = lowestIndex - numItemsInGap;

            // Check if that item is greater than the max items
            if (gotoIndex < 0)
            {
                gotoIndex = 0;
            }

            // Jump to that item. We now simulate the "scroll"
            GoToListItem(gotoIndex);

            return(true);
        }

        // Check if an item should be generated at the front of the list
        if (lowestVal - spacing > topPosValue && lowestIndex > 0)
        {
            GenerateListItem(lowestIndex - 1, isVertical ? -lowestVal : lowestVal, true);

            return(true);
        }

        // Check if we have scrolled so much that the end most item has scolled past the beginning of the viewport
        if (highestVal <= topPosValue)
        {
            // Calculate how many items we think will go in that gap
            float gapSize       = topPosValue - highestVal;
            int   numItemsInGap = Mathf.CeilToInt(gapSize / listInfo.CurrentAvgSize);

            // Calculate what item to go to
            int gotoIndex = highestIndex + numItemsInGap;

            // Check if that item is greater than the max items
            if (gotoIndex >= itemCount)
            {
                gotoIndex = itemCount - 1;
            }

            // Jump to that item. We now simulate the "scroll"
            GoToListItem(gotoIndex);

            return(true);
        }

        // Check if an item should be generated at the end of the list
        if (highestVal + spacing < bottomPosValue && highestIndex < itemCount - 1)
        {
            GenerateListItem(highestIndex + 1, isVertical ? -highestVal : highestVal, false);

            return(true);
        }

        return(false);
    }
Exemplo n.º 29
0
 private void addListItem(ListItemInfo<string> info)
 {
     _syncContext.Post((y) =>
     {
         var item = (ListItemInfo<string>)y;
         var listItem = listView.Items.Insert(0, item.Message);
         listItem.Tag = item.Message;
     }, info);
 }
 private static ListItemInfo GetListItemInfo(XDocument numbering, XDocument styles,
     XElement paragraph)
 {
     // The following is an optimization - only determine ListItemInfo once for a
     // paragraph.
     ListItemInfo listItemInfo = paragraph.Annotation<ListItemInfo>();
     if (listItemInfo != null)
         return listItemInfo;
     XElement paragraphNumberingProperties = paragraph.Elements(W.pPr)
         .Elements(W.numPr).FirstOrDefault();
     string paragraphStyle = (string)paragraph.Elements(W.pPr).Elements(W.pStyle)
         .Attributes(W.val).FirstOrDefault();
     if (paragraphNumberingProperties != null &&
         paragraphNumberingProperties.Element(W.numId) != null)
     {
         // Paragraph numbering properties must contain a numId.
         int numId = (int)paragraphNumberingProperties.Elements(W.numId)
             .Attributes(W.val).FirstOrDefault();
         int? ilvl = (int?)paragraphNumberingProperties.Elements(W.ilvl)
             .Attributes(W.val).FirstOrDefault();
         if (ilvl != null)
         {
             listItemInfo = GetListItemInfoByNumIdAndIlvl(numbering, styles, numId,
                 (int)ilvl);
             paragraph.AddAnnotation(listItemInfo);
             return listItemInfo;
         }
         if (paragraphStyle != null)
         {
             listItemInfo = GetListItemInfoByNumIdAndStyleId(numbering, styles,
                 numId, paragraphStyle);
             paragraph.AddAnnotation(listItemInfo);
             return listItemInfo;
         }
         listItemInfo = new ListItemInfo(false);
         paragraph.AddAnnotation(listItemInfo);
         return listItemInfo;
     }
     if (paragraphStyle != null)
     {
         XElement style = styles.Root.Elements(W.style).Where(s =>
             (string)s.Attribute(W.type) == "paragraph" &&
             (string)s.Attribute(W.styleId) == paragraphStyle).FirstOrDefault();
         if (style != null)
         {
             XElement styleNumberingProperties = style.Elements(W.pPr)
                 .Elements(W.numPr).FirstOrDefault();
             if (styleNumberingProperties != null &&
                 styleNumberingProperties.Element(W.numId) != null)
             {
                 int numId = (int)styleNumberingProperties.Elements(W.numId)
                     .Attributes(W.val).FirstOrDefault();
                 int? ilvl = (int?)styleNumberingProperties.Elements(W.ilvl)
                     .Attributes(W.val).FirstOrDefault();
                 if (ilvl == null)
                     ilvl = 0;
                 listItemInfo = GetListItemInfoByNumIdAndIlvl(numbering, styles,
                     numId, (int)ilvl);
                 paragraph.AddAnnotation(listItemInfo);
                 return listItemInfo;
             }
         }
     }
     listItemInfo = new ListItemInfo(false);
     paragraph.AddAnnotation(listItemInfo);
     return listItemInfo;
 }
Exemplo n.º 31
0
 protected override bool Insert()
 {
     ListItemInfo listItemInfo = new ListItemInfo();
     listItemInfo.Name = txtName.Text;
     listItemInfo.Description = txtDescription.Text;
     listItemInfo.ListId = ValidationHelper.GetInteger(drlList.SelectedValue, 0);
     listItemInfo.ParentId = ValidationHelper.GetInteger(drlParentList.SelectedValue, 0);
     listItemInfo.SeoTemplate = SiteHelper.ToUrl(txtName.Text);
     _listItemProvider.Create(listItemInfo, ErrorList);
     return CheckErrors();
 }
        private static void AddListItemInfoIntoCache(XDocument numXDoc, string styleName, int? numId, ListItemInfo listItemInfo)
        {
            string key =
                (styleName == null ? "" : styleName) +
                "|" +
                (numId == null ? "" : numId.ToString());

            var numXDocRoot = numXDoc.Root;
            Dictionary<string, ListItemInfo> listItemInfoCache =
                numXDocRoot.Annotation<Dictionary<string, ListItemInfo>>();
            if (listItemInfoCache == null)
            {
                listItemInfoCache = new Dictionary<string, ListItemInfo>();
                numXDocRoot.AddAnnotation(listItemInfoCache);
            }
            if (!listItemInfoCache.ContainsKey(key))
                listItemInfoCache.Add(key, listItemInfo);
        }
        private static int[] GetLevelNumbers(XDocument numbering, XDocument styles,
                                             XElement paragraph)
        {
            IEnumerable <XElement> paragraphsBeforeSelf = paragraph
                                                          .ElementsBeforeSelfReverseDocumentOrder().Where(e => e.Name == W.p);
            int          level;
            ListItemInfo listItemInfo = GetListItemInfo(numbering, styles, paragraph);

            level = (int)listItemInfo.Lvl.Attribute(W.ilvl);
            List <int> levelNumbers = new List <int>();

            for (int indentationLevel = 0; indentationLevel <= level; ++indentationLevel)
            {
                XElement currentIndentLvl = GetRelatedLevel(listItemInfo.Lvl,
                                                            indentationLevel);
                int?start = (int?)currentIndentLvl.Elements(W.start).Attributes(W.val)
                            .FirstOrDefault();
                if (start == null)
                {
                    start = 1;
                }
                XElement paragraphWithSameAbstractNumId = paragraphsBeforeSelf
                                                          .FirstOrDefault(p =>
                {
                    ListItemInfo pListItemInfo = GetListItemInfo(numbering, styles, p);
                    return(pListItemInfo.IsListItem &&
                           pListItemInfo.AbstractNumId == listItemInfo.AbstractNumId);
                });
                if (paragraphWithSameAbstractNumId != null)
                {
                    LevelNumbers pLevelNumbers = paragraphWithSameAbstractNumId
                                                 .Annotation <LevelNumbers>();
                    if (pLevelNumbers.LevelNumbersArray.Length > indentationLevel)
                    {
                        if (indentationLevel == level)
                        {
                            levelNumbers.Add(
                                pLevelNumbers.LevelNumbersArray[indentationLevel] + 1);
                        }
                        else
                        {
                            levelNumbers.Add(pLevelNumbers
                                             .LevelNumbersArray[indentationLevel]);
                        }
                        continue;
                    }
                }

                if (level == indentationLevel)
                {
                    int c1 = GetLevelNumberForLevel(numbering, styles, paragraph,
                                                    indentationLevel);
                    int?start2 = listItemInfo.Start;
                    if (start2 == null)
                    {
                        start2 = 1;
                    }
                    levelNumbers.Add(c1 + (int)start2);
                    continue;
                }
                levelNumbers.Add((int)start);
            }
            return(levelNumbers.ToArray());
        }
        private static void InitializeListItemRetrieverForStory(XDocument numXDoc, XDocument stylesXDoc, XElement rootNode)
        {
            var paragraphs = rootNode
                .DescendantsTrimmed(W.txbxContent)
                .Where(p => p.Name == W.p);

            foreach (var paragraph in paragraphs)
                InitListItemInfo(numXDoc, stylesXDoc, paragraph);

            var abstractNumIds = paragraphs
                .Select(paragraph =>
                {
                    ListItemInfo listItemInfo = paragraph.Annotation<ListItemInfo>();
                    if (!listItemInfo.IsListItem)
                        return (int?)null;
                    return listItemInfo.AbstractNumId;
                })
                .Where(a => a != null)
                .Distinct()
                .ToList();

            // when debugging, it is sometimes useful to cause processing of a specific abstractNumId first.
            // the following code enables this.
            //int? abstractIdToProcessFirst = null;
            //if (abstractIdToProcessFirst != null)
            //{
            //    abstractNumIds = (new[] { abstractIdToProcessFirst })
            //        .Concat(abstractNumIds.Where(ani => ani != abstractIdToProcessFirst))
            //        .ToList();
            //}

            foreach (var abstractNumId in abstractNumIds)
            {
                var listItems = paragraphs
                    .Where(paragraph =>
                    {
                        var listItemInfo = paragraph.Annotation<ListItemInfo>();
                        if (!listItemInfo.IsListItem)
                            return false;
                        return listItemInfo.AbstractNumId == abstractNumId;
                    })
                    .ToList();

                // annotate paragraphs with previous paragraphs so that we can look backwards with good perf
                XElement prevParagraph = null;
                foreach (var paragraph in listItems)
                {
                    ReverseAxis reverse = new ReverseAxis()
                    {
                        PreviousParagraph = prevParagraph,
                    };
                    paragraph.AddAnnotation(reverse);
                    prevParagraph = paragraph;
                }

                var startOverrideAlreadyUsed = new List<int>();
                List<int> previous = null;
                ListItemInfo[] listItemInfoInEffectForStartOverride = new ListItemInfo[] {
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                };
                foreach (var paragraph in listItems)
                {
                    var listItemInfo = paragraph.Annotation<ListItemInfo>();
                    var ilvl = GetParagraphLevel(paragraph);
                    listItemInfoInEffectForStartOverride[ilvl] = listItemInfo;
                    ListItemInfo listItemInfoInEffect = null;
                    if (ilvl > 0)
                        listItemInfoInEffect = listItemInfoInEffectForStartOverride[ilvl - 1];
                    var levelNumbers = new List<int>();

                    for (int level = 0; level <= ilvl; level++)
                    {
                        var numId = listItemInfo.NumId;
                        var startOverride = listItemInfo.StartOverride(level);
                        int? inEffectStartOverride = null;
                        if (listItemInfoInEffect != null)
                            inEffectStartOverride = listItemInfoInEffect.StartOverride(level);

                        if (level == ilvl)
                        {
                            var lvl = listItemInfo.Lvl(ilvl);
                            var lvlRestart = (int?)lvl.Elements(W.lvlRestart).Attributes(W.val).FirstOrDefault();
                            if (lvlRestart != null)
                            {
                                var previousPara = PreviousParagraphsForLvlRestart(paragraph, (int)lvlRestart)
                                    .FirstOrDefault(p =>
                                    {
                                        var plvl = GetParagraphLevel(p);
                                        return plvl == ilvl;
                                    });
                                if (previousPara != null)
                                    previous = previousPara.Annotation<LevelNumbers>().LevelNumbersArray.ToList();
                            }
                        }

                        if (previous == null ||
                            level >= previous.Count() ||
                            (level == ilvl && startOverride != null && !startOverrideAlreadyUsed.Contains(numId)))
                        {
                            if (previous == null || level >= previous.Count())
                            {
                                var start = listItemInfo.Start(level);
                                // only look at startOverride if the level that we're examining is same as the paragraph's level.
                                if (level == ilvl)
                                {
                                    if (startOverride != null && !startOverrideAlreadyUsed.Contains(numId))
                                    {
                                        startOverrideAlreadyUsed.Add(numId);
                                        start = (int)startOverride;
                                    }
                                    else
                                    {
                                        if (startOverride != null)
                                            start = (int)startOverride;
                                        if (inEffectStartOverride != null && inEffectStartOverride > start)
                                            start = (int)inEffectStartOverride;
                                    }
                                }
                                levelNumbers.Add(start);
                            }
                            else
                            {
                                var start = listItemInfo.Start(level);
                                // only look at startOverride if the level that we're examining is same as the paragraph's level.
                                if (level == ilvl)
                                {
                                    if (startOverride != null)
                                    {
                                        if (!startOverrideAlreadyUsed.Contains(numId))
                                        {
                                            startOverrideAlreadyUsed.Add(numId);
                                            start = (int)startOverride;
                                        }
                                    }
                                }
                                levelNumbers.Add(start);
                            }
                        }
                        else
                        {
                            int? thisNumber = null;
                            if (level == ilvl)
                            {
                                if (startOverride != null)
                                {
                                    if (!startOverrideAlreadyUsed.Contains(numId))
                                    {
                                        startOverrideAlreadyUsed.Add(numId);
                                        thisNumber = (int)startOverride;
                                    }
                                    thisNumber = previous.ElementAt(level) + 1;
                                }
                                else
                                {
                                    thisNumber = previous.ElementAt(level) + 1;
                                }
                            }
                            else
                            {
                                thisNumber = previous.ElementAt(level);
                            }
                            levelNumbers.Add((int)thisNumber);
                        }
                    }
                    var levelNumbersAnno = new LevelNumbers()
                    {
                        LevelNumbersArray = levelNumbers.ToArray()
                    };
                    paragraph.AddAnnotation(levelNumbersAnno);
                    previous = levelNumbers;
                }
            }
        }
Exemplo n.º 35
0
 public IList<ListItemInfo> GetListItems()
 {
     try
     {
         ObjectPersistence persistence = new ObjectPersistence(DbAccess);
         IList<ListItemInfo> list = persistence.GetAll<ListItemInfo>(new SortInfo("CreateTime", SortDirection.Desc));
         ListItemInfo other = new ListItemInfo();
         other.Id = Guid.Empty.ToString("N");
         other.Name = "<其他>";
         other.CreateTime = DateTime.Now;
         other.LastUpdateTime = DateTime.Now;
         list.Insert(0, other);
         return list;
     }
     catch (Exception ex)
     {
         throw HandleException("Page", "GetListItems", ex);
     }
 }
Exemplo n.º 36
0
        public static void InitListItemInfo(XDocument numXDoc, XDocument stylesXDoc, XElement paragraph)
        {
            if (FirstRunIsEmptySectionBreak(paragraph))
            {
                paragraph.AddAnnotation(NotAListItem);
                return;
            }

            int?paragraphNumId = null;

            XElement paragraphNumberingProperties = paragraph
                                                    .Elements(W.pPr)
                                                    .Elements(W.numPr)
                                                    .FirstOrDefault();

            if (paragraphNumberingProperties != null)
            {
                paragraphNumId = (int?)paragraphNumberingProperties
                                 .Elements(W.numId)
                                 .Attributes(W.val)
                                 .FirstOrDefault();

                // if numPr of paragraph does not contain numId, then it is not a list item.
                // if numId of paragraph == 0, then this is not a list item, regardless of the markup in the style.
                if (paragraphNumId == null || paragraphNumId == 0)
                {
                    paragraph.AddAnnotation(NotAListItem);
                    return;
                }
            }

            string paragraphStyleName = GetParagraphStyleName(stylesXDoc, paragraph);

            var listItemInfo = GetListItemInfoFromCache(numXDoc, paragraphStyleName, paragraphNumId);

            if (listItemInfo != null)
            {
                paragraph.AddAnnotation(listItemInfo);

                if (listItemInfo.FromParagraph != null)
                {
                    var para_ilvl = (int?)paragraphNumberingProperties
                                    .Elements(W.ilvl)
                                    .Attributes(W.val)
                                    .FirstOrDefault();

                    if (para_ilvl == null)
                    {
                        para_ilvl = 0;
                    }

                    var abstractNum    = listItemInfo.FromParagraph.Main.AbstractNum;
                    var multiLevelType = (string)abstractNum.Elements(W.multiLevelType).Attributes(W.val).FirstOrDefault();
                    if (multiLevelType == "singleLevel")
                    {
                        para_ilvl = 0;
                    }

                    SetParagraphLevel(paragraph, (int)para_ilvl);
                }
                else if (listItemInfo.FromStyle != null)
                {
                    int this_ilvl      = listItemInfo.FromStyle.Style_ilvl;
                    var abstractNum    = listItemInfo.FromStyle.Main.AbstractNum;
                    var multiLevelType = (string)abstractNum.Elements(W.multiLevelType).Attributes(W.val).FirstOrDefault();
                    if (multiLevelType == "singleLevel")
                    {
                        this_ilvl = 0;
                    }

                    SetParagraphLevel(paragraph, this_ilvl);
                }
                return;
            }

            listItemInfo = new ListItemInfo();

            int? style_ilvl     = null;
            bool?styleZeroNumId = null;

            if (paragraphStyleName != null)
            {
                listItemInfo.FromStyle = InitializeStyleListItemSource(numXDoc, stylesXDoc, paragraph, paragraphStyleName,
                                                                       out style_ilvl, out styleZeroNumId);
            }

            int? paragraph_ilvl     = null;
            bool?paragraphZeroNumId = null;

            if (paragraphNumberingProperties != null && paragraphNumberingProperties.Element(W.numId) != null)
            {
                listItemInfo.FromParagraph = InitializeParagraphListItemSource(numXDoc, stylesXDoc, paragraph, paragraphNumberingProperties, out paragraph_ilvl, out paragraphZeroNumId);
            }

            if (styleZeroNumId == true && paragraphZeroNumId == null ||
                paragraphZeroNumId == true)
            {
                paragraph.AddAnnotation(NotAListItem);
                AddListItemInfoIntoCache(numXDoc, paragraphStyleName, paragraphNumId, NotAListItem);
                return;
            }

            int ilvlToSet = 0;

            if (paragraph_ilvl != null)
            {
                ilvlToSet = (int)paragraph_ilvl;
            }
            else if (style_ilvl != null)
            {
                ilvlToSet = (int)style_ilvl;
            }

            if (listItemInfo.FromParagraph != null)
            {
                var abstractNum    = listItemInfo.FromParagraph.Main.AbstractNum;
                var multiLevelType = (string)abstractNum.Elements(W.multiLevelType).Attributes(W.val).FirstOrDefault();
                if (multiLevelType == "singleLevel")
                {
                    ilvlToSet = 0;
                }
            }
            else if (listItemInfo.FromStyle != null)
            {
                var abstractNum    = listItemInfo.FromStyle.Main.AbstractNum;
                var multiLevelType = (string)abstractNum.Elements(W.multiLevelType).Attributes(W.val).FirstOrDefault();
                if (multiLevelType == "singleLevel")
                {
                    ilvlToSet = 0;
                }
            }

            SetParagraphLevel(paragraph, ilvlToSet);

            listItemInfo.IsListItem = listItemInfo.FromStyle != null || listItemInfo.FromParagraph != null;
            paragraph.AddAnnotation(listItemInfo);
            AddListItemInfoIntoCache(numXDoc, paragraphStyleName, paragraphNumId, listItemInfo);
        }
Exemplo n.º 37
0
        private static void InitializeListItemRetrieverForStory(XDocument numXDoc, XDocument stylesXDoc, XElement rootNode)
        {
            var paragraphs = rootNode
                             .DescendantsTrimmed(W.txbxContent)
                             .Where(p => p.Name == W.p);

            foreach (var paragraph in paragraphs)
            {
                InitListItemInfo(numXDoc, stylesXDoc, paragraph);
            }

            var abstractNumIds = paragraphs
                                 .Select(paragraph =>
            {
                ListItemInfo listItemInfo = paragraph.Annotation <ListItemInfo>();
                if (!listItemInfo.IsListItem)
                {
                    return((int?)null);
                }
                return(listItemInfo.AbstractNumId);
            })
                                 .Where(a => a != null)
                                 .Distinct()
                                 .ToList();

            // when debugging, it is sometimes useful to cause processing of a specific abstractNumId first.
            // the following code enables this.
            //int? abstractIdToProcessFirst = null;
            //if (abstractIdToProcessFirst != null)
            //{
            //    abstractNumIds = (new[] { abstractIdToProcessFirst })
            //        .Concat(abstractNumIds.Where(ani => ani != abstractIdToProcessFirst))
            //        .ToList();
            //}

            foreach (var abstractNumId in abstractNumIds)
            {
                var listItems = paragraphs
                                .Where(paragraph =>
                {
                    var listItemInfo = paragraph.Annotation <ListItemInfo>();
                    if (!listItemInfo.IsListItem)
                    {
                        return(false);
                    }
                    return(listItemInfo.AbstractNumId == abstractNumId);
                })
                                .ToList();

                // annotate paragraphs with previous paragraphs so that we can look backwards with good perf
                XElement prevParagraph = null;
                foreach (var paragraph in listItems)
                {
                    ReverseAxis reverse = new ReverseAxis()
                    {
                        PreviousParagraph = prevParagraph,
                    };
                    paragraph.AddAnnotation(reverse);
                    prevParagraph = paragraph;
                }

                var            startOverrideAlreadyUsed = new List <int>();
                List <int>     previous = null;
                ListItemInfo[] listItemInfoInEffectForStartOverride = new ListItemInfo[] {
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                };
                foreach (var paragraph in listItems)
                {
                    var listItemInfo = paragraph.Annotation <ListItemInfo>();
                    var ilvl         = GetParagraphLevel(paragraph);
                    listItemInfoInEffectForStartOverride[ilvl] = listItemInfo;
                    ListItemInfo listItemInfoInEffect = null;
                    if (ilvl > 0)
                    {
                        listItemInfoInEffect = listItemInfoInEffectForStartOverride[ilvl - 1];
                    }
                    var levelNumbers = new List <int>();

                    for (int level = 0; level <= ilvl; level++)
                    {
                        var numId                 = listItemInfo.NumId;
                        var startOverride         = listItemInfo.StartOverride(level);
                        int?inEffectStartOverride = null;
                        if (listItemInfoInEffect != null)
                        {
                            inEffectStartOverride = listItemInfoInEffect.StartOverride(level);
                        }

                        if (level == ilvl)
                        {
                            var lvl        = listItemInfo.Lvl(ilvl);
                            var lvlRestart = (int?)lvl.Elements(W.lvlRestart).Attributes(W.val).FirstOrDefault();
                            if (lvlRestart != null)
                            {
                                var previousPara = PreviousParagraphsForLvlRestart(paragraph, (int)lvlRestart)
                                                   .FirstOrDefault(p =>
                                {
                                    var plvl = GetParagraphLevel(p);
                                    return(plvl == ilvl);
                                });
                                if (previousPara != null)
                                {
                                    previous = previousPara.Annotation <LevelNumbers>().LevelNumbersArray.ToList();
                                }
                            }
                        }

                        if (previous == null ||
                            level >= previous.Count() ||
                            (level == ilvl && startOverride != null && !startOverrideAlreadyUsed.Contains(numId)))
                        {
                            if (previous == null || level >= previous.Count())
                            {
                                var start = listItemInfo.Start(level);
                                // only look at startOverride if the level that we're examining is same as the paragraph's level.
                                if (level == ilvl)
                                {
                                    if (startOverride != null && !startOverrideAlreadyUsed.Contains(numId))
                                    {
                                        startOverrideAlreadyUsed.Add(numId);
                                        start = (int)startOverride;
                                    }
                                    else
                                    {
                                        if (startOverride != null)
                                        {
                                            start = (int)startOverride;
                                        }
                                        if (inEffectStartOverride != null && inEffectStartOverride > start)
                                        {
                                            start = (int)inEffectStartOverride;
                                        }
                                    }
                                }
                                levelNumbers.Add(start);
                            }
                            else
                            {
                                var start = listItemInfo.Start(level);
                                // only look at startOverride if the level that we're examining is same as the paragraph's level.
                                if (level == ilvl)
                                {
                                    if (startOverride != null)
                                    {
                                        if (!startOverrideAlreadyUsed.Contains(numId))
                                        {
                                            startOverrideAlreadyUsed.Add(numId);
                                            start = (int)startOverride;
                                        }
                                    }
                                }
                                levelNumbers.Add(start);
                            }
                        }
                        else
                        {
                            int?thisNumber = null;
                            if (level == ilvl)
                            {
                                if (startOverride != null)
                                {
                                    if (!startOverrideAlreadyUsed.Contains(numId))
                                    {
                                        startOverrideAlreadyUsed.Add(numId);
                                        thisNumber = (int)startOverride;
                                    }
                                    thisNumber = previous.ElementAt(level) + 1;
                                }
                                else
                                {
                                    thisNumber = previous.ElementAt(level) + 1;
                                }
                            }
                            else
                            {
                                thisNumber = previous.ElementAt(level);
                            }
                            levelNumbers.Add((int)thisNumber);
                        }
                    }
                    var levelNumbersAnno = new LevelNumbers()
                    {
                        LevelNumbersArray = levelNumbers.ToArray()
                    };
                    paragraph.AddAnnotation(levelNumbersAnno);
                    previous = levelNumbers;
                }
            }
        }
        public static void InitListItemInfo(XDocument numXDoc, XDocument stylesXDoc, XElement paragraph)
        {
            if (FirstRunIsEmptySectionBreak(paragraph))
            {
                paragraph.AddAnnotation(NotAListItem);
                return;
            }

            int? paragraphNumId = null;

            XElement paragraphNumberingProperties = paragraph
                .Elements(W.pPr)
                .Elements(W.numPr)
                .FirstOrDefault();

            if (paragraphNumberingProperties != null)
            {
                paragraphNumId = (int?)paragraphNumberingProperties
                    .Elements(W.numId)
                    .Attributes(W.val)
                    .FirstOrDefault();

                // if numPr of paragraph does not contain numId, then it is not a list item.
                // if numId of paragraph == 0, then this is not a list item, regardless of the markup in the style.
                if (paragraphNumId == null || paragraphNumId == 0)
                {
                    paragraph.AddAnnotation(NotAListItem);
                    return;
                }
            }

            string paragraphStyleName = GetParagraphStyleName(stylesXDoc, paragraph);

            var listItemInfo = GetListItemInfoFromCache(numXDoc, paragraphStyleName, paragraphNumId);
            if (listItemInfo != null)
            {
                paragraph.AddAnnotation(listItemInfo);

                if (listItemInfo.FromParagraph != null)
                {
                    var para_ilvl = (int?)paragraphNumberingProperties
                        .Elements(W.ilvl)
                        .Attributes(W.val)
                        .FirstOrDefault();

                    if (para_ilvl == null)
                        para_ilvl = 0;

                    var abstractNum = listItemInfo.FromParagraph.Main.AbstractNum;
                    var multiLevelType = (string)abstractNum.Elements(W.multiLevelType).Attributes(W.val).FirstOrDefault();
                    if (multiLevelType == "singleLevel")
                        para_ilvl = 0;

                    SetParagraphLevel(paragraph, (int)para_ilvl);
                }
                else if (listItemInfo.FromStyle != null)
                {
                    int this_ilvl = listItemInfo.FromStyle.Style_ilvl;
                    var abstractNum = listItemInfo.FromStyle.Main.AbstractNum;
                    var multiLevelType = (string)abstractNum.Elements(W.multiLevelType).Attributes(W.val).FirstOrDefault();
                    if (multiLevelType == "singleLevel")
                        this_ilvl = 0;

                    SetParagraphLevel(paragraph, this_ilvl);
                }
                return;
            }

            listItemInfo = new ListItemInfo();

            int? style_ilvl = null;
            bool? styleZeroNumId = null;

            if (paragraphStyleName != null)
            {
                listItemInfo.FromStyle = InitializeStyleListItemSource(numXDoc, stylesXDoc, paragraph, paragraphStyleName,
                        out style_ilvl, out styleZeroNumId);
            }

            int? paragraph_ilvl = null;
            bool? paragraphZeroNumId = null;

            if (paragraphNumberingProperties != null && paragraphNumberingProperties.Element(W.numId) != null)
            {
                listItemInfo.FromParagraph = InitializeParagraphListItemSource(numXDoc, stylesXDoc, paragraph, paragraphNumberingProperties, out paragraph_ilvl, out paragraphZeroNumId);
            }

            if (styleZeroNumId == true && paragraphZeroNumId == null ||
                paragraphZeroNumId == true)
            {
                paragraph.AddAnnotation(NotAListItem);
                AddListItemInfoIntoCache(numXDoc, paragraphStyleName, paragraphNumId, NotAListItem);
                return;
            }

            int ilvlToSet = 0;
            if (paragraph_ilvl != null)
                ilvlToSet = (int)paragraph_ilvl;
            else if (style_ilvl != null)
                ilvlToSet = (int)style_ilvl;

            if (listItemInfo.FromParagraph != null)
            {
                var abstractNum = listItemInfo.FromParagraph.Main.AbstractNum;
                var multiLevelType = (string)abstractNum.Elements(W.multiLevelType).Attributes(W.val).FirstOrDefault();
                if (multiLevelType == "singleLevel")
                    ilvlToSet = 0;
            }
            else if (listItemInfo.FromStyle != null)
            {
                var abstractNum = listItemInfo.FromStyle.Main.AbstractNum;
                var multiLevelType = (string)abstractNum.Elements(W.multiLevelType).Attributes(W.val).FirstOrDefault();
                if (multiLevelType == "singleLevel")
                    ilvlToSet = 0;
            }

            SetParagraphLevel(paragraph, ilvlToSet);

            listItemInfo.IsListItem = listItemInfo.FromStyle != null || listItemInfo.FromParagraph != null;
            paragraph.AddAnnotation(listItemInfo);
            AddListItemInfoIntoCache(numXDoc, paragraphStyleName, paragraphNumId, listItemInfo);
        }
 private static string FormatListItem(ListItemInfo lii, int[] levelNumbers, int ilvl,
     string lvlText, XDocument styles, string languageCultureName, ListItemRetrieverSettings settings)
 {
     string[] formatTokens = GetFormatTokens(lvlText).ToArray();
     XElement lvl = lii.Lvl(ilvl);
     bool isLgl = lvl.Elements(W.isLgl).Any();
     string listItem = formatTokens.Select((t, l) =>
     {
         if (t.Substring(0, 1) != "%")
             return t;
         int indentationLevel;
         if (!Int32.TryParse(t.Substring(1), out indentationLevel))
             return t;
         indentationLevel -= 1;
         if (indentationLevel >= levelNumbers.Length)
             indentationLevel = levelNumbers.Length - 1;
         int levelNumber = levelNumbers[indentationLevel];
         string levelText = null;
         XElement rlvl = lii.Lvl(indentationLevel);
         string numFmtForLevel = (string)rlvl.Elements(W.numFmt).Attributes(W.val).FirstOrDefault();
         if (numFmtForLevel == null)
         {
             var numFmtElement = rlvl.Elements(MC.AlternateContent).Elements(MC.Choice).Elements(W.numFmt).FirstOrDefault();
             if (numFmtElement != null && (string)numFmtElement.Attribute(W.val) == "custom")
                 numFmtForLevel = (string)numFmtElement.Attribute(W.format);
         }
         if (numFmtForLevel != "none")
         {
             if (isLgl && numFmtForLevel != "decimalZero")
                 numFmtForLevel = "decimal";
         }
         if (languageCultureName != null && settings != null)
         {
             if (settings.ListItemTextImplementations.ContainsKey(languageCultureName))
             {
                 var impl = settings.ListItemTextImplementations[languageCultureName];
                 levelText = impl(languageCultureName, levelNumber, numFmtForLevel);
             }
         }
         if (levelText == null)
             levelText = ListItemTextGetter_Default.GetListItemText(languageCultureName, levelNumber, numFmtForLevel);
         return levelText;
     }).StringConcatenate();
     return listItem;
 }
Exemplo n.º 40
0
 private void addListItem(ListItemInfo<object> info)
 {
     _syncContext.Post((y) =>
     {
         var item = (ListItemInfo<object>)y;
         var time = DateTime.Now;
         var listItem = listView.Items.Insert(0, string.Format("{0}:{1}:{2}.{3}",
             time.Hour.ToString().PadLeft(2, '0'),
             time.Minute.ToString().PadLeft(2, '0'),
             time.Second.ToString().PadLeft(2, '0'),
             time.Millisecond));
         listItem.SubItems.Add(item.Message.GetType().ToString());
         listItem.Tag = item.Message;
     }, info);
 }
Exemplo n.º 41
0
        private static void AddListItemInfoIntoCache(XDocument numXDoc, string styleName, int?numId, ListItemInfo listItemInfo)
        {
            string key =
                (styleName == null ? "" : styleName) +
                "|" +
                (numId == null ? "" : numId.ToString());

            var numXDocRoot = numXDoc.Root;
            Dictionary <string, ListItemInfo> listItemInfoCache =
                numXDocRoot.Annotation <Dictionary <string, ListItemInfo> >();

            if (listItemInfoCache == null)
            {
                listItemInfoCache = new Dictionary <string, ListItemInfo>();
                numXDocRoot.AddAnnotation(listItemInfoCache);
            }
            if (!listItemInfoCache.ContainsKey(key))
            {
                listItemInfoCache.Add(key, listItemInfo);
            }
        }
        private static ListItemInfo GetListItemInfo(XDocument numbering, XDocument styles,
                                                    XElement paragraph)
        {
            // The following is an optimization - only determine ListItemInfo once for a
            // paragraph.
            ListItemInfo listItemInfo = paragraph.Annotation <ListItemInfo>();

            if (listItemInfo != null)
            {
                return(listItemInfo);
            }
            XElement paragraphNumberingProperties = paragraph.Elements(W.pPr)
                                                    .Elements(W.numPr).FirstOrDefault();
            string paragraphStyle = (string)paragraph.Elements(W.pPr).Elements(W.pStyle)
                                    .Attributes(W.val).FirstOrDefault();

            if (paragraphNumberingProperties != null &&
                paragraphNumberingProperties.Element(W.numId) != null)
            {
                // Paragraph numbering properties must contain a numId.
                int numId = (int)paragraphNumberingProperties.Elements(W.numId)
                            .Attributes(W.val).FirstOrDefault();
                int?ilvl = (int?)paragraphNumberingProperties.Elements(W.ilvl)
                           .Attributes(W.val).FirstOrDefault();
                if (ilvl != null)
                {
                    listItemInfo = GetListItemInfoByNumIdAndIlvl(numbering, styles, numId,
                                                                 (int)ilvl);
                    paragraph.AddAnnotation(listItemInfo);
                    return(listItemInfo);
                }
                if (paragraphStyle != null)
                {
                    listItemInfo = GetListItemInfoByNumIdAndStyleId(numbering, styles,
                                                                    numId, paragraphStyle);
                    paragraph.AddAnnotation(listItemInfo);
                    return(listItemInfo);
                }
                listItemInfo = new ListItemInfo(false);
                paragraph.AddAnnotation(listItemInfo);
                return(listItemInfo);
            }
            if (paragraphStyle != null)
            {
                XElement style = styles.Root.Elements(W.style).Where(s =>
                                                                     (string)s.Attribute(W.type) == "paragraph" &&
                                                                     (string)s.Attribute(W.styleId) == paragraphStyle).FirstOrDefault();
                if (style != null)
                {
                    XElement styleNumberingProperties = style.Elements(W.pPr)
                                                        .Elements(W.numPr).FirstOrDefault();
                    if (styleNumberingProperties != null &&
                        styleNumberingProperties.Element(W.numId) != null)
                    {
                        int numId = (int)styleNumberingProperties.Elements(W.numId)
                                    .Attributes(W.val).FirstOrDefault();
                        int?ilvl = (int?)styleNumberingProperties.Elements(W.ilvl)
                                   .Attributes(W.val).FirstOrDefault();
                        if (ilvl == null)
                        {
                            ilvl = 0;
                        }
                        listItemInfo = GetListItemInfoByNumIdAndIlvl(numbering, styles,
                                                                     numId, (int)ilvl);
                        paragraph.AddAnnotation(listItemInfo);
                        return(listItemInfo);
                    }
                }
            }
            listItemInfo = new ListItemInfo(false);
            paragraph.AddAnnotation(listItemInfo);
            return(listItemInfo);
        }