Esempio n. 1
0
        public override void Set(string key, object value,
                                 CacheItemPolicy policy, string regionName = null)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (policy == null)
            {
                policy = DefaultPolicy;
            }

            var now   = GetCurrentDate(0);
            var entry = new CacheEntry(policy, now)
            {
                Value = value
            };
            var cacheKey = new CacheKey(key)
            {
                TimeStamp = now
            };

            lock (_locker)
            {
                var e = MruManager.GetItem(cacheKey);
                if (e == null)
                {
                    MruManager.Add(cacheKey, entry);
                    return;
                }
                entry       = e.Value as CacheEntry;
                entry.Value = value;
                // if priotiry is not removable, just update the store w/ value
                if (entry.NonExpiring)
                {
                    return;
                }

                if (!entry.IsExpired(now))
                {
                    // slide the expire time...
                    if (entry.SlidingExpiration > 0)
                    {
                        entry.ExpirationTime = GetCurrentDate(entry.SlidingExpiration);
                    }
                    return;
                }
                // adjust policy (set to slide every 5 mins) of the expired item to accomodate this update...
                if (entry.SlidingExpiration == 0)
                {
                    entry.SlidingExpiration = TimeSpan.TicksPerMinute * 5;
                }
                entry.ExpirationTime = GetCurrentDate(entry.SlidingExpiration);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Update the data stored at a given Address.
 /// </summary>
 /// <param name="value"></param>
 public virtual void Update(object value)
 {
     //** Update the Current Entry w/ 'value'
     CurrentItem.Data = value;
     //** CurrentItem.DataAddress should be the same as DiskBuffer.DataAddress.
     WriteToDisk(CurrentItem, false);
     MruManager.Add(CurrentItem.DiskBuffer.DataAddress, CurrentItem);
     RegisterChange(true);
     //IsDirty = true;
 }
Esempio n. 3
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);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Open file
        /// </summary>
        void FileOpenCommand(object sender, ExecutedRoutedEventArgs args)
        {
            if (!PromptToSave())
            {
                return;
            }

            // Show Open File dialog
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter           = "XML files (*.xml)|*.xml|All Files|*.*";
            dlg.DefaultExt       = "xml";
            dlg.InitialDirectory = SettingsManager.ApplicationSettings.InitialDirectory;
            dlg.RestoreDirectory = true;

            if (dlg.ShowDialog().GetValueOrDefault() != true)
            {
                return;
            }

            try
            {
                // Load file
                drawingCanvas.Load(dlg.FileName);
            }
            catch (DrawingCanvasException e)
            {
                ShowError(e.Message);
                mruManager.Delete(dlg.FileName);
                return;
            }

            this.fileName = dlg.FileName;
            UpdateTitle();
            mruManager.Add(this.fileName);

            // Remember initial directory
            SettingsManager.ApplicationSettings.InitialDirectory = System.IO.Path.GetDirectoryName(dlg.FileName);
        }
Esempio n. 5
0
        /// <summary>
        /// Add 'Value' to the Collection
        /// </summary>
        public long Add(object value)
        {
            var o = new LinkedItemOnDisk(this.DataBlockSize)
            {
                Data = value
            };

            WriteToDisk(o, false);
            UpdateCount(UpdateCountType.Increment);
            //*** update Current, Last & First
            if (LastItem.DiskBuffer.DataAddress != -1)
            {
                o.PreviousItemAddress = LastItem.DiskBuffer.DataAddress;
                WriteToDisk(o, false);
                LinkedItemOnDisk biod = CurrentItem;
                biod.NextItemAddress = o.DiskBuffer.DataAddress;
                Sop.DataBlock db = DataBlockDriver.ReadBlockFromDisk(this, LastItem.DiskBuffer.DataAddress, true);
                if (CurrentItem.DiskBuffer.DataAddress != LastItem.DiskBuffer.DataAddress)
                {
                    biod = (LinkedItemOnDisk)ReadFromBlock(db);
                    biod.NextItemAddress = o.DiskBuffer.DataAddress;
                }
                else
                {
                    PurifyMeta(biod, db);
                    if (db.SizeOccupied > 0)
                    {
                        biod.DiskBuffer = db;
                    }
                }
                WriteToDisk(biod, false);
            }
            else
            {
                FirstItem.DiskBuffer.DataAddress = o.DiskBuffer.DataAddress;
            }

            currentEntry                    = null;
            CurrentItem                     = o;
            CurrentEntryDataAddress         = o.DiskBuffer.DataAddress;
            currentDataBlock                = o.DiskBuffer;
            LastItem.DiskBuffer.DataAddress = o.DiskBuffer.DataAddress;

            MruManager.Add(CurrentEntryDataAddress, o);

            //** update the header
            RegisterChange(true);
            //IsDirty = true;

            return(o.DiskBuffer.DataAddress);
        }
Esempio n. 6
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);
            };
        }
Esempio n. 7
0
 System.IO.FileStream IFileStream.Open()
 {
     MruManager.Add(Id, this);
     return(SystemAdaptor.Instance.SystemInterface.UnbufferedOpen(_path, _mode, _access, _share,
                                                                  _sequential, _async, _blockSize));
 }
Esempio n. 8
0
 private System.IO.FileStream Open()
 {
     MruManager.Add(Id, this);
     return(Win32.UnbufferedOpen(_path, _mode, _access, _share,
                                 _sequential, _async, _blockSize));
 }