Ejemplo n.º 1
0
        public static bool IsMatchShortcut(this PostKey keyType, KeyEventArgs e)
        {
            if (e.Key != Key.Enter)
            {
                return(false);
            }
            switch (keyType)
            {
            case PostKey.EnterOnly:
                return(true);

            case PostKey.CtrlEnter:
                return(Keyboard.Modifiers.HasFlag(ModifierKeys.Control));

            case PostKey.ShiftEnter:
                return(Keyboard.Modifiers.HasFlag(ModifierKeys.Shift));

            default:
                throw new ArgumentOutOfRangeException(nameof(keyType), keyType, null);
            }
        }
Ejemplo n.º 2
0
        private Dictionary <FileIdentity, PostKey> GetCache()
        {
            // Ensure that the cache is fully up to date with respect to
            // what's actually on disk.

            Dictionary <FileIdentity, PostKey> filesInCache = LoadCache();
            bool dirty = false;

            // Read all files on disk--this is cheap since we don't actually look inside them
            Dictionary <string, FileIdentity> filesOnDisk = new Dictionary <string, FileIdentity>();

            foreach (FileInfo fi in dir.GetFiles(pattern, SearchOption.TopDirectoryOnly))
            {
                filesOnDisk.Add(fi.Name, new FileIdentity(fi));
            }

            // Remove any entries in the cache that are either no longer on disk or are
            // stale (file on disk has changed, according to size or last modified).
            // For any entries that are on disk and have an up-to-date copy in the cache,
            // remove from filesOnDisk to ensure they get ignored for the next step.
            // This step should also be cheap, no I/O involved.
            foreach (FileIdentity fid in new List <FileIdentity>(filesInCache.Keys))
            {
                FileIdentity fidDisk;
                if (!filesOnDisk.TryGetValue(fid.Filename, out fidDisk))
                {
                    fidDisk = null;
                }

                if (fidDisk == null || !fidDisk.Equals(fid))
                {
                    dirty = true;
                    filesInCache.Remove(fid);
                }
                else
                {
                    filesOnDisk.Remove(fid.Filename);
                }
            }

            // Anything left in filesOnDisk needs to be added to the cache, expensively.
            if (filesOnDisk.Count > 0)
            {
                foreach (FileIdentity fid in filesOnDisk.Values)
                {
                    PostKey postKey = pkg(new FileInfo(Path.Combine(dir.FullName, fid.Filename)));
                    if (postKey != null)
                    {
                        dirty             = true;
                        filesInCache[fid] = postKey;
                    }
                }
            }

            // Only persist if changes were made
            if (dirty)
            {
                SaveCache(filesInCache);
            }

            return(filesInCache);
        }