/// <summary>
        /// The connection method to Storage4 (modal).
        /// Called from an event handler lstFriends_MouseDoubleClick.
        /// </summary>
        /// <param name="context">The context of the interaction with the database.</param>
        /// <param name="userId">User ID.</param>
        /// <param name="services">Services class object to check - whether our services work.</param>
        /// <param name="logging">Logging class object to create the log.</param>
        /// <param name="friend">User friend.</param>
        /// <param name="lstFriends">ListBox control where your friends list will be added.</param>
        /// <param name="frm">Instance a modal window.</param>
        public void ConnectToServer4(Storage4Context context, int userId, Services services, Logging logging, Friend friend, System.Windows.Controls.ListBox lstFriends, InfoWindow frm)
        {
            RedisOrSQLStorage4(context, userId, services, logging, frm);

            var queryFriendsStorage = context.Friends.Where(x => x.User_Id == userId);
            var friends = queryFriendsStorage.ToList();
            foreach (var f in friends)
            {
                if (f.Friend_Id < 100000)
                {
                    using (var storage1Context = new Storage1Context())
                    {
                        frm.FriendsParam = friend.FindFriendsStorage1(storage1Context, f, frm);
                    }
                }
                else if (f.Friend_Id > 100000 && f.Friend_Id < 200000)
                {
                    using (var storage2Context = new Storage2Context())
                    {
                        frm.FriendsParam = friend.FindFriendsStorage2(storage2Context, f, frm);
                    }
                }
                else if (f.Friend_Id > 200000 && f.Friend_Id < 300000)
                {
                    using (var storage3Context = new Storage3Context())
                    {
                        frm.FriendsParam = friend.FindFriendsStorage3(storage3Context, f, frm);
                    }
                }
                else if (f.Friend_Id > 300000 && f.Friend_Id < 400000)
                {
                    frm.FriendsParam = friend.FindFriendsStorage4(context, f, frm);
                }
                else if (f.Friend_Id > 400000 && f.Friend_Id < 500000)
                {
                    using (var storage5Context = new Storage5Context())
                    {
                        frm.FriendsParam = friend.FindFriendsStorage5(storage5Context, f, frm);
                    }
                }
            }
        }
        /// <summary>
        /// Check Method cached user in Redis or not (modal).
        /// If the user is not cached in Redis then its cache.
        /// Called from the method ConnectToServer (modal).
        /// </summary>
        /// <param name="context">The context of the interaction with the database.</param>
        /// <param name="userId">User ID.</param>
        /// <param name="services">Services class object to check - whether our services work.</param>
        /// <param name="logging">Logging class object to create the log.</param>
        /// <param name="frm">Instance a modal window.</param>
        private static void RedisOrSQLStorage5(Storage5Context context, int userId, Services services, Logging logging, InfoWindow frm)
        {
            IDatabase db = null;
            if (services.RedisIsStarted)
            {
                using (var redisClient = ConnectionMultiplexer.Connect("localhost"))
                {
                    db = redisClient.GetDatabase();
                    string value = db.StringGet($"user:{userId}");

                    if (string.IsNullOrEmpty(value))
                    {
                        var queryUserStorage = context.User.Where(x => x.Id == userId);
                        GetDataFromSQL(queryUserStorage, db, true, logging, frm);
                    }
                    else
                    {
                        GetDataFromRedis(value, frm);
                    }
                }
            }
            else
            {
                var queryUserStorage = context.User.Where(x => x.Id == userId);
                GetDataFromSQL(queryUserStorage, db, false, logging, frm);
            }
        }
        /// <summary>
        /// The connection method to Storage5.
        /// Called from an event handler btnConnected_Click.
        /// </summary>
        /// <param name="context">The context of the interaction with the database.</param>
        /// <param name="userId">User ID.</param>
        /// <param name="listOfFriends">User's friends list.</param>
        /// <param name="services">Services class object to check - whether our services work.</param>
        /// <param name="logging">Logging class object to create the log.</param>
        /// <param name="friend">User friend.</param>
        /// <param name="view">View class object to display the changes.</param>
        /// <param name="textboxs">An array of text fields to fill.</param>
        /// <param name="lstFriends">ListBox control where your friends list will be added.</param>
        public void ConnectToServer5(Storage5Context context, int userId, List<int> listOfFriends, Services services, Logging logging, Friend friend, View.View view, System.Windows.Controls.TextBox[] textboxs, System.Windows.Controls.ListBox lstFriends)
        {
            RedisOrSQLStorage5(context, userId, services, logging, view, textboxs);

            var queryFriendsStorage = context.Friends.Where(x => x.User_Id == userId);
            var friends = queryFriendsStorage.ToList();
            foreach (var f in friends)
            {
                if (f.Friend_Id < 100000)
                {
                    using (var storage1Context = new Storage1Context())
                    {
                        lstFriends.Items.Add(friend.FindFriendsStorage1(storage1Context, f, listOfFriends));
                    }
                }
                else if (f.Friend_Id > 100000 && f.Friend_Id < 200000)
                {
                    using (var storage2Context = new Storage2Context())
                    {
                        lstFriends.Items.Add(friend.FindFriendsStorage2(storage2Context, f, listOfFriends));
                    }
                }
                else if (f.Friend_Id > 200000 && f.Friend_Id < 300000)
                {
                    using (var storage3Context = new Storage3Context())
                    {
                        lstFriends.Items.Add(friend.FindFriendsStorage3(storage3Context, f, listOfFriends));
                    }
                }
                else if (f.Friend_Id > 300000 && f.Friend_Id < 400000)
                {
                    using (var storage4Context = new Storage4Context())
                    {
                        lstFriends.Items.Add(friend.FindFriendsStorage4(storage4Context, f, listOfFriends));
                    }
                }
                else if (f.Friend_Id > 400000 && f.Friend_Id < 500000)
                {
                    lstFriends.Items.Add(friend.FindFriendsStorage5(context, f, listOfFriends));
                }
            }
        }
        /// <summary>
        /// Check Method cached user in Redis or not.
        /// If the user is not cached in Redis then its cache.
        /// Called from the method ConnectToServer.
        /// </summary>
        /// <param name="context">The context of the interaction with the database.</param>
        /// <param name="userId">User ID.</param>
        /// <param name="services">Services class object to check - whether our services work.</param>
        /// <param name="logging">Logging class object to create the log.</param>
        /// <param name="view">View class object to display the changes.</param>
        /// <param name="textboxs">An array of text fields to fill.</param>
        private static void RedisOrSQLStorage1(Storage1Context context, int userId, Services services, Logging logging, View.View view, System.Windows.Controls.TextBox[] textboxs)
        {
            IDatabase db = null;
            // If Redis is enabled.
            if (services.RedisIsStarted)
            {
                using (var redisClient = ConnectionMultiplexer.Connect("localhost"))
                {
                    db = redisClient.GetDatabase();
                    string value = db.StringGet($"user:{userId}");

                    // If Redis is on and there is no required us to record.
                    if (string.IsNullOrEmpty(value))
                    {
                        // Sample.
                        var queryUserStorage = context.User.Where(x => x.Id == userId);
                        // Take data from SQL.
                        GetDataFromSQL(queryUserStorage, db, true, logging, view, textboxs);
                    }
                    // If Redis is turned on and the correct recording us there.
                    else
                    {
                        // Take the data from the Redis.
                        GetDataFromRedis(value, view, textboxs);
                    }
                }
            }
            // If Redis is not enabled then take out the data from SQL.
            else
            {
                // Sample.
                var queryUserStorage = context.User.Where(x => x.Id == userId);
                // Take data from SQL.
                GetDataFromSQL(queryUserStorage, db, false, logging, view, textboxs);
            }
        }