Beispiel #1
0
        public async Task <bool> SetValueAsync(string key, string value, int hours = 0)
        {
            bool result = false;

            try
            {
                TimeSpan?expiration = null;

                if (hours > 0)
                {
                    expiration = TimeSpan.FromHours(hours);
                }

                ConnectionMultiplexer redisConnection = await GetRedisConnectionAsync();

                result = await redisConnection.GetDatabase().StringSetAsync(key, value, expiration);
            }
            catch (Exception exception)
            {
                ElmahUtils.LogToElmah(exception);

                result = false;
            }

            return(result);
        }
Beispiel #2
0
        protected override async Task OutgoingMessageAsync(string correlationId, string requestInfo, byte[] message, Stopwatch timeRequest)
        {
            await Task.Run(() =>
            {
                //Debug.WriteLine(string.Format("{0} - Response (ms):{1} - {2}\r\n{3}", correlationId, timeRequest.ElapsedMilliseconds, requestInfo, Encoding.UTF8.GetString(message)));

                ElmahUtils.LogSuccessToElmah(string.Format("{0} - Response (ms):{1} - {2}\r\n{3}", correlationId, timeRequest.ElapsedMilliseconds, requestInfo, Encoding.UTF8.GetString(message)));
            });
        }
Beispiel #3
0
        protected override async Task IncommingMessageAsync(string correlationId, string requestInfo, byte[] message, string authorization)
        {
            await Task.Run(() =>
            {
                //Debug.WriteLine(string.Format("{0} - Request: {1}\r\n{2}", correlationId, requestInfo, Encoding.UTF8.GetString(message)));
                //Debug.WriteLine(string.Format("Token {0}", authorization));

                ElmahUtils.LogSuccessToElmah(string.Format("{0} - Request: {1}\r\n{2}\r\n{3}", correlationId, requestInfo, Encoding.UTF8.GetString(message), authorization));
            });
        }
Beispiel #4
0
        public NotificationBusiness()
        {
            try
            {
                string NOTIFICATION_HUB_CONNECTION_STRING = ConfigurationManager.AppSettings["NotificationHubConnectionString"];
                string NOTIFICATION_HUB_NAME = ConfigurationManager.AppSettings["NotificationHubName"];

                _hubClient = NotificationHubClient.CreateClientFromConnectionString(NOTIFICATION_HUB_CONNECTION_STRING, NOTIFICATION_HUB_NAME);
            }
            catch (Exception exception)
            {
                ElmahUtils.LogToElmah(exception);
            }
        }
Beispiel #5
0
        public string GetValue(string key)
        {
            string result = null;

            try
            {
                ConnectionMultiplexer redisConnection = GetRedisConnection();

                result = redisConnection.GetDatabase().StringGet(key);
            }
            catch (Exception exception)
            {
                ElmahUtils.LogToElmah(exception);

                result = null;
            }

            return(result);
        }
Beispiel #6
0
        public async Task <string> GetValueAsync(string key)
        {
            string result = null;

            try
            {
                ConnectionMultiplexer redisConnection = await GetRedisConnectionAsync();

                result = await redisConnection.GetDatabase().StringGetAsync(key);
            }
            catch (Exception exception)
            {
                ElmahUtils.LogToElmah(exception);

                result = null;
            }

            return(result);
        }
Beispiel #7
0
        public async Task <bool> RemoveKeyAsync(string key)
        {
            bool result = false;

            try
            {
                ConnectionMultiplexer redisConnection = await GetRedisConnectionAsync();

                result = await redisConnection.GetDatabase().KeyDeleteAsync(key);
            }
            catch (Exception exception)
            {
                ElmahUtils.LogToElmah(exception);

                result = false;
            }

            return(result);
        }
        public override void OnException(HttpActionExecutedContext context)
        {
            if (context.Exception != null)
            {
                if (context.Exception is MyTrapBusinessException)
                {
                    BaseApiResult response = new BaseApiResult();

                    response.Error   = true;
                    response.Code    = 500;
                    response.Message = ((MyTrapBusinessException)context.Exception).Inconsistency;

                    string json = JsonConvert.SerializeObject(response);

                    context.Response = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent(json, Encoding.UTF8, "application/json")
                    };
                }
                else
                {
                    BaseApiResult response = new BaseApiResult();

                    response.Error   = true;
                    response.Code    = 500;
                    response.Message = "General error";

                    string json = JsonConvert.SerializeObject(response);

                    context.Response = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                    {
                        Content = new StringContent(json, Encoding.UTF8, "application/json")
                    };

                    ElmahUtils.LogToElmah(context.Exception);
                }
            }
        }
Beispiel #9
0
        public async Task SendNotificationTrapDisarmed(string email, string msg, bool owner, int points, string trapNameKey, double latitude, double longitude, string otherUserName, string otherUserImage)
        {
            try
            {
                var date = DateUtils.DateToString(DateTime.Now);

                var androidPayload = "{ \"data\" : {\"message\":\"" + msg + "\", \"owner\":\"" + (owner ? "1" : "0") + "\", \"points\":\"" + points + "\", \"show\":\"1\", \"trap\":\"" + trapNameKey + "\", \"lat\":\"" + latitude + "\", \"lng\":\"" + longitude + "\", \"date\":\"" + date + "\", \"userName\":\"" + otherUserName + "\", \"img\":\"" + otherUserImage + "\"}}";
                var windowsPayload = "{\"message\":\"" + msg + "\", \"owner\":" + (owner ? "1" : "0") + ", \"points\":" + points + ", \"show\":1, \"trap\":\"" + trapNameKey + "\", \"lat\":" + latitude.ToString(CultureInfo.InvariantCulture) + ", \"lng\":" + longitude.ToString(CultureInfo.InvariantCulture) + ", \"date\":\"" + date + "\", \"userName\":\"" + otherUserName + "\", \"img\":\"" + otherUserImage + "\"}";

                var notificationOutcomeAndroid = await _hubClient.SendGcmNativeNotificationAsync(androidPayload, email);

                WindowsNotification notificationWindows = new WindowsNotification(windowsPayload);

                notificationWindows.Headers.Add("X-NotificationClass", "3");
                notificationWindows.Headers.Add("X-WNS-Type", "wns/raw");

                var notificationOutcomeWindows = await _hubClient.SendNotificationAsync(notificationWindows, email);
            }
            catch (Exception exception)
            {
                ElmahUtils.LogToElmah(exception);
            }
        }
Beispiel #10
0
        public async Task Register(string email, int platformId, string pushRegistrationId)
        {
            try
            {
                var registrationsCollection = await _hubClient.GetRegistrationsByTagAsync(email, 100);

                var registrations = registrationsCollection.ToList();

                if (registrations != null && registrations.Count > 0)
                {
                    foreach (var register in registrations)
                    {
                        await _hubClient.DeleteRegistrationAsync(register);
                    }
                }

                switch ((EPlatform)platformId)
                {
                case EPlatform.ANDROID:

                    await _hubClient.CreateGcmNativeRegistrationAsync(pushRegistrationId, new string[] { email });

                    break;

                case EPlatform.WP:

                    await _hubClient.CreateWindowsNativeRegistrationAsync(pushRegistrationId, new string[] { email });

                    break;
                }
            }
            catch (Exception exception)
            {
                ElmahUtils.LogToElmah(exception);
            }
        }