Пример #1
0
 IRunnableInstance IInstanceManager.Register(string name, string rootPath, string targetPath, InstanceOptions defaultOptions, PlaceholderVersion rootVersionInfo, Guid instanceGuid)
 {
     lock (_instanceLock)
     {
         if (_names.ContainsKey(name))
         {
             throw new ArgumentException("Name already registered", nameof(name));
         }
         if (_paths.ContainsKey(rootPath))
         {
             throw new ArgumentException("Path already registered", nameof(rootPath));
         }
         if (_guids.ContainsKey(instanceGuid))
         {
             throw new ArgumentException("Instance already registered", nameof(instanceGuid));
         }
         if (_outboundFunctions.PrjMarkDirectoryAsPlaceholder(rootPath, targetPath, LevelShifter.PRJ_PLACEHOLDER_VERSION_INFOFromPlaceholderVersion(rootVersionInfo), instanceGuid) != HRESULT.S_OK)
         {
             throw new NotSupportedException("Could not register path with System");
         }
         var instance = new RunnableInstance(name, rootPath, instanceGuid, defaultOptions, _outboundFunctions);
         _names.Add(name, instance);
         _paths.Add(rootPath, instance);
         _guids.Add(instanceGuid, instance);
         WriteRecord(instance);
         _dataFile.Flush();
         return(instance);
     }
 }
        public async Task QuickEnumeration_SmallBuffer_MultiFile_Successful()
        {
            //Arrange
            const string RootPath  = @"D:\";
            var          functions = new Mock <Functions>();
            var          nsVirtualizationContext = (IntPtr)4;
            var          instanceGuid            = Guid.NewGuid();
            var          tcsStarted    = new TaskCompletionSource <IntPtr>();
            var          enumerationId = Guid.NewGuid();
            var          callbackData  = new PRJ_CALLBACK_DATA
            {
                VersionInfo = new PRJ_PLACEHOLDER_VERSION_INFO()
            };
            var dirBuffer1 = (IntPtr)99;
            var dirBuffer2 = (IntPtr)713;

            functions.Setup(f => f.PrjStartVirtualizing(RootPath, It.IsAny <IntPtr>(), IntPtr.Zero, It.IsAny <PRJ_STARTVIRTUALIZING_OPTIONS>(), out It.Ref <IntPtr> .IsAny))
            .Callback(new StartVirtualizingCallback((String virtualizationRootPath,
                                                     IntPtr callbacks,
                                                     IntPtr instanceContext,
                                                     PRJ_STARTVIRTUALIZING_OPTIONS options,
                                                     out IntPtr namespaceVirtualizationContext) =>
            {
                tcsStarted.SetResult(callbacks);
                namespaceVirtualizationContext = nsVirtualizationContext;
            })
                      ).Returns(() => HRESULT.S_OK);
            functions.Setup(f => f.PrjFileNameMatch(It.IsAny <string>(), null)).Returns(true);
            functions.SetupSequence(f => f.PrjFillDirEntryBuffer("Boris.txt", It.IsAny <PRJ_FILE_BASIC_INFO>(), dirBuffer1))
            .Returns(HRESULT.S_OK)
            .Returns(HRESULT.ERROR_INSUFFICIENT_BUFFER)
            .Returns(HRESULT.S_OK);
            ConfigureVirtualizationInfo(functions, nsVirtualizationContext, instanceGuid);
            var runnable = new RunnableInstance("Boris", RootPath, instanceGuid, new InstanceOptions(), functions.Object);
            var fs       = TestableFileSystem.MultiFile();

            //Act
            using (var running = runnable.Start(fs))
            {
                var callbacks = NativeBuffer <PRJ_CALLBACKS> .Recover(await tcsStarted.Task);

                var hr = callbacks.StartDirectoryEnumerationCallback(callbackData, enumerationId);
                Assert.Equal(HRESULT.S_OK, hr);
                hr = callbacks.GetDirectoryEnumerationCallback(callbackData, enumerationId, null, dirBuffer1);
                Assert.Equal(HRESULT.S_OK, hr);
                hr = callbacks.GetDirectoryEnumerationCallback(callbackData, enumerationId, null, dirBuffer2);
                Assert.Equal(HRESULT.S_OK, hr);
                hr = callbacks.EndDirectoryEnumerationCallback(callbackData, enumerationId);
                Assert.Equal(HRESULT.S_OK, hr);

                //Assert
                functions.VerifyAll();
            }
        }
Пример #3
0
        private bool ReadRecord()
        {
            byte[] smallBuffer = new byte[36];
            var    bytesRead   = _dataFile.Read(smallBuffer, 0, smallBuffer.Length);

            if (bytesRead == 0)
            {
                return(false);
            }
            if (bytesRead != smallBuffer.Length)
            {
                throw new NotSupportedException(UnexpectedFF);
            }
            if (smallBuffer[0] != 0xFF)
            {
                throw new NotSupportedException(UnexpectedFF);
            }
            var options = new InstanceOptions();

            if ((smallBuffer[1] & 1) == 1)
            {
                options.NegativePathCache = true;
            }
            options.PoolThreadCount       = BinaryPrimitives.ReadInt32BigEndian(smallBuffer.AsSpan(4, 4));
            options.ConcurrentThreadCount = BinaryPrimitives.ReadInt32BigEndian(smallBuffer.AsSpan(8, 4));
            var instanceGuid = new Guid(smallBuffer.AsSpan(12, 16).ToArray());
            var nameLength   = BinaryPrimitives.ReadInt32BigEndian(smallBuffer.AsSpan(28, 4));
            var pathLength   = BinaryPrimitives.ReadInt32BigEndian(smallBuffer.AsSpan(32, 4));
            var nameBuffer   = new byte[nameLength];
            var pathBuffer   = new byte[pathLength];

            if (_dataFile.Read(nameBuffer, 0, nameLength) != nameLength)
            {
                throw new NotSupportedException(UnexpectedFF);
            }
            if (_dataFile.Read(pathBuffer, 0, pathLength) != pathLength)
            {
                throw new NotSupportedException(UnexpectedFF);
            }
            var name = Encoding.UTF8.GetString(nameBuffer);
            var path = Encoding.UTF8.GetString(pathBuffer);

            if (_names.ContainsKey(name) || _paths.ContainsKey(path) || _guids.ContainsKey(instanceGuid))
            {
                throw new NotSupportedException(UnexpectedFF);
            }
            var runnable = new RunnableInstance(name, path, instanceGuid, options, _outboundFunctions);

            _names.Add(name, runnable);
            _paths.Add(path, runnable);
            _guids.Add(instanceGuid, runnable);
            return(true);
        }
Пример #4
0
        public void CanExecuteStartupAndShutdown()
        {
            //Arrange
            const string RootPath  = @"D:\";
            var          functions = new Mock <Functions>();
            var          nsVirtualizationContext = (IntPtr)4;
            var          instanceGuid            = Guid.NewGuid();

            functions.Setup(f => f.PrjStartVirtualizing(RootPath, It.IsAny <IntPtr>(), IntPtr.Zero, It.IsAny <PRJ_STARTVIRTUALIZING_OPTIONS>(), out It.Ref <IntPtr> .IsAny))
            .Callback(new StartVirtualizingCallback((String virtualizationRootPath,
                                                     IntPtr callbacks,
                                                     IntPtr instanceContext,
                                                     PRJ_STARTVIRTUALIZING_OPTIONS options,
                                                     out IntPtr namespaceVirtualizationContext) =>
            {
                namespaceVirtualizationContext = nsVirtualizationContext;
            })
                      );
            functions.Setup(f => f.PrjGetVirtualizationInstanceInfo(nsVirtualizationContext, ref It.Ref <PRJ_VIRTUALIZATION_INSTANCE_INFO> .IsAny))
            .Callback(new GetVirtualizationInfoCallback((IntPtr namespaceVirtualizationContext,
                                                         ref PRJ_VIRTUALIZATION_INSTANCE_INFO virtualizationInstanceInfo) =>
            {
                virtualizationInstanceInfo.InstanceID     = instanceGuid;
                virtualizationInstanceInfo.WriteAlignment = 2048;
            })
                      );
            functions.Setup(f => f.PrjStopVirtualizing(nsVirtualizationContext));
            var runnable = new RunnableInstance("Boris", RootPath, instanceGuid, new InstanceOptions(), functions.Object);
            var fs       = SingleFile();

            //Act
            var running = runnable.Start(fs);

            running.Shutdown();

            //Assert
            functions.VerifyAll();
            functions.VerifyNoOtherCalls();
            Assert.Same(runnable, running.InstanceOf);
            Assert.Same(fs, running.FileSystem);
        }
 public void Dispose()
 {
     RunnableInstance.Dispose();
     RunnableInstance = null;
 }