Example #1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Generates the key with the temporal and computer specific attributes
        /// </summary>
        protected StringBuilder GenerateKey()
        {
            //-----a----- Start building the encrypted string
            StringBuilder tokenToEncrypt = new StringBuilder();

            tokenToEncrypt.Append(MGLEncryption.GetSalt(1));

            //-----b----- Double check that the anonID cookie has been set and set it again if not... (this should never not have happened as it is called first OnInit in the MGLBasePage)
            SetAnonIDCookie();

            //-----c----- The AnonID is a GUID - always 36 characters
            string tempValue = DefaultAnonID;

            if (Request.Cookies["AnonID"] != null)
            {
                tempValue = Request.Cookies["AnonID"].Value;
            }
            tokenToEncrypt.Append(tempValue);

            //-----d----- Add some padding
            tokenToEncrypt.Append(MGLEncryption.GetSalt(1));

            //-----e----- The date time will be of the form yyyy-mm-dd hh:mm:ss - and will always be dd and mm (not d and m for e.g. 01)
            tokenToEncrypt.Append(DateTimeInformation.FormatDatabaseDate(DateTime.Now, true, true));
            tokenToEncrypt.Append(MGLEncryption.GetSalt(1));

            //-----f----- Do the encryption itself
            StringBuilder authKey = MGLEncryption.Encrypt(tokenToEncrypt);

            //-----g----- And lastly, lets make this key HTML secure ...
            authKey = MGLEncryption.HTMLifyString(authKey);

            return(authKey);
        }
Example #2
0
        //--------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Generates a series of simple integer range searches... useful for more specific testing
        /// </summary>
        public static void TestSorting()
        {
            List <DatabaseIndexInfo> riis = rw.IndexFindAll(new TestObj());

            int      randomVal  = MGLEncryption.GenerateRandomInt(1, 1000000);
            long     randomVal2 = MGLEncryption.GenerateRandomLong(8000000000, 12000000000);
            double   randomVal3 = MGLEncryption.GenerateRandomDouble(0, 1);
            DateTime randomVal4 = MGLEncryption.GenerateRandomDateTime(TestParameters.DateMin, TestParameters.DateMax);

            List <DatabaseSearchPattern> testPatterns = new List <DatabaseSearchPattern>()
            {
                // Bool
                new DatabaseSearchPattern("TestBool", MGLEncryption.GenerateRandomBool()),
                // Score - equivalent (int)
                new DatabaseSearchPattern("TestInt", randomVal),
                // Score - greater than
                new DatabaseSearchPattern("TestInt", randomVal, true),
                // Score - less than
                new DatabaseSearchPattern("TestInt", randomVal, false),
                // Score - between
                new DatabaseSearchPattern("TestInt", randomVal, randomVal + TestParameters.SearchRangeSize),
                // Text - Starts with
                new DatabaseSearchPattern("TestStr", MGLEncryption.GetSalt(RedisWrapper.TextIndexLength).ToString().ToLower()),
                // Score - between (long)
                new DatabaseSearchPattern("TestLong", randomVal2, randomVal2 + (4000000000 * TestParameters.SearchRangeSize / 1000000)),
                // Primary key
                new DatabaseSearchPattern((long)randomVal),
                // Score - between
                new DatabaseSearchPattern("TestDouble", randomVal3, randomVal3 + ((double)TestParameters.SearchRangeSize / 1000000.0)),
                // Date time - betwen
                new DatabaseSearchPattern("TestDT", randomVal4, randomVal4.AddDays(1)),
                // Date time - less than
                new DatabaseSearchPattern("TestDT", randomVal4, false),
                // Date time - greater than
                new DatabaseSearchPattern("TestDT", randomVal4, true),
                // Date time - equivalent
                new DatabaseSearchPattern("TestDT", randomVal4)
            };


            // sort it
            testPatterns.Sort(DatabaseSearchPattern.Sort(riis));

            string isItGucci = "";
        }
Example #3
0
        //--------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Generates a number of randomly generated RedisTestObj objects, with each parameter between a range...
        ///     These are ONLY used for writing, so we can ignore if the readonly flag is enabled
        /// </summary>
        public static void GenerateRandomObjects()
        {
            // These are ONLY used for writing, so we can ignore if the readonly flag is enabled
            if (TestParameters.DoWrite == false)
            {
                Logger.Log("Skipping generating the random objects as the global TestParameter.JustDoRead parameter is set to read only.");
                return;
            }

            RandomObjects = new List <object>();

            // Generate some random data!
            Logger.LogSubHeading("Generating " + NumIterations + " randomly generated TestObj objects...");

            int i = 0;

            for (i = 0; i < NumIterations; i++)
            {
                RandomObjects.Add(
                    // The primary key
                    new TestObj((ulong)i,
                                // A random int
                                MGLEncryption.GenerateRandomInt(1, MaxIntegerInRange),
                                // longs ...
                                MGLEncryption.GenerateRandomLong(TestParameters.MinLongInRange, TestParameters.MaxLongInRange),
                                // doubles ...
                                MGLEncryption.GenerateRandomDouble(TestParameters.MinDoubleInRange, TestParameters.MaxDoubleInRange),
                                // bools ...
                                MGLEncryption.GenerateRandomBool(),
                                // strings ...
                                MGLEncryption.GetSalt(20).ToString(),
                                // DateTime - Standardise the dates to the nearest second so that the MySQL vs Redis comparison is consistent
                                // Otherwise Redis is stored to the nearest MS while MySQL only stores to the nearest second
                                DatabaseSearchPattern.StandardiseDateToStartOfSecond(MGLEncryption.GenerateRandomDateTime(TestParameters.DateMin, TestParameters.DateMax), false)));

                // Log the progress ...
                Logger.Log(i, 1000, NumIterations);
            }
            Logger.Log(i, 1, NumIterations);
            Logger.Log("\n");
        }
Example #4
0
 //--------------------------------------------------------------------------------------------------------------------------------------------------------------
 public static DatabaseSearchPattern GenerateSearchPatternString()
 {
     return(new DatabaseSearchPattern("TestStr", MGLEncryption.GetSalt(RedisWrapper.TextIndexLength).ToString().ToLower()));
 }