Exemplo n.º 1
0
        public RedisCache(GenericConfig config)
        {
            // init config
            _config = config;

            var configurationOptions = new ConfigurationOptions
            {
                SyncTimeout = int.MaxValue,
            };


            foreach (var e in _config.Endpoints)
            {
                configurationOptions.EndPoints.Add(e);
            }

            redis = ConnectionMultiplexer.Connect(configurationOptions);

            db = redis.GetDatabase();

            _serializationSettings = new JsonSerializerSettings
            {
                //PreserveReferencesHandling = PreserveReferencesHandling.Objects
                Formatting = Formatting.Indented
            };
        }
 private void CreateCollection(IHandlePromiseActions handlePromiseActions, GenericConfig genericConfig, NewCollectionWorkload newCollectionWorkload, NewCollectionRequest request, GenericResponse arg5)
 {
     using (var redisManager = new PooledRedisClientManager(new[] { "127.0.0.1:6379" }))
         using (var redis = redisManager.GetClient())
         {
             redis.SetEntryInHash(request.CollectionName, "visibility",
                                  request.Visibility.ToString(CultureInfo.InvariantCulture));
         }
 }
        private void BuildCollectionName(IHandlePromiseActions handlePromiseActions, GenericConfig genericConfig, NewCollectionWorkload newCollectionWorkload, NewCollectionRequest request, GenericResponse arg5)
        {
            request.CollectionName = request.CollectionName.ToLowerInvariant();

            // if (not public), prepend the applicationName

            if (request.Visibility == 1)
            {
                return;
            }

            request.CollectionName =
                string.Format("{0}.{1}", "app", request.CollectionName).ToLowerInvariant();
        }
Exemplo n.º 4
0
 public void SetValueFromGenericConfig(IAutoConfig instanse, GenericConfig config)
 {
     if (instanse == null)
     {
         throw new ArgumentNullException(nameof(instanse));
     }
     if (config == null)
     {
         throw new ArgumentNullException(nameof(config));
     }
     if (config.AppName != AppName || config.Key != PropertyAttribute.Key)
     {
         throw new ConfigNotMatchException($"config is not for app {AppName} and key {PropertyAttribute.Key}");
     }
     SetValue(instanse, JsonConvert.DeserializeObject(config.Value, Property.PropertyType));
 }
Exemplo n.º 5
0
        public GenericConfig MakeGenericConfig(IAutoConfig instanse)
        {
            if (instanse == null)
            {
                throw new ArgumentNullException(nameof(instanse));
            }
            GenericConfig result = new GenericConfig()
            {
                AppName     = AppName,
                Key         = PropertyAttribute.Key,
                Value       = JsonConvert.SerializeObject(GetValue(instanse)),
                LastUpdated = DateTime.Now
            };

            return(result);
        }
        public static GenericConfig ToGenericConfig(this RedisConfigurationSection section)
        {
            if (null != section)
            {
                var genericConfig = new GenericConfig();
                genericConfig.Endpoints = new List <string>();
                foreach (var e in section.Endpoints)
                {
                    var endPoint = (RedisEndpointElement)e;
                    genericConfig.Endpoints.Add(endPoint.Host);
                }

                return(genericConfig);
            }

            return(null);
        }
Exemplo n.º 7
0
        public Task SendMessage(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post")] object message,
            [SignalR(HubName = GlobalConstants.SignalR_HubName)] IAsyncCollector <SignalRMessage> signalRMessages,
            ExecutionContext executionContext)
        {
            _genericConfig = StartupHelper.GetConfig(executionContext);

            // relay the message to the WhatsApp API
            HttpHelper.PostMessage(_genericConfig.ApiEndpoint + GlobalConstants.FunctionName_SendWhatsAppMessage, message);

            //relay the message to the SignalR Service
            return(signalRMessages.AddAsync(
                       new SignalRMessage
            {
                Target = GlobalConstants.SignalR_TargetGroup,
                Arguments = new[] { message }
            }));
        }
Exemplo n.º 8
0
        public ActionResult AcademyAdmin(string id)
        {
            var values = new
            {
                AcademyID = id
            };

            var serializer = new JavaScriptSerializer();
            var json       = serializer.Serialize(values);

            var config = new GenericConfig()
            {
                Module   = "6weekschallenge.academyAdmin",
                Settings = json
            };

            Response.ContentType = "text/javascript";
            return(View(config));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)]
            HttpRequest httpRequest,
            ExecutionContext executionContext)
        {
            _genericConfig = StartupHelper.GetConfig(executionContext);

            string requestBody = await new StreamReader(httpRequest.Body).ReadToEndAsync();

            UserMessage userMessage = new UserMessage
            {
                User    = HttpUtility.ParseQueryString(requestBody).Get("From"),
                Message = HttpUtility.ParseQueryString(requestBody).Get("Body")
            };

            HttpHelper.PostMessage(
                _genericConfig.ApiEndpoint + GlobalConstants.FunctionName_BroadcastSignalRMessage,
                userMessage);

            return(new OkResult());
        }
Exemplo n.º 10
0
        // GET: Config
        public ActionResult Core()
        {
            var settings = CManager.Settings;
            var values   = new
            {
                AWSAccessKeyId  = settings.AWSAccessKeyID,
                UrlS3           = settings.AWSS3Upload.URL,
                UploadPolicy    = settings.AWSS3Upload.GetPolicyInBase64(),
                UploadSignature = settings.AWSS3Upload.GetSignature()
            };

            var serializer = new JavaScriptSerializer();
            var json       = serializer.Serialize(values);

            var config = new GenericConfig()
            {
                Module   = "6weekschallenge.core",
                Settings = json
            };

            Response.ContentType = "text/javascript";
            return(View(config));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest httpRequest,
            ExecutionContext executionContext
            )
        {
            _genericConfig = StartupHelper.GetConfig(executionContext);

            string  requestBody   = await new StreamReader(httpRequest.Body).ReadToEndAsync();
            dynamic requestObject = JsonConvert.DeserializeObject(requestBody);

            // connect to Twilio
            TwilioClient.Init(_genericConfig.TwilioAccountSid, _genericConfig.TwilioAuthToken);

            // query twilio api ... and get distinct phone numbers of whatsapp users subscribed to chat
            ResourceSet <MessageResource> messageCollection = await MessageResource.ReadAsync(to : _genericConfig.TwilioWhatsAppPhoneNumber);

            IEnumerable <PhoneNumber> distinctPhoneNumbers = messageCollection.GroupBy(a => a.From.ToString()).Select(b => b.FirstOrDefault().From);

            foreach (var phoneNumber in distinctPhoneNumbers)
            {
                if (phoneNumber.ToString() == requestObject.User.ToString())
                {
                    // if message originated from whatsapp, don't send a copy straight back to sender
                    continue;
                }

                // send message to whatsapp user
                var message = MessageResource.Create(
                    from: new Twilio.Types.PhoneNumber(_genericConfig.TwilioWhatsAppPhoneNumber),
                    body: $"{requestObject.User} : {requestObject.Message}",
                    to: phoneNumber
                    );
            }

            return((ActionResult) new OkResult());
        }
Exemplo n.º 12
0
        public void AddOrUpdate(GenericConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            GenericConfig find = null;

            if (config.Id > 0)
            {
                find = Repository <GenericConfigRepository>().ReadSingle(e => e.Id == config.Id);
            }
            if (find == null)
            {
                find = Repository <GenericConfigRepository>().ReadSingle(e => e.AppName == config.AppName && e.Key == config.Key);
            }
            if (find == null)
            {
                find = new GenericConfig()
                {
                    AppName     = config.AppName,
                    Key         = config.Key,
                    Value       = config.Value,
                    LastUpdated = DateTime.Now
                };
                Repository <GenericConfigRepository>().AddSingle(find);
            }
            else
            {
                find.AppName     = config.AppName;
                find.Key         = config.Key;
                find.Value       = config.Value;
                find.LastUpdated = DateTime.Now;
                Repository <GenericConfigRepository>().UpdateSingle(find);
            }
        }
Exemplo n.º 13
0
 public RedisCache(JsonSerializerSettings serializationSettings, GenericConfig config) : this(config)
 {
     this._serializationSettings = serializationSettings;
 }
Exemplo n.º 14
0
 private void BuildRedisCollectionName(IHandlePromiseActions handlePromiseActions, GenericConfig genericConfig, NewCollectionWorkload newCollectionWorkload, NewCollectionRequest request, GenericResponse arg5)
 {
     request.CollectionName = string.Format("olrt:{0}", request.CollectionName);
 }
Exemplo n.º 15
0
        private void ValidateNewCollection(IHandlePromiseActions handlePromiseActions, GenericConfig genericConfig, NewCollectionWorkload newCollectionWorkload, NewCollectionRequest request, GenericResponse arg5)
        {
            if (string.IsNullOrEmpty(request.CollectionName))
            {
                handlePromiseActions.Abort(new NullCollectionName());
                return;
            }

            if (Regex.Match(request.CollectionName, @"^|:olr.*:", RegexOptions.IgnoreCase).Success)
            {
                handlePromiseActions.Abort(new InvalidCollectionName(request.CollectionName));
            }
        }
Exemplo n.º 16
0
        public void Init()
        {
            var config = (RedisConfigurationSection)ConfigurationManager.GetSection("redis");

            _config = config.ToGenericConfig();
        }