Пример #1
0
        public void TestTimingSM()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            var sb = new StringManipulator();

            for (int x = 0; x < 1000; x++)
            {
                sb.Append("Hello ");
            }

            for (int x = 0; x < 1000; x++)
            {
                sb.Insert("World", 50);
            }

            for (int x = 0; x < 1000; x++)
            {
                sb.Replace("Hello ", "Hey ");
            }
            sw.Stop();

            Assert.IsFalse(true, $"{sw.ElapsedMilliseconds}");
        }
        public ActionResult GenerateInvite(string email)
        {
            // Only allow admins to submit a new code
            if (MembershipAuth.IsAdmin(HttpContext.Request))
            {
                // Generate the invite code
                Random rand = new Random();
                string code = StringManipulator.CreateInviteCode(rand.Next(58, 65));

                // Get information from database to populate the invite
                string userName  = MembershipAuth.GetCurrentUser(HttpContext.Request);
                int    orgID     = db.Users.SingleOrDefault(u => u.Email == userName).OrganizationID;
                int    createdBy = db.Users.SingleOrDefault(u => u.Email == userName).Id;

                // Create new invite code
                InviteCode invite = new InviteCode
                {
                    Code           = code,
                    DateCreated    = DateTime.Now,
                    OrganizationID = orgID,
                    IsExpired      = false,
                    CreatedBy      = createdBy,
                    SentTo         = email
                };

                // Add and commit to database
                db.InviteCodes.Add(invite);
                db.SaveChanges();
            }

            // Return error screen
            return(RedirectToAction("Error", "Error", new { error = 3 }));
        }
Пример #3
0
        private static void TestStringManipulator()
        {
            Console.Write("String Manipulator: ");
            Stopwatch sw = new Stopwatch();

            sw.Start();

            var sb = new StringManipulator();

            for (int x = 0; x < 1000; x++)
            {
                sb.Append("Hello ");
            }

            for (int x = 0; x < 1000; x++)
            {
                sb.Insert("World", 50);
            }

            for (int x = 0; x < 1000; x++)
            {
                sb.Replace("Hello ", "Hey ");
            }
            sw.Stop();

            Console.WriteLine(sw.ElapsedMilliseconds);
        }
Пример #4
0
        public ActionResult Login(User user, string ReturnUrl)
        {
            // Check that credentials were entered
            if (user != null || !string.IsNullOrEmpty(user.Email))
            {
                // Find the user with the appropriate username, and check hashed password
                User   login = db.Users.FirstOrDefault(a => a.Email.Equals(user.Email));
                string pass  = StringManipulator.GenerateHashedPassword(login.Salt, user.Password);

                // If a user was found, log them in
                if (login != null && login.Password == pass)
                {
                    FormsAuthentication.SetAuthCookie(login.Email.Trim(), false);

                    // If user was previouly logged in, redirect them to their previous page.
                    // Otherwise send them to the default page.
                    if (this.Url.IsLocalUrl(ReturnUrl))
                    {
                        EventLogger.LogNewEvent(login.Id, login.OrganizationID, LoggingEventType.UserLogin, "");
                        return(Redirect(ReturnUrl));
                    }
                    else
                    {
                        EventLogger.LogNewEvent(login.Id, login.OrganizationID, LoggingEventType.UserLogin, "");
                        return(RedirectToAction("Time", "TimeCard"));
                    }
                }
            }

            // A user wasn't found, try again
            ViewBag.Error = true;

            return(View());
        }
Пример #5
0
        public void Test_StringManipulator_SubstringSingleSection()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cruel world");

            Assert.AreEqual("cruel", m.Substring(6, 5));
        }
Пример #6
0
        public void Test_StringManipulator_AddString()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello");

            Assert.AreEqual("hello", m.ToString());
        }
Пример #7
0
        public void SortStringsViaLamda()
        {
            var masResult = StringManipulator.SortStrings(new StringManipulator.SortSchema((x, y) => string.CompareOrdinal(x, y)), _masUnsorted);

            var masExpected = _masUnsorted.OrderBy(x => x);

            Assert.IsTrue(masExpected.SequenceEqual(masResult), "Строки отсиротированы не корректно");
        }
Пример #8
0
        public void SortStringsViaInterface()
        {
            var masResult = StringManipulator.SortStrings(new StringAscendingComparer(), _masUnsorted);

            var masExpected = _masUnsorted.OrderBy(x => x);

            Assert.IsTrue(masExpected.SequenceEqual(masResult), "Строки отсиротированы не корректно");
        }
Пример #9
0
        public void Init()
        {
            var _stringManipulator = new StringManipulator();

            stringManipulator = _stringManipulator;
            validData         = "Hello out there.";
            inValidData       = "";
        }
Пример #10
0
        public void Test_StringManipulator_IndexOfStringInSecondSections()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cru");
            m.Append("el world");

            Assert.AreEqual("hello cruel world".IndexOf("rld"), m.IndexOf("rld"));
        }
Пример #11
0
        public void Test_StringManipulator_InsertString()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello");
            m.Append("  world");
            m.Insert("cruel", 6);
            Assert.AreEqual("hello cruel world", m.ToString());
        }
Пример #12
0
        public void Test_StringManipulator_RemoveTwoStringsInsideSection()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cruel world");
            m.Remove("l");

            Assert.AreEqual("heo crue word", m.ToString());
        }
Пример #13
0
        public void Test_StringManipulator_ReplaceMany()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cruel world");
            m.Replace("l", "L");

            Assert.AreEqual("heLLo crueL worLd", m.ToString());
        }
Пример #14
0
        public void Test_StringManipulator_ReplaceSingle()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cruel world");
            m.Replace("cruel", "big");

            Assert.AreEqual("hello big world", m.ToString());
        }
Пример #15
0
        public void Test_StringManipulator_IndexOfSingleLetter()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cru");
            m.Append("el world");

            Assert.AreEqual("hello".IndexOf('l'), m.IndexOf("l"));
        }
Пример #16
0
        public void Test_StringManipulator_IndexOfStringStartIndexInLaterSectionNotFound()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cru");
            m.Append("el world");

            Assert.AreEqual("hello cruel world".IndexOf("k", 7), m.IndexOf("k", 7));
        }
Пример #17
0
        public void Test_StringManipulator_IndexOfStringStartIndex()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cru");
            m.Append("el world");

            Assert.AreEqual("hello cruel world".IndexOf("l", 3), m.IndexOf("l", 3));
        }
Пример #18
0
    public static void Main()
    {
        new StringFormatterTests();

        var StringManipulator = new StringManipulator(new StringFormatter());

        Console.WriteLine(StringManipulator.DisplayWordsOnNewLineAndPadWithAstericks("Blue"));
        Console.ReadLine();
    }
Пример #19
0
        public string parse(string val)
        {
            NumberOfNibble = Int32.Parse(StringManipulator.getByte(val, 1));
            TON_NPI        = StringManipulator.getByte(val, 2);
            int temp = (NumberOfNibble + 1) / 2;

            Address = StringManipulator.getBytes(val, 3, temp).ToUpper();
            return(val.Substring((temp + 2) * 2));
        }
Пример #20
0
        public void Test_StringManipulator_RemoveWholeFirstSection()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello ");
            m.Append("world");
            m.Remove("hello ");

            Assert.AreEqual("world", m.ToString());
        }
Пример #21
0
        public void Test_StringManipulator_RemoveSingleStringAcrossTwoSections()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cr");
            m.Append("uel world");
            m.Remove("cruel");

            Assert.AreEqual("hello  world", m.ToString());
        }
Пример #22
0
        public void SortStringsViaFunc()
        {
            var comparer = new Func <string, string, int>((x, y) => string.CompareOrdinal(x, y));

            var masResult = StringManipulator.SortStrings(comparer, _masUnsorted);

            var masExpected = _masUnsorted.OrderBy(x => x);

            Assert.IsTrue(masExpected.SequenceEqual(masResult), "Строки отсиротированы не корректно");
        }
Пример #23
0
        public void Test_StringManipulator_RemoveWholeLastSectionAndReplace()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello ");
            m.Append("cruel ");
            m.Append("world");
            m.Replace("world", "suzy");

            Assert.AreEqual("hello cruel suzy", m.ToString());
        }
Пример #24
0
        public void ShouldReplace()
        {
            string inStr     = "PARM1=${PARM1}, PARM2=${PARM2}, PARM3=${PARM3}";
            string expected1 = "PARM1=PARM1, PARM2=${PARM2}, PARM3=${PARM3}";
            string expected2 = "PARM1=PARM1, PARM2=PARM2, PARM3=${PARM3}";
            string expected3 = "PARM1=PARM1, PARM2=PARM2, PARM3=PARM3";

            Assert.True(StringManipulator.Replace(inStr, "PARM1", "PARM1") == expected1);
            Assert.True(StringManipulator.Replace(expected1, "PARM2", "PARM2") == expected2);
            Assert.True(StringManipulator.Replace(expected2, "PARM3", "PARM3") == expected3);
        }
Пример #25
0
        public void Test_StringManipulator_RemoveSingleStringAcrossThreeSections()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cr");
            m.Append("u");
            m.Append("el world");
            m.Remove("cruel");

            Assert.AreEqual("hello  world", m.ToString());
            Assert.AreEqual("hello  world".Length, m.Length, "The Lengths should be the same too");
        }
        public void ReplaceWords_StrDictIsNotNull_ReturnsTrue()
        {
            string testStr  = "This is a test";
            var    testDict = new Dictionary <string, string>()
            {
                { "test", "hest" }
            };
            var sm = new StringManipulator();

            var result = sm.ReplaceWords(testStr, testDict);

            Assert.IsNotNull(result);
        }
Пример #27
0
        public void SortStringsViaDelegate()
        {
            var comparer = new StringManipulator.SortSchema(delegate(string x, string y)
            {
                return(string.CompareOrdinal(x, y));
            });

            var masResult = StringManipulator.SortStrings(comparer, _masUnsorted);

            var masExpected = _masUnsorted.OrderBy(x => x);

            Assert.IsTrue(masExpected.SequenceEqual(masResult), "Строки отсиротированы не корректно");
        }
Пример #28
0
        public static string ConvertToBaseN(ulong Number, int TargetBase, CharAlphabet alphabet = null, int MinDigits = 1, int sign = 0)
        {
            //Exceptions
            if (alphabet.Chars.Count() < TargetBase)
            {
                throw new ArgumentException(LangManager.GetString("exception_alphabet_too_short", CurrentCulture));
            }

            if (Number < 0)
            {
                sign = -1;
            }

            //Defaults
            if (alphabet == null)
            {
                alphabet = Alphabet.Hexadecimal;
            }

            //Init
            string result      = "";
            ulong  placeholder = Number;

            //Conversion
            if (Number == 0)
            {
                sign   = 0;
                result = result.Insert(0, alphabet.Chars[0].ToString());
            }
            else
            {
                while (placeholder != 0)
                {
                    result      += alphabet.Chars[(int)placeholder % TargetBase];
                    placeholder -= placeholder % (ulong)TargetBase;
                    placeholder /= (ulong)TargetBase;
                }
            }

            //Add mindigits
            if (result.Length < MinDigits)
            {
                for (int x = result.Length; x < MinDigits; x++)
                {
                    result = result.Insert(0, alphabet.Chars[0].ToString());
                }
            }

            return(StringManipulator.Reverse(result));
        }
Пример #29
0
        public void ShouldReplaceDictionary()
        {
            Dictionary <string, string> data = new Dictionary <string, string>()
            {
                { "PARM1", "PARM1" },
                { "PARM2", "PARM2" },
                { "PARM3", "PARM3" }
            };
            string inStr    = "PARM1=${PARM1}, PARM2=${PARM2}, PARM3=${PARM3}";
            string expected = "PARM1=PARM1, PARM2=PARM2, PARM3=PARM3";
            string result   = StringManipulator.Replace(inStr, data);

            Assert.True(result == expected);
        }
Пример #30
0
        public static string GetReplied(ITweetable tweet)
        {
            string textReplied = "";

            textReplied = "@" + tweet.Author.ScreenName + " ";
            foreach (string user in StringManipulator.GetUserNames(tweet.Text))
            {
                if (DataTransfer.CurrentAccount != null && user != "@" + DataTransfer.CurrentAccount.ScreenName)
                {
                    textReplied += user + " ";
                }
            }

            return(textReplied);
        }