Ejemplo n.º 1
0
        internal List<HOHEvent> parseSMS(SMSMessageProcess smsMessageProces)
        {
            HOHTeam team = null;
            HOHPuzzle puzzle = null;
            string teamName = "", puzzleName = "", remaining = "";
            List<HOHEvent> newEvents = new List<HOHEvent>();
            string smsBody = smsMessageProces.getMessageBody();
            smsBody = " " + smsBody.Trim().ToUpper();
            teamName = smsBody;

            do
            {
                teamName = teamName.Substring(0, teamName.LastIndexOf(" "));
                remaining = smsBody.Substring(teamName.Length);
                team = this.smsManager.dataManager.gameModel.getTeamForTeamId(teamName.Trim().ToUpper());
            } while (team == null && teamName.CompareTo("") != 0);

            if (team == null) return null;
            if (remaining.EndsWith("NAPOVEDA"))
            {
                puzzleName = remaining.Substring(0, remaining.Length - "NAPOVEDA".Length).Trim();
                puzzle = this.smsManager.dataManager.gameModel.getPuzzleForPuzzleId(puzzleName.Trim().ToUpper());
                if (puzzle == null) return null;
                HOHEvent newEvent = new HOHEvent();
                newEvent.eventType = HOHEvent.HOHEventType.HintRequestEventType;
                newEvent.SMSText = smsBody;
                newEvent.phoneNumber = smsMessageProces.getRecipientPhoneNumber();
                newEvent.dateTime = smsMessageProces.getReceivedDate();
                newEvent.team = team;
                newEvent.puzzle = puzzle;
                newEvents.Add(newEvent);
            }
            else
                if (remaining.EndsWith("PORADI"))
                {
                    HOHEvent newEvent = new HOHEvent();
                    newEvent.eventType = HOHEvent.HOHEventType.StandigsRequestType;
                    newEvent.SMSText = smsBody;
                    newEvent.phoneNumber = smsMessageProces.getRecipientPhoneNumber();
                    newEvent.dateTime = smsMessageProces.getReceivedDate();
                    newEvent.team = team;
                    newEvent.puzzle = null;
                    newEvents.Add(newEvent);
                }
            else if (remaining.EndsWith("VZDAVAME"))
            {
                HOHEvent newEvent = new HOHEvent();
                newEvent.eventType = HOHEvent.HOHEventType.GivingUpEventType;
                newEvent.SMSText = smsBody;
                newEvent.phoneNumber = smsMessageProces.getRecipientPhoneNumber();
                newEvent.dateTime = smsMessageProces.getReceivedDate();
                newEvent.team = team;
                newEvent.puzzle = null;
                newEvents.Add(newEvent);
            }
            else
                {
                    String answer = "";
                    if (remaining.LastIndexOf(puzzleIdVsSolutionSeparator) != -1)
                    do
                    {
                        int lastdelim = remaining.LastIndexOf(puzzleIdVsSolutionSeparator);
                        puzzle = null;
                        puzzleName = remaining.Substring(0, lastdelim);
                        answer = remaining.Substring(lastdelim + 1);
                        do
                        {
                            puzzleName = puzzleName.Substring(puzzleName.IndexOf(" ") + 1);
                            puzzle = this.smsManager.dataManager.gameModel.getPuzzleForPuzzleId(puzzleName.Trim().ToUpper());
                        } while (puzzle == null && puzzleName.IndexOf(" ") > -1);
                        remaining = remaining.Substring(0, lastdelim - puzzleName.Length);
                        if (puzzle != null) {
                            HOHEvent newEvent = new HOHEvent();
                            newEvent.eventType = HOHEvent.HOHEventType.SolutionEventType;
                            newEvent.SMSText = smsBody;
                            newEvent.phoneNumber = smsMessageProces.getRecipientPhoneNumber();
                            newEvent.dateTime = smsMessageProces.getReceivedDate();
                            newEvent.team = team;
                            newEvent.puzzle = puzzle;
                            newEvent.solutionText = answer.Trim().ToUpper();
                            newEvents.Add(newEvent);
                        }
                    } while (remaining.LastIndexOf(puzzleIdVsSolutionSeparator) != -1 && puzzle != null);
                    if (remaining.Trim().CompareTo("") != 0 || puzzle == null)
                        return null;
                }

            return newEvents;
        }
Ejemplo n.º 2
0
        public int importSMSFromPocketOutlook(bool liveImport)
        {
            List<string> smsTexts = new List<string>();

            foreach (HOHEvent oneEvent in this.dataManager.gameModel.events)
            {
                string item = String.Format("{0}{1}{2}", oneEvent.dateTime, oneEvent.phoneNumber.Trim(), oneEvent.SMSText.Trim());
                if (!smsTexts.Contains(item))
                    smsTexts.Add(item);
            }
            lock (smsList)
            {
                foreach (SMSMessageProcess oneSMS in this.smsList)
                {
                    string item = String.Format("{0}{1}{2}{3}", oneSMS.getReceivedDate().ToShortDateString(), oneSMS.getReceivedDate().ToShortTimeString(), oneSMS.getRecipientPhoneNumber().Trim(), oneSMS.getOriginalMessageBody().Trim()).ToUpper();
                    if (!smsTexts.Contains(item))
                        smsTexts.Add(item);
                }
            }
            lock (unparsableSmsList)
            {
                foreach (SMSMessageProcess oneSMS in this.unparsableSmsList)
                {
                    string item = String.Format("{0}{1}{2}{3}", oneSMS.getReceivedDate().ToShortDateString(), oneSMS.getReceivedDate().ToShortTimeString(), oneSMS.getRecipientPhoneNumber().Trim(), oneSMS.getOriginalMessageBody().Trim()).ToUpper();
                    if (!smsTexts.Contains(item))
                        smsTexts.Add(item);
                }
            }
            lock (dataManager.gameModel.events)
            {
                foreach (HOHEvent oneEvent in dataManager.gameModel.events)
                {
                    string item = String.Format("{0}{1}{2}{3}", oneEvent.dateTime.ToShortDateString(), oneEvent.dateTime.ToShortTimeString(), oneEvent.phoneNumber.Trim(), oneEvent.SMSText.Trim()).ToUpper();
                    if (!smsTexts.Contains(item))
                        smsTexts.Add(item);
                }
            }

            int importedSmsCount = 0;
            //TODO: Idea: to import missed SMS from Mobile Outlook up to fetchBackUpToHours back
            StringBuilder smsBlock = new StringBuilder();
            smsBlock.Capacity = 1024 * 1024;
            SaveSmsMessages(smsBlock, smsBlock.Capacity);
            string[] componentList = smsBlock.ToString().Split('`');
            int i = 1;
            while (i <= componentList.Length - 3) {
                    SMSMessageProcess smsMessage = new SMSMessageProcess(null);
                    smsMessage.live = liveImport;
                    string[] ft = componentList[i].Split(':');
                    Int64 h = Int64.Parse(ft[0]);
                    Int64 l = Int64.Parse(ft[1]);
                    long hFT2 = (((long)h) << 32) + l;

                    DateTime dt = DateTime.FromFileTimeUtc(hFT2);
                    smsMessage.setReceivedDate(dt);
            //                    smsMessage.setReceivedDate(DateTime.Now);
                    smsMessage.setRecipientPhoneNumber(componentList[i + 1]);
                    smsMessage.setMessageBody(componentList[i + 2]);

                    string item = String.Format("{0}{1}{2}{3}", smsMessage.getReceivedDate().ToShortDateString(), smsMessage.getReceivedDate().ToShortTimeString(), smsMessage.getRecipientPhoneNumber().Trim(), smsMessage.getMessageBody().Trim()).ToUpper();
                    if (!smsTexts.Contains(item)) {
                        lock (smsList)
                        {
                            int j = 0;
                            while (j < smsList.Count && smsList[j].getReceivedDate() < smsMessage.getReceivedDate())
                                j++;
                            smsList.Insert(j, smsMessage);
                        }
                        importedSmsCount++;
                    }
                    i += 3;
            }
            return importedSmsCount;
        }