Exemplo n.º 1
0
        public void Handshake()
        {
            try
            {
                {
                    var samCommand = new SamCommand();
                    samCommand.Commands.Add("HELLO");
                    samCommand.Commands.Add("VERSION");
                    samCommand.Parameters.Add("MIN", "3.0");
                    samCommand.Parameters.Add("MAX", "3.0");

                    this.Send(samCommand);
                }

                {
                    var samCommand = this.Receive();

                    if (samCommand.Commands[0] != "HELLO" || samCommand.Commands[1] != "REPLY" || samCommand.Parameters["RESULT"] != "OK")
                    {
                        throw new SamException(samCommand.Parameters["RESULT"]);
                    }
                }
            }
            catch (SamException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new SamException(e.Message, e);
            }
        }
Exemplo n.º 2
0
        public string NamingLookup(string name)
        {
            try
            {
                {
                    var samCommand = new SamCommand();
                    samCommand.Commands.Add("NAMING");
                    samCommand.Commands.Add("LOOKUP");
                    samCommand.Parameters.Add("NAME", name);

                    this.Send(samCommand);
                }

                {
                    var samCommand = this.Receive();

                    if (samCommand.Commands[0] != "NAMING" || samCommand.Commands[1] != "REPLY")
                    {
                        throw new SamException();
                    }

                    return samCommand.Parameters["VALUE"];
                }
            }
            catch (SamException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new SamException(e.Message, e);
            }
        }
Exemplo n.º 3
0
 private void Send(SamCommand samCommand)
 {
     _writer.WriteLine(samCommand.GetText());
     _writer.Flush();
 }
Exemplo n.º 4
0
        public void StreamConnect(string sessionId, string destination)
        {
            try
            {
                {
                    var samCommand = new SamCommand();
                    samCommand.Commands.Add("STREAM");
                    samCommand.Commands.Add("CONNECT");
                    samCommand.Parameters.Add("ID", sessionId);
                    samCommand.Parameters.Add("DESTINATION", destination);
                    samCommand.Parameters.Add("SILENCE", "false");

                    this.Send(samCommand);
                }

                {
                    var samCommand = this.Receive();

                    if (samCommand.Commands[0] != "STREAM" || samCommand.Commands[1] != "STATUS" || samCommand.Parameters["RESULT"] != "OK")
                    {
                        throw new SamException();
                    }
                }
            }
            catch (SamException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new SamException(e.Message, e);
            }
        }
Exemplo n.º 5
0
        public string StreamAccept(string sessionId)
        {
            try
            {
                {
                    var samCommand = new SamCommand();
                    samCommand.Commands.Add("STREAM");
                    samCommand.Commands.Add("ACCEPT");
                    samCommand.Parameters.Add("ID", sessionId);
                    samCommand.Parameters.Add("SILENCE", "false");

                    this.Send(samCommand);
                }

                {
                    var samCommand = this.Receive();

                    if (samCommand.Commands[0] != "STREAM" || samCommand.Commands[1] != "STATUS" || samCommand.Parameters["RESULT"] != "OK")
                    {
                        throw new SamException();
                    }
                }

                return _reader.ReadLine().Split(' ')[0];
            }
            catch (SamException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new SamException(e.Message, e);
            }
        }
Exemplo n.º 6
0
        public string SessionCreate(string sessionId, string caption)
        {
            try
            {
                {
                    var samCommand = new SamCommand();
                    samCommand.Commands.Add("SESSION");
                    samCommand.Commands.Add("CREATE");
                    samCommand.Parameters.Add("STYLE", "STREAM");
                    samCommand.Parameters.Add("ID", sessionId);
                    samCommand.Parameters.Add("DESTINATION", "TRANSIENT");
                    samCommand.Parameters.Add("inbound.nickname", caption);
                    samCommand.Parameters.Add("outbound.nickname", caption);

                    this.Send(samCommand);
                }

                {
                    var samCommand = this.Receive();

                    if (samCommand.Commands[0] != "SESSION" || samCommand.Commands[1] != "STATUS")
                    {
                        throw new SamException(samCommand.Parameters["RESULT"]);
                    }

                    return samCommand.Parameters["DESTINATION"];
                }
            }
            catch (SamException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new SamException(e.Message, e);
            }
        }