Beispiel #1
0
        private static void LogStatus(bool receiving, byte[] buffer, int length, string terminalId, string userCrm)
        {
            lock (consoleLock)
            {
                //Console.ForegroundColor = receiving ? ConsoleColor.Green : ConsoleColor.Gray;
                //Console.WriteLine("{0} {1} bytes... ", receiving ? "Received" : "Sent", length);

                if (verbose)
                {
                    string result = Encoding.UTF8.GetString(buffer, 0, length);
                    if (result != "ping" && result.Contains("listenerName"))
                    {
                        try
                        {
                            Console.WriteLine(terminalId);
                            Console.WriteLine();
                            Console.WriteLine(result);
                            JObject o                 = JObject.Parse(result);
                            string  _event            = (string)o.SelectToken("item[0].event");
                            string  callId            = (string)o.SelectToken("item[0].callId");
                            string  incoming          = (string)o.SelectToken("item[0].incoming");
                            string  type              = (string)o.SelectToken("item[0].type");
                            string  acdId             = (string)o.SelectToken("item[0].acdId");
                            string  displayNumber     = (string)o.SelectToken("item[0].displayNumber");
                            string  displayLabel      = (string)o.SelectToken("item[0].displayLabel");
                            string  displayNumberE164 = (string)o.SelectToken("item[0].displayNumberE164");

                            var objCall = new CRMCall();
                            objCall._event            = _event;
                            objCall.callId            = callId;
                            objCall.incoming          = incoming;
                            objCall.type              = type;
                            objCall.acdId             = acdId;
                            objCall.displayNumber     = displayNumber;
                            objCall.displayLabel      = displayLabel;
                            objCall.displayNumberE164 = displayNumberE164;
                            objCall.terminalId        = terminalId;
                            objCall.userCrm           = userCrm;

                            if (_event == "callRinging")
                            {
                                InsertCall.Insert(objCall);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    else
                    {
                        Console.WriteLine(result);
                    }
                }
                //Console.ResetColor();
            }
        }
Beispiel #2
0
        public static CRMCall GetCall()
        {
            var obj = new CRMCall();

            using (var _connection = new SqlConnection(Database.GetConnection))
            {
                _connection.Open();
                var tr = _connection.BeginTransaction(IsolationLevel.Serializable);
                using (var command = new SqlCommand())
                {
                    command.Transaction = tr;
                    command.Connection  = _connection;
                    command.CommandText = @"select TOP (1) [displayNumberE164], _event
                                          ,[AddedOn]
                                          ,[terminalId]
                                          ,[userCrm] from [Call] where _event = 'callRinging'  order by [AddedOn] desc";
                    try
                    {
                        using (var rd = command.ExecuteReader())
                        {
                            if (rd.HasRows)
                            {
                                if (rd.Read())
                                {
                                    obj.displayNumberE164 = rd["displayNumberE164"].ToString();
                                    obj._event            = rd["_event"].ToString();
                                    obj.AddedOn           = Convert.ToDateTime(rd["AddedOn"]);
                                    obj.terminalId        = rd["terminalId"].ToString();
                                    obj.userCrm           = rd["userCrm"].ToString();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        tr.Rollback();
                        throw ex;
                    }
                }
            }
            return(obj);
        }
Beispiel #3
0
        public static int Insert(CRMCall obj)
        {
            var newID = 0;

            using (var _connection = new SqlConnection(Database.GetConnection))
            {
                _connection.Open();
                var tr = _connection.BeginTransaction(IsolationLevel.Serializable);
                using (var command = new SqlCommand())
                {
                    command.Transaction = tr;
                    command.Connection  = _connection;
                    command.CommandText = @"INSERT INTO [Call](_event
                                               ,callId
                                               ,incoming
                                               ,[type]
                                               ,acdId
                                               ,displayNumber
                                               ,displayLabel
                                               ,displayNumberE164
                                               ,AddedOn
                                               ,terminalId
                                               ,userCrm)
                                         VALUES
                                               (@_event
                                               ,@callId
                                               ,@incoming
                                               ,@type
                                               ,@acdId
                                               ,@displayNumber
                                               ,@displayLabel
                                               ,@displayNumberE164
                                               ,@AddedOn
                                               ,@terminalId
                                               ,@userCrm)";

                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@_event", obj._event);
                    command.Parameters.AddWithValue("@callId", obj.callId);
                    command.Parameters.AddWithValue("@incoming", obj.incoming);
                    command.Parameters.AddWithValue("@type", obj.type);
                    command.Parameters.AddWithValue("@acdId", obj.acdId);
                    command.Parameters.AddWithValue("@displayNumber", obj.displayNumber);
                    command.Parameters.AddWithValue("@displayLabel", obj.displayLabel);
                    command.Parameters.AddWithValue("@displayNumberE164", obj.displayNumberE164);
                    command.Parameters.AddWithValue("@AddedOn", DateTime.Now);
                    command.Parameters.AddWithValue("@terminalId", obj.terminalId);
                    command.Parameters.AddWithValue("@userCrm", obj.userCrm);

                    try
                    {
                        command.ExecuteNonQuery();
                        tr.Commit();
                    }
                    catch (Exception ex)
                    {
                        tr.Rollback();
                        throw ex;
                    }
                }
            }
            return(newID);
        }