public string ProcessRequest(Dictionary<string, string> parameters, JsonData json)
    {

      var uri = parameters.Find("SCRIPT_NAME") + parameters.Find("PATH_INFO");
      var queryString = parameters.Find("QUERY_STRING");

      Console.WriteLine("{0} {1}, {2}", uri, queryString, Handlers.Select(pair => pair.Key).FirstOrDefault());

      var handlerPair = Handlers.FirstOrDefault(pair => uri?.StartsWith(pair.Key) ?? false);
      if (handlerPair.Value == null)
      {

        return "<html><body>invalid page</body></html>";
      }
      var handler = handlerPair.Value;
      var pageName = handlerPair.Key;

      if (uri.EndsWith(".js"))
      {
        var query = queryString.OrEmpty().Split('&').Select(pair => pair.Split('='))
          .ToDictionary(ss => ss.FirstOrDefault(), ss => ss.ElementAtOrDefault(1));
        var prevCycle = int.Parse(query.Find("cycle"));
        var prevUpdate = Updates.FirstOrDefault(_update => _update.Cycle == prevCycle);
        var prevPage = prevUpdate != null ? prevUpdate.Page : null;

        var update = PushUpdate(null);

        var result = handler(pageName, update.Cycle, json);
        //lock (locker)
        //{
        //  update.Page = result.Html;

        //}
        var page = result.Html;


        var commands = HtmlJavaScriptDiffer.JsSync(new HElementProvider(), prevPage == null ? null : prevPage.Element("body"), page.Element("body")).ToArray();
        var jupdate = new Dictionary<string, object>() { { "cycle", update.Cycle }, { "prev_cycle", prevCycle }, { "commands", commands } };

        var jsSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        return jsSerializer.Serialize(jupdate);
      }
      else
      {
        var update = PushUpdate(null);

        var result = handler(pageName, update.Cycle, json);
        var page = result.Html;
        if (!uri.EndsWith(".raw.html"))
          page = h.Html(new HRaw(page.Element("head")?.ToString()), h.Body());

        //lock (locker)
        //{
        //  update.Page = page;
        //}
        return page.ToString();
      }
    }
Example #2
0
		public void WhenDictionaryContainsEntry_ThenReturnsValue()
		{
			var dictionary = new Dictionary<string, int>();
			dictionary.Add("foo", 25);

			var value = dictionary.Find("foo");

			Assert.Equal(25, value);
		}
Example #3
0
		public void WhenDictionaryDoesNotContainEntry_ThenReturnsNull()
		{
			var dictionary = new Dictionary<string, int>();
			dictionary.Add("foo", 25);

			var value = dictionary.Find("bar");

			Assert.Equal(default(int), value);
		}
Example #4
0
        //
        //  см. также Global.Application_AuthenticateRequest
        //
        public static NitroBolt.Wui.HtmlResult<HElement> HView(object _state, JsonData[] jsons, HttpRequestMessage request)
        {
            Action<HttpResponseMessage> cookieSetter = null;
            var logins = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) { { "Demo", "demodemo" }, { "Test", "test" } };

            foreach (var json in jsons.OrEmpty())
            {

                switch (json.JPath("data", "command")?.ToString())
                {
                    case "login":
                        {
                            var login = json.JPath("data", "login")?.ToString();
                            var password = json.JPath("data", "password")?.ToString();
                            if (logins.Find(login) == password)
                                cookieSetter = request.SetUserAndGetCookieSetter(login);
                            else
                            {
                                //display error
                            }
                        }
                        break;
                    case "logout":
                        cookieSetter = request.SetUserAndGetCookieSetter(null);
                        break;
                    default:
                        break;
                }

                if (request.UserName() != null)
                {
                    switch (json.JPath("data", "command")?.ToString())
                    {
                        default:
                            break;
                    }

                }
            }
            var account = request.UserName();


            var page = Page(logins, account, request);
            return new HtmlResult
            {
                Html = page,
                State = null,
                ResponseProcessor = cookieSetter,
            };
        }
Example #5
0
        static void AutoSpells(EventArgs args)
        {
            if (Player.IsDead || Player.recalling())
            {
                return;
            }
            if (SpellSlot.E.IsReady() && CassioUtils.Active("Combo.UseE") && (CassiopeiaMenu.Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.Combo || CassioUtils.Active("Misc.autoe")))
            {
                Obj_AI_Hero etarg;
                etarg = target;
                if (etarg == null)
                {
                    etarg = HeroManager.Enemies.FirstOrDefault(h => h.IsValidTarget(Spells[SpellSlot.E].Range) && h.isPoisoned() && !h.IsInvulnerable && !h.IsZombie);
                }
                if (etarg != null && CassioUtils.Active("Combo.useepoison") && etarg.isPoisoned())
                {
                    if ((Utils.GameTimeTickCount - laste) > edelay)
                    {
                        Spells[SpellSlot.E].Cast(etarg);
                        laste = Utils.GameTimeTickCount;
                    }
                }
                else if (!CassioUtils.Active("Combo.useepoison"))
                {
                    if ((Utils.GameTimeTickCount - laste) > edelay)
                    {
                        Spells[SpellSlot.E].Cast(target);
                        laste = Utils.GameTimeTickCount;
                    }
                }
            }

            /*

            if (SpellSlot.R.IsReady() && CassioUtils.Active("Combo.UseR") &&
                CassiopeiaMenu.Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.Combo)
            {
                var targets = HeroManager.Enemies.Where(x => x.IsValidTarget(Spells[SpellSlot.R].Range) && !x.IsZombie).OrderBy(x => x.Health);
                foreach (var targ in targets)
                {
                    var pred = Spells[SpellSlot.R].GetPrediction(targ);
                    if (pred.Hitchance >= CassioUtils.GetHitChance("Hitchance.R"))
                    {
                        int enemhitpred = 0;
                        int enemfacingpred = 0;
                        foreach (var hero in targets)
                        {
                            if (Spells[SpellSlot.R].WillHit(hero, pred.CastPosition, 0, CassioUtils.GetHitChance("Hitchance.R")))
                            {
                                enemhitpred++;
                                if (hero.IsFacing(Player))
                                {
                                    enemfacingpred++;
                                }
                            }
                        }

                        if (enemfacingpred >= CassioUtils.GetSlider("Combo.Rcount"))
                        {
                            Spells[SpellSlot.R].Cast(pred.CastPosition);
                            return;
                        }
                        if (enemhitpred >= CassioUtils.GetSlider("Combo.Rcountnf") && CassioUtils.Active("Combo.UseRNF"))
                        {
                            Spells[SpellSlot.R].Cast(pred.CastPosition);
                            return;
                        }
                    }
                }

                var easycheck = HeroManager.Enemies.FirstOrDefault(x =>
                     !x.IsInvulnerable && !x.IsZombie && x.IsValidTarget(Spells[SpellSlot.R].Range) &&
                     x.IsFacing(Player) && x.isImmobile());

                if (easycheck != null)
                {
                    Spells[SpellSlot.R].Cast(easycheck.ServerPosition);
                    return;
                }
            }
            */

            /* © ® ™ Work on patented algorithms in the future! XD © ® ™ */
            if (SpellSlot.R.IsReady() && CassioUtils.Active("Combo.UseR") && CassiopeiaMenu.Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.Combo)
            {
                var easycheck =
                    HeroManager.Enemies.FirstOrDefault(
                        x =>
                            !x.IsInvulnerable && !x.IsZombie && x.IsValidTarget(Spells[SpellSlot.R].Range) &&
                            x.IsFacing(Player) && x.isImmobile() && (Player.HealthPercent <= 20 || x.HealthPercent > 30));

                if (easycheck != null)
                {
                    Spells[SpellSlot.R].Cast(easycheck.ServerPosition);
                    DontMove = true;
                    Utility.DelayAction.Add(50, () => DontMove = false);
                    return;
                }
                var targs = HeroManager.Enemies.Where(h => h.IsValidTarget(Spells[SpellSlot.R].Range));
                Dictionary<Vector3, double> Hitatpos = new Dictionary<Vector3, double>();
                Dictionary<Vector3, double> Hitatposfacing = new Dictionary<Vector3, double>();
                foreach (var t in targs)
                {
                    var pred = Spells[SpellSlot.R].GetPrediction(t, false);
                    var enemshit = pred.CastPosition.GetEnemiesInRange(Spells[SpellSlot.R].Width).Where(x=> x.Distance(Player) <= Spells[SpellSlot.R].Range);
                    var counthit = enemshit.Count();
                    var hitfacing = enemshit.Count(x => x.IsFacing(Player) && !x.IsDashing() && !x.IsZombie && !x.IsInvulnerable);
                    var anymovingtome = enemshit.Any(x => x.isMovingToMe() || x.IsFacing(Player));

                    if (pred.Hitchance >= CassioUtils.GetHitChance("Hitchance.R") && anymovingtome)
                    {
                         Hitatposfacing.Add(pred.CastPosition, hitfacing);
                    }
                    if (CassioUtils.Active("Combo.UseRNF") && pred.Hitchance >= CassioUtils.GetHitChance("Hitchance.R"))
                    {
                        Hitatpos.Add(pred.CastPosition, counthit);
                    }
                }
                if (Hitatposfacing.Any())
                {
                    var bestpos = Hitatposfacing.Find(pos => pos.Value.Equals(Hitatposfacing.Values.Max())).Key;
                    if (bestpos.IsValid() && bestpos.CountEnemiesInRange(Spells[SpellSlot.R].Width) >= CassioUtils.GetSlider("Combo.Rcount"))
                    {
                        Spells[SpellSlot.R].Cast(bestpos);
                        DontMove = true;
                        Utility.DelayAction.Add(50, () => DontMove = false);
                    }
                }
                else if (Hitatpos.Any() && CassioUtils.Active("Combo.UseRNF") &&
                         CassioUtils.GetSlider("Combo.Rcountnf") >= Hitatpos.Values.Max())
                {
                    var bestposnf = Hitatpos.Find(pos => pos.Value.Equals(Hitatpos.Values.Max())).Key;
                    if (bestposnf.IsValid() && bestposnf.CountEnemiesInRange(Spells[SpellSlot.R].Width) >= CassioUtils.GetSlider("Combo.Rcountnf"))
                    {
                        Spells[SpellSlot.R].Cast(bestposnf);
                        DontMove = true;
                        Utility.DelayAction.Add(50, () => DontMove = false);
                    }
                }
            
            }   
             

        }
Example #6
0
        /// <summary>
        /// Testowanie prędkości:
        ///		* Ładowanie słownika
        ///		* Wyszukiwanie istnienia słów:
        ///			- ęą
        ///			- żyznościach
        ///			- żywotopisarstwa
        ///			- dwuwiosłowymi
        ///			- żżż
        ///		* Dopasowanie:
        ///			- żyźnicom do m @ 7, cionyźż
        ///			- żyźnicom do m @ 7, cio yźż
        /// </summary>
        /// <param name="D">Implementacja słownika do przetestowania</param>
        public static void Benchmark1(Dictionary D)
        {
            System.Diagnostics.Stopwatch SW = new System.Diagnostics.Stopwatch();

            Console.WriteLine("=== {0} ===", D.GetType().Name);

            ///////////////////////////////////////////////////////////

            SW.Restart();
            D.Reload();
            SW.Stop();

            Console.WriteLine("Load: {0}ms", SW.ElapsedMilliseconds);

            ///////////////////////////////////////////////////////////

            String[] FindWords = new string[] { "ęą", "żyznościach", "żywotopisarstwa", "dwuwiosłowymi", "żżż" };

            foreach(String FindWord in FindWords)
            {
                SW.Restart();
                bool Result = D.Exists(FindWord);
                SW.Stop();
                Console.WriteLine("Exists: '{0}': {1}ms ({2})", FindWord, SW.ElapsedMilliseconds, Result);
            }

            ///////////////////////////////////////////////////////////

            Dictionary.AlreadySetLetters ASL = new Dictionary.AlreadySetLetters();
            ASL.Set(7, 'm');

            Dictionary.HeldCharacters HC1 = new Dictionary.HeldCharacters(D.GetDictionaryEncoding());
            HC1.Add("cionyźż");

            Dictionary.HeldCharacters HC2 = new Dictionary.HeldCharacters(D.GetDictionaryEncoding());
            HC2.Add("cio yźż");

            SW.Restart();
            Dictionary.WordsFound WF1 = D.Find(ASL, HC1);
            SW.Stop();

            Console.WriteLine("Find1 (m): {0}ms ({1})", SW.ElapsedMilliseconds, WF1.Count);

            SW.Restart();
            Dictionary.WordsFound WF2 = D.Find(ASL, HC2);
            SW.Stop();

            Console.WriteLine("Find2 (blank): {0}ms ({1})", SW.ElapsedMilliseconds, WF2.Count);

            ///////////////////////////////////////////////////////////

            foreach(Dictionary.WordFound WF in WF1)
                Console.Write(WF.GetWord() + ", ");

            Console.WriteLine();
            Console.WriteLine();

            foreach(Dictionary.WordFound WF in WF2)
                Console.Write(WF.GetWord() + ", ");

            ///////////////////////////////////////////////////////////

            Console.WriteLine();
        }
Example #7
0
    //
    //  см. также Global.Application_AuthenticateRequest
    //
    public static HtmlResult<HElement> HView(object _state, JsonData[] jsons, HContext context)
    {

      var logins = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase){{"Demo", "demodemo"}, {"Test", "test"}};

      foreach (var json in jsons.Else_Empty())
      {

        switch (json.JPath("data", "command").ToString_Fair())
        {
          case "login":
            {
              var login = json.JPath("data", "login").ToString_Fair();
              var password = json.JPath("data", "password").ToString_Fair();
              if (logins.Find(login) == password)
                context.HttpContext.SetUserAndCookie(login);
              else
              {
                //display error
              }
            }
            break;
          case "logout":
            context.HttpContext.SetUserAndCookie(null);
            break;
          default:
            break;
        }

        if (context.HttpContext.UserName() != null)
        {
          switch (json.JPath("data", "command").ToString_Fair())
          {
            case "login":
              {
                var login = json.JPath("data", "login").ToString_Fair();
                var password = json.JPath("data", "password").ToString_Fair();
                if (logins.Find(login) == password)
                  context.HttpContext.SetUserAndCookie(login);
                else
                {
                  //display error
                }
              }
              break;
            case "logout":
              context.HttpContext.SetUserAndCookie(null);
              break;
            default:
              break;
          }

        }
      }
      var account = context.HttpContext.UserName();


      var page = Page(logins, account);
      return new HtmlResult<HElement>
      {
        Html = page,
        State = null,
      };
    }
		public void Find_CollectionEmpty()
		{
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			KeyValuePair<int, int>? foundItem = dictionary.Find(new Predicate<KeyValuePair<int, int>>((kvp) => { return false; }));

			Assert.IsTrue(foundItem.HasValue == false);
		}
		public void Find_PredicateNull()
		{
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			dictionary.Find(null);
		}