Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WordTableWorkItem"/> class.
        /// </summary>
        /// <param name="table">Table to wrap.</param>
        /// <param name="workItemType">Work item to wrap.</param>
        /// <param name="configuration">Configuration of all work items</param>
        /// <param name="configurationItem">The configuration of this work item</param>
        /// <exception cref="ConfigurationException">Thrown if the configuration contains invalid cell column or row for standard fields.</exception>
        internal WordTableWorkItem(Table table, string workItemType, IConfiguration configuration, IConfigurationItem configurationItem)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (workItemType == null)
            {
                throw new ArgumentNullException("workItemType");
            }
            if (configurationItem == null)
            {
                throw new ArgumentNullException("configurationItem");
            }

            Table              = table;
            TableStart         = table.Range.Start;
            WorkItemType       = workItemType;
            _configuration     = configuration;
            _configurationItem = configurationItem.Clone();

            // Create fields
            IList <IField> fields = new List <IField>();

            foreach (var fieldItem in _configurationItem.FieldConfigurations)
            {
                if (fieldItem.IsMapped)
                {
                    var cellRange = WordSyncHelper.GetCellRange(Table, fieldItem.RowIndex, fieldItem.ColIndex);

                    if (fieldItem.FieldValueType == FieldValueType.BasedOnVariable || fieldItem.FieldValueType == FieldValueType.BasedOnSystemVariable)
                    {
                        fields.Add(new StaticValueField(cellRange, fieldItem, true));
                    }
                    else
                    {
                        fields.Add(new WordTableField(cellRange, fieldItem, _configurationItem.GetConverter(fieldItem.ReferenceFieldName), true));
                    }
                }
                else
                {
                    // Initialize unmapped fields with default values
                    var hiddenField = new HiddenField(fieldItem, _configurationItem.GetConverter(fieldItem.ReferenceFieldName));
                    if (fieldItem.DefaultValue != null)
                    {
                        hiddenField.Value = fieldItem.DefaultValue.DefaultValue;
                    }

                    fields.Add(hiddenField);
                }
            }

            Fields = new WordTableFieldCollection(fields);

            IsNew = Id <= 0;
        }