Beispiel #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;
        }
Beispiel #2
0
        private void InitializeFields()
        {
            IList <IField>     fields = new List <IField>();
            IConfigurationItem config = _configuration.GetWorkItemConfigurationExtended(WorkItemType, fieldName =>
            {
                if (string.IsNullOrEmpty(fieldName))
                {
                    return(null);
                }
                var fieldToEvaluate = Fields[fieldName];
                return(fieldToEvaluate == null ? null : fieldToEvaluate.Value);
            });

            if (null != config)
            {
                foreach (IConfigurationFieldItem fieldItem in config.FieldConfigurations)
                {
                    // We need to map only configured items in IConfigurationFieldToLinkedItem
                    foreach (IConfigurationFieldAssignment linkedFieldItem in ConfigurationToLinkedItem.FieldAssignmentConfiguration)
                    {
                        if (linkedFieldItem.ReferenceName == fieldItem.ReferenceFieldName)
                        {
                            IField field   = null;
                            Range  content = null;
                            if (linkedFieldItem.FieldPosition == FieldPositionType.Hidden)
                            {
                                // ToDo: Finish this implementation
                                field = new HiddenField(fieldItem, config.GetConverter(fieldItem.ReferenceFieldName));
                            }
                            if (linkedFieldItem.FieldPosition == FieldPositionType.NumberedListItemFirstAddition)
                            {
                                content = NumberedListItemFirstAddition;
                            }
                            else if (linkedFieldItem.FieldPosition == FieldPositionType.NumberedListItemSecondAddition)
                            {
                                content = NumberedListItemSecondAddition;
                            }
                            else if (linkedFieldItem.FieldPosition == FieldPositionType.NumberedListItemThirdAddition)
                            {
                                content = NumberedListItemThirdAddition;
                            }
                            else if (linkedFieldItem.FieldPosition == FieldPositionType.NumberedListItem)
                            {
                                content = WorkItemTitle;
                            }
                            else if (linkedFieldItem.FieldPosition == FieldPositionType.Remainder)
                            {
                                content = WorkItemDescription;
                            }
                            if (content != null)
                            {
                                var newField = new WordTableField(content, fieldItem, config.GetConverter(fieldItem.ReferenceFieldName), false);
                                fields.Add(newField);
                            }
                            else if (field != null)
                            {
                                fields.Add(field);
                            }
                        }
                    }
                }
            }

            _fields = new WordTableFieldCollection(fields);
        }