Exemple #1
0
        /// <summary>
        /// Remove an entry with a given key. Notifies subscriber, if there is any,
        /// of the removed item.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="regionName"></param>
        /// <returns></returns>
        public override object Remove(string key, string regionName = null)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var        cacheKey   = new CacheKey(key);
            CacheEntry cacheValue = null;

            // remove the item, return if not found.
            lock (_locker)
            {
                var mruEntry = MruManager.GetItem(cacheKey);
                if (mruEntry == null)
                {
                    return(null);
                }
                // get the Store's Current Key containing the TimeStamp!
                cacheKey   = (CacheKey)mruEntry.Key;
                cacheValue = mruEntry.Value as CacheEntry;
                MruManager.Remove(cacheKey);
            }
            // Notify the subscriber of the removed item.
            if (CacheEntrySetRemovedCallback != null)
            {
                CacheEntrySetRemovedCallback(new[]
                {
                    new CacheEntryRemovedArguments(this, CacheEntryRemovedReason.Removed, cacheValue.Convert(cacheKey))
                });
            }
            return(cacheValue);
        }
Exemple #2
0
 /// <summary>
 /// Dispose the File Stream.
 /// </summary>
 public void Dispose()
 {
     _isDisposed = true;
     if (_fileStream == null)
     {
         return;
     }
     if (!_unBuffered)
     {
         _fileStream.Dispose();
         InUse       = false;
         _fileStream = null;
         return;
     }
     MruManager.Remove(Id);
     lock (_locker)
     {
         if (_fileStream == null)
         {
             return;
         }
         _fileStream.Dispose();
         _fileStream = null;
         InUse       = false;
     }
 }
Exemple #3
0
 private void MaintainOpenedFileCount()
 {
     if (MruManager.Count <= MaxInstanceCount)
     {
         return;
     }
     while (MruManager.Count > MruManager.MinCapacity)
     {
         Mru.Generic.MruItem <int, FileStream> item = MruManager.PeekInTail();
         if (item.Value.InUse)
         {
             return;
         }
         lock (item.Value._locker)
         {
             if (item.Value.InUse || item.Value._fileStream == null)
             {
                 return;
             }
             MruManager.Remove(item.Value.Id);
             //item.Value._streamPosition = item.Value._fileStream.Position;
             item.Value._fileStream.Flush();
             item.Value._fileStream.Close();
             item.Value._fileStream = null;
         }
     }
 }
Exemple #4
0
 /// <summary>
 /// DocManager reports about successful/unsuccessful Open File operation
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void docManager_OpenEvent(object sender, OpenFileEventArgs e)
 {
     // Update MRU List
     if (e.Succeeded)
     {
         mruManager.Add(e.FileName);
     }
     else
     {
         mruManager.Remove(e.FileName);
     }
 }
Exemple #5
0
 /// <summary>
 /// Remove ObjectToRemove from the Collection if found, else throws an exception
 /// </summary>
 public void Remove(object item)
 {
     if (!Contains(item))
     {
         return;
     }
     Sop.DataBlock currBlock = this.GetCurrentDataBlock(true);
     if (GetId(currBlock) >= 0)
     {
         MruManager.Remove(GetId(currBlock), true);
     }
     DataBlockDriver.Remove(this, currBlock);
 }
Exemple #6
0
 public void Close()
 {
     if (_isDisposed || _fileStream == null)
     {
         return;
     }
     _fileStream.Close();
     if (_unBuffered)
     {
         InUse = false;
         MruManager.Remove(Id);
         _fileStream = null;
     }
 }
Exemple #7
0
 //internal override bool RemoveInMemory(long DataAddress, Transaction.ITransactionLogger Transaction)
 //{
 //    if (LastItem != null)
 //        LastItem.Clear();
 //    if (FirstItem != null)
 //        FirstItem.Clear();
 //    CurrentItem = null;
 //    base.RemoveInMemory(DataAddress, Transaction);
 //    return true;
 //}
 private void RemoveAt(long dataAddress, bool willMove)
 {
     if (willMove && !MoveTo(dataAddress))
     {
         return;
     }
     if (IsDeletedBlocksList && Count == 1)
     {
         return;
     }
     Sop.DataBlock currBlock = this.GetCurrentDataBlock(true);
     if (FirstItem.DiskBuffer.DataAddress == dataAddress)
     {
         MoveFirst();
         if (MoveNext())
         {
             FirstItem.DiskBuffer.DataAddress = CurrentItem.DiskBuffer.DataAddress;
             CurrentItem.PreviousItemAddress  = -1;
             Sop.DataBlock db = WriteToBlock(CurrentItem, CurrentItem.DiskBuffer);
             DataBlockDriver.SetDiskBlock(this, db, false);
         }
         else
         {
             long address = FirstItem.DiskBuffer.DataAddress;
             FirstItem.DiskBuffer.DataAddress = LastItem.DiskBuffer.DataAddress = -1;
             CurrentItem = FirstItem;
             Sop.DataBlock db = WriteToBlock(CurrentItem, CurrentItem.DiskBuffer);
             db.DataAddress = address;
             DataBlockDriver.SetDiskBlock(this, db, false);
             db.DataAddress = -1;
         }
     }
     else if (LastItem.DiskBuffer.DataAddress == dataAddress)
     {
         if (MovePrevious() || FirstItem.DiskBuffer.DataAddress == CurrentItem.DiskBuffer.DataAddress)
         {
             LastItem.DiskBuffer.DataAddress = CurrentItem.DiskBuffer.DataAddress;
             CurrentItem.NextItemAddress     = -1;
             Sop.DataBlock db = WriteToBlock(CurrentItem, CurrentItem.DiskBuffer);
             DataBlockDriver.SetDiskBlock(this, db, false);
         }
         else
         {
             throw new InvalidOperationException("Can't go previous but First is not the only item.");
         }
     }
     else
     {
         LinkedItemOnDisk curr = CurrentItem;
         LinkedItemOnDisk prev = null, next = null;
         if (MoveTo(curr.PreviousItemAddress))
         {
             prev = CurrentItem;
         }
         if (MoveTo(curr.NextItemAddress))
         {
             next = CurrentItem;
         }
         if (prev != null && next != null)
         {
             prev.NextItemAddress     = curr.NextItemAddress;
             next.PreviousItemAddress = curr.PreviousItemAddress;
             Sop.DataBlock db = WriteToBlock(prev, prev.DiskBuffer);
             DataBlockDriver.SetDiskBlock(this, db, false);
             db = WriteToBlock(next, next.DiskBuffer);
             DataBlockDriver.SetDiskBlock(this, db, false);
         }
     }
     if (MruManager.Count > 0)
     {
         MruManager.Remove(dataAddress, true);
     }
     DataBlockDriver.Remove(this, currBlock);
 }
Exemple #8
0
        /// <summary>
        /// Initialize helper objects from the DocToolkit Library.
        ///
        /// Called from Form1_Load. Initialized all objects except
        /// PersistWindowState wich must be initialized in the
        /// form constructor.
        /// </summary>
        private void InitializeHelperObjects()
        {
            // DocManager

            DocManagerData data = new DocManagerData();

            data.FormOwner        = this;
            data.UpdateTitle      = true;
            data.FileDialogFilter = "DrawTools files (*.dtl)|*.dtl|All Files (*.*)|*.*";
            data.NewDocName       = "Untitled.dtl";
            data.RegistryPath     = registryPath;

            docManager = new DocManager(data);
            docManager.RegisterFileType("dtl", "dtlfile", "DrawTools File");

            // Subscribe to DocManager events.
            docManager.SaveEvent += docManager_SaveEvent;
            docManager.LoadEvent += docManager_LoadEvent;

            // Make "inline subscription" using anonymous methods.
            docManager.OpenEvent += delegate(object sender, OpenFileEventArgs e)
            {
                // Update MRU List
                if (e.Succeeded)
                {
                    mruManager.Add(e.FileName);
                }
                else
                {
                    mruManager.Remove(e.FileName);
                }
            };

            docManager.DocChangedEvent += delegate(object o, EventArgs e)
            {
                drawArea.Refresh();
                drawArea.ClearHistory();
            };

            docManager.ClearEvent += delegate(object o, EventArgs e)
            {
                if (drawArea.GraphicsList != null)
                {
                    drawArea.GraphicsList.Clear();
                    drawArea.ClearHistory();
                    drawArea.Refresh();
                }
            };

            docManager.NewDocument();

            // DragDropManager
            dragDropManager = new DragDropManager(this);
            dragDropManager.FileDroppedEvent += delegate(object sender, FileDroppedEventArgs e)
            {
                OpenDocument(e.FileArray.GetValue(0).ToString());
            };

            // MruManager
            mruManager = new MruManager();
            mruManager.Initialize(
                this,                             // owner form
                recentFilesToolStripMenuItem,     // Recent Files menu item
                fileToolStripMenuItem,            // parent
                registryPath);                    // Registry path to keep MRU list

            mruManager.MruOpenEvent += delegate(object sender, MruFileOpenEventArgs e)
            {
                OpenDocument(e.FileName);
            };
        }
Exemple #9
0
 private static void MaintainOpenedFileCount(bool closeAll = false)
 {
     if (MruManager.Count <= MaxInstanceCount)
     {
         return;
     }
     lock (MruManager)
     {
         int ctr = 0;
         while (closeAll || MruManager.Count > MruManager.MinCapacity)
         {
             if (ctr++ >= MruManager.MaxCapacity - 10)
             {
                 Log.Logger.Instance.Verbose("MaintainOpenedFileCount FileStream trimming loop reached {0}, ending trimming...", ctr);
                 break;
             }
             Mru.Generic.MruItem <int, FileStream> item = MruManager.PeekInTail();
             //if (item.Value.InUse) return;
             lock (item.Value._locker)
             {
                 if (MruManager.Count <= MruManager.MinCapacity)
                 {
                     if (item.Value._fileStream == null)
                     {
                         MruManager.Remove(item.Value.Id);
                         return;
                     }
                     if (item.Value.InUse)
                     {
                         return;
                     }
                 }
                 if (item.Value.InUse)
                 {
                     item.Value.InUse = true;
                     continue;
                 }
                 //item.Value._streamPosition = item.Value._fileStream.Position;
                 if (item.Value._fileStream != null || !item.Value._isDisposed)
                 {
                     item.Value.InUse = true;
                     if (item.Value._fileStream != null || !item.Value._isDisposed)
                     {
                         try
                         {
                             item.Value._fileStream.Flush();
                             if (item.Value._fileStream != null)
                             {
                                 item.Value._fileStream.Close();
                             }
                         }
                         catch { }
                     }
                     item.Value._fileStream = null;
                     MruManager.Remove(item.Value.Id);
                     item.Value.InUse = false;
                 }
                 else
                 {
                     MruManager.Remove(item.Value.Id);
                 }
             }
         }
     }
 }