/// <summary>Adds the specified <see cref="ExcelPoolItemCreator"/> object.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <exception cref="ArgumentException">Thrown, if a <see cref="ExcelPoolItemCreator"/> with the same (identifier) string or <see cref="System.Guid"/> representation
        /// has already been added.</exception>
        private static void Add(ExcelPoolItemCreator value)
        {
            Guid identifier = value.ObjectType.Identifier;

            if (sm_ObjectCreatorsByGuid.ContainsKey(identifier) == false)
            {
                if (sm_ObjectCreatorsByName.ContainsKey(value.Name) == false)
                {
                    sm_ObjectCreatorsByGuid.Add(identifier, value);
                    sm_ObjectCreatorsByName.Add(value);
                    return;
                }
            }
            throw new ArgumentException("Invalid 'ExcelPoolItemCreator' with name '" + value.Name.String + "' added. GUID or string representation is not unique.");
        }
示例#2
0
        /// <summary>Adds a collection of items into the <see cref="ExcelPool"/> which are given in its <see cref="GuidedExcelDataQuery"/> representation.
        /// </summary>
        /// <param name="objects">The objects to add, i.e. a collection where the first component is the object type in its <see cref="ExcelPoolItemType"/> representation,
        /// the second component is the object name and the third component represents the data needed to construct the desired objector; or the first and third component
        /// is <c>null</c> if no entry with the desired object name is available.</param>
        /// <param name="infoMessage">A <see cref="System.String"/> which represent a summary of the file operation, perhaps a error message (output).</param>
        /// <param name="excelPoolItems">The collection of added <see cref="ExcelPoolItem"/> objects (output).</param>
        /// <returns>A value indicating whether the operation was succeeded.</returns>
        /// <remarks>The <see cref="ExcelPoolItem"/> objects to insert must be given in a correct order taken into account dependencies of the input.</remarks>
        private static bool TryAddObjects(IEnumerable <Tuple <ExcelPoolItemType, string, IIdentifierStringDictionary <GuidedExcelDataQuery> > > objects, out string infoMessage, out IEnumerable <ExcelPoolItem> excelPoolItems)
        {
            if ((objects == null) || (objects.Count() == 0))
            {
                infoMessage    = "No data to add.";
                excelPoolItems = null;
                return(false);
            }
            List <ExcelPoolItem> addedItems = new List <ExcelPoolItem>();
            StringBuilder        strBuilder = new StringBuilder();

            int objectCount = 0;
            int errorCount  = 0;

            foreach (var obj in objects)
            {
                if (obj.Item1 == null)
                {
                    strBuilder.AppendLine("No data found for object with name '" + obj.Item2 + "'.");
                    errorCount++;
                }
                else if (obj.Item2 == null)
                {
                    strBuilder.AppendLine("No data found for object for type '" + obj.Item1.Name.String + "'.");
                }
                else
                {
                    ExcelPoolItemCreator guidedObjectCreator;
                    if (ExcelPoolItemCreator.TryGetValue(obj.Item1.Identifier, out guidedObjectCreator) == false)
                    {
                        strBuilder.AppendLine("No method found for generation objects of type '" + obj.Item1.Name.String + "'.");
                        errorCount++;
                    }
                    else
                    {
                        string errorMessage;
                        IEnumerable <ExcelPoolItem> excelPoolItemSet;
                        if (guidedObjectCreator.CreatingFunction(obj.Item3, out excelPoolItemSet, out errorMessage) == true)
                        {
                            foreach (ExcelPoolItem excelPoolItem in excelPoolItemSet)
                            {
                                if (InsertObject(excelPoolItem) == ItemAddedState.Rejected)
                                {
                                    strBuilder.AppendLine("Object '" + excelPoolItem.Name.String + "' of type '" + obj.Item1.Name.String + "' rejected, i.e. not added to the pool.");
                                    errorCount++;
                                }
                                else
                                {
                                    addedItems.Add(excelPoolItem);
                                    objectCount++;
                                }
                            }
                        }
                        else
                        {
                            strBuilder.AppendLine(errorMessage);
                            errorCount++;
                        }
                    }
                }
            }
            if (objectCount == 1)
            {
                strBuilder.AppendLine("Load 1 object.");
            }
            else if (objectCount > 1)
            {
                strBuilder.AppendLine("Load " + objectCount + " objects.");
            }
            else
            {
                strBuilder.AppendLine("No object loaded.");
            }
            if (errorCount > 0)
            {
                strBuilder.AppendLine(errorCount + " errors detected.");
            }
            infoMessage    = strBuilder.ToString();
            excelPoolItems = addedItems;
            return(errorCount == 0);
        }
 /// <summary>Registers a specific <see cref="ExcelPoolItemCreator"/> object, i.e. stores a mapping from a collection of <see cref="IExcelDataQuery"/> to <see cref="ExcelPoolItem"/>.
 /// </summary>
 /// <param name="value">The <see cref="ExcelPoolItemCreator"/> to register, i.e. used to create objects of a specific type via a collection of <see cref="IExcelDataQuery"/> instances.</param>
 /// <returns>A value indicating whether <paramref name="value"/> has been inserted.</returns>
 /// <exception cref="ArgumentException">Thrown, if a <see cref="ExcelPoolItemCreator"/> with the same (identifier) string or <see cref="System.Guid"/> representation has already been added.</exception>
 public void Add(ExcelPoolItemCreator value)
 {
     ExcelPoolItemCreator.Add(value);
 }
 /// <summary>Gets a specific <see cref="ExcelPoolItemCreator"/> object.
 /// </summary>
 /// <param name="key">The key, i.e. the unique (identifier) string representation of the <see cref="ExcelPoolItemCreator"/> to search.</param>
 /// <param name="value">The value (output).</param>
 /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
 public static bool TryGetValue(IdentifierString key, out ExcelPoolItemCreator value)
 {
     OnInitialize();
     return(sm_ObjectCreatorsByName.TryGetValue(key, out value));
 }
 /// <summary>Gets a specific <see cref="ExcelPoolItemCreator"/> object.
 /// </summary>
 /// <param name="key">The key, i.e. the unique <see cref="System.Guid"/> representation of the <see cref="ExcelPoolItemCreator"/> to search.</param>
 /// <param name="value">The value (output).</param>
 /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
 public static bool TryGetValue(Guid key, out ExcelPoolItemCreator value)
 {
     OnInitialize();
     return(sm_ObjectCreatorsByGuid.TryGetValue(key, out value));
 }