コード例 #1
0
        /// <summary>
        /// Table adapter specific load. Loads <c>WordTableWorkItems</c> from tables.
        /// </summary>
        /// <param name="loadCriteria">Selects which items to actually load. This is a performance enhancer...</param>
        protected bool LoadStructure(Func <Table, IConfigurationItem, bool> loadCriteria)
        {
            WorkItems = new WordTableWorkItemCollection();

            if (Document.Tables == null)
            {
                return(true);
            }

            foreach (Table table in Document.Tables)
            {
                try
                {
                    var workItem = CreateWorkItem(table, loadCriteria);

                    // add successfully created items if the id is in the list or no list was set
                    if (workItem != null)
                    {
                        ApplyHeaders(workItem);
                        WorkItems.Add(workItem);

                        // Load embedded work items
                        foreach (var subItem in workItem.CreateLinkedWorkItems())
                        {
                            ApplyHeaders(workItem);
                            WorkItems.Add(subItem);
                        }
                    }
                    else
                    {
                        var header = CreateHeader(table);

                        // If the table was a header, remove all headers of higher or the same level from the stack
                        if (header != null)
                        {
                            while (_headers.Count > 0 && _headers.Peek().Configuration.Level >= header.Configuration.Level)
                            {
                                _headers.Pop();
                            }
                            _headers.Push(header);
                            SyncServiceTrace.D("Found new header, new stack: {0}", string.Join(",", _headers.Select(x => x.Configuration.WorkItemType).ToArray()));
                        }
                    }
                }
                catch (Exception ex)
                {
                    SyncServiceTrace.LogException(ex);
                    var infoStorage = SyncServiceFactory.GetService <IInfoStorageService>();
                    if (infoStorage != null)
                    {
                        infoStorage.NotifyError(Resources.Error_LoadWordWI, ex);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// The method creates work items dependent on this work item
        /// </summary>
        /// <returns>Collection of dependent work items.</returns>
        /// <exception cref="ConfigurationException">Thrown if the configuration contains invalid cell column or row for FieldToLinkedItemConfiguration.</exception>
        public IWorkItemCollection CreateLinkedWorkItems()
        {
            var retValue = new WordTableWorkItemCollection();

            LinkedWorkItems = new Dictionary <string, IWorkItemCollection>();
            // Get the associated configuration

            if (!_configurationItem.ConfigurationSupportsLinkedItem)
            {
                return(retValue);
            }
            if (_configurationItem.FieldToLinkedItemConfiguration == null)
            {
                return(retValue);
            }
            if (_configurationItem.FieldToLinkedItemConfiguration.Count == 0)
            {
                return(retValue);
            }
            foreach (var configurationLinkedItem in _configurationItem.FieldToLinkedItemConfiguration)
            {
                // Get the cell of the table, where the linked work items are defined.
                var cellRange = WordSyncHelper.GetCellRange(Table, configurationLinkedItem.RowIndex, configurationLinkedItem.ColIndex);
                if (cellRange == null)
                {
                    continue;
                }
                // At this moment only 'NumberedList' supported
                if (configurationLinkedItem.WorkItemBindType != WorkItemBindType.NumberedList)
                {
                    continue;
                }
                var numberedListItems = new List <Range>();
                foreach (Paragraph paragraph in cellRange.Paragraphs)
                {
                    if (paragraph.Range.ListFormat != null && paragraph.Range.ListFormat.ListLevelNumber == 1 &&
                        paragraph.Range.ListFormat.ListValue > 0)
                    {
                        // We need to store only ranges of 'valid' list items
                        // Valid list item is for us item with level 1 and value bigger as 0
                        numberedListItems.Add(paragraph.Range);
                    }
                }
                for (int index = 0; index < numberedListItems.Count; index++)
                {
                    var title = numberedListItems[index];
                    int end   = cellRange.End - 1; // -1 to cut the last charactar in the cell - \v
                    if (index + 1 < numberedListItems.Count)
                    {
                        end = numberedListItems[index + 1].Start;
                    }
                    var description = title.Document.Range(title.End, end);
                    var newWorkItem = new WordNumberedListItemWorkItem(configurationLinkedItem, title, description,
                                                                       _configuration);
                    retValue.Add(newWorkItem);
                    if (!LinkedWorkItems.ContainsKey(configurationLinkedItem.LinkType.ToString()))
                    {
                        LinkedWorkItems[configurationLinkedItem.LinkType.ToString()] = new WordTableWorkItemCollection();
                    }
                    LinkedWorkItems[configurationLinkedItem.LinkType.ToString()].Add(newWorkItem);
                }
            }
            return(retValue);
        }