Пример #1
0
        private static bool TryParse(string input, out TryingEvent e)
        {
            e = null;
            if (Regex.IsMatch(input, $@"\A{CtiProtocol.PropertyType.EVENT}: {CtiProtocol.EventType.TRAYING}"))
            {
                e = new TryingEvent
                {
                    SessionId           = Parse(input, CtiProtocol.PropertyType.SESSION_ID),
                    Timestamp           = Parse(input, CtiProtocol.PropertyType.TIMESTAMP),
                    CallStartDate       = Parse(input, CtiProtocol.PropertyType.CALL_START_DATE),
                    SourceCallerId      = Parse(input, CtiProtocol.PropertyType.SOURCE_CALLER_ID),
                    DestinationCallerId = Parse(input, CtiProtocol.PropertyType.DESTINATION_CALLER_ID)
                };
                return(true);
            }

            return(false);
        }
Пример #2
0
        private CtiEvent ParseTryingEvent(string input)
        {
            TryingEvent e = new TryingEvent();

            int idx   = CtiProtocol.FIRST_TRYING_LINE_LEN + CtiProtocol.SESSION_ID_PROP_LEN + CtiProtocol.COLON_AND_SPACE_LEN;
            int limit = idx + CtiProtocol.SESSION_ID_VALU_LEN;

            e.SessionId = input.Substring(idx, CtiProtocol.SESSION_ID_VALU_LEN);

            idx = limit + CtiProtocol.END_LINE_LEN + CtiProtocol.SOURCE_CALLER_ID_PROP_LEN + CtiProtocol.COLON_AND_SPACE_LEN;
            for (int i = idx; ; i++)
            {
                if (input[i + 1] == CtiProtocol.CARRIAGE_RETURN && input[i + 2] == CtiProtocol.LINE_FEED)
                {
                    e.SourceCallerId = input.Substring(idx, i - idx + 1);
                    idx = i;
                    break;
                }
            }

            idx += CtiProtocol.END_LINE_LEN + CtiProtocol.DESTINATION_CALLER_ID_PROP_LEN + CtiProtocol.COLON_AND_SPACE_LEN + 1;
            for (int i = idx; ; i++)
            {
                if (input[i + 1] == CtiProtocol.CARRIAGE_RETURN && input[i + 2] == CtiProtocol.LINE_FEED)
                {
                    e.DestinationCallerId = input.Substring(idx, i - idx + 1);
                    idx = i;
                    break;
                }
            }

            idx            += CtiProtocol.END_LINE_LEN + CtiProtocol.CALL_START_DATE_PROP_LEN + CtiProtocol.COLON_AND_SPACE_LEN + 1;
            limit           = idx + CtiProtocol.CALL_START_DATE_VALU_LEN;
            e.CallStartDate = input.Substring(idx, limit - idx);

            idx         = limit + CtiProtocol.END_LINE_LEN + CtiProtocol.TIMESTAMP_PROP_LEN + CtiProtocol.COLON_AND_SPACE_LEN;
            limit       = idx + CtiProtocol.TIMESTAMP_VALU_LEN;
            e.Timestamp = input.Substring(idx, limit - idx);

            return(e);
        }
Пример #3
0
        private CtiEvent ParseTryingEvent(string input)
        {
            TryingEvent e = new TryingEvent();

            e.SessionId = input.Substring(CtiProtocol.SESSION_ID_IDX_SHIFT, CtiProtocol.SESSION_ID_VALU_LEN);

            int idx = WithEndLineFound(CtiProtocol.SOURCE_CALLER_ID_IDX_SHIFT, input, value => e.SourceCallerId = value);

            idx = WithEndLineFound(idx += CtiProtocol.DESTINATION_CALLER_ID_SHIFT, input, value => e.DestinationCallerId = value);

            idx += CtiProtocol.CALL_START_DATE_SHIFT;
            int limit = idx + CtiProtocol.CALL_START_DATE_VALU_LEN;

            e.CallStartDate = input.Substring(idx, limit - idx);

            idx         = limit + CtiProtocol.TIMESTAMP_SHIFT;
            limit       = idx + CtiProtocol.TIMESTAMP_VALU_LEN;
            e.Timestamp = input.Substring(idx, limit - idx);

            return(e);
        }
Пример #4
0
        private CtiEvent ParseTryingEvent(string input)
        {
            TryingEvent e = new TryingEvent();

            int idx   = CtiProtocol.FIRST_TRYING_LINE_LEN + CtiProtocol.SESSION_ID_PROP_LEN + CtiProtocol.COLON_AND_SPACE_LEN;
            int limit = idx + CtiProtocol.SESSION_ID_VALU_LEN;

            e.SessionId = input.Substring(idx, CtiProtocol.SESSION_ID_VALU_LEN);

            idx = limit + CtiProtocol.END_LINE_LEN + CtiProtocol.SOURCE_CALLER_ID_PROP_LEN + CtiProtocol.COLON_AND_SPACE_LEN;
            for (int i = idx; ; i += 2)
            {
                switch (input[i])
                {
                case CtiProtocol.CARRIAGE_RETURN:
                {
                    e.SourceCallerId = input.Substring(idx, i - idx);
                    idx = i - 1;
                    goto LEAVE_FOR_1;
                }

                case CtiProtocol.LINE_FEED:
                {
                    e.SourceCallerId = input.Substring(idx, i - idx - 1);
                    idx = i - 2;
                    goto LEAVE_FOR_1;
                }
                }
            }

LEAVE_FOR_1:

            idx += CtiProtocol.END_LINE_LEN + CtiProtocol.DESTINATION_CALLER_ID_PROP_LEN + CtiProtocol.COLON_AND_SPACE_LEN + 1;
            for (int i = idx; ; i += 2)
            {
                switch (input[i])
                {
                case CtiProtocol.CARRIAGE_RETURN:
                {
                    e.DestinationCallerId = input.Substring(idx, i - idx);
                    idx = i - 1;
                    goto LEAVE_FOR_2;
                }

                case CtiProtocol.LINE_FEED:
                {
                    e.DestinationCallerId = input.Substring(idx, i - idx - 1);
                    idx = i - 2;
                    goto LEAVE_FOR_2;
                }
                }
            }

LEAVE_FOR_2:

            idx            += CtiProtocol.END_LINE_LEN + CtiProtocol.CALL_START_DATE_PROP_LEN + CtiProtocol.COLON_AND_SPACE_LEN + 1;
            limit           = idx + CtiProtocol.CALL_START_DATE_VALU_LEN;
            e.CallStartDate = input.Substring(idx, limit - idx);

            idx         = limit + CtiProtocol.END_LINE_LEN + CtiProtocol.TIMESTAMP_PROP_LEN + CtiProtocol.COLON_AND_SPACE_LEN;
            limit       = idx + CtiProtocol.TIMESTAMP_VALU_LEN;
            e.Timestamp = input.Substring(idx, limit - idx);

            return(e);
        }
Пример #5
0
        private void ParseTryingEvent(string input)
        {
            TryingEvent outputEvent = new TryingEvent();

            outputEvent.SessionId = input.Substring(Shift.Trying.SESSION_ID_IDX_SHIFT, Shift.SESSION_ID_VALU);

            int idx = Shift.Trying.SOURCE_CALLER_ID_IDX_SHIFT;

            for (int i = idx; ; i += 2)
            {
                switch ((byte)input[i])
                {
                case Asci.CR:
                {
                    outputEvent.SourceCallerId = input.Substring(idx, i - idx);
                    idx = i - 1;
                    goto LEAVE_FOR_1;
                }

                case Asci.LF:
                {
                    outputEvent.SourceCallerId = input.Substring(idx, i - idx - 1);
                    idx = i - 2;
                    goto LEAVE_FOR_1;
                }
                }
            }

LEAVE_FOR_1:

            idx += Shift.Trying.DESTINATION_CALLER_ID_SHIFT;
            for (int i = idx; ; i += 2)
            {
                switch ((byte)input[i])
                {
                case Asci.CR:
                {
                    outputEvent.DestinationCallerId = input.Substring(idx, i - idx);
                    idx = i - 1;
                    goto LEAVE_FOR_2;
                }

                case Asci.LF:
                {
                    outputEvent.DestinationCallerId = input.Substring(idx, i - idx - 1);
                    idx = i - 2;
                    goto LEAVE_FOR_2;
                }
                }
            }

LEAVE_FOR_2:

            idx += Shift.Trying.CALL_START_DATE_SHIFT;
            int limit = idx + Shift.CALL_START_DATE_VALU;

            outputEvent.CallStartDate = input.Substring(idx, limit - idx);

            idx   = limit + Shift.Trying.TIMESTAMP_SHIFT;
            limit = idx + Shift.TIMESTAMP_VALU;
            outputEvent.Timestamp = input.Substring(idx, limit - idx);

            observer.OnNext(outputEvent);
        }
Пример #6
0
        public void OnNext(ByteString value)
        {
            buffer += value.DecodeString();

            bool foundDelimiter;

            do
            {
                foundDelimiter = false;
                for (int i = 0; i < buffer.Length - 2; i += 4)
                {
                    switch ((byte)buffer[i])
                    {
                    case CtiProtocol.CARRIAGE_RETURN:
                    {
                        if (buffer[i + CtiProtocol.SHIFT_FOR_DELIMITER] == CtiProtocol.CARRIAGE_RETURN && buffer.Length > i + 3)
                        {
                            foundDelimiter = true;
                            switch ((byte)buffer[CtiProtocol.SHIFT_FOR_EVENT_TYPE])
                            {
                            case CtiProtocol.T:
                            {
                                TryingEvent e = new TryingEvent();

                                e.SessionId = buffer.Substring(CtiProtocol.SESSION_ID_IDX_SHIFT, CtiProtocol.SESSION_ID_VALU_LEN);

                                int idx = CtiProtocol.SOURCE_CALLER_ID_IDX_SHIFT;
                                for (int k = idx; ; k += 2)
                                {
                                    switch ((byte)buffer[k])
                                    {
                                    case CtiProtocol.CARRIAGE_RETURN:
                                    {
                                        e.SourceCallerId = buffer.Substring(idx, k - idx);
                                        idx = k - 1;
                                        goto LEAVE_FOR_1;
                                    }

                                    case CtiProtocol.LINE_FEED:
                                    {
                                        e.SourceCallerId = buffer.Substring(idx, k - idx - 1);
                                        idx = k - 2;
                                        goto LEAVE_FOR_1;
                                    }
                                    }
                                }

LEAVE_FOR_1:

                                idx += CtiProtocol.DESTINATION_CALLER_ID_SHIFT;
                                for (int k = idx; ; k += 2)
                                {
                                    switch ((byte)buffer[k])
                                    {
                                    case CtiProtocol.CARRIAGE_RETURN:
                                    {
                                        e.DestinationCallerId = buffer.Substring(idx, k - idx);
                                        idx = k - 1;
                                        goto LEAVE_FOR_2;
                                    }

                                    case CtiProtocol.LINE_FEED:
                                    {
                                        e.DestinationCallerId = buffer.Substring(idx, k - idx - 1);
                                        idx = k - 2;
                                        goto LEAVE_FOR_2;
                                    }
                                    }
                                }

LEAVE_FOR_2:

                                idx += CtiProtocol.CALL_START_DATE_SHIFT;
                                int limit = idx + CtiProtocol.CALL_START_DATE_VALU_LEN;
                                e.CallStartDate = buffer.Substring(idx, limit - idx);

                                idx         = limit + CtiProtocol.TIMESTAMP_SHIFT;
                                limit       = idx + CtiProtocol.TIMESTAMP_VALU_LEN;
                                e.Timestamp = buffer.Substring(idx, limit - idx);

                                observer.OnNext(e);

                                string cleanUpBuffer = buffer.Remove(0, i + 4);
                                buffer = cleanUpBuffer;
                                goto FIND_NEXT_DELIMITER;
                            }

                            case CtiProtocol.R:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.D:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.H:
                            {
                                switch ((byte)buffer[CtiProtocol.SHIFT_FOR_EVENT_TYPE + 1])
                                {
                                case CtiProtocol.a:
                                {
                                    throw new NotImplementedException();
                                }

                                case CtiProtocol.o:
                                {
                                    throw new NotImplementedException();
                                }
                                }

                                throw new Exception("todo: create message...");
                            }

                            case CtiProtocol.L:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.P:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.U:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.S:
                            {
                                throw new NotImplementedException();
                            }

                            default:
                            {
                                throw new Exception("todo: create message...");
                            }
                            }
                        }
                        else if (buffer[i - CtiProtocol.SHIFT_FOR_DELIMITER] == CtiProtocol.CARRIAGE_RETURN && buffer.Length > i + 3)
                        {
                            foundDelimiter = true;
                            switch ((byte)buffer[CtiProtocol.SHIFT_FOR_EVENT_TYPE])
                            {
                            case CtiProtocol.T:
                            {
                                TryingEvent e = new TryingEvent();

                                e.SessionId = buffer.Substring(CtiProtocol.SESSION_ID_IDX_SHIFT, CtiProtocol.SESSION_ID_VALU_LEN);

                                int idx = CtiProtocol.SOURCE_CALLER_ID_IDX_SHIFT;
                                for (int k = idx; ; k += 2)
                                {
                                    switch ((byte)buffer[k])
                                    {
                                    case CtiProtocol.CARRIAGE_RETURN:
                                    {
                                        e.SourceCallerId = buffer.Substring(idx, k - idx);
                                        idx = k - 1;
                                        goto LEAVE_FOR_1;
                                    }

                                    case CtiProtocol.LINE_FEED:
                                    {
                                        e.SourceCallerId = buffer.Substring(idx, k - idx - 1);
                                        idx = k - 2;
                                        goto LEAVE_FOR_1;
                                    }
                                    }
                                }

LEAVE_FOR_1:

                                idx += CtiProtocol.DESTINATION_CALLER_ID_SHIFT;
                                for (int k = idx; ; k += 2)
                                {
                                    switch ((byte)buffer[k])
                                    {
                                    case CtiProtocol.CARRIAGE_RETURN:
                                    {
                                        e.DestinationCallerId = buffer.Substring(idx, k - idx);
                                        idx = k - 1;
                                        goto LEAVE_FOR_2;
                                    }

                                    case CtiProtocol.LINE_FEED:
                                    {
                                        e.DestinationCallerId = buffer.Substring(idx, k - idx - 1);
                                        idx = k - 2;
                                        goto LEAVE_FOR_2;
                                    }
                                    }
                                }

LEAVE_FOR_2:

                                idx += CtiProtocol.CALL_START_DATE_SHIFT;
                                int limit = idx + CtiProtocol.CALL_START_DATE_VALU_LEN;
                                e.CallStartDate = buffer.Substring(idx, limit - idx);

                                idx         = limit + CtiProtocol.TIMESTAMP_SHIFT;
                                limit       = idx + CtiProtocol.TIMESTAMP_VALU_LEN;
                                e.Timestamp = buffer.Substring(idx, limit - idx);

                                observer.OnNext(e);

                                string cleanUpBuffer = buffer.Remove(0, i + 2);
                                buffer = cleanUpBuffer;
                                goto FIND_NEXT_DELIMITER;
                            }

                            case CtiProtocol.R:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.D:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.H:
                            {
                                switch ((byte)buffer[CtiProtocol.SHIFT_FOR_EVENT_TYPE + 1])
                                {
                                case CtiProtocol.a:
                                {
                                    throw new NotImplementedException();
                                }

                                case CtiProtocol.o:
                                {
                                    throw new NotImplementedException();
                                }
                                }

                                throw new Exception("todo: create message...");
                            }

                            case CtiProtocol.L:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.P:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.U:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.S:
                            {
                                throw new NotImplementedException();
                            }

                            default:
                            {
                                throw new Exception("todo: create message...");
                            }
                            }
                        }
                        break;
                    }

                    case CtiProtocol.LINE_FEED:
                    {
                        if (buffer[i + CtiProtocol.SHIFT_FOR_DELIMITER] == CtiProtocol.LINE_FEED)
                        {
                            foundDelimiter = true;
                            switch ((byte)buffer[CtiProtocol.SHIFT_FOR_EVENT_TYPE])
                            {
                            case CtiProtocol.T:
                            {
                                TryingEvent e = new TryingEvent();

                                e.SessionId = buffer.Substring(CtiProtocol.SESSION_ID_IDX_SHIFT, CtiProtocol.SESSION_ID_VALU_LEN);

                                int idx = CtiProtocol.SOURCE_CALLER_ID_IDX_SHIFT;
                                for (int k = idx; ; k += 2)
                                {
                                    switch ((byte)buffer[k])
                                    {
                                    case CtiProtocol.CARRIAGE_RETURN:
                                    {
                                        e.SourceCallerId = buffer.Substring(idx, k - idx);
                                        idx = k - 1;
                                        goto LEAVE_FOR_1;
                                    }

                                    case CtiProtocol.LINE_FEED:
                                    {
                                        e.SourceCallerId = buffer.Substring(idx, k - idx - 1);
                                        idx = k - 2;
                                        goto LEAVE_FOR_1;
                                    }
                                    }
                                }

LEAVE_FOR_1:

                                idx += CtiProtocol.DESTINATION_CALLER_ID_SHIFT;
                                for (int k = idx; ; k += 2)
                                {
                                    switch ((byte)buffer[k])
                                    {
                                    case CtiProtocol.CARRIAGE_RETURN:
                                    {
                                        e.DestinationCallerId = buffer.Substring(idx, k - idx);
                                        idx = k - 1;
                                        goto LEAVE_FOR_2;
                                    }

                                    case CtiProtocol.LINE_FEED:
                                    {
                                        e.DestinationCallerId = buffer.Substring(idx, k - idx - 1);
                                        idx = k - 2;
                                        goto LEAVE_FOR_2;
                                    }
                                    }
                                }

LEAVE_FOR_2:

                                idx += CtiProtocol.CALL_START_DATE_SHIFT;
                                int limit = idx + CtiProtocol.CALL_START_DATE_VALU_LEN;
                                e.CallStartDate = buffer.Substring(idx, limit - idx);

                                idx         = limit + CtiProtocol.TIMESTAMP_SHIFT;
                                limit       = idx + CtiProtocol.TIMESTAMP_VALU_LEN;
                                e.Timestamp = buffer.Substring(idx, limit - idx);

                                observer.OnNext(e);

                                string cleanUpBuffer = buffer.Remove(0, i + 3);
                                buffer = cleanUpBuffer;
                                goto FIND_NEXT_DELIMITER;
                            }

                            case CtiProtocol.R:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.D:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.H:
                            {
                                switch ((byte)buffer[CtiProtocol.SHIFT_FOR_EVENT_TYPE + 1])
                                {
                                case CtiProtocol.a:
                                {
                                    throw new NotImplementedException();
                                }

                                case CtiProtocol.o:
                                {
                                    throw new NotImplementedException();
                                }
                                }

                                throw new Exception("todo: create message...");
                            }

                            case CtiProtocol.L:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.P:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.U:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.S:
                            {
                                throw new NotImplementedException();
                            }

                            default:
                            {
                                throw new Exception("todo: create message...");
                            }
                            }
                        }
                        else if (buffer[i - CtiProtocol.SHIFT_FOR_DELIMITER] == CtiProtocol.LINE_FEED)
                        {
                            foundDelimiter = true;
                            switch ((byte)buffer[CtiProtocol.SHIFT_FOR_EVENT_TYPE])
                            {
                            case CtiProtocol.T:
                            {
                                TryingEvent e = new TryingEvent();

                                e.SessionId = buffer.Substring(CtiProtocol.SESSION_ID_IDX_SHIFT, CtiProtocol.SESSION_ID_VALU_LEN);

                                int idx = CtiProtocol.SOURCE_CALLER_ID_IDX_SHIFT;
                                for (int k = idx; ; k += 2)
                                {
                                    switch ((byte)buffer[k])
                                    {
                                    case CtiProtocol.CARRIAGE_RETURN:
                                    {
                                        e.SourceCallerId = buffer.Substring(idx, k - idx);
                                        idx = k - 1;
                                        goto LEAVE_FOR_1;
                                    }

                                    case CtiProtocol.LINE_FEED:
                                    {
                                        e.SourceCallerId = buffer.Substring(idx, k - idx - 1);
                                        idx = k - 2;
                                        goto LEAVE_FOR_1;
                                    }
                                    }
                                }

LEAVE_FOR_1:

                                idx += CtiProtocol.DESTINATION_CALLER_ID_SHIFT;
                                for (int k = idx; ; k += 2)
                                {
                                    switch ((byte)buffer[k])
                                    {
                                    case CtiProtocol.CARRIAGE_RETURN:
                                    {
                                        e.DestinationCallerId = buffer.Substring(idx, k - idx);
                                        idx = k - 1;
                                        goto LEAVE_FOR_2;
                                    }

                                    case CtiProtocol.LINE_FEED:
                                    {
                                        e.DestinationCallerId = buffer.Substring(idx, k - idx - 1);
                                        idx = k - 2;
                                        goto LEAVE_FOR_2;
                                    }
                                    }
                                }

LEAVE_FOR_2:

                                idx += CtiProtocol.CALL_START_DATE_SHIFT;
                                int limit = idx + CtiProtocol.CALL_START_DATE_VALU_LEN;
                                e.CallStartDate = buffer.Substring(idx, limit - idx);

                                idx         = limit + CtiProtocol.TIMESTAMP_SHIFT;
                                limit       = idx + CtiProtocol.TIMESTAMP_VALU_LEN;
                                e.Timestamp = buffer.Substring(idx, limit - idx);

                                observer.OnNext(e);

                                string cleanUpBuffer = buffer.Remove(0, i + 1);
                                buffer = cleanUpBuffer;
                                goto FIND_NEXT_DELIMITER;
                            }

                            case CtiProtocol.R:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.D:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.H:
                            {
                                switch ((byte)buffer[CtiProtocol.SHIFT_FOR_EVENT_TYPE + 1])
                                {
                                case CtiProtocol.a:
                                {
                                    throw new NotImplementedException();
                                }

                                case CtiProtocol.o:
                                {
                                    throw new NotImplementedException();
                                }
                                }

                                throw new Exception("todo: create message...");
                            }

                            case CtiProtocol.L:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.P:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.U:
                            {
                                throw new NotImplementedException();
                            }

                            case CtiProtocol.S:
                            {
                                throw new NotImplementedException();
                            }

                            default:
                            {
                                throw new Exception("todo: create message...");
                            }
                            }
                        }
                        break;
                    }
                    }
                }
                FIND_NEXT_DELIMITER :;
            } while (foundDelimiter);
        }