예제 #1
0
        /// <summary>Writes a specific object into a <see cref="IObjectStreamWriter"/> and all its dependency input objects.
        /// </summary>
        /// <param name="objectStreamWriter">The object stream writer.</param>
        /// <param name="value">The <c>root</c> item to add, i.e. all dependency input will be added in a recursive way.</param>
        /// <param name="setOfInsertedItems">A collection of the <see cref="ExcelPoolItem"/> objects which are already stored in <paramref name="objectStreamWriter"/>.</param>
        /// <param name="infoStrBuilder">A collector for info string, as for example error messages.</param>
        /// <param name="storedObjectCount">The number of objects added into the <paramref name="objectStreamWriter"/> (output).</param>
        /// <param name="errorCount">The number of error mesages in <paramref name="infoStrBuilder"/> (output).</param>
        /// <remarks><paramref name="setOfInsertedItems"/> is used to avoid multiply entries in <paramref name="objectStreamWriter"/> with the same name.</remarks>
        private static void WriteObject(IObjectStreamWriter objectStreamWriter, ExcelPoolItem value, IdentifierStringDictionary <ExcelPoolItem> setOfInsertedItems, StringBuilder infoStrBuilder, ref int storedObjectCount, ref int errorCount)
        {
            IEnumerable <ExcelPoolItem> inputItems = value.InputDependencyItems;

            if ((inputItems != null) && (inputItems.Count() > 0))  // there are dependencies, i.e. store the dependencies first
            {
                foreach (var dependentExcelPoolItem in inputItems)
                {
                    WriteObject(objectStreamWriter, dependentExcelPoolItem, setOfInsertedItems, infoStrBuilder, ref storedObjectCount, ref errorCount);
                }
            }

            /* if a item with the same name is already added to the stream check whether both objects are equal:  */
            ExcelPoolItem alreadyAddedItem;

            if (setOfInsertedItems.TryGetValue(value.ObjectName, out alreadyAddedItem) == true)
            {
                if (value.Equals(alreadyAddedItem) == false)  // assume that both objects share the same adress
                {
                    infoStrBuilder.AppendLine("Inconsistent data input: Object '" + value.ObjectName.String + "' with time stamp '" + value.TimeStamp.ToString("HH:mm:ss.ff") + " and " + alreadyAddedItem.TimeStamp.ToString("HH:mm:ss.ff") + " [is added]");
                }
            }
            else
            {
                /*  check whether the item is equal to an element of the Excel pool with the
                 *  same name and add a warning message if it is different: (plausibility check) */

                ExcelPoolItem excelPoolItem;
                if (sm_Pool.TryGetValue(value.ObjectName, out excelPoolItem) == false)
                {
                    infoStrBuilder.AppendLine("Item to add is not in the Excel pool any more.");  // a internal error message
                    errorCount++;
                }
                else if (value.Equals(excelPoolItem) == false)
                {
                    infoStrBuilder.AppendLine("Inconsistent data input: Object '" + value.ObjectName.String + "' with time stamp '" + value.TimeStamp.ToString("HH:mm:ss.ff") + " [is added] and " + excelPoolItem.TimeStamp.ToString("HH:mm:ss.ff"));
                    errorCount++;
                }

                string errorMessage;
                if (TryWriteObject(objectStreamWriter, value, out errorMessage) == false)
                {
                    infoStrBuilder.AppendLine(errorMessage);
                    errorCount++;
                }
                else
                {
                    storedObjectCount++;
                }
                setOfInsertedItems.Add(value.Name, value);
            }
        }
예제 #2
0
        /// <summary>Initializes a new instance of the <see cref="ExcelPoolItem"/> class.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="objectName">The name of <paramref name="value"/>.</param>
        /// <param name="objectType">The type of <paramref name="value"/>.</param>
        /// <param name="excelDataQueries">The excel data queries, i.e. the (user) input.</param>
        /// <param name="inputDependencyItems">A collection of <see cref="ExcelPoolItem"/> objects which are used as input for the construction of <paramref name="value"/>, i.e. dependent objects.</param>
        /// <remarks>The <see cref="IExcelDataQuery.QueryCompleted(bool)"/> will be called for each element of <paramref name="excelDataQueries"/> and the <see cref="GuidedExcelDataQuery"/> representation
        /// will be stored internally.</remarks>
        /// <example><paramref name="inputDependencyItems"/> are for example swap rates, deposit rates etc. if the current instance is a discount factor curve etc.</example>
        public ExcelPoolItem(IInfoOutputQueriable value, string objectName, ExcelPoolItemType objectType, IEnumerable <IExcelDataQuery> excelDataQueries, IEnumerable <ExcelPoolItem> inputDependencyItems = null)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            Value = value;

            if (objectName == null)
            {
                throw new ArgumentNullException("objectName");
            }
            ObjectName = objectName.ToIdentifierString();

            if (objectType == null)
            {
                throw new ArgumentNullException("objectType");
            }
            ObjectType = objectType;

            if (excelDataQueries == null)
            {
                throw new ArgumentNullException("excelDataQueries");
            }
            var guidedExcelDataQueryInput = new IdentifierStringDictionary <GuidedExcelDataQuery>(isReadOnlyExceptAdding: false);

            foreach (var inputExcelDataQuery in excelDataQueries)
            {
                inputExcelDataQuery.QueryCompleted();
                guidedExcelDataQueryInput.Add(inputExcelDataQuery.Name, inputExcelDataQuery.AsCustomizeData());
            }
            m_ExcelDataQueries = guidedExcelDataQueryInput;

            InputDependencyItems = inputDependencyItems;
            TimeStamp            = DateTime.Now;
        }