Exemplo n.º 1
0
        protected override void ProcessInternal(IFlowData data)
        {
            // Create a new IStarSignData, and cast to StarSignData so the 'setter' is available.
            StarSignData starSignData = (StarSignData)data.GetOrAdd(ElementDataKey, CreateElementData);

            if (data.TryGetEvidence("date-of-birth", out DateTime dateOfBirth))
            {
                // "date-of-birth" is there, so set the star sign.
                var monthAndDay = new DateTime(1, dateOfBirth.Month, dateOfBirth.Day);
                foreach (var starSign in _starSigns)
                {
                    if (monthAndDay > starSign.Start &&
                        monthAndDay < starSign.End)
                    {
                        // The star sign has been found, so set it in the
                        // results.
                        starSignData.StarSign = starSign.Name;
                        break;
                    }
                }
            }
            else
            {
                // "date-of-birth" is not there, so set the star sign to unknown.
                starSignData.StarSign = "Unknown";
            }
        }
        protected override void ProcessEngine(IFlowData data, IStarSignData aspectData)
        {
            // Cast aspectData to AgeData so the 'setter' is available.
            StarSignData starSignData = (StarSignData)aspectData;

            if (data.TryGetEvidence("date-of-birth", out DateTime dateOfBirth))
            {
                // "date-of-birth" is there, so set the star sign.
                var monthAndDay = new DateTime(1, dateOfBirth.Month, dateOfBirth.Day);
                foreach (var starSign in _starSigns)
                {
                    if (monthAndDay > starSign.Start &&
                        monthAndDay < starSign.End)
                    {
                        // The star sign has been found, so set it in the
                        // results.
                        starSignData.StarSign = starSign.Name;
                        break;
                    }
                }
            }
            else
            {
                // "date-of-birth" is not there, so set the star sign to unknown.
                starSignData.StarSign = "Unknown";
            }
        }
Exemplo n.º 3
0
        protected override void ProcessInternal(IFlowData data)
        {
            var monthAndDay = new DateTime(1, 1, 1);

            // Create a new IStarSignData, and cast to StarSignData so the 'setter' is available.
            StarSignData starSignData = (StarSignData)data.GetOrAdd(ElementDataKey, CreateElementData);

            bool validDateOfBirth = false;

            if (data.TryGetEvidence("cookie.date-of-birth", out string dateString))
            {
                // "date-of-birth" is there, so parse it.
                string[] dateSections = dateString.Split('/');
                try
                {
                    monthAndDay = new DateTime(
                        1,
                        int.Parse(dateSections[1]),
                        int.Parse(dateSections[0]));
                    validDateOfBirth = true;
                }
                catch (Exception)
                {
                }
            }
            if (validDateOfBirth)
            {
                // "date-of-birth" is valid, so set the star sign.
                foreach (var starSign in _starSigns)
                {
                    if (monthAndDay > starSign.Start &&
                        monthAndDay < starSign.End)
                    {
                        // The star sign has been found, so set it in the
                        // results.
                        starSignData.StarSign = starSign.Name;
                        break;
                    }
                }
                // No need to run the client side code again.
                starSignData.DobJavaScript = new JavaScript("");
            }
            else
            {
                // "date-of-birth" is not there, so set the star sign to unknown.
                starSignData.StarSign = "Unknown";
                // Set the client side JavaScript to get the date of birth.
                starSignData.DobJavaScript = new JavaScript(
                    "var dob = window.prompt('Enter your date of birth.','dd/mm/yyyy');" +
                    "if (dob != null) {" +
                    "document.cookie='date-of-birth='+dob;" +
                    "location.reload();" +
                    "}");
            }
        }
Exemplo n.º 4
0
        protected override void ProcessCloudEngine(IFlowData data, IStarSignData aspectData, string json)
        {
            // Cast aspectData to StarSignData so the 'setter' is available.
            StarSignData starSignData = (StarSignData)aspectData;

            // Extract data from json to the aspectData instance.
            var dictionary = JsonConvert.DeserializeObject <Dictionary <string, object> >(json);
            // Get the results for the star sign component.
            var starSign = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            JsonConvert.PopulateObject(dictionary["starsign"].ToString(), starSign);
            // Now get the values from the star sign results.
            starSignData.StarSign = starSign["starsign"].ToString();
        }
Exemplo n.º 5
0
        protected override void ProcessEngine(IFlowData data, IStarSignData aspectData)
        {
            // Cast aspectData to StarSignData so the 'setter' is available.
            StarSignData starSignData = (StarSignData)aspectData;

            // Get the JSON response which the cloud request engine has
            // fetched from the cloud service.
            var requestData = data.Get <CloudRequestData>();
            var json        = requestData.JsonResponse;

            // Extract data from json to the aspectData instance.
            var dictionary = JsonConvert.DeserializeObject <Dictionary <string, object> >(json);
            // Get the results for the star sign component.
            var starSign = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            JsonConvert.PopulateObject(dictionary["starsign"].ToString(), starSign);
            // Now get the values from the star sign results.
            starSignData.StarSign = starSign["starsign"].ToString();
        }