Esempio n. 1
0
        /// <summary>
        /// Adds or updates <paramref name="sourceFileName"/> in the given <paramref name="scopeManager"/>.
        /// The file is removed from the global scope in <paramref name="scopeManager"/> if it already exists via <see cref="TryRemoveFile"/>.
        /// </summary>
        /// <param name="scopeManager">The global scope manager</param>
        /// <param name="sourceFileName">The source file to check for</param>
        /// <returns>True if the global scope was modified; false otherwise</returns>
        protected bool TryAddOrUpdateFile(GlobalScopeManager scopeManager, string sourceFileName)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(null);
            }
            if (null == Archive)
            {
                throw new InvalidOperationException("Archive is null");
            }
            if (null == scopeManager)
            {
                throw new ArgumentNullException("scopeManager");
            }

            bool workingSetChanged = false;
            var  data = Archive.GetData(sourceFileName);

            if (null != data)
            {
                if (null == scopeManager.GlobalScope)
                {
                    scopeManager.GlobalScope = data;
                }
                else
                {
                    TryRemoveFile(scopeManager, sourceFileName);
                    scopeManager.GlobalScope = scopeManager.GlobalScope.Merge(data);
                }
                workingSetChanged = true;
            }

            return(workingSetChanged);
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a new working set object
 /// </summary>
 /// <param name="archive">The archive to monitor</param>
 /// <param name="factory">The task factory</param>
 protected AbstractWorkingSet(DataArchive archive, TaskFactory factory)
 {
     Archive                = archive;
     Factory                = factory;
     IsDisposed             = false;
     UseAsynchronousMethods = false;
     _globalScopeManager    = new GlobalScopeManager();
     _globalScopeLock       = new ReaderWriterLockSlim();
 }
Esempio n. 3
0
        /// <summary>
        /// Gets a write lock for this working set. If timeout is exceeded, then false is returned and <paramref name="scopeManager"/> will be null.
        /// If the write lock is obtained, true is returned and <paramref name="scopeManager"/> will contain the internal scope manager for this object.
        /// </summary>
        /// <param name="millisecondsTimeout">the timeout</param>
        /// <param name="scopeManager">out parameter for the global scope manager</param>
        /// <returns>True if the write lock was obtained; false otherwise</returns>
        protected bool TryObtainWriteLock(int millisecondsTimeout, out GlobalScopeManager scopeManager)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(null);
            }

            if (_globalScopeLock.TryEnterWriteLock(millisecondsTimeout))
            {
                scopeManager = _globalScopeManager;
                return(true);
            }
            scopeManager = null;
            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// <see cref="TryRemoveFile">Removes</see> <paramref name="oldSourceFileName"/> and
        /// <see cref="TryAddOrUpdateFile">adds or updates</see> <paramref name="newSourceFileName"/>from
        /// the global scope.
        /// </summary>
        /// <param name="scopeManager">The global scope manager</param>
        /// <param name="oldSourceFileName">The old file name to remove</param>
        /// <param name="newSourceFileName">The new file name to add or update</param>
        /// <returns>True if the global scope was modified; false otherwise</returns>
        protected bool TryRenameFile(GlobalScopeManager scopeManager, string oldSourceFileName, String newSourceFileName)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(null);
            }
            if (null == scopeManager)
            {
                throw new ArgumentNullException("scopeManager");
            }

            bool workingSetChanged = TryRemoveFile(scopeManager, oldSourceFileName);

            workingSetChanged = TryAddOrUpdateFile(scopeManager, newSourceFileName);
            return(workingSetChanged);
        }
Esempio n. 5
0
        /// <summary>
        /// Dispose of this working set. The methods on this class will throw an ObjectDisposedException if they are called after Dispose is called.
        /// This will also call <see cref="AbstractArchive.Dispose()"/> on the <see cref="Archive"/>.
        /// </summary>
        public void Dispose()
        {
            if (!IsDisposed)
            {
                StopMonitoring();
                _globalScopeManager.GlobalScope = null;
                _globalScopeManager             = null;

                if (null != Archive)
                {
                    Archive.Dispose();
                }

                IsDisposed = true;
                Changed    = null;
                _globalScopeLock.Dispose();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Removes <paramref name="sourceFileName"/> from <paramref name="scopeManager"/>
        /// </summary>
        /// <param name="scopeManager">The global scope manager</param>
        /// <param name="sourceFileName">the source file to remove</param>
        /// <returns>True if the global scope was modified; false otherwise</returns>
        protected bool TryRemoveFile(GlobalScopeManager scopeManager, string sourceFileName)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(null);
            }
            if (null == scopeManager)
            {
                throw new ArgumentNullException("scopeManager");
            }

            bool workingSetChanged = false;

            if (ContainsFile(scopeManager.GlobalScope, sourceFileName))
            {
                scopeManager.GlobalScope.RemoveFile(sourceFileName);
                workingSetChanged = true;
            }

            return(workingSetChanged);
        }