コード例 #1
0
        protected void GetRequestStreamCallback(IAsyncResult asynchronousResult)
        {
            WebRequest webRequest = (WebRequest)asynchronousResult.AsyncState;
            Stream     postStream = webRequest.EndGetRequestStream(asynchronousResult);


            var formData = new Dictionary <string, string>();

            using (var responseSetRepository = new ResponseSetRepository())
                formData["surveyId"] = responseSetRepository.GetResponseSetForUserByID(_responseSetID).Survey.SystemID;

            Stream postDataStream = MultipartRequestFactory.GetMultipartRequestForResultUpload(formData, _boundary, _responseSetID, formData["surveyId"]);

            postDataStream.Position = 0;

            byte[] buffer    = new byte[1024];
            int    bytesRead = 0;

            while ((bytesRead = postDataStream.Read(buffer, 0, buffer.Length)) != 0)
            {
                postStream.Write(buffer, 0, bytesRead);
            }

            postDataStream.Close();
            postStream.Flush();
            postStream.Close();


            webRequest.BeginGetResponse(new AsyncCallback(SendResponseSetCallback), webRequest);
        }
コード例 #2
0
        protected void GetRequestStreamCallback(IAsyncResult asynchronousResult)
        {
            WebRequest webRequest = (WebRequest)asynchronousResult.AsyncState;
            Stream postStream = webRequest.EndGetRequestStream(asynchronousResult);


            var formData = new Dictionary<string, string>();
            using (var responseSetRepository = new ResponseSetRepository())
                formData["surveyId"] = responseSetRepository.GetResponseSetForUserByID(_responseSetID).Survey.SystemID;

            Stream postDataStream = MultipartRequestFactory.GetMultipartRequestForResultUpload(formData, _boundary, _responseSetID, formData["surveyId"]);

            postDataStream.Position = 0;

            byte[] buffer = new byte[1024];
            int bytesRead = 0;

            while ((bytesRead = postDataStream.Read(buffer, 0, buffer.Length)) != 0)
            {
                postStream.Write(buffer, 0, bytesRead);
            }

            postDataStream.Close();
            postStream.Flush();
            postStream.Close();


            webRequest.BeginGetResponse(new AsyncCallback(SendResponseSetCallback), webRequest);
        }
コード例 #3
0
        public string ParseResponseSetToRequestXml(int responseSetID)
        {
            using (var responseSetRepository = new ResponseSetRepository())
            {
                var responseSet = responseSetRepository.GetResponseSetForUserByID(responseSetID);

                XDocument resultDocument = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
                XElement root = new XElement("data", new XAttribute("id", responseSet.Survey.SystemID), new XAttribute(XNamespace.Xmlns + "orx", Namespaces.JavaRosaMetaDataNamespace));

                #region meta tag creation
                XElement meta = new XElement(Namespaces.JavaRosaMetaDataNamespace + "meta");
                root.Add(meta);
                meta.Add(new XElement(Namespaces.JavaRosaMetaDataNamespace + "instanceID")
                {
                    Value = responseSet.SystemID,

                });
                meta.Add(new XElement(Namespaces.JavaRosaMetaDataNamespace + "deviceID")
                {
                    Value = Convert.ToBase64String((byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId"))
                });
                meta.Add(new XElement(Namespaces.JavaRosaMetaDataNamespace + "timeStart")
                {
                    Value = responseSet.DateSaved.Value.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture)
                });
                meta.Add(new XElement(Namespaces.JavaRosaMetaDataNamespace + "timeEnd")
                {
                    Value = responseSet.DateModified.Value.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture)
                });
                if (GpsTracker.Instance.UserLocation != null && new SettingsRepository().GetCurrentSettings().IsGpsEnabled)
                    meta.Add(new XElement(Namespaces.JavaRosaMetaDataNamespace + "geostamp")
                    {
                        Value = string.Format("{0} {1}", GpsTracker.Instance.UserLocation.Latitude, GpsTracker.Instance.UserLocation.Longitude),
                    });
                #endregion

                foreach (var category in responseSet.Survey.Category)
                {
                    XElement categoryXElement = new XElement(category.SystemID);
                    foreach (var question in category.Question)
                    {
                        XElement questionXElement = new XElement(question.SystemID);

                        var answer = responseSetRepository.GetQuestionAnswerByQuestionAndResponseSet(question.ID, responseSetID);

                        if (answer != null)
                            questionXElement.Value = answer.AnswerText;
                        else
                            questionXElement.Value = question.Data.GetResult();

                        categoryXElement.Add(questionXElement);
                    }
                    root.Add(categoryXElement);
                }

                return root.ToString();
            }
        }
コード例 #4
0
        public ResponseSet UpdateResponseSetWithAnswers(System.Collections.Generic.IEnumerable <DataAccessModels.Category> categories, int responseSetID)
        {
            ResponseSet responseSet;

            using (var responseSetRepository = new ResponseSetRepository())
            {
                var answersToAdd = new List <Answer>();
                responseSet = responseSetRepository.GetResponseSetForUserByID(responseSetID);

                responseSet.IsCompleted  = false;
                responseSet.DateModified = DateTime.Now;
                int incompletedAnswers = 0;
                int disabledQuestions  = 0;

                foreach (var category in categories)
                {
                    foreach (var question in category.Question)
                    {
                        var answer = responseSetRepository.GetQuestionAnswerByQuestionAndResponseSet(question.ID, responseSetID);


                        incompletedAnswers++;

                        if (question.Data.Validate())
                        {
                            incompletedAnswers--;
                            if (answer != null)
                            {
                                answer.AnswerText = question.Data.GetResult();
                            }
                            else
                            {
                                answer = new DataAccessModels.Answer
                                {
                                    AnswerText    = question.Data.GetResult(),
                                    QuestionID    = question.ID,
                                    ResponseSetID = responseSetID,
                                };
                                answersToAdd.Add(answer);
                            }
                        }
                        if (!question.Data.IsEnabled)
                        {
                            disabledQuestions++;
                        }
                    }
                }

                responseSet.Progress    = Math.Ceiling((1 - ((double)incompletedAnswers / (categories.Sum(c => c.Question.Count) - disabledQuestions))) * 100);
                responseSet.IsCompleted = incompletedAnswers == 0;
                responseSetRepository.AddAnswersToResponseSet(answersToAdd, responseSetID);
            }
            return(responseSet);
        }
コード例 #5
0
        public ResponseSet UpdateResponseSetWithAnswers(System.Collections.Generic.IEnumerable<DataAccessModels.Category> categories, int responseSetID)
        {
            ResponseSet responseSet;
            using (var responseSetRepository = new ResponseSetRepository())
            {
                var answersToAdd = new List<Answer>();
                responseSet = responseSetRepository.GetResponseSetForUserByID(responseSetID);

                responseSet.IsCompleted = false;
                responseSet.DateModified = DateTime.Now;
                int incompletedAnswers = 0;
                int disabledQuestions = 0;

                foreach (var category in categories)
                    foreach (var question in category.Question)
                    {

                        var answer = responseSetRepository.GetQuestionAnswerByQuestionAndResponseSet(question.ID, responseSetID);


                        incompletedAnswers++;

                        if (question.Data.Validate())
                        {
                            incompletedAnswers--;
                            if (answer != null)
                                answer.AnswerText = question.Data.GetResult();
                            else
                            {
                                answer = new DataAccessModels.Answer
                                {
                                    AnswerText = question.Data.GetResult(),
                                    QuestionID = question.ID,
                                    ResponseSetID = responseSetID,
                                };
                                answersToAdd.Add(answer);
                            }
                        }
                        if (!question.Data.IsEnabled)
                            disabledQuestions++;
                    }

                responseSet.Progress = Math.Ceiling((1 - ((double)incompletedAnswers / (categories.Sum(c => c.Question.Count) - disabledQuestions))) * 100);
                responseSet.IsCompleted = incompletedAnswers == 0;
                responseSetRepository.AddAnswersToResponseSet(answersToAdd, responseSetID);

            }
            return responseSet;
        }
コード例 #6
0
        public string ParseResponseSetToRequestXml(int responseSetID)
        {
            using (var responseSetRepository = new ResponseSetRepository())
            {
                var responseSet = responseSetRepository.GetResponseSetForUserByID(responseSetID);

                XDocument resultDocument = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
                XElement  root           = new XElement("data", new XAttribute("id", responseSet.Survey.SystemID), new XAttribute(XNamespace.Xmlns + "orx", Namespaces.JavaRosaMetaDataNamespace));

                #region meta tag creation
                XElement meta = new XElement(Namespaces.JavaRosaMetaDataNamespace + "meta");
                root.Add(meta);
                meta.Add(new XElement(Namespaces.JavaRosaMetaDataNamespace + "instanceID")
                {
                    Value = responseSet.SystemID,
                });
                meta.Add(new XElement(Namespaces.JavaRosaMetaDataNamespace + "deviceID")
                {
                    Value = Convert.ToBase64String((byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId"))
                });
                meta.Add(new XElement(Namespaces.JavaRosaMetaDataNamespace + "timeStart")
                {
                    Value = responseSet.DateSaved.Value.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture)
                });
                meta.Add(new XElement(Namespaces.JavaRosaMetaDataNamespace + "timeEnd")
                {
                    Value = responseSet.DateModified.Value.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture)
                });
                if (GpsTracker.Instance.UserLocation != null && new SettingsRepository().GetCurrentSettings().IsGpsEnabled)
                {
                    meta.Add(new XElement(Namespaces.JavaRosaMetaDataNamespace + "geostamp")
                    {
                        Value = string.Format("{0} {1}", GpsTracker.Instance.UserLocation.Latitude, GpsTracker.Instance.UserLocation.Longitude),
                    });
                }
                #endregion

                foreach (var category in responseSet.Survey.Category)
                {
                    XElement categoryXElement = new XElement(category.SystemID);
                    foreach (var question in category.Question)
                    {
                        XElement questionXElement = new XElement(question.SystemID);

                        var answer = responseSetRepository.GetQuestionAnswerByQuestionAndResponseSet(question.ID, responseSetID);

                        if (answer != null)
                        {
                            questionXElement.Value = answer.AnswerText;
                        }
                        else
                        {
                            questionXElement.Value = question.Data.GetResult();
                        }

                        categoryXElement.Add(questionXElement);
                    }
                    root.Add(categoryXElement);
                }

                return(root.ToString());
            }
        }