public static void Init(string sHost, int iPort, string sPassword)
        {
            CacheDatabase._Host = sHost;
            CacheDatabase._Port = iPort;
            CacheDatabase._Password = sPassword;
            if (CacheDatabase._Password.Length > 0)
            {
                CacheDatabase._AuthRequired = true;
            }
            else
            {
                CacheDatabase._AuthRequired = false;
            }

            _oConectionOptions = new ConfigurationOptions();
            if (CacheDatabase._AuthRequired)
            {
                CacheDatabase._oConectionOptions.Password = CacheDatabase._Password;
            }

            CacheDatabase._oConectionOptions.EndPoints.Add(CacheDatabase._Host + ":" + CacheDatabase._Port.ToString());
            CacheDatabase._oCacheConnection = ConnectionMultiplexer.Connect(CacheDatabase._oConectionOptions);
            CacheDatabase._oCommand = CacheDatabase._oCacheConnection.GetDatabase();
            //Check to make sure the Key Exists and if not then set it to 0
            if (!_oCommand.KeyExists(CacheDatabase._ObjectCounterKeyName))
            {
                CacheDatabase._oCommand.StringSet(CacheDatabase._ObjectCounterKeyName, 0);
            }
        }
Exemple #2
0
        static string getTokenDetails(string Key)
        {
            Redis.ConnectionMultiplexer connection = Redis.ConnectionMultiplexer.Connect("localhost,password=ZLDe3wse");
            Redis.IDatabase             db         = connection.GetDatabase();

            Redis.RedisValue Value = db.StringGet(Key);

            return(Value);
        }
        public static StackExchange.Redis.IDatabase GetDatabase()
        {
            StackExchange.Redis.IDatabase databaseReturn = null;
            string connectionString      = (string)CommonUtils.AppConfig.ConnectionStrings.RedisConnection;
            var    connectionMultiplexer = ConnectionMultiplexer.Connect(connectionString);

            if (connectionMultiplexer.IsConnected)
            {
                databaseReturn = connectionMultiplexer.GetDatabase();
            }

            return(databaseReturn);
        }
Exemple #4
0
 public RedisCacheProvider(StackExchange.Redis.IDatabase cache, IServer server)
 {
     RedisCache = new RedisCache(new JsonSerializerSettings
     {
         DateTimeZoneHandling   = DateTimeZoneHandling.Unspecified,
         NullValueHandling      = NullValueHandling.Ignore,
         ObjectCreationHandling = ObjectCreationHandling.Replace,
         ReferenceLoopHandling  = ReferenceLoopHandling.Ignore,
         TypeNameHandling       = TypeNameHandling.Objects,
         Converters             = new List <JsonConverter> {
             new ReportPartContentConverter(), new DBServerTypeSupportingConverter()
         }
     }, cache, server);
 }
        public string Post([FromBody] string value)
        {
            var id = Guid.NewGuid().ToString();

            try {
                StackExchange.Redis.ConnectionMultiplexer redis   = ConnectionMultiplexer.Connect("localhost");
                StackExchange.Redis.IDatabase             redisDb = redis.GetDatabase();
                this.SaveDataToRedis(redisDb, id, value);
                this.makeEvent(redis, id, value);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
            return(id);
        }
Exemple #6
0
        public RedisCacheStackExchange()
        {
            if (Configuration == null)
            {
                this.Configuration = Container.Resolve <IWebConfiguration>();
            }
            var redisConfig = this.Configuration.GetSection <RedisConfigSection>("redis");

            if (redisConfig == null)
            {
                return;
            }
            var cacheStrings = redisConfig.GetCacheStrings();
            var cacheString  = cacheStrings.FirstOrDefault();

            this.connectionName = cacheString.Name;
            DefaultRedisActivator.InitializeStackExchange();
            this.Database = Container.Resolve <StackExchange.Redis.IDatabase>();
        }
Exemple #7
0
        /// <summary>
        /// Get Bidder E-mails
        /// </summary>
        /// <param name="id">The ID of the Auction</param>
        /// <returns>The e-mail addresses of the bidders registered for the auction</returns>
        public string[] getBidderEmails(string id)
        {
            StackExchange.Redis.IDatabase database = null;

            // Connect to the database
            try
            {
                ConnectionMultiplexer redisConn =
                    ConnectionMultiplexer.Connect(ConfigurationManager.AppSettings["serverName"]);
                database = redisConn.GetDatabase(Int32.Parse(ConfigurationManager.AppSettings["namespace"]));
            }
            catch (RedisConnectionException e)
            {
                Console.WriteLine("Could not connect to database - " + e.Message);
                return(null);
            }
            // Return all of the values in the set under the given key
            return(Array.ConvertAll(database.SetMembers(id), x => (string)x));
        }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisDatabase"/> class.
        /// </summary>
        internal RedisDatabase()
        {
            ConfigurationOptions Configuration = new ConfigurationOptions();

            Configuration.EndPoints.Add("163.172.110.110", 6379);

            Configuration.Password   = "******";
            Configuration.ClientName = this.GetType().Assembly.FullName;

            Configuration.SyncTimeout     = 7000;
            Configuration.ConnectTimeout  = 7000;
            Configuration.ResponseTimeout = 7000;

            this.Multiplexer = ConnectionMultiplexer.Connect(Configuration);
            this.Server      = this.Multiplexer.GetServer(Configuration.EndPoints[0]);

            this.Players   = this.Multiplexer.GetDatabase((int)Database.Players);
            this.Alliances = this.Multiplexer.GetDatabase((int)Database.Alliances);

            this.Multiplexer.ErrorMessage     += this.OnError;
            this.Multiplexer.ConnectionFailed += this.OnConnectionFailed;

            this.CacheLifeTime = TimeSpan.FromHours(4);
        }
Exemple #9
0
        public void Put(Guid teamId, MemberLocation memberLocation)
        {
            IDatabase db = connection.GetDatabase();

            db.HashSet(teamId.ToString(), memberLocation.MemberID.ToString(), memberLocation.ToJsonString());
        }
Exemple #10
0
 /// <summary>
 /// Constructs a Redis IAppCache implementation using the given Redis configuration object
 /// </summary>
 /// <param name="redisConfig"></param>
 public RedisAppCache(RedisConfig redisConfig)
 {
     _redisConfig   = redisConfig;
     _redisDatabase = _redisConfig.RedisMultiplexer.GetDatabase(_redisConfig.RedisDatabaseId);
 }
        protected override async Task OnMembersAddedAsync(IList <ChannelAccount> membersAdded, ITurnContext <IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
        {
            foreach (var member in membersAdded)
            {
                // Greet anyone that was not the target (recipient) of this message.
                // To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards for more details.
                if (member.Id != turnContext.Activity.Recipient.Id)
                {
                    string botClientUserId   = turnContext.Activity.From.Id;
                    string botConversationId = turnContext.Activity.Conversation.Id;
                    string botchannelID      = turnContext.Activity.ChannelId;

                    var welcomeCard = CreateAdaptiveCardAttachment(botClientUserId, botConversationId);

                    var response = MessageFactory.Attachment(welcomeCard);
                    await turnContext.SendActivityAsync(response, cancellationToken);

                    await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>("DialogState"), cancellationToken);



                    string cacheConnectionString = _iconfiguration["RedisCacheConnection"];

                    try
                    {
                        ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(cacheConnectionString);

                        StackExchange.Redis.IDatabase db = connection.GetDatabase();

                        SessionModel SessionModel = new SessionModel();
                        SessionModel.DisplayName               = "";
                        SessionModel.EmailId                   = "";
                        SessionModel.SessionKey                = botClientUserId;
                        SessionModel.ConversationID            = botConversationId;
                        SessionModel.IsSkipIntro               = false;
                        SessionModel.UserLoginDetectServiceChk = 0;

                        db.StringSet(botClientUserId, JsonConvert.SerializeObject(SessionModel));
                        db.StringSet(botClientUserId + "artEnroll", JsonConvert.SerializeObject(SessionModel));

                        var sessionModelsAccessors = UserState.CreateProperty <SessionModel>(nameof(SessionModel));
                        var sessionModels          = await sessionModelsAccessors.GetAsync(turnContext, () => new SessionModel());

                        if (string.IsNullOrWhiteSpace(sessionModels.DisplayName) && sessionModels.UserLoginDetectServiceChk == 0)
                        {
                            sessionModels.Password       = "";
                            sessionModels.DisplayName    = "";
                            sessionModels.EmailId        = "";
                            sessionModels.SessionKey     = botClientUserId;
                            sessionModels.ConversationID = botConversationId;
                            sessionModels.IsSkipIntro    = false;
                            UserLoginDetectService userLoginDetect = new UserLoginDetectService(cancellationToken, _cache, turnContext, cacheConnectionString, UserState);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            //if (turnContext.Activity.ChannelId != "directline" && turnContext.Activity.ChannelId != "webchat")
            //{
            //    foreach (var member in membersAdded)
            //    {
            //        if (member.Id != turnContext.Activity.Recipient.Id)
            //        {
            //            bool stat = CheckSignin(turnContext.Activity.From.Id);
            //            if (!stat)
            //                await ShowSigninCard(turnContext, cancellationToken);
            //        }
            //    }
            //}
        }
Exemple #12
0
 public TodoItemsController(IOptions <AppSettings> appSettings, TodoContext context, StackExchange.Redis.IDatabase database)
 {
     _context     = context;
     _database    = database;
     _appSettings = appSettings.Value;
 }
Exemple #13
0
 public RedisCacheProvider()
 {
     _cacheDatabase = RedisConnectionHelper.RedisConnection.GetDatabase();
 }
 public RedisCacheService()
 {
     _connection = ConnectionMultiplexer.Connect(AppSetting.RedisConnectionString);
     _cache      = _connection.GetDatabase(3);
     _instance   = "nc";
 }
        private async Task ShowSigninCard(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            //StateClient stateClient = new StateClient(new MicrosoftAppCredentials("xxxxxxxxxxx-4d43-4131-be5b-xxxxxxxxxxxx", "jkmbt39>:xxxxxxxxxxxx!~"));
            ////BotData userData = stateClient.BotState.GetUserData(context.Activity.ChannelId, context.Activity.From.Id);
            //BotData userData = stateClient.BotState.GetUserData("Azure", turnContext.Activity.From.Id);
            //string accesstoken = userData.GetProperty<string>("AccessToken");

            string botClientUserId   = turnContext.Activity.From.Id;
            string botConversationId = turnContext.Activity.Conversation.Id;
            string botchannelID      = turnContext.Activity.ChannelId;
            //var loginUrl = "http://localhost:3978/index.html?userid={botClientUserId}&conversationid={botConversationId}";
            //var loginUrl = "https://localhost:44327?userid={" + botClientUserId+"}&conversationid={"+botConversationId+"}";

            // string loginUrl = "http://localhost:29190/home/Index?botId={" + botClientUserId + "}&conversationid={" + botConversationId + "}";
            // string loginUrl = "http://localhost:29190/Home/Index?botId=" + botClientUserId + "&conversationid=" + botConversationId + "";
            string loginUrl = _iconfiguration["RedirectURL"] + "?botId=" + botClientUserId + "&conversationid=" + botConversationId + "&request_Type=artMainLogin";



            var attachments = new List <Attachment>();
            var reply       = MessageFactory.Attachment(attachments);
            var signinCard  = new SigninCard
            {
                Text    = "Please Sign In",
                Buttons = new List <CardAction> {
                    new CardAction(ActionTypes.Signin, "Sign-in", value: loginUrl)
                },
            };

            reply.Attachments.Add(signinCard.ToAttachment());

            //List<CacheUser> users;
            //if (!_cache.TryGetValue("users", out users))
            //{
            //    users = new List<CacheUser>();
            //}
            //if (!users.Any(u => u.BotClientUserId == botClientUserId && u.BotConversationId == botConversationId))
            //{
            //    users.Add(new CacheUser(botClientUserId, botConversationId, turnContext, cancellationToken));
            //    _cache.Set("users", users, new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromDays(7)));
            //}
            await turnContext.SendActivityAsync(reply, cancellationToken);

            //string cacheConnectionString = "HexaChatBotRedis.redis.cache.windows.net:6380,password=gItUtui8ogouVxo48BUEozsSnMg4JeHkgg2RX7TmPH8=,ssl=True,abortConnect=False";
            string cacheConnectionString = _iconfiguration["RedisCacheConnection"];

            try
            {
                ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(cacheConnectionString);

                StackExchange.Redis.IDatabase db = connection.GetDatabase();

                SessionModel SessionModel = new SessionModel();
                SessionModel.DisplayName    = "";
                SessionModel.EmailId        = "";
                SessionModel.SessionKey     = botClientUserId;
                SessionModel.ConversationID = botConversationId;
                SessionModel.IsSkipIntro    = false;

                db.StringSet(botClientUserId, JsonConvert.SerializeObject(SessionModel));
                db.StringSet(botClientUserId + "artEnroll", JsonConvert.SerializeObject(SessionModel));

                //var userStateAccessors = UserState.CreateProperty<UserProfile>(nameof(SessionModel));
                //var userProfile = await userStateAccessors.GetAsync(turnContext, () => new SessionModel());
                //if (string.IsNullOrEmpty(userProfile.DisplayName))
                //{

                //    //// Set the name to what the user provided.
                //    //userProfile.Name = turnContext.Activity.Text?.Trim();
                //    //userProfile.botID = turnContext.Activity.From.Id;
                //    //// Acknowledge that we got their name.
                //    //await turnContext.SendActivityAsync($"Thanks {userProfile.Name}. To see conversation data, type anything.");
                //}
            }
            catch (Exception ex)
            {
            }

            var sessionModelsAccessors = UserState.CreateProperty <SessionModel>(nameof(SessionModel));
            var sessionModels          = await sessionModelsAccessors.GetAsync(turnContext, () => new SessionModel());

            if (string.IsNullOrWhiteSpace(sessionModels.DisplayName))
            {
                sessionModels.Password       = "";
                sessionModels.DisplayName    = "";
                sessionModels.EmailId        = "";
                sessionModels.SessionKey     = botClientUserId;
                sessionModels.ConversationID = botConversationId;
                sessionModels.IsSkipIntro    = false;
            }
            UserLoginDetectService userLoginDetect = new UserLoginDetectService(cancellationToken, _cache, turnContext, cacheConnectionString, UserState);
        }
 public RedisCacheService(RedisCacheOptions options, int database = 0)
 {
     _connection = ConnectionMultiplexer.Connect(options.Configuration);
     _database   = _connection.GetDatabase(database);
     _instance   = options.InstanceName;
 }
 public HomeController(ILogger <HomeController> logger, StackExchange.Redis.IDatabase database)
 {
     _logger   = logger;
     _database = database;
 }
Exemple #18
0
 private void SaveToDatabase(StackExchange.Redis.IDatabase database, string id, string value)
 {
     database.StringSet(id, value);
 }
Exemple #19
0
 public Redis()
 {
     this.client   = ConnectionMultiplexer.Connect("localhost,allowAdmin=true");
     this.db       = client.GetDatabase();
     this.m_random = new Random(DateTime.Now.Millisecond);
 }
 public RedisQueue(string name, StackExchange.Redis.IDatabase database) : base(name, database)
 {
 }
Exemple #21
0
 public RedisHashset(string name, StackExchange.Redis.IDatabase database) : base(name, database)
 {
     _syncRoot = new object();
 }
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            Logger.LogInformation("Running dialog with Message Activity.");

            // Run the Dialog with the new message Activity.
            //await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken);

            var val      = turnContext.Activity.Value;
            var activity = turnContext.Activity;

            if (val != null)
            {
                if (val.ToString().Contains("Employeeid"))
                {
                    activity.Text       = "ART Enrollment";
                    activity.TextFormat = "message";
                }
            }
            //var activity = turnContext.Activity;

            IMessageActivity reply = null;

            if (activity.Attachments != null && activity.Attachments.Any())
            {
                // We know the user is sending an attachment as there is at least one item
                // in the Attachments list.
                reply = HandleIncomingAttachment(activity);
            }
            else
            {
                await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken);

                // Send at attachment to the user.
                //reply = await HandleOutgoingAttachment(turnContext, activity, cancellationToken);
            }


            //await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);

            CacheUser user = GetLogOnUser(turnContext);

            if (user == null)
            {
                //(bool, string, bool) stat = CheckSignin(turnContext.Activity.From.Id);
                //if (!stat.Item1)
                //{
                //    var text = "Please login first";
                //    await turnContext.SendActivityAsync(MessageFactory.Text(text, text), cancellationToken);
                //    await ShowSigninCard(turnContext, cancellationToken);
                //}
                //else
                //{
                //    if (!stat.Item3)
                //    {
                //        string cacheConnectionString = "HexaChatBotRedis.redis.cache.windows.net:6380,password=gItUtui8ogouVxo48BUEozsSnMg4JeHkgg2RX7TmPH8=,ssl=True,abortConnect=False";
                //        ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(cacheConnectionString);

                //        StackExchange.Redis.IDatabase db = connection.GetDatabase();

                //        SessionModel SessionModel = new SessionModel();
                //        SessionModel.IsSkipIntro = true;

                //        db.StringSet("RamukDB", JsonConvert.SerializeObject(SessionModel));

                //        var text = $"Hi {stat.Item2}, welcome to use the Bot!";
                //        await turnContext.SendActivityAsync(MessageFactory.Text(text, text), cancellationToken);
                //        IsSkipIntro = true;
                //    }
                //}

                //var userStateAccessors = UserState.CreateProperty<UserProfile>(nameof(UserProfile));
                //var userProfile = await userStateAccessors.GetAsync(turnContext, () => new UserProfile());
                //if (string.IsNullOrEmpty(userProfile.Name))
                //{
                //    // Set the name to what the user provided.
                //    userProfile.Name = turnContext.Activity.Text?.Trim();
                //    userProfile.botID = turnContext.Activity.From.Id;
                //    // Acknowledge that we got their name.
                //    await turnContext.SendActivityAsync($"Thanks {userProfile.Name}. To see conversation data, type anything.");
                //}

                //var sessionModelsAccessors = UserState.CreateProperty<SessionModel>(nameof(SessionModel));
                //var sessionModels = await sessionModelsAccessors.GetAsync(turnContext, () => new SessionModel());
                //sessionModels.Password = "******";
                //sessionModels.DisplayName = "1234567";
                //sessionModels.EmailId = "*****@*****.**";
                //sessionModels.SessionKey = turnContext.Activity.From.Id.ToString();

                string botClientUserId   = turnContext.Activity.From.Id;
                string botConversationId = turnContext.Activity.Conversation.Id;
                string botchannelID      = turnContext.Activity.ChannelId;

                string cacheConnectionString = _iconfiguration["RedisCacheConnection"];

                try
                {
                    ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(cacheConnectionString);

                    StackExchange.Redis.IDatabase db = connection.GetDatabase();

                    SessionModel SessionModel = new SessionModel();
                    SessionModel.DisplayName               = "";
                    SessionModel.EmailId                   = "";
                    SessionModel.SessionKey                = botClientUserId;
                    SessionModel.ConversationID            = botConversationId;
                    SessionModel.IsSkipIntro               = false;
                    SessionModel.UserLoginDetectServiceChk = 0;

                    db.StringSet(botClientUserId, JsonConvert.SerializeObject(SessionModel));
                    db.StringSet(botClientUserId + "artEnroll", JsonConvert.SerializeObject(SessionModel));

                    var sessionModelsAccessors = UserState.CreateProperty <SessionModel>(nameof(SessionModel));
                    var sessionModels          = await sessionModelsAccessors.GetAsync(turnContext, () => new SessionModel());

                    if (string.IsNullOrWhiteSpace(sessionModels.DisplayName) && sessionModels.UserLoginDetectServiceChk == 0)
                    {
                        sessionModels.Password       = "";
                        sessionModels.DisplayName    = "";
                        sessionModels.EmailId        = "";
                        sessionModels.SessionKey     = botClientUserId;
                        sessionModels.ConversationID = botConversationId;
                        sessionModels.IsSkipIntro    = false;
                        UserLoginDetectService userLoginDetect = new UserLoginDetectService(cancellationToken, _cache, turnContext, cacheConnectionString, UserState);
                    }
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                var text = $"Hi {user.UserName}, welcome to use the Bot!";
                await turnContext.SendActivityAsync(MessageFactory.Text(text, text), cancellationToken);
            }
        }