Ejemplo n.º 1
0
        //create/update a client object based on a client event received from the client
        public static Client CreateFromClientEvent(ClientEvent clientEvent, ClientStateEnum clientState)
        {
            if (log.IsDebugEnabled) { log.Debug("CreateFromClientEvent.ClientEvent." + (clientEvent == null ? "null" : clientEvent.ToJsonString())); }

            Client client = null;

            if (clientEvent != null &&
                clientEvent.ClientData != null)
            {
                MongoDatabase mongoDb = Helper.MongoDb.GetDatabase();

                //try to find existing
                client = Client.FindOneBySessionNodeId(mongoDb, clientEvent.SessionNodeId);
                if (client == null)
                    client = Client.FindOneBySessionAspNetId(mongoDb, clientEvent.ClientData.SessionAspNetId);
                if (client == null)
                    client = new Client();

                //upsert the client for future use
                client.ClientSessionNodeId = clientEvent.SessionNodeId;
                client.ClientSessionAspNetId = clientEvent.ClientData.SessionAspNetId;
                client.ClientState = clientState;
                client.Save(mongoDb);
            }

            if (log.IsDebugEnabled) { log.Debug("CreateFromClientEvent.Client." + (client == null ? "null" : client.ToJsonString())); }

            return client;
        }
Ejemplo n.º 2
0
        //create a call object from a twilio request and save the call to the database
        public static Call CreateFromTwilioRequest(MongoDatabase mongoDb, TwilioComm.TwilioRequestVoice twilioRequest, Client client, bool saveCall)
        {
            if (twilioRequest == null)
                return null;

            if (mongoDb == null ||
                mongoDb.Server == null)
            {
                mongoDb = Helper.MongoDb.GetDatabase();
            }

            Call call = Call.CreateFromTwilioRequest(twilioRequest);

            if (client != null)
                call.ClientToId = client._id;

            if (call.CallDateCreate == null)
                call.CallDateCreate = DateTime.Now;
            call.CallDateUpdate = DateTime.Now;

            if (saveCall)
                call.Save();

            if (log.IsDebugEnabled) { log.Debug("CreateFromTwilioRequest.call." + (call == null ? "null" : call.ToJsonString())); }

            return call;
        }
Ejemplo n.º 3
0
        public static Client Save(MongoDatabase mongoDb, Client client)
        {
            if (mongoDb == null ||
                client == null)
            {
                return null;
            }

            if (mongoDb.Server == null)
                mongoDb = Helper.MongoDb.GetDatabase();

            try
            {
                if (client.ClientDateCreate == null)
                    client.ClientDateCreate = DateTime.Now;
                client.ClientDateUpdate = DateTime.Now;

                var clientCol = mongoDb.GetCollection<Client>("Client");
                clientCol.Save(client);
            }
            catch (Exception ex)
            {
                if (log.IsDebugEnabled) { log.Error("Save.Client." + (client == null ? "null" : client.ToJsonString()), ex); }

                throw ex;
                return null; //"Error: unable to Client.FindOneBySessionAspNetId for " + sessionAspNetId;
            }

            if (log.IsDebugEnabled) { log.Debug("Save.Client." + (client == null ? "null" : client.ToJsonString())); }

            return client;
        }
Ejemplo n.º 4
0
        //create a call object from a twilio request and save the call to the database
        public static Call CreateFromTwilioRequest(TwilioComm.TwilioRequestVoice twilioRequest, Client client, bool saveCall)
        {
            if (twilioRequest == null)
                return null;

            return CreateFromTwilioRequest(null, twilioRequest, client, saveCall);
        }
Ejemplo n.º 5
0
 public static Client Save(Client client)
 {
     MongoDatabase mongoDb = Helper.MongoDb.GetDatabase();
     return Save(mongoDb, client);
 }