Esempio n. 1
0
        /// <summary>Gets a specific rounding rule with respect to its <see cref="System.String"/> representation.
        /// </summary>
        /// <param name="name">The name of the rounding rule.</param>
        /// <param name="value">The rounding rule (output).</param>
        /// <param name="addIntoPool">If a individual rounding rule has been created, the corresponding
        /// <paramref name="value"/> object will be added to the <see cref="RoundingRule"/> if set to <c>true</c>.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        public static bool TryGetValue(string name, out IRoundingRule value, bool addIntoPool = false)
        {
            if (sm_Pool.TryGetValue(name, out value) == true)
            {
                return(true);
            }

            // Format: "Rulename:Unit=23.1" or "Rulename:Digits=5" etc.
            string[] ruleNameSplit = name.Split(':', '=');
            if ((ruleNameSplit != null) && (ruleNameSplit.Length == 3))
            {
                Type roundingRuleType;
                if (sm_RoundingRuleTypes.TryGetValue(ruleNameSplit[0].ToIDString(), out roundingRuleType) == true)
                {
                    try
                    {
                        /* assume that the rounding rule needs exactly one argument in the constructor:
                         */
                        Type parameterType = roundingRuleType.GetConstructors()[0].GetParameters()[0].ParameterType;
                        if (parameterType.Equals(typeof(Int32)) == true)
                        {
                            value = (IRoundingRule)Activator.CreateInstance(roundingRuleType, Int32.Parse(ruleNameSplit[2]));
                        }
                        else if (parameterType.Equals(typeof(Double)) == true)
                        {
                            value = (IRoundingRule)Activator.CreateInstance(roundingRuleType, Double.Parse(ruleNameSplit[2], CultureInfo.InvariantCulture));
                        }
                        else if (parameterType.Equals(typeof(String)) == true)
                        {
                            value = (IRoundingRule)Activator.CreateInstance(roundingRuleType, ruleNameSplit[2]);
                        }
                        if (value != null)
                        {
                            if (addIntoPool == true)
                            {
                                sm_Pool.Add(value);
                            }
                            return(true);
                        }
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>Adds a specified business day convention.
        /// </summary>
        /// <param name="value">The business day convention to add.</param>
        /// <returns>A value indicating whether <paramref name="value"/> has been added.</returns>
        public static ItemAddedState Add(IBusinessDayConvention value)
        {
            ItemAddedState state = sm_Pool.Add(value);

//            sm_Logger.Add_PoolItemState(state, value.Name);
            return(state);
        }
Esempio n. 3
0
        /// <summary>Adds the specified holiday calendar.
        /// </summary>
        /// <param name="value">The holiday calendar.</param>
        /// <returns>A value indicating whether <paramref name="value"/> has been inserted.</returns>
        public static ItemAddedState Add(IHolidayCalendar value)
        {
            ItemAddedState state = sm_Pool.Add(value);

//            sm_Logger.Add_PoolItemState(state, (value != null) ? value.Name : null);
            return(state);
        }
Esempio n. 4
0
        /// <summary>Adds the specified day count convention.
        /// </summary>
        /// <param name="value">The business day convention to add.</param>
        /// <returns>A value indicating whether <paramref name="value"/> has been added.</returns>
        public static ItemAddedState Add(IDayCountConvention value)
        {
            ItemAddedState state = sm_Pool.Add(value);

//            sm_Logger.Add_PoolItemState(state, (value != null) ? value.Name : null);
            return(state);
        }
        /// <summary>Adds a specified compounding convention.
        /// </summary>
        /// <param name="value">The compounding convention to add.</param>
        /// <returns>A value indicating whether <paramref name="value"/> has been added.</returns>
        public ItemAddedState Add(IInterestRateCompounding value)
        {
            ItemAddedState state = m_Pool.Add(value);

            //m_LoggingStream.Add_PoolItemState(state, value.Name);
            return(state);
        }
Esempio n. 6
0
        /// <summary>Gets a date schedule frequency.
        /// </summary>
        /// <param name="frequency">The frequency in its <see cref="System.String"/> representation; perhaps a <see cref="TenorTimeSpan"/> in its <see cref="System.String"/> representation.</param>
        /// <param name="value">The date schedule frequency (output).</param>
        /// <param name="addIntoPool">If <paramref name="frequency"/> represents a individual frequency,
        /// the corresponding <see cref="IDateScheduleFrequency"/> will be added to the <see cref="DateScheduleFrequency"/> if set to <c>true</c>.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <remarks>If <paramref name="frequency"/> does not represents an item of the pool, try to create to convert <paramref name="frequency"/> to a  <see cref="TenorTimeSpan"/> object first.</remarks>
        public static bool TryGetValue(string frequency, out IDateScheduleFrequency value, bool addIntoPool = false)
        {
            if ((frequency == null) || (frequency.Length == 0))
            {
                value = null;
                return(false);
            }
            if (sm_Pool.TryGetValue(frequency, out value) == true)
            {
                return(true);
            }

            TenorTimeSpan tenorFrequency;   // try to generate a individual frequency:

            if (TenorTimeSpan.TryParse(frequency, out tenorFrequency) == false)
            {
                value = null;
                return(false);
            }
            if (IndividualDateScheduleFrequency.TryCreate(tenorFrequency, out value) == true)
            {
                if (addIntoPool)
                {
                    sm_Pool.Add(value);
                }
                return(true);
            }
            value = null;
            return(false);
        }
Esempio n. 7
0
        /// <summary>Raises the <see cref="Initialize"/> event.
        /// </summary>
        private static void OnInitialize()
        {
            if (sm_InitializeChanged == true)
            {
                /* first remove all IHolidayCalendar objects */
                sm_Pool = new IdentifierNameableDictionary <IHolidayCalendar>(100, isReadOnlyExceptAdding: true);  // clear is not allowed, it is readonly
                sm_Pool.Add(EmptyHolidayCalendar);
                sm_Pool.Add(WeekendCalendar);

                /* add all IHolidayCalendar objects */
                if (sm_Initialize != null)
                {
                    InitializeEventArgs eventArgs = new InitializeEventArgs();
                    sm_Initialize(eventArgs);
                }
                sm_InitializeChanged = false;
            }
        }
        /// <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.");
        }
Esempio n. 9
0
        /// <summary>Adds a specific <see cref="ExcelPoolItem"/> object into the <see cref="ExcelPool"/>.
        /// </summary>
        /// <param name="excelPoolItem">The object to insert into the pool.</param>
        /// <returns>A value indicating whether <paramref name="excelPoolItem"/> has been inserted to the pool.</returns>
        public static ItemAddedState InsertObject(ExcelPoolItem excelPoolItem)
        {
            lock (sm_Pool)
            {
                if (excelPoolItem == null)
                {
                    if (ItemAdded != null)
                    {
                        ItemAdded(new ItemAddedEventArgs(null, ItemAddedState.Rejected));
                    }
                    return(ItemAddedState.Rejected);
                }
                ExcelPoolItem oldItem;

                if (sm_Pool.TryGetValue(excelPoolItem.ObjectName, out oldItem) == true)
                {
                    if (oldItem.Value is IDisposable)
                    {
                        ((IDisposable)oldItem.Value).Dispose();
                    }
                    sm_Pool[excelPoolItem.ObjectName] = excelPoolItem;
                    if (sm_LoggingLevel == ExcelPoolLoggingLevel.TrackPoolChanges)
                    {
                        // Logger.Stream.Add_Info_PoolItemReplaced(senderObjectTypeName: "ExcelPool", senderObjectType: typeof(ExcelPool), senderObjectName: excelPoolItem.ObjectName.String);
                    }
                    if (ItemAdded != null)
                    {
                        ItemAdded(new ItemAddedEventArgs(excelPoolItem, ItemAddedState.Replaced));
                    }
                    return(ItemAddedState.Replaced);
                }
                sm_Pool.Add(excelPoolItem);
                if (sm_LoggingLevel == ExcelPoolLoggingLevel.TrackPoolChanges)
                {
                    //  Logger.Stream.Add_Info_PoolItemAdded(senderObjectTypeName: "ExcelPool", senderObjectType: typeof(ExcelPool), senderObjectName: excelPoolItem.ObjectName.String);
                }
                if (ItemAdded != null)
                {
                    ItemAdded(new ItemAddedEventArgs(excelPoolItem, ItemAddedState.Added));
                }
                return(ItemAddedState.Added);
            }
        }
Esempio n. 10
0
 /// <summary>Initializes a new instance of the <see cref="ExcelDataAdvicePool"/> class.
 /// </summary>
 internal ExcelDataAdvicePool()
 {
     m_ExcelDataAdvice.Add(m_BooleanAdvice);
 }
Esempio n. 11
0
 /// <summary>Adds a specific <see cref="IObjectStreamer"/>.
 /// </summary>
 /// <param name="objectStreamer">The <see cref="IObjectStreamer"/> to add.</param>
 /// <returns>A value indicating whether <paramref name="objectStreamer"/> has been added.</returns>
 public static ItemAddedState Add(IObjectStreamer objectStreamer)
 {
     return(sm_Pool.Add(objectStreamer));
 }
 /// <summary>Adds the <see cref="Currency"/> objects provided by the current object into a specific <see cref="IdentifierNameableDictionary{Currency}"/> object.
 /// </summary>
 /// <param name="commonCurrencyPool">The common currency pool.</param>
 internal void FillPool(IdentifierNameableDictionary <Currency> commonCurrencyPool)
 {
     commonCurrencyPool.Add(EUR);
     commonCurrencyPool.Add(GBP);
 }