Ejemplo n.º 1
0
        public PollQuestion GetActiveQuestion()
        {
            PollQuestion ret = null;

            //For real-time applications, you can get data from databases like SQL Server
            string sampleXmlString = SampleData.GetActivePollQuestion();

            XmlDocument pollQuestionXmlDoc = new XmlDocument();
            pollQuestionXmlDoc.LoadXml(sampleXmlString);

            XmlElement root = pollQuestionXmlDoc.DocumentElement;

            XmlNode activeNode = pollQuestionXmlDoc.SelectSingleNode("//PollQuestion/Active");
            if (root.Name == "PollQuestion")
            {
                ret = new PollQuestion();
                ret.ID = pollQuestionXmlDoc.SelectSingleNode("//PollQuestion/ID").InnerText;
                ret.Question = pollQuestionXmlDoc.SelectSingleNode("//PollQuestion/Question").InnerText;
                string activeStatus = pollQuestionXmlDoc.SelectSingleNode("//PollQuestion/Active").InnerText;
                ret.Active = Boolean.Parse(activeStatus);

                XmlNodeList answerChoices = pollQuestionXmlDoc.SelectNodes("//PollQuestion/AnswerGroup/Answer");
                if (answerChoices != null && answerChoices.Count > 0)
                {
                    ret.AnswerGroup = new List<string>();
                    foreach (XmlNode answer in answerChoices)
                    {
                        ret.AnswerGroup.Add(answer.InnerText);
                    }
                }
            }


            return ret;
        }
Ejemplo n.º 2
0
        public static bool ConfigurePollQuestionMonitor(PollQuestion pollQuestion)
        {
            bool ret = false;

            //Based on the design of the application, you can have unique id or name
            string pubnubChannel = pollQuestion.ID;

            mrePresenceConnect.AddOrUpdate(pubnubChannel, new ManualResetEvent(false), (key, oldState) => new ManualResetEvent(false));
            presenceChannelConnected[pubnubChannel] = false;

            pubnub.Presence<string>(pubnubChannel, PollQuestionMonitorRegularCallback, PollQuestionMonitorConfiguredCallback, PollQuestionMonitorErrorCallback);
            mrePresenceConnect[pubnubChannel].WaitOne(TimeSpan.FromSeconds(10));

            if (presenceChannelConnected[pubnubChannel])
            {
                ret = true;
            }

            return ret;
        }