示例#1
0
        public static ContentIndexMap CreateInMemory()
        {
            var result = new ContentIndexMap {
                stream = new MemoryStream()
            };

            result.LoadNewValues();
            return(result);
        }
示例#2
0
        public static ContentIndexMap NewTool(string indexName)
        {
            if (indexName == null)
            {
                throw new ArgumentNullException(nameof(indexName));
            }

            var result = new ContentIndexMap
            {
                // Try to open with read-write
                stream = VirtualFileSystem.OpenStream(
                    VirtualFileSystem.ApplicationDatabasePath + '/' + indexName,
                    VirtualFileMode.OpenOrCreate,
                    VirtualFileAccess.ReadWrite,
                    VirtualFileShare.ReadWrite)
            };

            return(result);
        }
示例#3
0
        public static ContentIndexMap Load(string indexFile, bool isReadOnly = false)
        {
            if (indexFile == null)
            {
                throw new ArgumentNullException(nameof(indexFile));
            }

            var result = new ContentIndexMap();

            var isAppDataWriteable = !isReadOnly;

            if (isAppDataWriteable)
            {
                try
                {
                    // Try to open with read-write
                    result.stream = VirtualFileSystem.OpenStream(
                        indexFile,
                        VirtualFileMode.OpenOrCreate,
                        VirtualFileAccess.ReadWrite,
                        VirtualFileShare.ReadWrite);
                }
                catch (UnauthorizedAccessException)
                {
                    isAppDataWriteable = false;
                }
            }

            if (!isAppDataWriteable)
            {
                // Try to open read-only
                result.stream = VirtualFileSystem.OpenStream(
                    indexFile,
                    VirtualFileMode.Open,
                    VirtualFileAccess.Read);
            }

            result.LoadNewValues();

            return(result);
        }