コード例 #1
0
ファイル: BdoDataContext.cs プロジェクト: bindopen/BindOpen
        // --------------------------------------------------

        /// <summary>
        /// Merges this instance with the specified data context.
        /// </summary>
        /// <param name="dataContext">The data context to consider.</param>
        public void Merge(IBdoDataContext dataContext)
        {
            if (dataContext != null)
            {
                foreach (KeyValuePair <string, object> entry in dataContext.SingletonItems)
                {
                    if (!SingletonItems.ContainsKey(entry.Key))
                    {
                        SingletonItems.Add(entry.Key, entry.Value);
                    }
                }

                foreach (KeyValuePair <string, object> entry in dataContext.ScopedItems)
                {
                    if (!ScopedItems.ContainsKey(entry.Key))
                    {
                        ScopedItems.Add(entry.Key, entry.Value);
                    }
                }

                foreach (KeyValuePair <string, object> entry in dataContext.TransientItems)
                {
                    if (!TransientItems.ContainsKey(entry.Key))
                    {
                        TransientItems.Add(entry.Key, entry.Value);
                    }
                }
            }
        }
コード例 #2
0
ファイル: BdoDataContext.cs プロジェクト: bindopen/BindOpen
 /// <summary>
 /// Removes the singleton items of a specific type.
 /// </summary>
 /// <param name="contextSectionName">Name of the context section to consider.</param>
 /// <param name="persistenceLevel">The persistence level to consider.</param>
 public void RemoveItems(
     string contextSectionName          = null,
     PersistenceLevels persistenceLevel = PersistenceLevels.Singleton)
 {
     if ((persistenceLevel == PersistenceLevels.Any) || (persistenceLevel == PersistenceLevels.Singleton))
     {
         var items = SingletonItems.Keys.Where(p =>
                                               (string.IsNullOrEmpty(contextSectionName)) ||
                                               (p?.ToString().ToLower().StartsWith(contextSectionName.ToLower() + "$") == true));
         foreach (string key in items)
         {
             SingletonItems.Remove(key);
         }
     }
     if ((persistenceLevel == PersistenceLevels.Any) || (persistenceLevel == PersistenceLevels.Scoped))
     {
         var items = ScopedItems.Keys.Where(p =>
                                            (string.IsNullOrEmpty(contextSectionName)) ||
                                            (p?.ToString().ToLower().StartsWith(contextSectionName.ToLower() + "$") == true));
         foreach (string key in items)
         {
             ScopedItems.Remove(key);
         }
     }
     if ((persistenceLevel == PersistenceLevels.Any) || (persistenceLevel == PersistenceLevels.Transient))
     {
         var items = TransientItems.Keys.Where(p =>
                                               (string.IsNullOrEmpty(contextSectionName)) ||
                                               (p?.ToString().ToLower().StartsWith(contextSectionName.ToLower() + "$") == true));
         foreach (string key in items)
         {
             TransientItems.Remove(key);
         }
     }
 }
コード例 #3
0
ファイル: BdoDataContext.cs プロジェクト: bindopen/BindOpen
        /// <summary>
        /// Adds a new singleton item to this instance.
        /// </summary>
        /// <param name="name">Name of the item to add.</param>
        /// <param name="item">The item to consider.</param>
        /// <param name="contextSectionName">Name of the context section to consider.</param>
        public void AddSingletonItem(
            string name,
            object item,
            string contextSectionName = null)
        {
            string itemName = BdoDataContext.GetItemUniqueName(name, contextSectionName);

            SingletonItems.Remove(itemName);
            SingletonItems.Add(itemName, item);
        }
コード例 #4
0
ファイル: BdoDataContext.cs プロジェクト: bindopen/BindOpen
        /// <summary>
        /// Clears the specified items of this instance.
        /// </summary>
        /// <param name="persistenceLevel">Persistence level of the item to add.</param>
        public void ClearItems(PersistenceLevels persistenceLevel = PersistenceLevels.Singleton)
        {
            switch (persistenceLevel)
            {
            case PersistenceLevels.Singleton:
                SingletonItems.Clear();
                break;

            case PersistenceLevels.Scoped:
                ScopedItems.Clear();
                break;

            case PersistenceLevels.Transient:
                TransientItems.Clear();
                break;

            case PersistenceLevels.Any:
                SingletonItems.Clear();
                ScopedItems.Clear();
                TransientItems.Clear();
                break;
            }
        }
コード例 #5
0
ファイル: BdoDataContext.cs プロジェクト: bindopen/BindOpen
        /// <summary>
        /// Returns a specific singleton item.
        /// </summary>
        /// <param name="name">Name of the dynamic item to return.</param>
        /// <param name="contextSectionName">Name of the context section to consider.</param>
        /// <returns>The dynamic item with specified name and type.</returns>
        public object GetSingletonItem(string name, string contextSectionName = null)
        {
            string itemName = BdoDataContext.GetItemUniqueName(name, contextSectionName);

            return(SingletonItems.ContainsKey(itemName) ? SingletonItems[itemName] : null);
        }
コード例 #6
0
ファイル: BdoDataContext.cs プロジェクト: bindopen/BindOpen
 /// <summary>
 /// Clears all the data of this instance.
 /// </summary>
 public void Clear()
 {
     SingletonItems.Clear();
     ScopedItems.Clear();
     TransientItems.Clear();
 }