public string WriteResponse(IProtocolObject protocolObject)
        {
            var message = EncapsulateString(protocolObject.Response());

            WriterTarget.Write(message);
            return(message);
        }
Esempio n. 2
0
        public IProtocolObject CreateObject(Protocol.Types objectType, string jsonString = null)
        {
            IProtocolObject newObject = null;

            switch (objectType)
            {
            case Protocol.Types.NewDriver:
                newObject = string.IsNullOrEmpty(jsonString) ? new NewDriver() : JsonSerializer.Deserialize <NewDriver>(jsonString);
                break;

            case Protocol.Types.NewSession:
                newObject = string.IsNullOrEmpty(jsonString) ? new NewSession() : JsonSerializer.Deserialize <NewSession>(jsonString);
                break;

            case Protocol.Types.AuthorizationToken:
                newObject = string.IsNullOrEmpty(jsonString) ? new AuthorizationToken() : JsonSerializer.Deserialize <AuthorizationToken>(jsonString);
                break;

            case Protocol.Types.SessionRun:
                newObject = string.IsNullOrEmpty(jsonString) ? new SessionRun() : JsonSerializer.Deserialize <SessionRun>(jsonString);
                break;

            case Protocol.Types.TransactionRun:
                newObject = string.IsNullOrEmpty(jsonString) ? new TransactionRun() : JsonSerializer.Deserialize <TransactionRun>(jsonString);
                break;

            case Protocol.Types.Result:
                //not used in requests so should not be produced by factory.
                break;

            case Protocol.Types.SessionReadTransaction:
                newObject = string.IsNullOrEmpty(jsonString) ? new SessionReadTransaction() : JsonSerializer.Deserialize <SessionReadTransaction>(jsonString);
                break;

            case Protocol.Types.DriverClose:
                newObject = string.IsNullOrEmpty(jsonString) ? new DriverClose() : JsonSerializer.Deserialize <DriverClose>(jsonString);
                break;

            case Protocol.Types.SessionClose:
                newObject = string.IsNullOrEmpty(jsonString) ? new SessionClose() : JsonSerializer.Deserialize <SessionClose>(jsonString);
                break;

            case Protocol.Types.ResultNext:
                newObject = string.IsNullOrEmpty(jsonString) ? new ResultNext() : JsonSerializer.Deserialize <ResultNext>(jsonString);
                break;
            }

            if (newObject is null)
            {
                throw new System.Exception("Trying to create a none supported object in the ProtocolObjectFactory");
            }

            newObject.SetObjectManager(ObjManager);
            ObjManager.AddProtocolObject(newObject);
            return(newObject);
        }
        public async Task <string> WriteResponseAsync(IProtocolObject protocolObject)
        {
            var response = protocolObject.Response();

            Trace.WriteLine($"Sending response: {response}\n");

            var message = EncapsulateString(response);
            await WriterTarget.WriteAsync(message).ConfigureAwait(false);

            return(message);
        }
Esempio n. 4
0
 public void AddProtocolObject(IProtocolObject obj)
 {
     obj.SetUniqueId(GenerateUniqueId());
     ProtocolObjects[obj.uniqueId] = obj;
 }
Esempio n. 5
0
 public async Task SendResponse(IProtocolObject protocolObject)
 {
     await ResponseWriter.WriteResponseAsync(protocolObject).ConfigureAwait(false);
 }
Esempio n. 6
0
 public async Task <string> WriteResponseAsync(IProtocolObject protocolObject)
 {
     return(await WriteResponseAsync(protocolObject.Respond()));
 }
 private static void ProcessNewObject(IProtocolObject newObject)
 {
     newObject.SetObjectManager(ObjManager);
     ObjManager.AddProtocolObject(newObject);
 }