Exemplo n.º 1
0
        private void DoUpdate()
        {
            List <Task> targetItems = targetProjectView.Find(targetFind);
            List <Task> sourceItems = sourceProjectView.Find(targetFind);

            foreach (Hansoft.ObjectWrapper.Task targetTask in targetItems)
            {
                Hansoft.ObjectWrapper.Task sourceTask = sourceItems.FirstOrDefault(s => s.LinkedTasks.Contains(targetTask));
                if (sourceTask != null)
                {
                    foreach (ColumnMapping mapping in columnMappings)
                    {
                        // TODO: Simplify the sequence below
                        if (mapping.SourceColumn.IsCustomColumn && mapping.TargetColumn.IsCustomColumn && (mapping.SourceColumn.CustomColumn.m_Type == mapping.TargetColumn.CustomColumn.m_Type))
                        {
                            targetTask.SetCustomColumnValue(mapping.TargetColumn.CustomColumn, CustomColumnValue.FromInternalValue(targetTask, mapping.TargetColumn.CustomColumn, sourceTask.GetCustomColumnValue(mapping.SourceColumn.CustomColumn).InternalValue));
                        }
                        else
                        {
                            object sourceValue;
                            if (mapping.SourceColumn.IsCustomColumn)
                            {
                                sourceValue = sourceTask.GetCustomColumnValue(mapping.SourceColumn.CustomColumn);
                            }
                            else
                            {
                                sourceValue = sourceTask.GetDefaultColumnValue(mapping.SourceColumn.DefaultColumnType);
                            }
                            if (mapping.TargetColumn.IsCustomColumn)
                            {
                                string endUserString;
                                if (sourceValue is float || sourceValue is double)
                                {
                                    endUserString = String.Format(new System.Globalization.CultureInfo("en-US"), "{0:F1}", sourceValue);
                                }
                                else
                                {
                                    endUserString = sourceValue.ToString();
                                }
                                targetTask.SetCustomColumnValue(mapping.TargetColumn.CustomColumn, endUserString);
                            }
                            else
                            {
                                targetTask.SetDefaultColumnValue(mapping.TargetColumn.DefaultColumnType, sourceValue);
                            }
                        }
                    }
                }
            }
        }
            internal void DoUpdate(Task task)
            {
                try
                {
                    Debug.Print("DeriveBehaviour - {0} - {1} - processing task \"{2}\"",
                        isCustomColumn ? customColumnName : defaultColumnType.ToString(),
                        expression,
                        task.Name);
                    var expressionValue = mInfo.Invoke(null, new object[] { task });
                    if (isCustomColumn)
                    {
                        // Ensure that we get the custom column of the right project
                        var customColumn = task.ProjectView.GetCustomColumn(customColumnName);
                        var oldValue = task.GetCustomColumnValue(customColumnName);

                        if (customColumn != null && oldValue != null && !oldValue.Equals(expressionValue))
                            task.SetCustomColumnValue(customColumn, expressionValue);
                    }
                    else
                    {
                        var oldValue = task.GetDefaultColumnValue(defaultColumnType);
                        if (oldValue != null && !oldValue.Equals(expressionValue))
                            task.SetDefaultColumnValue(defaultColumnType, expressionValue);
                    }
                }
                catch (TargetInvocationException e)
                {
                    // Hack to let column handlers bail out when they don't have any new value to set.
                    if (!(e.InnerException is NoNewValueException))
                        throw;
                }
            }