internal RunningInstance(IFileSystem fileSystem, InstanceOptions options, IRunnableInstance instanceOf, Functions outboundFunctions)
        {
            FileSystem         = fileSystem;
            InstanceOf         = instanceOf;
            _outboundFunctions = outboundFunctions;
            _asyncOperations   = new AsyncManager(_outboundFunctions);
            var callbacks = new PRJ_CALLBACKS
            {
                CancelCommandCallback             = ProcessCancelCommand,
                QueryFileNameCallback             = fileSystem is ISeekableFileSystem ? ProcessQueryFileName : (PRJ_QUERY_FILE_NAME_CB)null,
                StartDirectoryEnumerationCallback = ProcessStartEnumeration,
                EndDirectoryEnumerationCallback   = ProcessEndEnumeration,
                GetDirectoryEnumerationCallback   = ProcessEnumerationStep,
                GetPlaceholderInfoCallback        = ProcessPlaceholderRequest,
                GetFileDataCallback = ProcessDataRequest
            };
            PRJ_STARTVIRTUALIZING_OPTIONS optionsNative = CreateOptions(fileSystem, options, callbacks);

            _callbacks = new NativeBuffer <PRJ_CALLBACKS>(callbacks);

            if (_outboundFunctions.PrjStartVirtualizing(
                    instanceOf.RootPath,
                    _callbacks.Buffer,
                    IntPtr.Zero,
                    optionsNative,
                    out _namespaceVirtualizationContext) != HRESULT.S_OK)
            {
                throw new Exception("Failed to start up");
            }
            if (_outboundFunctions.PrjGetVirtualizationInstanceInfo(_namespaceVirtualizationContext, ref _virtualizationInfo) != HRESULT.S_OK)
            {
                throw new Exception("Failed to start up");
            }
        }
Exemple #2
0
        private void WriteRecord(IRunnableInstance instance)
        {
            byte[] smallBuffer = new byte[36];
            smallBuffer[0] = 0xFF;
            if (instance.DefaultOptions.NegativePathCache)
            {
                smallBuffer[1] = 1;
            }
            BinaryPrimitives.WriteInt32BigEndian(smallBuffer.AsSpan(4, 4), instance.DefaultOptions.PoolThreadCount);
            BinaryPrimitives.WriteInt32BigEndian(smallBuffer.AsSpan(8, 4), instance.DefaultOptions.ConcurrentThreadCount);
            instance.InstanceGuid.ToByteArray().CopyTo(smallBuffer, 12);
            var nameBuffer = Encoding.UTF8.GetBytes(instance.Name);
            var pathBuffer = Encoding.UTF8.GetBytes(instance.RootPath);

            BinaryPrimitives.WriteInt32BigEndian(smallBuffer.AsSpan(28, 4), nameBuffer.Length);
            BinaryPrimitives.WriteInt32BigEndian(smallBuffer.AsSpan(32, 4), pathBuffer.Length);
            _dataFile.Write(smallBuffer, 0, smallBuffer.Length);
            _dataFile.Write(nameBuffer, 0, nameBuffer.Length);
            _dataFile.Write(pathBuffer, 0, pathBuffer.Length);
        }