Beispiel #1
0
        // PUT api/DropDeck12/5
        public IHttpActionResult PutDropDeck12(int id, DropDeck12 dropdeck12)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dropdeck12.DropDeck12Id)
            {
                return(BadRequest());
            }

            db.Entry(dropdeck12).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DropDeck12Exists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public IHttpActionResult GetDropDeck12(int id)
        {
            DropDeck12 dropdeck12 = db.DropDeck12s.Find(id);

            if (dropdeck12 == null)
            {
                return(NotFound());
            }

            return(Ok(dropdeck12));
        }
Beispiel #3
0
        public IHttpActionResult DeleteDropDeck12(int id)
        {
            DropDeck12 dropdeck12 = db.DropDeck12s.Find(id);

            if (dropdeck12 == null)
            {
                return(NotFound());
            }

            db.DropDeck12s.Remove(dropdeck12);
            db.SaveChanges();

            return(Ok(dropdeck12));
        }
Beispiel #4
0
        public static DropDeck12 GetDropDeck12(bool friendly)
        {
            //todo: init dropdeck chassis in controller
            //      set the order of chassis[1-12]to alphabetical mechname order
            //      add friendlyDropDeck12 and enemyDropDeck12 to MatchDrop
            string        api       = apiUrl + "DropDeck12";
            List <string> dd12mechs = new List <string>();

            if (friendly == true)
            {
                foreach (MatchStat lm in friendlyList)
                {
                    dd12mechs.Add(lm.mech);
                }
            }
            else
            {
                foreach (MatchStat lm in enemyList)
                {
                    dd12mechs.Add(lm.mech);
                }
            }

            string[] ddmechs = new string[12];

            for (int i = 0; i < dd12mechs.Count; i++)
            {
                ddmechs[i] = dd12mechs[i];
            }
            DropDeck12 dd12 = new DropDeck12 {
                MechName1  = dd12mechs[0],
                MechName2  = dd12mechs[1],
                MechName3  = dd12mechs[2],
                MechName4  = dd12mechs[3],
                MechName5  = dd12mechs[4],
                MechName6  = dd12mechs[5],
                MechName7  = dd12mechs[6],
                MechName8  = dd12mechs[7],
                MechName9  = dd12mechs[8],
                MechName10 = dd12mechs[9],
                MechName11 = dd12mechs[10],
                MechName12 = dd12mechs[11]
            };
            DropDeck12 dd;

            dd = (DropDeck12)HttpUtility.MakeRequest(api, dd12, null, null, typeof(DropDeck12));
            return(dd);
        }
Beispiel #5
0
        public void Get()
        {
            MatchLogger.MatchLogger.LoggedMatch lm = new MatchLogger.MatchLogger.LoggedMatch();
            DropDeck12 dde = new DropDeck12();
            DropDeck12 ddf = new DropDeck12();
            // Arrange
            ValuesController controller = new ValuesController();

            // Act
            IEnumerable <string> result = controller.Get();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("value1", result.ElementAt(0));
            Assert.AreEqual("value2", result.ElementAt(1));
        }
Beispiel #6
0
        public static MatchDrop getMatchDrop()
        {
            //TODO: think about what happens when two people are in the same drop drop but log it with different association names
            DropDeck12  friendlyDropDeck12 = GetDropDeck12(true);
            DropDeck12  enemyDropDeck12    = GetDropDeck12(false);
            Association association        = getAssociation();

            MWA.Models.MatchDrop matchDropToPush = new MWA.Models.MatchDrop();
            matchDropToPush.Association        = association;
            matchDropToPush.AssociationId      = association.AssociationId;
            matchDropToPush.AssociationName    = association.AssociationName;
            matchDropToPush.FriendlyDropDeck12 = friendlyDropDeck12;
            matchDropToPush.EnemyDropDeck12    = enemyDropDeck12;
            matchDropToPush.MatchHash          = GetMatchHash();
            string    api = GetApiUrl("MatchDrop");
            MatchDrop md;

            matchDrop = (MatchDrop)HttpUtility.MakeRequest(api, matchDropToPush, null, null, typeof(MatchDrop));
            return(matchDrop);
        }
Beispiel #7
0
        public void PostLoggedMatchLogicTest()
        {
            #region Create LoggedMatch
            MatchLogger.MatchLogger.LoggedMatch lm = new MatchLogger.MatchLogger.LoggedMatch();
            lm.AssociationName = "TEST";

            // DropDeck12 fdd = new DropDeck12{MechName1 = "blr-1gp",MechName2="cn9-a",MechName3= "drg-5nc",MechName4 = "hbk-4p",MechName5 ="shd-2d2",MechName6="shd-2hp",MechName7="shd-2hp",MechName8="stk-3h",MechName9="tbt-7m",MechName10="tbt-3c",MechName11="tdr-5ss",MechName12="vtr-9b"};
            // DropDeck12 edd = new DropDeck12{MechName1 = "as7-d-dc",MechName2="cda-2a",MechName3= "cn9-ac",MechName4 = "cplt-a1",MechName5 = "cplt-c1-founder",MechName6 ="drg-5nc",MechName7="hbk-4g",MechName8="lct-3m",MechName9="shd-5m",MechName10="stk-3h",MechName11="tdr-5ss",MechName12="tdr-5sp" };
            //lm.MatchHash ="2013~307~as7-d-dc.cda-2a.cn9-ac.cplt-a1.cplt-c1-founder.drg-5nc.hbk-4g.lct-3m.shd-5m.stk-3h.tdr-5ss.tdr-5sp~as7-d-dc.cda-2a.cn9-ac.cplt-a1.cplt-c1-founder.drg-5nc.hbk-4g.lct-3m.shd-5m.stk-3h.tdr-5ss.tdr-5sp~alpinepeaks~4929";
            lm.PublishingUserName = "******";
            #endregion

            #region create player lists,mech lists and matchhash

            List <string> friendlyplayers = new List <string>
            {
                "DrAmnesia",
                "Mountainhigh00",
                "Cubbyman",
                "DougStevens",
                "PyAlotz",
                "Dunkelgelb",
                "Kamenitaris",
                "Kaldorn",
                "Steeles",
                "pdox",
                "Pedroig",
                "Martis Gradivus",
            };
            List <string> enemyplayers = new List <string>
            {
                "Alaric VISIGOTH",
                "Ghosthunter15",
                "Baldrika",
                "RiotHero",
                "Uriam",
                "RED DOG RAIDER",
                "avgleandt",
                "Maurox",
                "Dimuborg",
                "Tess Loren",
                "Honkhonk",
                "Obeast"
            };
            List <string> friendlymechs = new List <string>
            {
                "drg-5nc",
                "cda-2a",
                "hbk-4g",
                "cplt-c1-founder",
                "stk-3h",
                "as7-d-dc",
                "shd-5m",
                "tbt-3c",
                "tdr-5ss",
                "cplt-a1",
                "vtr-9b",
                "stk-3h"
            }.OrderBy(o => o).ToList();
            ;

            List <string> enemymechs = new List <string>
            {
                "tdr-5sp",
                "shd-2hp",
                "tbt-7m",
                "cn9-ac",
                "blr-1gp",
                "lct-3m",
                "shd-2d2",
                "drg-5nc",
                "hbk-4p",
                "shd-2hp",
                "tdr-5ss",
                "cn9-a"
            }.OrderBy(o => o).ToList();
            int    y         = System.DateTime.UtcNow.Year;
            int    d         = System.DateTime.UtcNow.DayOfYear;
            string l         = "alpinepeaks";
            int    dmg       = 24000000;
            string matchHash = String.Format("y{0}d{1}f{2}e{3}l{4}d{5}", y, d, String.Join(".", friendlymechs),
                                             String.Join(".", enemymechs), l, dmg);



            #endregion

            //set matchhash
            lm.MatchHash = matchHash;

            #region Create MatchDrop
            MatchDrop md;
            md = new MatchDrop {
                AssociationName = lm.AssociationName
            };
            // set association
            md.Association   = db.Associations.FirstOrDefault(a => a.AssociationName == lm.AssociationName);
            md.AssociationId = md.AssociationId;
            // fetch or create dropdecks using friendlymechs and enemymechs
            DropDeck12 fdd = ModelHelper.SetDropDeck(friendlymechs, db);
            DropDeck12 edd = ModelHelper.SetDropDeck(enemymechs, db);

            md.FriendlyDropDeck12Id = fdd.DropDeck12Id;
            md.EnemyDropDeck12Id    = edd.DropDeck12Id;
            md.FriendlyDropDeck12   = db.DropDeck12s.FirstOrDefault(f => f.DropDeck12Id == fdd.DropDeck12Id);
            md.EnemyDropDeck12      = db.DropDeck12s.FirstOrDefault(e => e.DropDeck12Id == edd.DropDeck12Id);
            md.MatchHash            = lm.MatchHash;
            db.MatchDrops.Add(md);
            db.SaveChanges();
            #endregion

            #region create MatchStats
            Random           rnd  = new Random();
            int              seed = rnd.Next(1, 3);
            List <MatchStat> fml  = new List <MatchStat>();
            List <MatchStat> eml  = new List <MatchStat>();
            for (int i = 0; i < 12; i++)
            {
                var fm = TestHelpers.CreateMatchStat();
                fm.name = friendlyplayers[i];
                fm.mech = friendlymechs[i];
                int fdmg     = rnd.Next(100, 400);
                int fAssists = rnd.Next(0, 8);
                fm.damage  = fdmg * seed;
                fm.assists = fAssists;
                fm.kills   = 1;
                fm.lance   = (i + 1) / 4;
                fml.Add(fm);
                var em = TestHelpers.CreateMatchStat();
                em.name    = enemyplayers[i];
                em.mech    = enemymechs[i];
                em.team    = "enemy";
                em.status  = 1;
                em.victory = 2;
                em.kills   = 0;
                int edmg = rnd.Next(10, 40);
                em.damage = edmg * seed;
                em.lance  = (i + 1) / 4;
                eml.Add(em);
            }
            #endregion

            lm.EnemyMatchStats    = eml;
            lm.FriendlyMatchStats = fml;

            #region Create MwoAMatchMetric
            foreach (MatchStat fm in lm.FriendlyMatchStats)
            {
                MWA.Models.MwoAMatchMetric matchtopush = new MWA.Models.MwoAMatchMetric();
                matchtopush.assists            = fm.assists;
                matchtopush.damage             = fm.damage;
                matchtopush.kills              = fm.kills;
                matchtopush.lance              = fm.lance;
                matchtopush.level              = fm.level;
                matchtopush.matchType          = fm.matchType;
                matchtopush.matchscore         = fm.matchscore;
                matchtopush.mech               = fm.mech;
                matchtopush.name               = fm.name;
                matchtopush.ping               = fm.ping;
                matchtopush.status             = fm.status;
                matchtopush.team               = fm.team;
                matchtopush.victory            = fm.victory;
                matchtopush.victoryType        = fm.victoryType;
                matchtopush.time               = fm.time.ToUniversalTime().ToString();
                matchtopush.MatchHash          = lm.MatchHash;
                matchtopush.PublishFlag        = 1;
                matchtopush.PublishingUserName = (lm.PublishingUserName == fm.name);
                matchtopush.MatchDrop          = db.MatchDrops.FirstOrDefault(m => m.MatchDropId == md.MatchDropId);
                db.MwoAMatchMetrics.Add(matchtopush);
                db.SaveChanges();
            }
            foreach (MatchStat em in lm.EnemyMatchStats)
            {
                MWA.Models.MwoAMatchMetric matchtopush = new MWA.Models.MwoAMatchMetric();
                matchtopush.assists            = em.assists;
                matchtopush.damage             = em.damage;
                matchtopush.kills              = em.kills;
                matchtopush.lance              = em.lance;
                matchtopush.level              = em.level;
                matchtopush.matchType          = em.matchType;
                matchtopush.matchscore         = em.matchscore;
                matchtopush.mech               = em.mech;
                matchtopush.name               = em.name;
                matchtopush.ping               = em.ping;
                matchtopush.status             = em.status;
                matchtopush.team               = em.team;
                matchtopush.victory            = em.victory;
                matchtopush.victoryType        = em.victoryType;
                matchtopush.time               = em.time.ToUniversalTime().ToString();
                matchtopush.MatchHash          = lm.MatchHash;
                matchtopush.PublishFlag        = 1;
                matchtopush.PublishingUserName = (lm.PublishingUserName == em.name);
                matchtopush.MatchDrop          = db.MatchDrops.FirstOrDefault(m => m.MatchDropId == md.MatchDropId);
                db.MwoAMatchMetrics.Add(matchtopush);
                db.SaveChanges();
            }
            #endregion

            int matches = lm.EnemyMatchStats.Count + lm.FriendlyMatchStats.Count;
            Assert.IsTrue(matches == 24);
        }
Beispiel #8
0
        // POST api/DropDeck12
        public DropDeck12 PostDropDeck12(DropDeck12 dropdeck12)
        {
            //todo update the search algorithym to use the chassis not the mechnames, for greater fidelity
            if (!ModelState.IsValid)
            {
                return(null);
            }
            // todo:    logic to match the mechlist in dropdeck12 to a drop deck
            //          try concatentating the mechnames (ordered by mechname alphabetically)
            List <Chassis> chassisList = db.Chassis.ToList();

            String[]   dropDeckMechNames = new String[] { dropdeck12.MechName1, dropdeck12.MechName2, dropdeck12.MechName3, dropdeck12.MechName4, dropdeck12.MechName5, dropdeck12.MechName6, dropdeck12.MechName7, dropdeck12.MechName8, dropdeck12.MechName9, dropdeck12.MechName10, dropdeck12.MechName11, dropdeck12.MechName12 }.OrderBy(s => s).ToArray();
            DropDeck12 ddCriteria = new DropDeck12
            {
                MechName1  = dropDeckMechNames[0],
                MechName2  = dropDeckMechNames[1],
                MechName3  = dropDeckMechNames[2],
                MechName4  = dropDeckMechNames[3],
                MechName5  = dropDeckMechNames[4],
                MechName6  = dropDeckMechNames[5],
                MechName7  = dropDeckMechNames[6],
                MechName8  = dropDeckMechNames[7],
                MechName9  = dropDeckMechNames[8],
                MechName10 = dropDeckMechNames[9],
                MechName11 = dropDeckMechNames[10],
                MechName12 = dropDeckMechNames[10],
            };

            ddCriteria.Chassis1  = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName1);
            ddCriteria.Chassis2  = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName2);
            ddCriteria.Chassis3  = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName3);
            ddCriteria.Chassis4  = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName4);
            ddCriteria.Chassis5  = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName5);
            ddCriteria.Chassis6  = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName6);
            ddCriteria.Chassis7  = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName7);
            ddCriteria.Chassis8  = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName8);
            ddCriteria.Chassis9  = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName9);
            ddCriteria.Chassis10 = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName10);
            ddCriteria.Chassis11 = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName11);
            ddCriteria.Chassis12 = chassisList.FirstOrDefault(c => c.AltName2 == ddCriteria.MechName12);

            DropDeck12 dd12 = db.DropDeck12s.FirstOrDefault(dd =>
                                                            dd.Chassis1 == ddCriteria.Chassis1 &&
                                                            dd.Chassis2 == ddCriteria.Chassis2 &&
                                                            dd.Chassis3 == ddCriteria.Chassis3 &&
                                                            dd.Chassis4 == ddCriteria.Chassis4 &&
                                                            dd.Chassis5 == ddCriteria.Chassis5 &&
                                                            dd.Chassis6 == ddCriteria.Chassis6 &&
                                                            dd.Chassis7 == ddCriteria.Chassis7 &&
                                                            dd.Chassis8 == ddCriteria.Chassis8 &&
                                                            dd.Chassis9 == ddCriteria.Chassis9 &&
                                                            dd.Chassis10 == ddCriteria.Chassis10 &&
                                                            dd.Chassis11 == ddCriteria.Chassis11 &&
                                                            dd.Chassis12 == ddCriteria.Chassis12);

            if (dd12 == null)
            {
                db.DropDeck12s.Add(ddCriteria);
                db.SaveChanges();
            }
            else
            {
                ddCriteria.DropDeck12Id = dd12.DropDeck12Id;
            }



            return(ddCriteria);
        }