public static void PrepareOpen(ModelDialectRevision clientMaxDialect, DurableHandle durableHandle)
        {
            Condition.IsTrue(State == ModelState.Initialized);

            Connection_Dialect = ModelHelper.DetermineNegotiateDialect(clientMaxDialect, Config.MaxSmbVersionSupported);

            State = ModelState.Connected;
            Open  = new ModelOpen(durableHandle == DurableHandle.DurableHandle? true : false);
        }
        public static void PrepareOpen(ModelDialectRevision clientMaxDialect, DurableHandle durableHandle)
        {
            Condition.IsTrue(State == ModelState.Initialized);

            Connection_Dialect = ModelHelper.DetermineNegotiateDialect(clientMaxDialect, Config.MaxSmbVersionSupported);

            State = ModelState.Connected;
            Open = new ModelOpen(durableHandle == DurableHandle.DurableHandle? true : false);
        }
        public void PrepareOpen(ModelDialectRevision clientMaxDialect, DurableHandle durableHandle)
        {
            prepareOpenClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
            clientGuid        = Guid.NewGuid();
            DialectRevision[] dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect));

            // Connect to Share
            ConnectToShare(
                Site,
                testConfig,
                prepareOpenClient,
                dialects,
                clientGuid,
                testConfig.AccountCredential,
                out dialect,
                out treeId);
            Site.Assert.AreEqual(
                ModelUtility.GetDialectRevision(clientMaxDialect),
                dialect,
                "DialectRevision {0} is expected", ModelUtility.GetDialectRevision(clientMaxDialect));

            // SMB2 Create
            RequestedOplockLevel_Values opLockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;

            Smb2CreateContextRequest[] createContextRequests = new Smb2CreateContextRequest[0];
            createGuid = Guid.Empty;

            if (durableHandle == DurableHandle.DurableHandle)
            {// durable handle request context with batch opLock
                opLockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH;
                createGuid  = Guid.NewGuid();

                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST);

                createContextRequests = new Smb2CreateContextRequest[]
                {
                    new Smb2CreateDurableHandleRequest
                    {
                        DurableRequest = createGuid
                    }
                };
            }

            // create
            Smb2CreateContextResponse[] createContextResponse;
            prepareOpenClient.Create(
                treeId,
                GetTestFileName(Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare)),
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out createContextResponse,
                requestedOplockLevel_Values: opLockLevel,
                createContexts: createContextRequests,
                checker: (header, response) =>
            {
                Site.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "{0} should succeed", header.Command);

                if (durableHandle == DurableHandle.DurableHandle)
                {
                    Site.Assert.AreEqual <OplockLevel_Values>(
                        OplockLevel_Values.OPLOCK_LEVEL_BATCH,
                        response.OplockLevel,
                        "OplockLevel should be OPLOCK_LEVEL_BATCH if Durable Handle");
                }
            }
                );

            if (durableHandle == DurableHandle.DurableHandle)
            {
                // check whether response contain Durable Context
                Site.Assert.IsTrue(
                    ContainDurableHandleResponse(createContextResponse),
                    "Durable Handle Response should be in the Create response.");
            }
        }
        public void PrepareOpen(ModelDialectRevision clientMaxDialect, DurableHandle durableHandle)
        {
            prepareOpenClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
            clientGuid = Guid.NewGuid();
            DialectRevision[] dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect));

            // Connect to Share
            ConnectToShare(
                Site,
                testConfig,
                prepareOpenClient,
                dialects,
                clientGuid,
                testConfig.AccountCredential,
                out dialect,
                out treeId);
            Site.Assert.AreEqual(
                ModelUtility.GetDialectRevision(clientMaxDialect),
                dialect,
                "DialectRevision {0} is expected", ModelUtility.GetDialectRevision(clientMaxDialect));

            // SMB2 Create
            fileName = "ResilientHandlePrepareOpen_" + Guid.NewGuid() + ".txt";
            RequestedOplockLevel_Values opLockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;
            Smb2CreateContextRequest[] createContextRequests = new Smb2CreateContextRequest[0];
            createGuid = Guid.Empty;

            if (durableHandle == DurableHandle.DurableHandle)
            {// durable handle request context with batch opLock
                opLockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH;
                createGuid = Guid.NewGuid();

                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST);

                createContextRequests = new Smb2CreateContextRequest[]
                {
                    new Smb2CreateDurableHandleRequest
                    {
                        DurableRequest = createGuid
                    }
                };
            }

            // create
            Smb2CreateContextResponse[] createContextResponse;
            prepareOpenClient.Create(
                treeId,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out createContextResponse,
                requestedOplockLevel_Values: opLockLevel,
                createContexts: createContextRequests,
                checker: (header, response) =>
                    {
                        Site.Assert.AreEqual(
                            Smb2Status.STATUS_SUCCESS,
                            header.Status,
                            "{0} should succeed", header.Command);

                        if (durableHandle == DurableHandle.DurableHandle)
                        {
                            Site.Assert.AreEqual<OplockLevel_Values>(
                                OplockLevel_Values.OPLOCK_LEVEL_BATCH,
                                response.OplockLevel,
                                "OplockLevel should be OPLOCK_LEVEL_BATCH if Durable Handle");
                        }
                    }
                );

            if (durableHandle == DurableHandle.DurableHandle)
            {
                // check whether response contain Durable Context
                Site.Assert.IsTrue(
                    ContainDurableHandleResponse(createContextResponse),
                    "Durable Handle Response should be in the Create response.");
            }
        }