Esempio n. 1
0
        /// <summary>
        /// Adds a new transient 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 AddTransientItem(
            string name,
            object item,
            string contextSectionName = null)
        {
            string itemName = BdoDataContext.GetItemUniqueName(name, contextSectionName);

            TransientItems.Remove(itemName);
            TransientItems.Add(itemName, item);
        }
Esempio n. 2
0
        /// <summary>
        /// Loads a data context from file.
        /// </summary>
        /// <param name="filePath">The path of the file to load.</param>
        /// <param name="log">The log that receives the log of this loading task.</param>
        /// <returns>Returns the data context loaded from the specified file.</returns>
        public static BdoDataContext Load(string filePath, ref BdoLog log)
        {
            BdoDataContext dataContext = null;
            Stream         fileStream  = null;

            try
            {
                fileStream = File.Open(filePath, FileMode.Open);
                BinaryFormatter formatter = new BinaryFormatter();
                dataContext = (BdoDataContext)formatter.Deserialize(fileStream);
            }
            catch (IOException exception)
            {
                log.AddException(exception);
            }
            finally
            {
                fileStream?.Close();
            }

            return(dataContext);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns a specific transient 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 GetTransientItem(string name, string contextSectionName = null)
        {
            string itemName = BdoDataContext.GetItemUniqueName(name, contextSectionName);

            return(TransientItems.ContainsKey(itemName) ? TransientItems[itemName] : null);
        }