Beispiel #1
0
        public ActionResult CompanyCards(string company)
        {
            string companyId = "-1";

            TCompanies companyRecord = _clashdbContext.TCompanies.Where(record => record.CompanyName == company).FirstOrDefault();

            if (companyRecord != null)
            {
                companyId = companyRecord.CompanyId;
            }

            const int arenaGameModeNumber   = 1;
            const int warzoneGameModeNumber = 4;

            List <TClashdevset> companyMatches = _clashdbContext.TClashdevset
                                                 .Where( //Arena or Warzome match, with company participation.
                (x => (x.GameMode == arenaGameModeNumber ||
                       x.GameMode == warzoneGameModeNumber) &&
                 (x.Team1Company == companyId ||
                  x.Team2Company == companyId)
                )
                ).ToList();

            int count = companyMatches.Count;

            List <ClanBattle> battles = new List <ClanBattle>(companyMatches.Count);

            List <TMapmetadata> mapMetaData  = _clashdbContext.TMapmetadata.ToList();
            List <TCompanies>   allCompanies = _clashdbContext.TCompanies.ToList();

            foreach (TClashdevset match in companyMatches)
            {
                bool isTeamGame = BitConverter.ToBoolean(match.IsTeamGame, 0);

                ClanBattle battle = new ClanBattle(company, match, _clashdbContext, mapMetaData, allCompanies);


                if (isTeamGame)
                {
                    if (_playlistBroker.isTrackedPlaylist(match.HopperId))
                    {
                        battles.Add(battle);
                    }
                }
            }

            _userBehaviorTracker.LogCompanySearch(company);

            if (battles.Count < 1)
            {
                return(View("NoCompaniesFound", company));
            }

            return(View(battles.OrderByDescending(battle => battle.isClanBattle).ThenBy(battle => battle.enemyHeader).ThenByDescending(battle => battle.matchDate)));
        }
        private void SetEnemyHeader(string enemyCompanyId, List <TCompanies> companyRoster)
        {
            if (enemyCompanyId == missingCompanyValue)
            {
                enemyHeader = printableMissingCompanyValue;
            }
            else
            {
                TCompanies companyRecord = companyRoster.Where(record => record.CompanyId == enemyCompanyId).FirstOrDefault();

                if (companyRecord != null)
                {
                    enemyHeader = companyRecord.CompanyName;
                }
                else
                {
                    enemyHeader = printableMissingCompanyValue;
                }
            }
        }
Beispiel #3
0
        public void LogCompanySearch(string companyName)
        {
            TCompanies companyRecord = null;

            if (companyName != null && companyName != "")
            {
                companyRecord = _clashdbContext.TCompanies.Where(record => record.CompanyName == companyName).FirstOrDefault();
            }

            if (companyRecord != null)
            {
                /* ------------ [Dec 8th 2017]
                 *  Choosing to leave this simple for the MVP, but this will underestimate searches duing high traffic loads because it is not thread safe.
                 *  We can rely on Google Analytics data for a sanity check on the level of underestimation.  Diff of >5% is probably worth fixing.
                 *  Consider moving to a worker queue if we decide to add more user behavior tracking or need to guarantee thread safefy.*/
                companyRecord.TimesSearched++;
                //------------

                _clashdbContext.SaveChanges();
            }
            else
            {
                try
                {
                    string webhookString = Environment.GetEnvironmentVariable("SPARTANCLASH_SLACKWEBHOOKURL");
                    var    webhookUrl    = new Uri(webhookString);

                    var slackClient = new SlackClient(webhookUrl);


                    slackClient.SendMessageAsync("Failed search for '" + companyName + "'").Wait();
                }
                catch (Exception e)
                {
                    //TODO: What kind of errors do we experience?
                    //So far...
                    //  -> Bad environment variable formatting
                    //  -> No response from slack channel
                }
            }
        }