Пример #1
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);
        }
Пример #2
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);
            }
        }
Пример #3
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);
        }
Пример #4
0
 /// <summary>Gets a specified business day convention.
 /// </summary>
 /// <param name="name">The name of the business day convention to search.</param>
 /// <param name="value">The business day convention (output).</param>
 /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
 public static bool TryGetValue(IdentifierString name, out IBusinessDayConvention value)
 {
     return(sm_Pool.TryGetValue(name, out value));
 }
Пример #5
0
 /// <summary>Gets a specific <see cref="IExcelDataAdvice"/>.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value (output).</param>
 /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
 public bool TryGetValue(string name, out IExcelDataAdvice value)
 {
     OnInitialize();
     return(m_ExcelDataAdvice.TryGetValue(name, out value));
 }
Пример #6
0
 /// <summary>Gets a specified holiday calendar.
 /// </summary>
 /// <param name="name">The name of the holiday calendar.</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 name, out IHolidayCalendar value)
 {
     OnInitialize();
     return(sm_Pool.TryGetValue(name, out value));
 }
Пример #7
0
 /// <summary>Gets the <see cref="IObjectStreamer"/> object with repsect to a specific name.
 /// </summary>
 /// <param name="objectStreamerName">The (unique) name of the <see cref="IObjectStreamer"/>.</param>
 /// <param name="value">An instance of <see cref="IObjectStreamer"/>, where <see cref="IIdentifierNameable.Name"/> equals to
 /// <paramref name="objectStreamerName"/> (output).</param>
 /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
 public static bool TryGetObjectStreamer(IdentifierString objectStreamerName, out IObjectStreamer value)
 {
     return(sm_Pool.TryGetValue(objectStreamerName, out value));
 }
 /// <summary>Gets a specified compounding convention.
 /// </summary>
 /// <param name="name">The name of the compounding convention to search.</param>
 /// <param name="value">The compounding convention (output).</param>
 /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
 public bool TryGetValue(IdentifierString name, out IInterestRateCompounding value)
 {
     return(m_Pool.TryGetValue(name, out value));
 }
Пример #9
0
 /// <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(string key, out ExcelPoolItemCreator value)
 {
     OnInitialize();
     return(sm_ObjectCreatorsByName.TryGetValue(key, out value));
 }
Пример #10
0
 /// <summary>Gets a specified (interest rate) caplet tenor convention.
 /// </summary>
 /// <param name="name">The name of the caplet tenor convention.</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 name, out IIRCapletTenorConvention value)
 {
     return(sm_Pool.TryGetValue(name, out value));
 }